|
1 | 1 | import pytest |
2 | | -from azure.cosmos.exceptions import CosmosHttpResponseError, CosmosResourceExistsError, CosmosResourceNotFoundError |
| 2 | +from azure.cosmos.exceptions import ( |
| 3 | + CosmosHttpResponseError, |
| 4 | + CosmosResourceExistsError, |
| 5 | + CosmosResourceNotFoundError, |
| 6 | +) |
3 | 7 | from flask.testing import FlaskClient |
4 | 8 | from flask_restplus._http import HTTPStatus |
5 | 9 | from pytest_mock import MockFixture |
6 | 10 |
|
7 | 11 | from commons.data_access_layer.cosmos_db import CustomError |
8 | 12 |
|
9 | | -unexpected_errors_to_be_handled = [CustomError(HTTPStatus.BAD_REQUEST, "Anything"), |
10 | | - CosmosHttpResponseError, CosmosResourceNotFoundError, |
11 | | - CosmosResourceExistsError, AttributeError] |
| 13 | +unexpected_errors_to_be_handled = [ |
| 14 | + CustomError(HTTPStatus.BAD_REQUEST, "Anything"), |
| 15 | + CosmosHttpResponseError, |
| 16 | + CosmosResourceNotFoundError, |
| 17 | + CosmosResourceExistsError, |
| 18 | + AttributeError, |
| 19 | +] |
12 | 20 |
|
13 | 21 |
|
14 | 22 | def test_app_exists(app): |
15 | 23 | assert app is not None |
16 | 24 |
|
17 | 25 |
|
18 | 26 | @pytest.mark.parametrize("error_type", unexpected_errors_to_be_handled) |
19 | | -def test_exceptions_are_handled(error_type, client: FlaskClient, mocker: MockFixture): |
20 | | - from time_tracker_api.time_entries.time_entries_namespace import time_entries_dao |
21 | | - mocker.patch.object(time_entries_dao, |
22 | | - "get_all", |
23 | | - side_effect=error_type) |
| 27 | +def test_exceptions_are_handled( |
| 28 | + error_type, client: FlaskClient, mocker: MockFixture, time_entries_dao |
| 29 | +): |
| 30 | + mocker.patch.object(time_entries_dao, "get_all", side_effect=error_type) |
24 | 31 |
|
25 | 32 | response = client.get('/time-entries', follow_redirects=True) |
26 | 33 |
|
|
0 commit comments