Skip to content

Commit

Permalink
Add missing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
brainbot-devops committed Aug 9, 2019
1 parent 39e1631 commit be3af6e
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
3 changes: 1 addition & 2 deletions scenario_player/services/rpc/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
logging accordingly, if given.
"""
import logging
import pathlib

import flask
import structlog
Expand All @@ -28,7 +27,7 @@ def rpc_app():
"""Create a :mod:`flask` app using only the RPC blueprints."""
from scenario_player import __version__

log = logging.getLogger()
log = structlog.getLogger()
NAME = "SPaaS-RPC-Service"

log.info("Creating RPC Flask App", version=__version__, name=NAME)
Expand Down
22 changes: 22 additions & 0 deletions tests/unittests/services/common/test_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import logging
from unittest.mock import patch

from scenario_player.services.common.app import serve_spaas_stack

dummy_app = object()


@patch("scenario_player.services.common.app.construct_flask_app", return_value=dummy_app)
@patch("scenario_player.services.common.app.waitress.serve")
class TestServerSPaaSStack:
def test_calls_waitress_serve_with_args(self, mock_serve, _, tmp_path):
serve_spaas_stack(tmp_path.joinpath("tetst.log"), "127.0.0.666", 1000)
mock_serve.assert_called_once_with(dummy_app, host="127.0.0.666", port=1000)

@patch("scenario_player.services.common.app.logging.basicConfig", autospec=True)
@patch("scenario_player.services.common.app.structlog.getLogger", autospec=True)
def test_configures_logging(self, mock_structlog, mock_logging, _, __, tmp_path):
logfile = tmp_path.joinpath("test.log")
serve_spaas_stack(logfile, "127.0.0.1", 5000)
mock_structlog.assert_called_once()
mock_logging.assert_called_once_with(filename=logfile, filemode="a+", level=logging.DEBUG)
47 changes: 47 additions & 0 deletions tests/unittests/services/rpc/test_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import logging
from unittest.mock import patch

from scenario_player.services.rpc.app import (
admin_blueprint,
instances_blueprint,
metrics_blueprint,
rpc_app,
serve_rpc,
tokens_blueprint,
transactions_blueprint,
)
from scenario_player.services.rpc.utils import RPCRegistry

dummy_app = object()


@patch("scenario_player.services.rpc.app.rpc_app", return_value=dummy_app)
@patch("scenario_player.services.rpc.app.waitress.serve")
class TestServeRPC:
def test_calls_waitress_serve_with_args(self, mock_serve, _, tmp_path):
serve_rpc(tmp_path.joinpath("tetst.log"), "127.0.0.666", 1000)
mock_serve.assert_called_once_with(dummy_app, host="127.0.0.666", port=1000)

@patch("scenario_player.services.rpc.app.logging.basicConfig", autospec=True)
@patch("scenario_player.services.rpc.app.structlog.getLogger", autospec=True)
def test_configures_logging(self, mock_structlog, mock_logging, _, __, tmp_path):
logfile = tmp_path.joinpath("test.log")
serve_rpc(logfile, "127.0.0.1", 5000)
mock_structlog.assert_called_once()
mock_logging.assert_called_once_with(filename=logfile, filemode="a+", level=logging.DEBUG)


@patch("scenario_player.services.rpc.app.flask.Flask.register_blueprint")
def test_rpc_app_constructor(mock_register_bp):
app = rpc_app()
blueprints = [
admin_blueprint,
instances_blueprint,
metrics_blueprint,
tokens_blueprint,
transactions_blueprint,
]
for bp in blueprints:
mock_register_bp.assert_any_call(bp)

assert isinstance(app.config.get("rpc-client"), RPCRegistry)

0 comments on commit be3af6e

Please sign in to comment.