From b08f2742742c52400d9b8c984025c66f25c2bede Mon Sep 17 00:00:00 2001 From: cdietrich Date: Fri, 4 Mar 2022 08:19:55 +0100 Subject: [PATCH] add tests --- .gitignore | 1 + pyinfra/test/config.yaml | 8 ++++++++ pyinfra/test/mock_analyzer.py | 24 ++++++++++++++++++++++++ pyinfra/test/unit_tests/core_test.py | 20 ++++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 pyinfra/test/mock_analyzer.py create mode 100644 pyinfra/test/unit_tests/core_test.py diff --git a/.gitignore b/.gitignore index c258607..0d4477e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ pyinfra.egg-info bamboo-specs/target .pytest_cache /.coverage +.idea \ No newline at end of file diff --git a/pyinfra/test/config.yaml b/pyinfra/test/config.yaml index 16a13da..72bddfc 100644 --- a/pyinfra/test/config.yaml +++ b/pyinfra/test/config.yaml @@ -13,3 +13,11 @@ storage: connection_string: "DefaultEndpointsProtocol=https;AccountName=iqserdevelopment;AccountKey=4imAbV9PYXaztSOMpIyAClg88bAZCXuXMGJG0GA1eIBpdh2PlnFGoRBnKqLy2YZUSTmZ3wJfC7tzfHtuC6FEhQ==;EndpointSuffix=core.windows.net" bucket: "pyinfra-test-bucket" + +webserver: + host: $SERVER_HOST|"127.0.0.1" # webserver address + port: $SERVER_PORT|5000 # webserver port + mode: $SERVER_MODE|production # webserver mode: {development, production} + + +mock_analysis_endpoint: "http://127.0.0.1:5000" \ No newline at end of file diff --git a/pyinfra/test/mock_analyzer.py b/pyinfra/test/mock_analyzer.py new file mode 100644 index 0000000..2405426 --- /dev/null +++ b/pyinfra/test/mock_analyzer.py @@ -0,0 +1,24 @@ +import json +from multiprocessing import Process + +from flask import Flask, request, jsonify +from pyinfra.test.config import CONFIG + + +def start_mock_analyzer(): + app = Flask(__name__) + + @app.route("/", methods=["POST"]) + def predict_request(): + + data = request.data + section_text = json.loads(data) + + return jsonify(section_text) + + @app.get("/shut_down") + def shut_down(): + request.environ.get('werkzeug.server.shutdown') + + server = Process(target=app.run(host=CONFIG.webserver.host, port=CONFIG.webserver.port, debug=True)) + server.start() diff --git a/pyinfra/test/unit_tests/core_test.py b/pyinfra/test/unit_tests/core_test.py new file mode 100644 index 0000000..5be9726 --- /dev/null +++ b/pyinfra/test/unit_tests/core_test.py @@ -0,0 +1,20 @@ +from time import sleep + +from pyinfra.core import make_analyzer +from pyinfra.test.config import CONFIG +from pyinfra.test.mock_analyzer import start_mock_analyzer +import requests + + +def test_analyse(): + data = {"test": "Bliblablub"} + start_mock_analyzer() + sleep(5) + analyzer = make_analyzer(CONFIG.mock_analysis_endpoint) + assert analyzer(data) == data + + requests.get(CONFIG.mock_analysis_endpoint + "/shut_down") + + +def test_make_payload_processor_yields_dossier_id_file_id_predictions(): + pass