Skip to content

Commit d7dbb57

Browse files
author
stanislav-web
committed
[add] tests inside docker and run before start
1 parent 6ab78d4 commit d7dbb57

18 files changed

+153
-94
lines changed

app/Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ FROM python:3.6
77

88
MAINTAINER Stanislav WEB "[email protected]"
99

10+
ARG SERVERMODE
11+
1012
COPY . /app
1113

1214
WORKDIR /app
1315

1416
# Install requirements
1517
RUN pip install -r requirements.txt
18+
RUN pip install -r requirements-dev.txt
1619
RUN chmod +x server.py
1720

18-
EXPOSE 5001
21+
EXPOSE 5000
1922

2023
# Set the default command to execute
21-
ENTRYPOINT ["/usr/local/bin/gunicorn", "--config", "./config.py", "server", "--reload"]
24+
ENTRYPOINT ["sh", "./entrypoint.sh", "$SERVERMODE"]

app/config.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
from multiprocessing import cpu_count
1212

1313
SERVER_HOST = os.getenv('SERVER_HOST', '0.0.0.0')
14-
SERVER_PORT = int(os.getenv('SERVER_PORT', '5001'))
15-
APPLICATION = os.getenv('APPLICATION', 'PyRuc:DEVELOPMENT')
16-
17-
print('\033[32m'+"{app}".format(app=APPLICATION))
14+
SERVER_PORT = int(os.getenv('SERVER_PORT', '5000'))
1815

1916
#
2017
# Server socket

app/entrypoint.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
APPLICATION="${APPLICATION}"
4+
printf '\033[32m%s\n' "${APPLICATION}"
5+
6+
if [ $@ == '--reload' ]
7+
then
8+
/usr/local/bin/gunicorn --config ./config.py server "$@"
9+
else
10+
/usr/local/bin/coverage run setup.py test
11+
/usr/local/bin/coverage report
12+
/usr/local/bin/gunicorn --config ./config.py server
13+
fi

app/env/development.env

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Application
2+
13
APPLICATION=PyRuc:DEVELOPMENT
24
APPLICATION_LOG_LEVEL=20
35
APPLICATION_REG_CODE_TTL=3600
@@ -8,28 +10,43 @@ APPLICATION_LIMIT_AUTH=100000 per day
810
APPLICATION_LIMIT_RESTORE=100000 per day
911
APPLICATION_LIMIT_PER_SEC=500000 per second
1012
APPLICATION_LIMIT_PER_MIN=5000000 per minute
11-
APPLICATION_LIMIT_STORAGE_URI=redis://d70e25e734dedbd1ca52fe81459b23af88f82819d06a823e07a79a86955e8ac8@redis:6379
13+
APPLICATION_LIMIT_STORAGE_URI=redis://redis_db:6379
14+
15+
# Authentication
1216

1317
JWT_TOKEN_EXP_DELTA_SECONDS=60
1418
JWT_TOKEN_SECRET=secret
1519
JWT_TOKEN_ALGORITHM=HS256
1620

21+
# Server
22+
1723
SERVER_PROTOCOL=http://
1824
SERVER_HOST=0.0.0.0
19-
SERVER_PORT=5001
25+
SERVER_PORT=5000
26+
27+
# Users storage
2028

21-
REDIS_HOST=redis
29+
REDIS_HOST=redis_db
2230
REDIS_PORT=6379
2331
REDIS_DBNO=2
24-
REDIS_PASSWORD=d70e25e734dedbd1ca52fe81459b23af88f82819d06a823e07a79a86955e8ac8
32+
REDIS_PASSWORD=
2533
REDIS_SOCKET_TIMEOUT=10
2634
REDIS_SOCKET_CONNECT_TIMEOUT=3
2735
REDIS_MAX_CONNECTIONS=3
2836

37+
# Sms notifier
38+
2939
TWILIO_ACCOUNT_SID=ACfba6742794f57556d26f2362be925e03
3040
TWILIO_AUTH_TOKEN=5591456e24738c0c45277d1326c58f20
3141
TWILIO_SEND_FROM=+15005550006
3242

43+
# Logs server
44+
3345
LOGSTASH_NODENAME=pyruс
3446
LOGSTASH_PORT=6000
35-
LOGSTASH_HOST=127.0.0.1
47+
LOGSTASH_HOST=127.0.0.1
48+
49+
# Test params
50+
51+
TEST_PHONE_NO=15005550006
52+
TEST_EXPECTED_CTYPE=application/json

app/env/production.env

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Application
2+
13
APPLICATION=PyRuc:PRODUCTION
24
APPLICATION_LOG_LEVEL=50
35
APPLICATION_REG_CODE_TTL=300
@@ -8,28 +10,43 @@ APPLICATION_LIMIT_AUTH=3000 per hour
810
APPLICATION_LIMIT_RESTORE=6 per hour
911
APPLICATION_LIMIT_PER_SEC=1 per second
1012
APPLICATION_LIMIT_PER_MIN=10000 per minute
11-
APPLICATION_LIMIT_STORAGE_URI=redis://d70e25e734dedbd1ca52fe81459b23af88f82819d06a823e07a79a86955e8ac8@redis:6379
13+
APPLICATION_LIMIT_STORAGE_URI=redis://d70e25e734dedbd1ca52fe81459b23af88f82819d06a823e07a79a86955e8ac8@redis_db:6379
14+
15+
# Authentication
1216

1317
JWT_TOKEN_EXP_DELTA_SECONDS=604800
1418
JWT_TOKEN_SECRET=GNmcG5ddDvwjKqTaCcsfpW
1519
JWT_TOKEN_ALGORITHM=HS256
1620

21+
# Server
22+
1723
SERVER_PROTOCOL=http://
1824
SERVER_HOST=0.0.0.0
19-
SERVER_PORT=5001
25+
SERVER_PORT=5000
2026

21-
REDIS_HOST=redis
27+
# Users storage
28+
29+
REDIS_HOST=redis_db
2230
REDIS_PORT=6379
23-
REDIS_PASSWORD=d70e25e734dedbd1ca52fe81459b23af88f82819d06a823e07a79a86955e8ac8
2431
REDIS_DBNO=1
32+
REDIS_PASSWORD=d70e25e734dedbd1ca52fe81459b23af88f82819d06a823e07a79a86955e8ac8
2533
REDIS_SOCKET_TIMEOUT=10
2634
REDIS_SOCKET_CONNECT_TIMEOUT=3
2735
REDIS_MAX_CONNECTIONS=3
2836

37+
# Sms notifier
38+
2939
TWILIO_ACCOUNT_SID=ACa988afd5f42c8a4a9b21ddbc2f77b915
3040
TWILIO_AUTH_TOKEN=85d1cd8958c709634941caa2d3d7bb87
3141
TWILIO_SEND_FROM=+15005550006
3242

43+
# Logs server
44+
3345
LOGSTASH_NODENAME=pyruс
3446
LOGSTASH_PORT=6000
35-
LOGSTASH_HOST=127.0.0.1
47+
LOGSTASH_HOST=127.0.0.1
48+
49+
# Test params
50+
51+
TEST_PHONE_NO=15005550006
52+
TEST_EXPECTED_CTYPE=application/json

app/requirements-dev.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
coverage==4.4.1
22
coveralls==1.2.0
3-
unittest2py3k==0.5.1
4-
python-dotenv==0.7.1
3+
unittest2py3k==0.5.1

app/setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
from setuptools import setup, find_packages
1212

1313
VERSION = '1.0.0'
14-
LONG_DESCRIPTION = open('../README.md').read()
14+
try:
15+
LONG_DESCRIPTION = open('../README.md').read()
16+
except FileNotFoundError:
17+
LONG_DESCRIPTION = 'Docker build images in progress...'
1518

1619
setup(name='PyRuc',
1720

app/src/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
APPLICATION_LIMIT_RESTORE = os.getenv('APPLICATION_LIMIT_RESTORE', '100000 per day')
1717
APPLICATION_LIMIT_PER_SEC = os.getenv('APPLICATION_LIMIT_PER_SEC', '100000 per second')
1818
APPLICATION_LIMIT_PER_MIN = os.getenv('APPLICATION_LIMIT_PER_MIN', '100000 per minute')
19-
APPLICATION_LIMIT_STORAGE_URI = os.getenv('APPLICATION_LIMIT_STORAGE_URI', 'redis://127.0.0.1:6379')
19+
APPLICATION_LIMIT_STORAGE_URI = os.getenv('APPLICATION_LIMIT_STORAGE_URI', 'redis://redis_db:6379')
2020
LOGSTASH_HOST = os.getenv('LOGSTASH_HOST', '127.0.0.1')
2121
LOGSTASH_PORT = os.getenv('LOGSTASH_PORT', 6000)

app/tests/.env

Lines changed: 0 additions & 40 deletions
This file was deleted.

app/tests/test_authentication.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,10 @@
1313
import sys
1414

1515
from http import HTTPStatus
16-
from dotenv import load_dotenv
1716
from src import application
1817
from src.modules.mod_authentication.services.db.redis import RedisRepository
1918

2019

21-
dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
22-
load_dotenv(dotenv_path, verbose=True)
23-
24-
2520
class DevNull(object):
2621
def write(self, data):
2722
pass

0 commit comments

Comments
 (0)