55
66
77from collections .abc import AsyncIterator , Callable , Iterator
8- from http import HTTPStatus
98from typing import Any
109
1110import pytest
@@ -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+
5055async 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,7 +89,7 @@ async def test_tags_to_studies(
8689 ),
8790 exclude_unset = True ,
8891 )
89- data = await assert_get_same_project (client , user_project , expected )
92+ data = await assert_get_same_project (client , user_project , status . HTTP_200_OK )
9093
9194 # Delete tag0
9295 url = client .app .router ["delete_tag" ].url_for (tag_id = str (added_tags [0 ].get ("id" )))
@@ -95,19 +98,19 @@ async def test_tags_to_studies(
9598
9699 # Get project and check that tag is no longer there
97100 user_project ["tags" ].remove (added_tags [0 ]["id" ])
98- data = await assert_get_same_project (client , user_project , expected )
101+ data = await assert_get_same_project (client , user_project , status . HTTP_200_OK )
99102 assert added_tags [0 ].get ("id" ) not in data .get ("tags" )
100103
101104 # Remove tag1 from project
102105 url = client .app .router ["remove_project_tag" ].url_for (
103106 project_uuid = user_project .get ("uuid" ), tag_id = str (added_tags [1 ].get ("id" ))
104107 )
105108 resp = await client .post (f"{ url } " )
106- await assert_status (resp , expected )
109+ await assert_status (resp , status . HTTP_200_OK )
107110
108111 # Get project and check that tag is no longer there
109112 user_project ["tags" ].remove (added_tags [1 ]["id" ])
110- data = await assert_get_same_project (client , user_project , expected )
113+ data = await assert_get_same_project (client , user_project , status . HTTP_200_OK )
111114 assert added_tags [1 ].get ("id" ) not in data .get ("tags" )
112115
113116 # Delete tag1
@@ -139,11 +142,6 @@ async def everybody_tag_id(client: TestClient) -> AsyncIterator[int]:
139142 await delete_tag (conn , tag_id = tag_id )
140143
141144
142- @pytest .fixture
143- def user_role () -> UserRole :
144- return UserRole .USER
145-
146-
147145async def test_read_tags (
148146 client : TestClient ,
149147 logged_user : UserInfoDict ,
0 commit comments