Skip to content

Commit 3579686

Browse files
committed
add hostname
1 parent 3a12eac commit 3579686

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

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

Lines changed: 13 additions & 15 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
@@ -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,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-
147145
async def test_read_tags(
148146
client: TestClient,
149147
logged_user: UserInfoDict,

services/web/server/tests/unit/with_dbs/conftest.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
from pydantic import ByteSize, parse_obj_as
4242
from pytest_mock import MockerFixture
4343
from pytest_simcore.helpers.dict_tools import ConfigDict
44+
from pytest_simcore.helpers.monkeypatch_envs import (
45+
setenvs_from_dict,
46+
setenvs_from_envfile,
47+
)
4448
from pytest_simcore.helpers.typing_env import EnvVarsDict
4549
from pytest_simcore.helpers.webserver_login import NewUser, UserInfoDict
4650
from pytest_simcore.helpers.webserver_parametrizations import MockedStorageSubsystem
@@ -127,6 +131,7 @@ def app_cfg(default_app_cfg: ConfigDict, unused_tcp_port_factory) -> ConfigDict:
127131
def app_environment(
128132
app_cfg: ConfigDict,
129133
monkeypatch_setenv_from_app_config: Callable[[ConfigDict], dict[str, str]],
134+
monkeypatch: pytest.MonkeyPatch,
130135
) -> EnvVarsDict:
131136
# WARNING: this fixture is commonly overriden. Check before renaming.
132137
"""overridable fixture that defines the ENV for the webserver application
@@ -140,7 +145,12 @@ def app_environment(app_environment: dict[str, str], monkeypatch: pytest.MonkeyP
140145
"""
141146
print("+ web_server:")
142147
cfg = deepcopy(app_cfg)
143-
return monkeypatch_setenv_from_app_config(cfg)
148+
149+
envs = monkeypatch_setenv_from_app_config(cfg)
150+
# NOTE: this emulates hostname: "{{.Node.Hostname}}-{{.Task.Slot}}" in docker-compose that
151+
# affects PostgresSettings.POSTGRES_CLIENT_NAME
152+
extra = setenvs_from_dict(monkeypatch, {"HOSTNAME": "webserver_test_host.0"})
153+
return envs | extra
144154

145155

146156
@pytest.fixture

0 commit comments

Comments
 (0)