1010from random import choice
1111from typing import Protocol
1212
13+ import httpx
1314import pytest
1415from aiohttp .test_utils import TestClient
1516from faker import Faker
17+ from fastapi import FastAPI
1618from models_library .api_schemas_storage import FileMetaDataGet , SimcoreS3FileID
1719from models_library .projects import ProjectID
1820from models_library .users import UserID
1921from pydantic import ByteSize , TypeAdapter
2022from pytest_simcore .helpers .assert_checks import assert_status
2123from servicelib .aiohttp import status
24+ from yarl import URL
2225
2326pytest_simcore_core_services_selection = ["postgres" ]
2427pytest_simcore_ops_services_selection = ["adminer" ]
@@ -32,31 +35,39 @@ async def __call__(
3235 read : bool ,
3336 write : bool ,
3437 delete : bool ,
35- ) -> None : ...
38+ ) -> None :
39+ ...
3640
3741
3842async def test_list_files_metadata (
3943 upload_file : Callable [[ByteSize , str ], Awaitable [tuple [Path , SimcoreS3FileID ]]],
4044 create_project_access_rights : CreateProjectAccessRightsCallable ,
41- client : TestClient ,
45+ initialized_app : FastAPI ,
46+ client : httpx .AsyncClient ,
4247 user_id : UserID ,
4348 other_user_id : UserID ,
4449 location_id : int ,
4550 project_id : ProjectID ,
4651 faker : Faker ,
4752):
48- assert client .app
49-
5053 url = (
51- client .app .router ["list_files_metadata" ]
52- .url_for (location_id = f"{ location_id } " )
54+ URL (f"{ client .base_url } " )
55+ .with_path (
56+ initialized_app .url_path_for ("list_files_metadata" , location_id = location_id )
57+ )
5358 .with_query (user_id = f"{ user_id } " )
5459 )
60+ # url = (
61+ # client.app.router["list_files_metadata"]
62+ # .url_for(location_id=f"{location_id}")
63+ # .with_query(user_id=f"{user_id}")
64+ # )
5565
5666 # this should return an empty list
5767 response = await client .get (f"{ url } " )
58- data , error = await assert_status (response , status .HTTP_200_OK )
59- assert not error
68+ assert response .status_code == status .HTTP_200_OK
69+ data = response .json ()
70+ assert data
6071 list_fmds = TypeAdapter (list [FileMetaDataGet ]).validate_python (data )
6172 assert not list_fmds
6273
@@ -70,8 +81,8 @@ async def test_list_files_metadata(
7081
7182 # we should find these files now
7283 response = await client .get (f"{ url } " )
73- data , error = await assert_status ( response , status .HTTP_200_OK )
74- assert not error
84+ assert response . status_code == status .HTTP_200_OK
85+ data = response . json ()
7586 list_fmds = TypeAdapter (list [FileMetaDataGet ]).validate_python (data )
7687 assert len (list_fmds ) == NUM_FILES
7788
@@ -87,8 +98,8 @@ async def test_list_files_metadata(
8798 f"{ url .update_query (project_id = str (project_id ), user_id = other_user_id )} "
8899 )
89100 previous_data = deepcopy (data )
90- data , error = await assert_status ( response , status .HTTP_200_OK )
91- assert not error
101+ assert response . status_code == status .HTTP_200_OK
102+ data = response . json ()
92103 list_fmds = TypeAdapter (list [FileMetaDataGet ]).validate_python (data )
93104 assert len (list_fmds ) == (NUM_FILES )
94105 assert previous_data == data
@@ -104,15 +115,15 @@ async def test_list_files_metadata(
104115
105116 # we should find these files now
106117 response = await client .get (f"{ url } " )
107- data , error = await assert_status ( response , status .HTTP_200_OK )
108- assert not error
118+ assert response . status_code == status .HTTP_200_OK
119+ data = response . json ()
109120 list_fmds = TypeAdapter (list [FileMetaDataGet ]).validate_python (data )
110121 assert len (list_fmds ) == (2 * NUM_FILES )
111122
112123 # we can filter them now
113124 response = await client .get (f"{ url .update_query (uuid_filter = 'common_name' )} " )
114- data , error = await assert_status ( response , status .HTTP_200_OK )
115- assert not error
125+ assert response . status_code == status .HTTP_200_OK
126+ data = response . json ()
116127 list_fmds = TypeAdapter (list [FileMetaDataGet ]).validate_python (data )
117128 assert len (list_fmds ) == (NUM_FILES )
118129
0 commit comments