|
8 | 8 | import pytest
|
9 | 9 | from aiohttp import web
|
10 | 10 | from aiohttp.test_utils import make_mocked_request
|
| 11 | +from faker import Faker |
| 12 | +from pytest_simcore.helpers.faker_factories import random_product |
11 | 13 | from servicelib.aiohttp import status
|
12 | 14 | from servicelib.rest_constants import X_PRODUCT_NAME_HEADER
|
13 |
| -from simcore_postgres_database.models.products import LOGIN_SETTINGS_DEFAULT |
14 |
| -from simcore_postgres_database.webserver_models import products |
15 | 15 | from simcore_service_webserver.products import products_web
|
16 | 16 | from simcore_service_webserver.products._web_events import _set_app_state
|
17 | 17 | from simcore_service_webserver.products._web_middlewares import (
|
|
22 | 22 | from yarl import URL
|
23 | 23 |
|
24 | 24 |
|
25 |
| -@pytest.fixture() |
26 |
| -def mock_postgres_product_table() -> list[dict[str, Any]]: |
27 |
| - # NOTE: try here your product's host_regex before adding them in the database! |
28 |
| - column_defaults: dict[str, Any] = { |
29 |
| - c.name: f"{c.server_default.arg}" for c in products.columns if c.server_default |
30 |
| - } |
31 |
| - |
32 |
| - column_defaults["login_settings"] = LOGIN_SETTINGS_DEFAULT |
| 25 | +@pytest.fixture |
| 26 | +def mock_postgres_product_data( |
| 27 | + faker: Faker, product_db_server_defaults: dict[str, Any] |
| 28 | +) -> list[dict[str, Any]]: |
33 | 29 |
|
34 | 30 | _SUBDOMAIN_PREFIX = r"[\w-]+\."
|
35 | 31 |
|
36 | 32 | return [
|
37 |
| - dict( |
| 33 | + random_product( |
38 | 34 | name="osparc",
|
39 | 35 | host_regex=rf"^({_SUBDOMAIN_PREFIX})*osparc[\.-]",
|
40 |
| - **column_defaults, |
| 36 | + fake=faker, |
| 37 | + **product_db_server_defaults, |
41 | 38 | ),
|
42 |
| - dict( |
| 39 | + random_product( |
43 | 40 | name="s4l",
|
44 | 41 | host_regex=rf"^({_SUBDOMAIN_PREFIX})*(s4l|sim4life)[\.-]",
|
45 |
| - **column_defaults, |
| 42 | + fake=faker, |
| 43 | + **product_db_server_defaults, |
46 | 44 | ),
|
47 |
| - dict( |
| 45 | + random_product( |
48 | 46 | name="tis",
|
49 | 47 | host_regex=rf"^({_SUBDOMAIN_PREFIX})*(tis|^ti-solutions)[\.-]",
|
| 48 | + fake=faker, |
50 | 49 | vendor={
|
51 | 50 | "name": "ACME",
|
52 | 51 | "address": "sesame street",
|
53 | 52 | "copyright": "© ACME correcaminos",
|
54 | 53 | "url": "https://acme.com",
|
55 | 54 | "forum_url": "https://forum.acme.com",
|
56 | 55 | },
|
57 |
| - **column_defaults, |
| 56 | + **product_db_server_defaults, |
58 | 57 | ),
|
59 | 58 | ]
|
60 | 59 |
|
61 | 60 |
|
62 | 61 | @pytest.fixture
|
63 |
| -def mock_app(mock_postgres_product_table: list[dict[str, Any]]) -> web.Application: |
| 62 | +def mock_app(mock_postgres_product_data: list[dict[str, Any]]) -> web.Application: |
64 | 63 | app = web.Application()
|
65 | 64 |
|
66 | 65 | app_products: dict[str, Product] = {
|
67 | 66 | product_from_db["name"]: Product.model_validate(product_from_db)
|
68 |
| - for product_from_db in mock_postgres_product_table |
| 67 | + for product_from_db in mock_postgres_product_data |
69 | 68 | }
|
| 69 | + |
70 | 70 | default_product_name = next(iter(app_products.keys()))
|
71 | 71 | _set_app_state(app, app_products, default_product_name)
|
72 | 72 |
|
|
0 commit comments