-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First (failing) pass at tests for plugins
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
"""Pytest conftest for plugin tests.""" | ||
|
||
from routemaster.conftest import app | ||
|
||
__all__ = ( | ||
'app', | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from typing import Any, Dict, Type, Tuple, Iterable | ||
|
||
import pytest | ||
import requests | ||
from flask import Flask | ||
from routemaster_sentry import SentryLogger | ||
from routemaster_prometheus import PrometheusLogger | ||
|
||
from routemaster.logging import BaseLogger, SplitLogger | ||
|
||
SENTRY_KWARGS = {'dsn': 'https://xxxxxxx:xxxxxxx@sentry.io/xxxxxxx'} | ||
PROMETHEUS_KWARGS = {'path': '/metrics'} | ||
|
||
TEST_CASES: Iterable[Tuple[Type[BaseLogger], Dict[str, Any]]] = [ | ||
(SentryLogger, SENTRY_KWARGS), | ||
(PrometheusLogger, PROMETHEUS_KWARGS), | ||
(PrometheusLogger, {}), | ||
(SplitLogger, {'loggers': [ | ||
SentryLogger(None, **SENTRY_KWARGS), | ||
PrometheusLogger(None, **PROMETHEUS_KWARGS), | ||
]}), | ||
] | ||
|
||
|
||
@pytest.mark.parametrize('klass, kwargs', TEST_CASES) | ||
def test_logger(app, klass, kwargs): | ||
logger = klass(app.config, **kwargs) | ||
state_machine = app.config.state_machines['test_machine'] | ||
state = state_machine.states[0] | ||
feed_url = 'https://localhost' | ||
|
||
server = Flask('test_server') | ||
logger.init_flask(server) | ||
|
||
with logger.process_cron(state_machine, state, 'test_cron'): | ||
pass | ||
|
||
with pytest.raises(RuntimeError): | ||
with logger.process_cron(state_machine, state, 'test_cron'): | ||
raise RuntimeError("Error must propagate") | ||
|
||
with logger.process_feed(state_machine, state, feed_url): | ||
pass | ||
|
||
with pytest.raises(RuntimeError): | ||
with logger.process_feed(state_machine, state, feed_url): | ||
raise RuntimeError("Error must propagate") | ||
|
||
with logger.process_webhook(state_machine, state): | ||
pass | ||
|
||
with pytest.raises(RuntimeError): | ||
with logger.process_webhook(state_machine, state): | ||
raise RuntimeError("Error must propagate") | ||
|
||
with logger.process_request({}): | ||
pass | ||
|
||
with pytest.raises(RuntimeError): | ||
with logger.process_request({}): | ||
raise RuntimeError("Error must propagate") | ||
|
||
logger.debug("test") | ||
logger.info("test") | ||
logger.warning("test") | ||
logger.error("test") | ||
logger.critical("test") | ||
logger.exception("test") | ||
|
||
with pytest.raises(AttributeError): | ||
logger.non_existent_logging_fn("test") | ||
|
||
response = requests.Response() | ||
logger.webhook_response(state_machine, state, response) | ||
logger.feed_response(state_machine, state, feed_url, response) |