Compare commits

..

12 Commits

Author SHA1 Message Date
92ec26e2b8 fix coverage
All checks were successful
continuous-integration/drone/push Build is passing
2020-05-14 21:24:08 +02:00
6509049309 coverage
Some checks failed
continuous-integration/drone/push Build is failing
2020-05-14 21:22:41 +02:00
35bd1245c9 Update 'README.rst'
All checks were successful
continuous-integration/drone/push Build is passing
2020-05-14 13:45:31 +02:00
3b4bd7322e Update 'README.rst'
All checks were successful
continuous-integration/drone/push Build is passing
2020-05-14 13:44:39 +02:00
3b8b05c3c4 Update 'README.rst'
All checks were successful
continuous-integration/drone/push Build is passing
2020-05-14 13:44:16 +02:00
573cff2c4c Update 'README.md'
All checks were successful
continuous-integration/drone/push Build is passing
2020-05-14 13:35:36 +02:00
d4a2e7c272 Merge pull request 'dev-testing' (#2) from dev-testing into master
All checks were successful
continuous-integration/drone/push Build is passing
2020-05-08 22:24:57 +02:00
beaff9f62b fix my mistake
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2020-05-08 22:20:34 +02:00
b282b6a373 play with ci 2020-05-08 22:19:21 +02:00
644c2df888 unit test endpoint
All checks were successful
continuous-integration/drone/push Build is passing
2020-05-08 22:17:09 +02:00
e395915bf1 Merge pull request 'add cache' (#1) from dev-ci into master
All checks were successful
continuous-integration/drone/push Build is passing
2020-05-08 19:56:21 +02:00
07d14e013d add cache
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2020-05-08 19:49:13 +02:00
9 changed files with 145 additions and 8 deletions

View File

@ -3,16 +3,63 @@ type: docker
name: default name: default
steps: steps:
- name: restore-cache-with-filesystem
image: meltwater/drone-cache
settings:
backend: "filesystem"
restore: true
cache_key: "{{ .Repo.Name }}"
archive_format: "gzip"
filesystem_cache_root: "/tmp/cache"
mount:
- '.pipcache'
volumes:
- name: cache
path: /tmp/cache
- name: static_analysis - name: static_analysis
image: python:3.8 image: python:3.8
commands: commands:
- pip3 install pylint bandit mccabe - pip3 install --cache-dir='./.pipcache' pylint bandit mccabe
- pip3 install -r requirements.txt - pip3 install --cache-dir='./.pipcache' -r requirements.txt
- find . -name "*.py" -exec python3 -m py_compile '{}' \; - find . -name "*.py" -exec python3 -m py_compile '{}' \;
- find . -name "*.py" -exec pylint '{}' + || if [ $? -eq 1 ]; then echo "you fail"; fi - find . -name "*.py" -exec pylint '{}' + || 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 - 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: coverage
image: python:3.8
environment:
REDIS_URL: "redis://cache"
commands:
- pip3 install --cache-dir='./.pipcache' -r requirements.txt
- pip3 install --cache-dir='./.pipcache' coverage pytest
- coverage run -m pytest test.py
- coverage report -m
- name: rebuild-cache-with-filesystem
image: meltwater/drone-cache
pull: true
settings:
backend: "filesystem"
rebuild: true
cache_key: "{{ .Repo.Name }}"
archive_format: "gzip"
filesystem_cache_root: "/tmp/cache"
mount:
- '.pipcache'
volumes:
- name: cache
path: /tmp/cache
- name: build-app - name: build-app
image: banzaicloud/drone-kaniko image: banzaicloud/drone-kaniko
settings: settings:
@ -35,3 +82,12 @@ steps:
icon_url: https://cloudcdn.tormakristof.eu/static/drone.svg icon_url: https://cloudcdn.tormakristof.eu/static/drone.svg
when: when:
status: [ failure ] status: [ failure ]
services:
- name: cache
image: redis
volumes:
- name: cache
host:
path: "/tmp/cache"

View File

@ -1,2 +0,0 @@
# producer-endpoint

6
README.rst Normal file
View File

@ -0,0 +1,6 @@
=================
Producer endpoint
=================
Manages IP changes of consumers. If a consumer sends a message to /ip endpoint, it will write the gotten IP address into the redis DB.
Produced by GoldenPogácsa Inc.

6
curl-test.sh Normal file
View File

@ -0,0 +1,6 @@
#!/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

11
docker-compose.yml Normal file
View File

@ -0,0 +1,11 @@
version: '3'
networks:
redis:
external: false
services:
redis:
image: redis
ports:
- 6969:6379

View File

@ -1,6 +1,6 @@
import json import json
from redisclient import redis_client from redisclient import redis_client
from flask import jsonify, request, Response from flask import request, Response
from flask_classful import FlaskView from flask_classful import FlaskView
@ -14,4 +14,4 @@ class IPEndpoint(FlaskView):
strconsumer = json.dumps(consumer).encode('utf-8') strconsumer = json.dumps(consumer).encode('utf-8')
redis_client.set('currentConsumer', strconsumer) redis_client.set('currentConsumer', strconsumer)
return Response(status=204) return Response(status=204)

View File

@ -1,3 +1,3 @@
from flask_redis import FlaskRedis from flask_redis import FlaskRedis
redis_client = FlaskRedis() redis_client = FlaskRedis()

View File

@ -1,5 +1,9 @@
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 Normal file
View File

@ -0,0 +1,56 @@
#!/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