Compare commits
8 Commits
4e66533cbc
...
master
Author | SHA1 | Date | |
---|---|---|---|
c61e97a761 | |||
0b2cfbd760 | |||
35cce46eed | |||
4b264b22fd | |||
89522c0536 | |||
f5d293c11b | |||
858e18362f | |||
b226256187 |
2
.coveragerc
Normal file
2
.coveragerc
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
[run]
|
||||||
|
omit=venv/*
|
19
.drone.yml
19
.drone.yml
@ -28,6 +28,25 @@ steps:
|
|||||||
- find . -name "*.py" -exec python3 -m mccabe --min 3 '{}' + || if [ $? -eq 1 ]; then echo "you fail"; fi
|
- find . -name "*.py" -exec python3 -m mccabe --min 3 '{}' + || if [ $? -eq 1 ]; then echo "you fail"; fi
|
||||||
- bandit -r . + || if [ $? -eq 1 ]; then echo "you fail"; fi
|
- bandit -r . + || if [ $? -eq 1 ]; then echo "you fail"; fi
|
||||||
|
|
||||||
|
- name: unit_test
|
||||||
|
image: python:3.8
|
||||||
|
environment:
|
||||||
|
PRODUCER_REDIS: cache
|
||||||
|
commands:
|
||||||
|
- pip3 install --cache-dir='./.pipcache' -r requirements.txt
|
||||||
|
- pip3 install --cache-dir='./.pipcache' -r requirements_dev.txt
|
||||||
|
- pytest
|
||||||
|
|
||||||
|
- name: coverage
|
||||||
|
image: python:3.8
|
||||||
|
environment:
|
||||||
|
PRODUCER_REDIS: cache
|
||||||
|
commands:
|
||||||
|
- pip3 install --cache-dir='./.pipcache' -r requirements.txt
|
||||||
|
- pip3 install --cache-dir='./.pipcache' -r requirements_dev.txt
|
||||||
|
- coverage run -m pytest
|
||||||
|
- coverage report -m
|
||||||
|
|
||||||
- name: build-app
|
- name: build-app
|
||||||
image: banzaicloud/drone-kaniko
|
image: banzaicloud/drone-kaniko
|
||||||
settings:
|
settings:
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
# Setup environment variables for testing
|
# Setup environment variables for testing
|
||||||
os.environ["INITIAL_SERVERS"] = "192.168.111.22"
|
|
||||||
os.environ["LOCAL_UUID"] = "d8b2e5e2-f675-4194-9324-af58e4b70c54"
|
os.environ["LOCAL_UUID"] = "d8b2e5e2-f675-4194-9324-af58e4b70c54"
|
||||||
os.environ["REDIS_URL"] = "redis://192.168.111.121/0"
|
os.environ["REDIS_URL"] = "redis://192.168.111.121/0"
|
||||||
|
@ -1,21 +1,22 @@
|
|||||||
import json
|
import db
|
||||||
import os
|
|
||||||
import pytest
|
import pytest
|
||||||
from flask import current_app
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def client():
|
def client(mocker):
|
||||||
current_app.config['TESTING'] = True
|
mocker.patch("db.redis_client")
|
||||||
|
db.redis_client.get.side_effect=lambda a: None
|
||||||
|
|
||||||
with current_app.test_client() as client:
|
from app import app
|
||||||
|
|
||||||
|
app.config['TESTING'] = True
|
||||||
|
|
||||||
|
with app.test_client() as client:
|
||||||
yield client
|
yield client
|
||||||
|
|
||||||
|
|
||||||
def test_response_length(client):
|
def test_response_length(client):
|
||||||
data = {
|
r = client.get('/consumers')
|
||||||
"uuid": os.environ["LOCAL_UUID"],
|
|
||||||
"message": "Hello There!"
|
assert r.status_code == 200
|
||||||
}
|
|
||||||
r = client.get('/consumers', data = json.dumps(data))
|
|
||||||
assert len(r) == 0
|
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
import json
|
import db
|
||||||
import os
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from flask import current_app
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def client():
|
def client(mocker):
|
||||||
current_app.config['TESTING'] = True
|
mocker.patch("db.redis_client")
|
||||||
|
db.redis_client.get.side_effect=lambda a: None
|
||||||
|
|
||||||
with current_app.test_client() as client:
|
from app import app
|
||||||
|
|
||||||
|
app.config['TESTING'] = True
|
||||||
|
|
||||||
|
with app.test_client() as client:
|
||||||
yield client
|
yield client
|
||||||
|
|
||||||
|
|
||||||
@ -22,9 +22,9 @@ def test_log_code_get(client):
|
|||||||
|
|
||||||
def test_log_code_post(client):
|
def test_log_code_post(client):
|
||||||
data = {
|
data = {
|
||||||
"uuid": os.environ["LOCAL_UUID"],
|
"uuid": "asdasdasd",
|
||||||
"message": "Hello There!"
|
"message": "Hello There!"
|
||||||
}
|
}
|
||||||
r = client.post('/log', data = json.dumps(data))
|
r = client.post('/log', json=data)
|
||||||
|
|
||||||
assert r.status_code == 204
|
assert r.status_code == 204
|
||||||
|
@ -1,19 +1,20 @@
|
|||||||
import json
|
import db
|
||||||
import os
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from flask import current_app
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def client():
|
def client(mocker):
|
||||||
current_app.config['TESTING'] = True
|
mocker.patch("db.redis_client")
|
||||||
|
db.redis_client.get.side_effect=lambda a: None
|
||||||
|
|
||||||
with current_app.test_client() as client:
|
from app import app
|
||||||
|
|
||||||
|
app.config['TESTING'] = True
|
||||||
|
|
||||||
|
with app.test_client() as client:
|
||||||
yield client
|
yield client
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_log_code_get(client):
|
def test_log_code_get(client):
|
||||||
r = client.get('/sync')
|
r = client.get('/sync')
|
||||||
|
|
||||||
@ -22,8 +23,8 @@ def test_log_code_get(client):
|
|||||||
|
|
||||||
def test_log_code_post(client):
|
def test_log_code_post(client):
|
||||||
data = {
|
data = {
|
||||||
"uuid": os.environ["LOCAL_UUID"]
|
"uuid": "tesuuid"
|
||||||
}
|
}
|
||||||
r = client.post('/sync', data = json.dumps(data))
|
r = client.post('/sync', json=data)
|
||||||
|
|
||||||
assert r.status_code == 204
|
assert r.status_code == 200
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from db import redis_client
|
from db import redis_client
|
||||||
from flask import jsonify, request
|
from flask import jsonify
|
||||||
from flask_classful import FlaskView
|
from flask_classful import FlaskView
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,7 +9,15 @@ class SyncView(FlaskView):
|
|||||||
|
|
||||||
def post(self):
|
def post(self):
|
||||||
remote_uuid = request.json['uuid']
|
remote_uuid = request.json['uuid']
|
||||||
remote_ip = request.remote_addr
|
|
||||||
|
if 'ip' in request.json:
|
||||||
|
remote_ip = request.json['ip']
|
||||||
|
|
||||||
|
if request.remote_addr != remote_ip:
|
||||||
|
current_app.logger.debug(f"IP was overriden by the remote consumer {remote_ip} instead of {request.remote_addr}")
|
||||||
|
|
||||||
|
else:
|
||||||
|
remote_ip = request.remote_addr
|
||||||
|
|
||||||
cust_key = f"consumer_{remote_uuid}"
|
cust_key = f"consumer_{remote_uuid}"
|
||||||
|
|
||||||
|
4
requirements_dev.txt
Normal file
4
requirements_dev.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
pytest
|
||||||
|
pytest-mock
|
||||||
|
mock
|
||||||
|
coverage
|
Reference in New Issue
Block a user