Compare commits
No commits in common. "d4a2e7c2721d714994bc643a8cf17aa3c97ab678" and "e395915bf173450201267d1e43af74a755552b8a" have entirely different histories.
d4a2e7c272
...
e395915bf1
16
.drone.yml
16
.drone.yml
@ -27,15 +27,6 @@ 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:
|
|
||||||
REDIS_URL: "redis://cache"
|
|
||||||
commands:
|
|
||||||
- pip3 install --cache-dir='./.pipcache' -r requirements.txt
|
|
||||||
- pytest test.py
|
|
||||||
|
|
||||||
|
|
||||||
- name: rebuild-cache-with-filesystem
|
- name: rebuild-cache-with-filesystem
|
||||||
image: meltwater/drone-cache
|
image: meltwater/drone-cache
|
||||||
pull: true
|
pull: true
|
||||||
@ -74,11 +65,6 @@ steps:
|
|||||||
when:
|
when:
|
||||||
status: [ failure ]
|
status: [ failure ]
|
||||||
|
|
||||||
services:
|
|
||||||
- name: cache
|
|
||||||
image: redis
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
- name: cache
|
- name: cache
|
||||||
host:
|
temp: {}
|
||||||
path: "/tmp/cache"
|
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
curl --header "Content-Type: application/json" \
|
|
||||||
--request POST \
|
|
||||||
--data '{"uuid":"c959ad81-58f9-4445-aab4-8f3d68aee1ad", "ip":"127.1.2.3"}' \
|
|
||||||
http://localhost:5000/ip
|
|
@ -1,11 +0,0 @@
|
|||||||
version: '3'
|
|
||||||
|
|
||||||
networks:
|
|
||||||
redis:
|
|
||||||
external: false
|
|
||||||
|
|
||||||
services:
|
|
||||||
redis:
|
|
||||||
image: redis
|
|
||||||
ports:
|
|
||||||
- 6969:6379
|
|
@ -1,6 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
from redisclient import redis_client
|
from redisclient import redis_client
|
||||||
from flask import request, Response
|
from flask import jsonify, request, Response
|
||||||
from flask_classful import FlaskView
|
from flask_classful import FlaskView
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
flask
|
flask
|
||||||
flask-classful
|
flask-classful
|
||||||
redis
|
|
||||||
flask-redis
|
flask-redis
|
||||||
gunicorn
|
gunicorn
|
||||||
sentry-sdk[flask]
|
sentry-sdk[flask]
|
||||||
pytest
|
|
||||||
pytest-flask
|
|
||||||
pytest-redis
|
|
56
test.py
56
test.py
@ -1,56 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
"""
|
|
||||||
Unit tests for the producer-endpoint module.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
|
||||||
import json
|
|
||||||
import pytest
|
|
||||||
import redis
|
|
||||||
from pytest_redis import factories
|
|
||||||
import app
|
|
||||||
|
|
||||||
|
|
||||||
generateduuid = 'c959ad81-58f9-4445-aab4-8f3d68aee1ad'
|
|
||||||
redis_proc = factories.redis_proc(host='cache', port=6379)
|
|
||||||
redis_db = factories.redisdb('redis_nooproc')
|
|
||||||
redstuff = redis.Redis.from_url(url=os.environ['REDIS_URL'])
|
|
||||||
redstuff.set('currentConsumer', json.dumps({'uuid': generateduuid, 'Host': "127.2.2.2"}).encode('utf-8'))
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def client():
|
|
||||||
"""Client fixture"""
|
|
||||||
with app.app.test_client() as client:
|
|
||||||
yield client
|
|
||||||
|
|
||||||
|
|
||||||
def test_set_currentconsumer_success(client):
|
|
||||||
|
|
||||||
r = client.post("/ip", json={'uuid': generateduuid, 'ip': "127.1.2.3"})
|
|
||||||
|
|
||||||
json_in_redis = json.loads(redstuff.get('currentConsumer'))
|
|
||||||
|
|
||||||
assert r.status_code == 204
|
|
||||||
assert json_in_redis == {'uuid': generateduuid, 'Host': "127.1.2.3"}
|
|
||||||
|
|
||||||
|
|
||||||
def test_set_currentconsumer_server_error(client):
|
|
||||||
|
|
||||||
r = client.post("/ip", json="unexpected")
|
|
||||||
|
|
||||||
assert r.status_code == 500
|
|
||||||
|
|
||||||
|
|
||||||
def test_set_currentconsumer_notfound(client):
|
|
||||||
|
|
||||||
r = client.post("/test")
|
|
||||||
|
|
||||||
assert r.status_code == 404
|
|
||||||
|
|
||||||
|
|
||||||
def test_set_currentconsumer_method_not_allowed(client):
|
|
||||||
|
|
||||||
r = client.get("/ip")
|
|
||||||
|
|
||||||
assert r.status_code == 405
|
|
Reference in New Issue
Block a user