Files
connexion/tests/test_metrics.py
Brian Price b0b83c4879 Converting response to raise a ProblemException (#955)
* Converting response to raise a ProblemException

* Centralizing around ProblemException for errors in the app.

* Adding the ability to skip error handlers, allow for defining exception payload.

* Fixing flake8

* Fixed some bugs found through unit testing.

* Unit tests are now passing.

* Added problem back to __init__

* Updating based on the feedback from the PR.
2019-10-24 10:59:05 +02:00

27 lines
850 B
Python

import json
import flask
import pytest
from mock import MagicMock
import connexion
from connexion.exceptions import ProblemException
from connexion.decorators.metrics import UWSGIMetricsCollector
def test_timer(monkeypatch):
wrapper = UWSGIMetricsCollector('/foo/bar/<param>', 'get')
def operation(req):
raise ProblemException(418, '', '')
op = wrapper(operation)
metrics = MagicMock()
monkeypatch.setattr('flask.request', MagicMock())
monkeypatch.setattr('flask.current_app', MagicMock(response_class=flask.Response))
monkeypatch.setattr('connexion.decorators.metrics.uwsgi_metrics', metrics)
with pytest.raises(ProblemException) as exc:
op(MagicMock())
assert metrics.timer.call_args[0][:2] == ('connexion.response',
'418.GET.foo.bar.{param}')