|
@ -40,22 +40,17 @@ class MockDatabaseConnection: |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture |
|
|
@pytest.fixture |
|
|
def database_connection_mocks(monkeypatch) -> List[MockDatabaseConnection]: |
|
|
def database_connection_mocks(monkeypatch) -> List[MockDatabaseConnection]: |
|
|
connections = [] |
|
|
connections = [] |
|
|
|
|
|
|
|
|
def _get_new_connection_mock(*args, **kwargs): |
|
|
def _get_new_connection_mock(*args, **kwargs): |
|
|
mock = MockDatabaseConnection() |
|
|
mock = MockDatabaseConnection() |
|
|
connections.append(mock) |
|
|
connections.append(mock) |
|
|
|
|
|
|
|
|
return mock |
|
|
return mock |
|
|
|
|
|
|
|
|
|
|
|
monkeypatch.setattr(MyDatabaseConnection, "__new__", _get_new_connection_mock) |
|
|
monkeypatch.setattr( |
|
|
|
|
|
MyDatabaseConnection, |
|
|
|
|
|
"__new__", |
|
|
|
|
|
_get_new_connection_mock |
|
|
|
|
|
) |
|
|
|
|
|
return connections |
|
|
return connections |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -70,7 +65,7 @@ def test_dependency_usage(database_connection_mocks): |
|
|
assert connection.get_records_count == 0 |
|
|
assert connection.get_records_count == 0 |
|
|
assert connection.get_record_count == 0 |
|
|
assert connection.get_record_count == 0 |
|
|
|
|
|
|
|
|
response = test_client.get('/users') |
|
|
response = test_client.get("/users") |
|
|
assert response.status_code == 200 |
|
|
assert response.status_code == 200 |
|
|
assert response.json() == [] |
|
|
assert response.json() == [] |
|
|
|
|
|
|
|
@ -80,9 +75,11 @@ def test_dependency_usage(database_connection_mocks): |
|
|
users_connection = connection |
|
|
users_connection = connection |
|
|
break |
|
|
break |
|
|
|
|
|
|
|
|
assert users_connection is not None, "No connection was found for users endpoint" |
|
|
assert ( |
|
|
|
|
|
users_connection is not None |
|
|
|
|
|
), "No connection was found for users endpoint" |
|
|
|
|
|
|
|
|
response = test_client.get('/groups') |
|
|
response = test_client.get("/groups") |
|
|
assert response.status_code == 200 |
|
|
assert response.status_code == 200 |
|
|
assert response.json() == [] |
|
|
assert response.json() == [] |
|
|
|
|
|
|
|
@ -92,7 +89,9 @@ def test_dependency_usage(database_connection_mocks): |
|
|
groups_connection = connection |
|
|
groups_connection = connection |
|
|
break |
|
|
break |
|
|
|
|
|
|
|
|
assert groups_connection is not None, "No connection was found for groups endpoint" |
|
|
assert ( |
|
|
|
|
|
groups_connection is not None |
|
|
|
|
|
), "No connection was found for groups endpoint" |
|
|
assert groups_connection.get_records_count == 1 |
|
|
assert groups_connection.get_records_count == 1 |
|
|
|
|
|
|
|
|
items_connection = None |
|
|
items_connection = None |
|
@ -101,16 +100,18 @@ def test_dependency_usage(database_connection_mocks): |
|
|
items_connection = connection |
|
|
items_connection = connection |
|
|
break |
|
|
break |
|
|
|
|
|
|
|
|
assert items_connection is not None, "No connection was found for items endpoint" |
|
|
assert ( |
|
|
|
|
|
items_connection is not None |
|
|
|
|
|
), "No connection was found for items endpoint" |
|
|
|
|
|
|
|
|
response = test_client.get('/items') |
|
|
response = test_client.get("/items") |
|
|
assert response.status_code == 200 |
|
|
assert response.status_code == 200 |
|
|
assert response.json() == [] |
|
|
assert response.json() == [] |
|
|
|
|
|
|
|
|
assert items_connection.get_records_count == 1 |
|
|
assert items_connection.get_records_count == 1 |
|
|
assert items_connection.get_record_count == 0 |
|
|
assert items_connection.get_record_count == 0 |
|
|
|
|
|
|
|
|
response = test_client.get('/items/asd') |
|
|
response = test_client.get("/items/asd") |
|
|
assert response.status_code == 200 |
|
|
assert response.status_code == 200 |
|
|
assert response.json() == { |
|
|
assert response.json() == { |
|
|
"table_name": "items", |
|
|
"table_name": "items", |
|
|