Skip to content

Commit f42aacf

Browse files
committed
updates tests
1 parent 2b7b74c commit f42aacf

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

services/web/server/tests/unit/with_dbs/03/tags/test_tags.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66

77
from collections.abc import AsyncIterator, Callable, Iterator
8-
from http import HTTPStatus
98
from typing import Any
109

1110
import pytest
@@ -27,7 +26,7 @@
2726
from servicelib.aiohttp import status
2827
from simcore_postgres_database.models.tags import tags
2928
from simcore_service_webserver.db.models import UserRole
30-
from simcore_service_webserver.db.plugin import get_database_engine
29+
from simcore_service_webserver.db.plugin import get_aiopg_engine
3130
from simcore_service_webserver.projects.models import ProjectDict
3231

3332

@@ -46,12 +45,16 @@ def fake_tags(faker: Faker) -> list[dict[str, Any]]:
4645
]
4746

4847

49-
@pytest.mark.parametrize("user_role,expected", [(UserRole.USER, status.HTTP_200_OK)])
48+
@pytest.fixture
49+
def user_role() -> UserRole:
50+
# All tests in test_tags assume USER's role
51+
# i.e. Used in `logged_user` and `user_project`
52+
return UserRole.USER
53+
54+
5055
async def test_tags_to_studies(
5156
client: TestClient,
52-
logged_user: UserInfoDict,
5357
user_project: ProjectDict,
54-
expected: HTTPStatus,
5558
fake_tags: dict[str, Any],
5659
catalog_subsystem_mock: Callable[[list[ProjectDict]], None],
5760
):
@@ -64,15 +67,15 @@ async def test_tags_to_studies(
6467
for tag in fake_tags:
6568
url = client.app.router["create_tag"].url_for()
6669
resp = await client.post(f"{url}", json=tag)
67-
added_tag, _ = await assert_status(resp, expected)
70+
added_tag, _ = await assert_status(resp, status.HTTP_200_OK)
6871
added_tags.append(added_tag)
6972

7073
# Add tag to study
7174
url = client.app.router["add_project_tag"].url_for(
7275
project_uuid=user_project.get("uuid"), tag_id=str(added_tag.get("id"))
7376
)
7477
resp = await client.post(f"{url}")
75-
data, _ = await assert_status(resp, expected)
78+
data, _ = await assert_status(resp, status.HTTP_200_OK)
7679

7780
# Tag is included in response
7881
assert added_tag["id"] in data["tags"]
@@ -86,8 +89,7 @@ async def test_tags_to_studies(
8689
),
8790
exclude_unset=True,
8891
)
89-
user_project["folderId"] = None
90-
data = await assert_get_same_project(client, user_project, expected)
92+
data = await assert_get_same_project(client, user_project, status.HTTP_200_OK)
9193

9294
# Delete tag0
9395
url = client.app.router["delete_tag"].url_for(tag_id=str(added_tags[0].get("id")))
@@ -96,19 +98,19 @@ async def test_tags_to_studies(
9698

9799
# Get project and check that tag is no longer there
98100
user_project["tags"].remove(added_tags[0]["id"])
99-
data = await assert_get_same_project(client, user_project, expected)
101+
data = await assert_get_same_project(client, user_project, status.HTTP_200_OK)
100102
assert added_tags[0].get("id") not in data.get("tags")
101103

102104
# Remove tag1 from project
103105
url = client.app.router["remove_project_tag"].url_for(
104106
project_uuid=user_project.get("uuid"), tag_id=str(added_tags[1].get("id"))
105107
)
106108
resp = await client.post(f"{url}")
107-
await assert_status(resp, expected)
109+
await assert_status(resp, status.HTTP_200_OK)
108110

109111
# Get project and check that tag is no longer there
110112
user_project["tags"].remove(added_tags[1]["id"])
111-
data = await assert_get_same_project(client, user_project, expected)
113+
data = await assert_get_same_project(client, user_project, status.HTTP_200_OK)
112114
assert added_tags[1].get("id") not in data.get("tags")
113115

114116
# Delete tag1
@@ -120,7 +122,7 @@ async def test_tags_to_studies(
120122
@pytest.fixture
121123
async def everybody_tag_id(client: TestClient) -> AsyncIterator[int]:
122124
assert client.app
123-
engine = get_database_engine(client.app)
125+
engine = get_aiopg_engine(client.app)
124126
assert engine
125127

126128
async with engine.acquire() as conn:
@@ -140,11 +142,6 @@ async def everybody_tag_id(client: TestClient) -> AsyncIterator[int]:
140142
await delete_tag(conn, tag_id=tag_id)
141143

142144

143-
@pytest.fixture
144-
def user_role() -> UserRole:
145-
return UserRole.USER
146-
147-
148145
async def test_read_tags(
149146
client: TestClient,
150147
logged_user: UserInfoDict,

0 commit comments

Comments
 (0)