-
-
Notifications
You must be signed in to change notification settings - Fork 52
Separate out test files to one file per endpoint #295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6a91a55
Separate out tests by endpoint
PGijsbers ce0f143
Rename test file to match endpoint it tests
PGijsbers a86a619
Separate out tests by endpoint
PGijsbers 234ec70
Separate tests out by endpoint
PGijsbers 559c05c
Add the _test prefix to make sure pytest collects the tests
PGijsbers 985aa26
Separate out tests by endpoint
PGijsbers a548b20
Use the provided study_id instead of a hardcoded value
PGijsbers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,81 @@ | ||
| from http import HTTPStatus | ||
|
|
||
| import httpx | ||
| import pytest | ||
| from pytest_mock import MockerFixture | ||
| from sqlalchemy.ext.asyncio import AsyncConnection | ||
|
|
||
| from core.errors import FlowNotFoundError | ||
| from routers.openml.flows import flow_exists | ||
| from tests.conftest import Flow | ||
|
|
||
|
|
||
| async def test_flow_exists(flow: Flow, py_api: httpx.AsyncClient) -> None: | ||
| response = await py_api.get(f"/flows/exists/{flow.name}/{flow.external_version}") | ||
| assert response.status_code == HTTPStatus.OK | ||
| assert response.json() == {"flow_id": flow.id} | ||
|
|
||
|
|
||
| async def test_flow_exists_not_exists(py_api: httpx.AsyncClient) -> None: | ||
| name, version = "foo", "bar" | ||
| response = await py_api.get(f"/flows/exists/{name}/{version}") | ||
| assert response.status_code == HTTPStatus.NOT_FOUND | ||
| assert response.headers["content-type"] == "application/problem+json" | ||
| error = response.json() | ||
| assert error["type"] == FlowNotFoundError.uri | ||
| assert name in error["detail"] | ||
| assert version in error["detail"] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("name", "external_version"), | ||
| [ | ||
| ("a", "b"), | ||
| ("c", "d"), | ||
| ], | ||
| ) | ||
| async def test_flow_exists_calls_db_correctly( | ||
| name: str, | ||
| external_version: str, | ||
| expdb_test: AsyncConnection, | ||
| mocker: MockerFixture, | ||
| ) -> None: | ||
| mocked_db = mocker.patch( | ||
| "database.flows.get_by_name", | ||
| new_callable=mocker.AsyncMock, | ||
| ) | ||
| await flow_exists(name, external_version, expdb_test) | ||
| mocked_db.assert_called_once_with( | ||
| name=name, | ||
| external_version=external_version, | ||
| expdb=mocker.ANY, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "flow_id", | ||
| [1, 2], | ||
| ) | ||
| async def test_flow_exists_processes_found( | ||
| flow_id: int, | ||
| mocker: MockerFixture, | ||
| expdb_test: AsyncConnection, | ||
| ) -> None: | ||
| fake_flow = mocker.MagicMock(id=flow_id) | ||
| mocker.patch( | ||
| "database.flows.get_by_name", | ||
| new_callable=mocker.AsyncMock, | ||
| return_value=fake_flow, | ||
| ) | ||
| response = await flow_exists("name", "external_version", expdb_test) | ||
| assert response == {"flow_id": fake_flow.id} | ||
|
|
||
|
|
||
| async def test_flow_exists_handles_flow_not_found( | ||
| mocker: MockerFixture, expdb_test: AsyncConnection | ||
| ) -> None: | ||
| mocker.patch("database.flows.get_by_name", return_value=None) | ||
| with pytest.raises(FlowNotFoundError) as error: | ||
| await flow_exists("foo", "bar", expdb_test) | ||
| assert error.value.status_code == HTTPStatus.NOT_FOUND | ||
| assert error.value.uri == FlowNotFoundError.uri | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.