-
-
Notifications
You must be signed in to change notification settings - Fork 50
Refactor setups_tag tests to use direct method calls for non-happy-path tests #298
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,12 +1,13 @@ | ||||||
| import re | ||||||
| from http import HTTPStatus | ||||||
|
|
||||||
| import httpx | ||||||
| import pytest | ||||||
| from sqlalchemy import text | ||||||
| from sqlalchemy.ext.asyncio import AsyncConnection | ||||||
|
|
||||||
| from tests.users import ApiKey | ||||||
| from core.errors import SetupNotFoundError, TagAlreadyExistsError | ||||||
| from routers.openml.setups import tag_setup | ||||||
| from tests.users import SOME_USER, ApiKey | ||||||
|
|
||||||
|
|
||||||
| async def test_setup_tag_missing_auth(py_api: httpx.AsyncClient) -> None: | ||||||
|
|
@@ -16,41 +17,62 @@ async def test_setup_tag_missing_auth(py_api: httpx.AsyncClient) -> None: | |||||
| assert response.json()["detail"] == "Authentication failed" | ||||||
|
|
||||||
|
|
||||||
| async def test_setup_tag_unknown_setup(py_api: httpx.AsyncClient) -> None: | ||||||
| @pytest.mark.mut | ||||||
| async def test_setup_tag_api_success( | ||||||
| py_api: httpx.AsyncClient, expdb_test: AsyncConnection | ||||||
| ) -> None: | ||||||
| response = await py_api.post( | ||||||
| f"/setup/tag?api_key={ApiKey.SOME_USER}", | ||||||
| json={"setup_id": 999999, "tag": "test_tag"}, | ||||||
| json={"setup_id": 1, "tag": "my_new_success_api_tag"}, | ||||||
| ) | ||||||
| assert response.status_code == HTTPStatus.NOT_FOUND | ||||||
| assert re.match(r"Setup \d+ not found.", response.json()["detail"]) | ||||||
|
|
||||||
| assert response.status_code == HTTPStatus.OK | ||||||
| assert "my_new_success_api_tag" in response.json()["setup_tag"]["tag"] | ||||||
|
|
||||||
| rows = await expdb_test.execute( | ||||||
| text("SELECT * FROM setup_tag WHERE id = 1 AND tag = 'my_new_success_api_tag'") | ||||||
| ) | ||||||
| assert len(rows.all()) == 1 | ||||||
|
|
||||||
|
|
||||||
| # ── Direct call tests: tag_setup ── | ||||||
|
|
||||||
|
|
||||||
| async def test_setup_tag_unknown_setup(expdb_test: AsyncConnection) -> None: | ||||||
| with pytest.raises(SetupNotFoundError, match=r"Setup \d+ not found."): | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tighten the exception regex in Line 45.
Proposed fix- with pytest.raises(SetupNotFoundError, match=r"Setup \d+ not found."):
+ with pytest.raises(SetupNotFoundError, match=r"Setup \d+ not found\."):📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| await tag_setup( | ||||||
| setup_id=999999, | ||||||
| tag="test_tag", | ||||||
| user=SOME_USER, | ||||||
| expdb_db=expdb_test, | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
| @pytest.mark.mut | ||||||
| async def test_setup_tag_already_exists( | ||||||
| py_api: httpx.AsyncClient, expdb_test: AsyncConnection | ||||||
| ) -> None: | ||||||
| async def test_setup_tag_already_exists(expdb_test: AsyncConnection) -> None: | ||||||
| await expdb_test.execute( | ||||||
| text("INSERT INTO setup_tag (id, tag, uploader) VALUES (1, 'existing_tag_123', 2);") | ||||||
| ) | ||||||
| response = await py_api.post( | ||||||
| f"/setup/tag?api_key={ApiKey.SOME_USER}", | ||||||
| json={"setup_id": 1, "tag": "existing_tag_123"}, | ||||||
| ) | ||||||
| assert response.status_code == HTTPStatus.CONFLICT | ||||||
| assert response.json()["detail"] == "Setup 1 already has tag 'existing_tag_123'." | ||||||
| with pytest.raises(TagAlreadyExistsError, match=r"Setup 1 already has tag 'existing_tag_123'."): | ||||||
| await tag_setup( | ||||||
| setup_id=1, | ||||||
| tag="existing_tag_123", | ||||||
| user=SOME_USER, | ||||||
| expdb_db=expdb_test, | ||||||
| ) | ||||||
|
|
||||||
|
|
||||||
| @pytest.mark.mut | ||||||
| async def test_setup_tag_success(py_api: httpx.AsyncClient, expdb_test: AsyncConnection) -> None: | ||||||
| response = await py_api.post( | ||||||
| f"/setup/tag?api_key={ApiKey.SOME_USER}", | ||||||
| json={"setup_id": 1, "tag": "my_new_success_tag"}, | ||||||
| async def test_setup_tag_direct_success(expdb_test: AsyncConnection) -> None: | ||||||
| result = await tag_setup( | ||||||
| setup_id=1, | ||||||
| tag="my_direct_success_tag", | ||||||
| user=SOME_USER, | ||||||
| expdb_db=expdb_test, | ||||||
| ) | ||||||
|
|
||||||
| assert response.status_code == HTTPStatus.OK | ||||||
| assert "my_new_success_tag" in response.json()["setup_tag"]["tag"] | ||||||
|
|
||||||
| assert "my_direct_success_tag" in result["setup_tag"]["tag"] | ||||||
| rows = await expdb_test.execute( | ||||||
| text("SELECT * FROM setup_tag WHERE id = 1 AND tag = 'my_new_success_tag'") | ||||||
| text("SELECT * FROM setup_tag WHERE id = 1 AND tag = 'my_direct_success_tag'") | ||||||
| ) | ||||||
| assert len(rows.all()) == 1 | ||||||
Uh oh!
There was an error while loading. Please reload this page.