Compare commits
2 Commits
4e66533cbc
...
dev-unitte
Author | SHA1 | Date | |
---|---|---|---|
858e18362f | |||
b226256187 |
2
.coveragerc
Normal file
2
.coveragerc
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
[run]
|
||||||
|
omit=venv/*
|
71
.drone.yml
71
.drone.yml
@ -3,68 +3,17 @@ 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
|
image: python:3
|
||||||
commands:
|
commands:
|
||||||
- pip3 install --cache-dir='./.pipcache' pylint bandit mccabe
|
- pip3 install pylint bandit mccabe
|
||||||
- pip3 install --cache-dir='./.pipcache' -r requirements.txt
|
- pip3 install -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: build-app
|
- name: build
|
||||||
image: banzaicloud/drone-kaniko
|
|
||||||
settings:
|
|
||||||
registry: registry.kmlabz.com
|
|
||||||
repo: goldenpogacsa/${DRONE_REPO_NAME}
|
|
||||||
username:
|
|
||||||
from_secret: DOCKER_USERNAME
|
|
||||||
password:
|
|
||||||
from_secret: DOCKER_PASSWORD
|
|
||||||
tags:
|
|
||||||
- latest
|
|
||||||
- ${DRONE_BUILD_NUMBER}
|
|
||||||
|
|
||||||
- name: make_docs
|
|
||||||
image: python:3.8
|
|
||||||
commands:
|
|
||||||
- pip3 install --cache-dir='./.pipcache' Sphinx sphinx_rtd_theme
|
|
||||||
- pip3 install -r requirements.txt
|
|
||||||
- cd docs
|
|
||||||
- make html
|
|
||||||
|
|
||||||
- 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_docs
|
|
||||||
image: docker:stable-dind
|
image: docker:stable-dind
|
||||||
volumes:
|
volumes:
|
||||||
- name: dockersock
|
- name: dockersock
|
||||||
@ -75,12 +24,11 @@ steps:
|
|||||||
DOCKER_PASSWORD:
|
DOCKER_PASSWORD:
|
||||||
from_secret: DOCKER_PASSWORD
|
from_secret: DOCKER_PASSWORD
|
||||||
commands:
|
commands:
|
||||||
- cd docs
|
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
|
||||||
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin registry.kmlabz.com
|
- docker build -t="$DOCKER_USERNAME/consumer_api" .
|
||||||
- docker build -t="registry.kmlabz.com/goldenpogacsa/consumer-api-docs" .
|
- docker build -t="$DOCKER_USERNAME/consumer_api:$DRONE_BUILD_NUMBER" .
|
||||||
- docker build -t="registry.kmlabz.com/goldenpogacsa/consumer-api-docs:$DRONE_BUILD_NUMBER" .
|
- docker push "$DOCKER_USERNAME/consumer_api"
|
||||||
- docker push "registry.kmlabz.com/goldenpogacsa/consumer-api-docs"
|
- docker push "$DOCKER_USERNAME/consumer_api:$DRONE_BUILD_NUMBER"
|
||||||
- docker push "registry.kmlabz.com/goldenpogacsa/consumer-api-docs:$DRONE_BUILD_NUMBER"
|
|
||||||
|
|
||||||
- name: slack
|
- name: slack
|
||||||
image: plugins/slack
|
image: plugins/slack
|
||||||
@ -103,6 +51,3 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- name: dockersock
|
- name: dockersock
|
||||||
temp: {}
|
temp: {}
|
||||||
- name: cache
|
|
||||||
host:
|
|
||||||
path: "/tmp/cache"
|
|
||||||
|
13
README.rst
13
README.rst
@ -1,13 +0,0 @@
|
|||||||
================
|
|
||||||
P2P Consumer API
|
|
||||||
================
|
|
||||||
|
|
||||||
Repository for the consumer's API
|
|
||||||
|
|
||||||
implemented interfaces / functionalities:
|
|
||||||
|
|
||||||
* consumer
|
|
||||||
* log
|
|
||||||
* sync
|
|
||||||
|
|
||||||
Produced by GoldenPogácsa Inc.
|
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,6 +29,4 @@ class LogView(FlaskView):
|
|||||||
# print out message
|
# print out message
|
||||||
current_app.logger.info(f"New message: {request.json['message']}")
|
current_app.logger.info(f"New message: {request.json['message']}")
|
||||||
|
|
||||||
# return HTTP 204 - No content message
|
|
||||||
return Response(status = 204)
|
return Response(status = 204)
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import json
|
|||||||
import time
|
import time
|
||||||
from flask import request, current_app, jsonify
|
from flask import request, current_app, jsonify
|
||||||
from flask_classful import FlaskView
|
from flask_classful import FlaskView
|
||||||
from db import redis_client
|
from db import redis_client # ez nagyon otvar
|
||||||
|
|
||||||
|
|
||||||
class SyncView(FlaskView):
|
class SyncView(FlaskView):
|
||||||
@ -31,8 +31,8 @@ class SyncView(FlaskView):
|
|||||||
redis_client.set(cust_key, json.dumps(info).encode('utf-8'))
|
redis_client.set(cust_key, json.dumps(info).encode('utf-8'))
|
||||||
redis_client.expire(cust_key, current_app.config["CUSTOMER_TIMEOUT"])
|
redis_client.expire(cust_key, current_app.config["CUSTOMER_TIMEOUT"])
|
||||||
|
|
||||||
# return with the current UUID
|
|
||||||
response = {
|
response = {
|
||||||
"uuid": current_app.config['LOCAL_UUID']
|
"uuid": current_app.config['LOCAL_UUID']
|
||||||
}
|
}
|
||||||
|
|
||||||
return jsonify(response)
|
return jsonify(response)
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
FROM nginx:latest
|
|
||||||
|
|
||||||
COPY _build/html/ /usr/share/nginx/html
|
|
@ -1,20 +0,0 @@
|
|||||||
# Minimal makefile for Sphinx documentation
|
|
||||||
#
|
|
||||||
|
|
||||||
# You can set these variables from the command line, and also
|
|
||||||
# from the environment for the first two.
|
|
||||||
SPHINXOPTS ?=
|
|
||||||
SPHINXBUILD ?= sphinx-build
|
|
||||||
SOURCEDIR = .
|
|
||||||
BUILDDIR = _build
|
|
||||||
|
|
||||||
# Put it first so that "make" without argument is like "make help".
|
|
||||||
help:
|
|
||||||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
|
||||||
|
|
||||||
.PHONY: help Makefile
|
|
||||||
|
|
||||||
# Catch-all target: route all unknown targets to Sphinx using the new
|
|
||||||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
|
||||||
%: Makefile
|
|
||||||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
|
55
docs/conf.py
55
docs/conf.py
@ -1,55 +0,0 @@
|
|||||||
# Configuration file for the Sphinx documentation builder.
|
|
||||||
#
|
|
||||||
# This file only contains a selection of the most common options. For a full
|
|
||||||
# list see the documentation:
|
|
||||||
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
|
||||||
|
|
||||||
# -- Path setup --------------------------------------------------------------
|
|
||||||
|
|
||||||
# If extensions (or modules to document with autodoc) are in another directory,
|
|
||||||
# add these directories to sys.path here. If the directory is relative to the
|
|
||||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
|
||||||
#
|
|
||||||
# import os
|
|
||||||
# import sys
|
|
||||||
# sys.path.insert(0, os.path.abspath('.'))
|
|
||||||
|
|
||||||
|
|
||||||
# -- Project information -----------------------------------------------------
|
|
||||||
|
|
||||||
project = 'Consumer API'
|
|
||||||
copyright = '2020, GoldenPogacsa Inc.'
|
|
||||||
author = 'GoldenPogacsa Inc.'
|
|
||||||
|
|
||||||
# The full version, including alpha/beta/rc tags
|
|
||||||
release = '0.1.0'
|
|
||||||
|
|
||||||
|
|
||||||
# -- General configuration ---------------------------------------------------
|
|
||||||
|
|
||||||
# Add any Sphinx extension module names here, as strings. They can be
|
|
||||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
|
||||||
# ones.
|
|
||||||
extensions = [
|
|
||||||
]
|
|
||||||
|
|
||||||
# Add any paths that contain templates here, relative to this directory.
|
|
||||||
templates_path = []
|
|
||||||
|
|
||||||
# List of patterns, relative to source directory, that match files and
|
|
||||||
# directories to ignore when looking for source files.
|
|
||||||
# This pattern also affects html_static_path and html_extra_path.
|
|
||||||
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
|
|
||||||
|
|
||||||
|
|
||||||
# -- Options for HTML output -------------------------------------------------
|
|
||||||
|
|
||||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
|
||||||
# a list of builtin themes.
|
|
||||||
#
|
|
||||||
html_theme = 'sphinx_rtd_theme'
|
|
||||||
|
|
||||||
# Add any paths that contain custom static files (such as style sheets) here,
|
|
||||||
# relative to this directory. They are copied after the builtin static files,
|
|
||||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
|
||||||
html_static_path = []
|
|
@ -1,23 +0,0 @@
|
|||||||
.. Consumer API documentation master file, created by
|
|
||||||
sphinx-quickstart on Wed Apr 8 21:31:18 2020.
|
|
||||||
You can adapt this file completely to your liking, but it should at least
|
|
||||||
contain the root `toctree` directive.
|
|
||||||
|
|
||||||
Welcome to Consumer API's documentation!
|
|
||||||
========================================
|
|
||||||
|
|
||||||
.. toctree::
|
|
||||||
:maxdepth: 2
|
|
||||||
:caption: Contents:
|
|
||||||
|
|
||||||
readme
|
|
||||||
source/modules
|
|
||||||
|
|
||||||
|
|
||||||
Indices and tables
|
|
||||||
==================
|
|
||||||
|
|
||||||
* :ref:`genindex`
|
|
||||||
* :ref:`modindex`
|
|
||||||
* :ref:`search`
|
|
||||||
* `Git repository <https://git.kmlabz.com/GoldenPogacsa/consumer-api>`_
|
|
@ -1,35 +0,0 @@
|
|||||||
@ECHO OFF
|
|
||||||
|
|
||||||
pushd %~dp0
|
|
||||||
|
|
||||||
REM Command file for Sphinx documentation
|
|
||||||
|
|
||||||
if "%SPHINXBUILD%" == "" (
|
|
||||||
set SPHINXBUILD=sphinx-build
|
|
||||||
)
|
|
||||||
set SOURCEDIR=.
|
|
||||||
set BUILDDIR=_build
|
|
||||||
|
|
||||||
if "%1" == "" goto help
|
|
||||||
|
|
||||||
%SPHINXBUILD% >NUL 2>NUL
|
|
||||||
if errorlevel 9009 (
|
|
||||||
echo.
|
|
||||||
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
|
|
||||||
echo.installed, then set the SPHINXBUILD environment variable to point
|
|
||||||
echo.to the full path of the 'sphinx-build' executable. Alternatively you
|
|
||||||
echo.may add the Sphinx directory to PATH.
|
|
||||||
echo.
|
|
||||||
echo.If you don't have Sphinx installed, grab it from
|
|
||||||
echo.http://sphinx-doc.org/
|
|
||||||
exit /b 1
|
|
||||||
)
|
|
||||||
|
|
||||||
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
|
||||||
goto end
|
|
||||||
|
|
||||||
:help
|
|
||||||
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
|
||||||
|
|
||||||
:end
|
|
||||||
popd
|
|
@ -1 +0,0 @@
|
|||||||
.. include:: ../README.rst
|
|
@ -1,7 +0,0 @@
|
|||||||
app module
|
|
||||||
==========
|
|
||||||
|
|
||||||
.. automodule:: app
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
@ -1,7 +0,0 @@
|
|||||||
db module
|
|
||||||
=========
|
|
||||||
|
|
||||||
.. automodule:: db
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
@ -1,9 +0,0 @@
|
|||||||
consumer_api
|
|
||||||
============
|
|
||||||
|
|
||||||
.. toctree::
|
|
||||||
:maxdepth: 4
|
|
||||||
|
|
||||||
app
|
|
||||||
db
|
|
||||||
views
|
|
@ -1,38 +0,0 @@
|
|||||||
views package
|
|
||||||
=============
|
|
||||||
|
|
||||||
Submodules
|
|
||||||
----------
|
|
||||||
|
|
||||||
views.consumers\_view module
|
|
||||||
----------------------------
|
|
||||||
|
|
||||||
.. automodule:: views.consumers_view
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
views.log\_view module
|
|
||||||
----------------------
|
|
||||||
|
|
||||||
.. automodule:: views.log_view
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
views.sync\_view module
|
|
||||||
-----------------------
|
|
||||||
|
|
||||||
.. automodule:: views.sync_view
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
|
|
||||||
Module contents
|
|
||||||
---------------
|
|
||||||
|
|
||||||
.. automodule:: views
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
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