Skip to content

Commit b3e4118

Browse files
committed
slowly but surely
1 parent c35c7ab commit b3e4118

File tree

4 files changed

+35
-57
lines changed

4 files changed

+35
-57
lines changed

services/storage/src/simcore_service_storage/core/settings.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@ class ApplicationSettings(BaseApplicationSettings, MixinLoggingSettings):
4242
None, description="Pennsieve API secret ONLY for testing purposes"
4343
)
4444

45-
STORAGE_POSTGRES: PostgresSettings = Field(
45+
STORAGE_POSTGRES: PostgresSettings | None = Field(
4646
json_schema_extra={"auto_default_from_env": True}
4747
)
4848

4949
STORAGE_REDIS: RedisSettings | None = Field(
5050
json_schema_extra={"auto_default_from_env": True}
5151
)
5252

53-
STORAGE_S3: S3Settings = Field(json_schema_extra={"auto_default_from_env": True})
53+
STORAGE_S3: S3Settings | None = Field(
54+
json_schema_extra={"auto_default_from_env": True}
55+
)
5456

5557
STORAGE_TRACING: TracingSettings | None = Field(
5658
json_schema_extra={"auto_default_from_env": True}

services/storage/tests/conftest.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,16 @@ async def cleanup_user_projects_file_metadata(sqlalchemy_async_engine: AsyncEngi
120120

121121

122122
@pytest.fixture
123-
def simcore_s3_dsm(client: TestClient) -> SimcoreS3DataManager:
124-
assert client.app
123+
def simcore_s3_dsm(initialized_app: FastAPI) -> SimcoreS3DataManager:
125124
return cast(
126125
SimcoreS3DataManager,
127-
get_dsm_provider(client.app).get(SimcoreS3DataManager.get_location_id()),
126+
get_dsm_provider(initialized_app).get(SimcoreS3DataManager.get_location_id()),
128127
)
129128

130129

131130
@pytest.fixture
132-
async def storage_s3_client(
133-
client: TestClient,
134-
) -> SimcoreS3API:
135-
assert client.app
136-
return get_s3_client(client.app)
131+
async def storage_s3_client(initialized_app: FastAPI) -> SimcoreS3API:
132+
return get_s3_client(initialized_app)
137133

138134

139135
@pytest.fixture

services/storage/tests/unit/test_cli.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,34 +33,3 @@ def test_run(cli_runner: CliRunner):
3333
result = cli_runner.invoke(main, ["run"])
3434
assert result.exit_code == 0
3535
assert "disabled" in result.stdout
36-
37-
38-
# @pytest.mark.parametrize(
39-
# "arguments", ["--help", "run --help".split(), "settings --help".split()]
40-
# )
41-
# def test_cli_help(arguments: list[str] | str, cli_runner: CliRunner):
42-
# result = cli_runner.invoke(main, arguments)
43-
# assert result.exit_code == os.EX_OK, result
44-
45-
46-
# def test_cli_settings_as_json(cli_runner: CliRunner):
47-
# result = cli_runner.invoke(main, ["settings", "--as-json"])
48-
# assert result.exit_code == os.EX_OK, result
49-
# # reuse resulting json to build settings
50-
# settings: dict = json.loads(result.stdout)
51-
# assert ApplicationSettings(settings)
52-
53-
54-
# def test_cli_settings_env_file(cli_runner: CliRunner):
55-
# result = cli_runner.invoke(main, ["settings", "--compact"])
56-
# assert result.exit_code == os.EX_OK, result
57-
58-
# # reuse resulting env_file to build settings
59-
# env_file = StringIO(result.stdout)
60-
61-
# settings = dotenv_values(stream=env_file)
62-
# for key, value in settings.items():
63-
# with contextlib.suppress(json.decoder.JSONDecodeError):
64-
# settings[key] = json.loads(str(value))
65-
66-
# assert ApplicationSettings(settings)

services/storage/tests/unit/test_handlers_files_metadata.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,18 @@
1010
from random import choice
1111
from typing import Protocol
1212

13+
import httpx
1314
import pytest
1415
from aiohttp.test_utils import TestClient
1516
from faker import Faker
17+
from fastapi import FastAPI
1618
from models_library.api_schemas_storage import FileMetaDataGet, SimcoreS3FileID
1719
from models_library.projects import ProjectID
1820
from models_library.users import UserID
1921
from pydantic import ByteSize, TypeAdapter
2022
from pytest_simcore.helpers.assert_checks import assert_status
2123
from servicelib.aiohttp import status
24+
from yarl import URL
2225

2326
pytest_simcore_core_services_selection = ["postgres"]
2427
pytest_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

3842
async 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

Comments
 (0)