sg-test-env 0.0.1
This is the SG_Test_Env Project

# Python test Environment

@Swissglider  
## short description

This image creates the base image for the Pythontest Environment
Class SGPytest for run tests against Source Code and runs unittest
## how to install (only this makes sense ;-))

- the Project to test (with setup.py etc..) are in: `~/developer/project1`
```sh
docker run -d --name sg_test_env -e TZ=Europe/Zurich -p 80:8888 -v ~/developer/project1:/data -w /app swissglider/sg_test_env:latest
docker exec -it sg_test_env tail -f /tmp/uwsgi.log
docker exec -it sg_test_env bash
```
## For other reasons (debugging / logs)

#### From Docker Hub
```sh
docker run -it --rm -p 80:8888 -e TZ=Europe/Zurich -w /app swissglider/sg_test_env:latest /start.sh

# or

docker run -d --name sg_test_env -p 80:8888 -e TZ=Europe/Zurich -w /app swissglider/sg_test_env:latest
docker exec -it sg_test_env bash
docker exec -it sg_test_env tail -f /tmp/uwsgi.log
```
#### From Github

```sh
docker build -t sg_test_env_i https://raw.githubusercontent.com/swissglider/SG_Test_Env/master/Dockerfile
docker -it --rm -p 80:8888 -e TZ=Europe/Zurich sg_test_env_i /start.sh

# or

docker build -t sg_test_env_i https://raw.githubusercontent.com/swissglider/SG_Test_Env/master/Dockerfile
docker run -d --name sg_test_env -p 80:8888 -e TZ=Europe/Zurich -w /app sg_test_env_i
docker exec -it sg_test_env bash
docker exec -it sg_test_env tail -f /tmp/uwsgi.log
```
#### From Dockerfile
```sh
docker build -t sg_test_env_i -f Dockerfile .
docker -it --rm -p 80:8888 -e TZ=Europe/Zurich sg_test_env_i /start.sh
docker -it --rm -p 80:8888 -e TZ=Europe/Zurich sg_test_env_i bash

# or

docker build -t sg_test_env_i -f Dockerfile .
docker run -d --name sg_test_env -p 80:8888 -e TZ=Europe/Zurich -w /app sg_test_env_i
docker exec -it sg_test_env bash
docker exec -it sg_test_env tail -f /tmp/uwsgi.log
```
#### For debugging flask
```sh
docker run -d --name sg_test_env -e TZ=Europe/Zurich -p 8888:8888 -v ~/developer/SG_Test_Env:/data -e FLASK_APP=main.py -e FLASK_DEBUG=1 swissglider/sg_test_env:latest bash -c "while true ; do sleep 10 ; done"
docker exec -it sg_test_env bash
flask run --host=0.0.0.0 --port=8888


docker run -it --rm -e TZ=Europe/Zurich -p 80:80 -v ~/developer/SG_Test_Env/:/app -w /app swissglider/sg_test_env:test sh install_script/sg_flask.sh
docker run -it --rm -e TZ=Europe/Zurich -p 80:80 -v ~/developer/SG_Test_Env/:/app -w /app swissglider/sg_test_env:test sh install_script/sg_clean.sh

```
## Install it for test in test docker python

```sh
docker run -it --rm --name sg_test_env -e TZ=Europe/Zurich -p 80:80 -v ~/developer/SG_Test_Env:/data -v ~/developer/SG_Test_Env:/app -w /data python:3.6.6 sh sg_flask.sh

docker run -it --rm --name sg_test_env -e TZ=Europe/Zurich -p 80:80 -v ~/developer/SG_Test_Env:/data -v ~/developer/SG_Test_Env -w /data python:3.6.6 bash

# Clean environment:
sh ./install_script/sg_clean.ch

# Test Pytest standalone - 1:
 pytest testing src --html=/data/src/sg_pytest/webapp/static/test.html --cov=src --cov-report=html:/data/src/sg_pytest/webapp/static/cov

# Test Pytest standalone - 2:
docker run -it --rm --name sg_test_env -e TZ=Europe/Zurich -p 80:80 -v ~/developer/SG_Test_Env:/data -v ~/developer/SG_Test_Env:/app -w /data python bash
pip install pytest
pip install pytest-cov
pip install pytest-html
pip install -e .
pytest --html=src/sg_pytest/webapp/static/test.html --cov --cov-report=html:src/sg_pytest/webapp/static/cov/ -s -vv

# Test setup.py test standalone - 3:
docker run -it --rm --name sg_test_env -e TZ=Europe/Zurich -p 80:80 -v ~/developer/SG_Test_Env:/data -v ~/developer/SG_Test_Env:/app -w /data python:3.6.5 bash
python setup.py test
sh sg_clean.sh


docker run -it --rm --name sg_test_env -e TZ=Europe/Zurich -v ~/developer/SG_Test_Env:/app -w /app python:3.6.5 bash
python setup.py test
sh ./install_script sg_clean.sh
```
## SG_Test_Env Tests
```sh
# standalone
docker run -it --rm -e TZ=Europe/Zurich -w /app swissglider/sg_test_env:test python setup.py test

# with own app (wiht setup.py and tests etc)
docker run -it --rm -e TZ=Europe/Zurich -v ~/developer/SG_Test_Env:/app -w /app swissglider/sg_test_env:test bash
python setup.py test

# with access to static dir to get html output
docker run -it --rm -e TZ=Europe/Zurich -v ~/developer/static:/static -w /app swissglider/sg_test_env:test bash
python setup.py test

# with own test data 
docker run -it --rm -e TZ=Europe/Zurich -v ~/developer/test_data:/data -w /app swissglider/sg_test_env:test bash
python setup.py test
```
## Directory architecture - Volumes

- code
  - setup.py
  - setup.cfg
  - README.md
  - plugin_packages.txt
  - requirements.txt
  - sg_pytest.ini
  - test_requirements.txt
  - src (source Directory)
  - test (test files)

- tmp_home
  - .pypirc
#### samples see 
- https://github.com/swissglider/SG_Test_Env
- https://github.com/swissglider/SG_Test_Env/tree/master/testing/data


## How to use it test framework

## How to build

[see howto Github build pypi](https://www.codementor.io/arpitbhayani/host-your-python-package-using-github-on-pypi-du107t7ku)

### .pypirc

```cfg
[distutils]
index-servers =
  pypi
  pypitest

[pypi]
repository: https://pypi.python.org/pypi
username: YOUR_USERNAME_HERE
password: YOUR_PASSWORD_HERE

[pypitest]
repository: https://testpypi.python.org/pypi
username: YOUR_USERNAME_HERE
password: YOUR_PASSWORD_HERE
```

## Open

- make pypi
- clean in web gui