Skip to content

Commit 83c7e67

Browse files
committed
moving isolated tests
1 parent e151946 commit 83c7e67

File tree

3 files changed

+46
-35
lines changed

3 files changed

+46
-35
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# pylint: disable=redefined-outer-name
2+
# pylint: disable=unused-argument
3+
# pylint: disable=unused-variable
4+
# pylint: disable=too-many-arguments
5+
6+
7+
import json
8+
import re
9+
from typing import Any
10+
11+
import pytest
12+
from faker import Faker
13+
from models_library.products import ProductName
14+
from pytest_simcore.helpers.faker_factories import random_product
15+
from simcore_postgres_database.models.products import products as products_table
16+
from simcore_service_webserver.constants import FRONTEND_APP_DEFAULT
17+
from sqlalchemy import String
18+
from sqlalchemy.dialects import postgresql
19+
20+
21+
@pytest.fixture(scope="session")
22+
def product_name() -> ProductName:
23+
return ProductName(FRONTEND_APP_DEFAULT)
24+
25+
26+
@pytest.fixture
27+
def fake_product_from_db(faker: Faker, product_name: ProductName) -> dict[str, Any]:
28+
server_defaults = {}
29+
for c in products_table.columns:
30+
if c.server_default is not None:
31+
if isinstance(c.type, String):
32+
server_defaults[c.name] = c.server_default.arg
33+
elif isinstance(c.type, postgresql.JSONB):
34+
m = re.match(r"^'(.+)'::jsonb$", c.server_default.arg.text)
35+
if m:
36+
server_defaults[c.name] = json.loads(m.group(1))
37+
return random_product(
38+
name=product_name,
39+
fake=faker,
40+
**server_defaults,
41+
)

services/web/server/tests/unit/isolated/test_products_middlewares.py renamed to services/web/server/tests/unit/isolated/products/test_products_middlewares.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
@pytest.fixture()
26-
def mock_postgres_product_table():
26+
def mock_postgres_product_table() -> list[dict[str, Any]]:
2727
# NOTE: try here your product's host_regex before adding them in the database!
2828
column_defaults: dict[str, Any] = {
2929
c.name: f"{c.server_default.arg}" for c in products.columns if c.server_default
@@ -60,11 +60,12 @@ def mock_postgres_product_table():
6060

6161

6262
@pytest.fixture
63-
def mock_app(mock_postgres_product_table: dict[str, Any]) -> web.Application:
63+
def mock_app(mock_postgres_product_table: list[dict[str, Any]]) -> web.Application:
6464
app = web.Application()
6565

6666
app_products: dict[str, Product] = {
67-
entry["name"]: Product(**entry) for entry in mock_postgres_product_table
67+
product_from_db["name"]: Product.model_validate(product_from_db)
68+
for product_from_db in mock_postgres_product_table
6869
}
6970
default_product_name = next(iter(app_products.keys()))
7071
_set_app_state(app, app_products, default_product_name)

services/web/server/tests/unit/isolated/test_products_model.py renamed to services/web/server/tests/unit/isolated/products/test_products_model.py

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,23 @@
44
# pylint: disable=too-many-arguments
55

66

7-
import json
87
import re
98
from itertools import chain
109
from typing import Any
1110

1211
import pytest
1312
import simcore_service_webserver.products
1413
import sqlalchemy as sa
15-
from faker import Faker
1614
from models_library.basic_regex import TWILIO_ALPHANUMERIC_SENDER_ID_RE
1715
from models_library.products import ProductName
1816
from pydantic import BaseModel, ValidationError
19-
from pytest_simcore.helpers.faker_factories import random_product
2017
from pytest_simcore.pydantic_models import (
2118
assert_validation_model,
2219
walk_model_examples_in_package,
2320
)
2421
from simcore_postgres_database.models.products import products as products_table
25-
from simcore_service_webserver.constants import (
26-
FRONTEND_APP_DEFAULT,
27-
FRONTEND_APPS_AVAILABLE,
28-
)
22+
from simcore_service_webserver.constants import FRONTEND_APPS_AVAILABLE
2923
from simcore_service_webserver.products.models import Product
30-
from sqlalchemy import String
31-
from sqlalchemy.dialects import postgresql
32-
33-
34-
@pytest.fixture(scope="session")
35-
def product_name() -> ProductName:
36-
return ProductName(FRONTEND_APP_DEFAULT)
3724

3825

3926
@pytest.mark.parametrize(
@@ -118,24 +105,6 @@ def test_product_host_regex_with_spaces():
118105
assert product.support_email == "[email protected]"
119106

120107

121-
@pytest.fixture
122-
def fake_product_from_db(faker: Faker, product_name: ProductName) -> dict[str, Any]:
123-
server_defaults = {}
124-
for c in products_table.columns:
125-
if c.server_default is not None:
126-
if isinstance(c.type, String):
127-
server_defaults[c.name] = c.server_default.arg
128-
elif isinstance(c.type, postgresql.JSONB):
129-
m = re.match(r"^'(.+)'::jsonb$", c.server_default.arg.text)
130-
if m:
131-
server_defaults[c.name] = json.loads(m.group(1))
132-
return random_product(
133-
name=product_name,
134-
fake=faker,
135-
**server_defaults,
136-
)
137-
138-
139108
def test_safe_load_empty_blanks_on_string_cols_from_db(
140109
fake_product_from_db: dict[str, Any]
141110
):

0 commit comments

Comments
 (0)