-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(tests): ♻️ add way to disable plugins in test for api units
- Loading branch information
1 parent
01ba679
commit 7b52da7
Showing
5 changed files
with
68 additions
and
14 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
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
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
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
29 changes: 29 additions & 0 deletions
29
tests/units/python_factory/example/api/v1/books/test_books.py
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,29 @@ | ||
"""Tests for the books API.""" | ||
|
||
from http import HTTPStatus | ||
from unittest.mock import MagicMock | ||
|
||
from fastapi.testclient import TestClient | ||
|
||
from python_factory.core.app.base.plugins_manager_abstract import PluginsActivationList | ||
from python_factory.example.api.books.routes import get_book_service | ||
from python_factory.example.app.app import App | ||
from python_factory.example.services.books.services import BookService | ||
|
||
|
||
class TestBookApi: | ||
"""Tests for the books API.""" | ||
|
||
def test_get_books(self) -> None: | ||
"""Test get_books.""" | ||
application: App = App.build(plugin_activation_list=PluginsActivationList(activate=[])) | ||
|
||
application.get_asgi_app().dependency_overrides[get_book_service] = lambda: MagicMock( | ||
spec=BookService, return_value=[] | ||
) | ||
|
||
with TestClient(application) as client: | ||
response = client.get("/api/v1/books") | ||
|
||
assert response.status_code == HTTPStatus.OK | ||
assert response.json()["books"] == [] |