|
6 | 6 |
|
7 | 7 | import pytest |
8 | 8 | from aiohttp import web |
9 | | -from aiohttp.test_utils import TestClient, make_mocked_request |
10 | | -from common_library.users_enums import UserRole |
| 9 | +from aiohttp.test_utils import TestClient |
11 | 10 | from models_library.products import ProductName |
12 | | -from pytest_simcore.helpers.webserver_login import UserInfoDict |
13 | | -from servicelib.rest_constants import X_PRODUCT_NAME_HEADER |
14 | | -from simcore_service_webserver.products import products_service, products_web |
15 | | - |
16 | | - |
17 | | -@pytest.fixture(params=["osparc", "tis", "s4l"]) |
18 | | -def product_name(request: pytest.FixtureRequest) -> ProductName: |
19 | | - return request.param |
20 | | - |
21 | | - |
22 | | -@pytest.fixture |
23 | | -def user_role() -> UserRole: |
24 | | - return UserRole.PRODUCT_OWNER |
| 11 | +from simcore_service_webserver.constants import FRONTEND_APP_DEFAULT |
| 12 | +from simcore_service_webserver.products import products_service |
| 13 | +from simcore_service_webserver.products._repository import ProductRepository |
| 14 | +from simcore_service_webserver.products.errors import ProductPriceNotDefinedError |
25 | 15 |
|
26 | 16 |
|
27 | 17 | @pytest.fixture |
28 | 18 | def app( |
29 | | - logged_user: UserInfoDict, |
30 | 19 | client: TestClient, |
31 | 20 | ) -> web.Application: |
32 | | - # TODO: remove client here |
| 21 | + # initialized app |
33 | 22 | assert client.app |
34 | 23 | return client.app |
35 | 24 |
|
36 | 25 |
|
37 | | -async def test_get_credit_amount(product_name: ProductName, app: web.Application): |
38 | | - await products_service.get_credit_amount( |
39 | | - app, dollar_amount=1, product_name=product_name |
40 | | - ) |
41 | | - |
42 | | - |
43 | | -async def test_get_product(product_name: ProductName, app: web.Application): |
44 | | - product = products_service.get_product(app, product_name=product_name) |
45 | | - assert product.name == product_name |
| 26 | +@pytest.fixture |
| 27 | +def default_product_name() -> ProductName: |
| 28 | + return FRONTEND_APP_DEFAULT |
46 | 29 |
|
47 | 30 |
|
48 | | -async def test_get_product_stripe_info(product_name: ProductName, app: web.Application): |
49 | | - await products_service.get_product_stripe_info(app, product_name=product_name) |
| 31 | +async def test_get_product(app: web.Application, default_product_name: ProductName): |
50 | 32 |
|
| 33 | + product = products_service.get_product(app, product_name=default_product_name) |
| 34 | + assert product.name == default_product_name |
51 | 35 |
|
52 | | -async def test_get_product_ui(product_name: ProductName, app: web.Application): |
| 36 | + products = products_service.list_products(app) |
| 37 | + assert len(products) == 1 |
| 38 | + assert products[0] == product |
53 | 39 |
|
54 | | - await products_service.get_product_ui(app, product_name=product_name) |
55 | 40 |
|
| 41 | +async def test_get_product_ui(app: web.Application, default_product_name: ProductName): |
| 42 | + # this feature is currently setup from adminer by an operator |
56 | 43 |
|
57 | | -async def test_list_products(app: web.Application): |
58 | | - products_service.list_products(app) |
| 44 | + repo = ProductRepository.create_from_app(app) |
| 45 | + ui = await products_service.get_product_ui(repo, product_name=default_product_name) |
| 46 | + assert ui == {}, "Expected empty by default" |
59 | 47 |
|
60 | 48 |
|
61 | | -@pytest.fixture |
62 | | -def fake_request( |
63 | | - app: web.Application, |
64 | | - product_name: ProductName, |
65 | | -) -> web.Request: |
66 | | - return make_mocked_request( |
67 | | - "GET", |
68 | | - "/fake", |
69 | | - headers={X_PRODUCT_NAME_HEADER: product_name}, |
70 | | - app=app, |
71 | | - ) |
72 | | - |
73 | | - |
74 | | -async def test_get_current_product( |
75 | | - product_name: ProductName, fake_request: web.Request |
| 49 | +async def test_get_product_stripe_info( |
| 50 | + app: web.Application, default_product_name: ProductName |
76 | 51 | ): |
77 | | - product = products_web.get_current_product(fake_request) |
78 | | - assert product.name == product_name |
79 | | - |
| 52 | + # this feature is currently setup from adminer by an operator |
80 | 53 |
|
81 | | -async def test_get_current_product_credit_price_info( |
82 | | - product_name: ProductName, fake_request: web.Request |
83 | | -): |
84 | | - await products_web.get_current_product_credit_price_info(fake_request) |
| 54 | + # default is not configured |
| 55 | + with pytest.raises(ValueError, match=default_product_name): |
| 56 | + await products_service.get_product_stripe_info( |
| 57 | + app, product_name=default_product_name |
| 58 | + ) |
85 | 59 |
|
86 | 60 |
|
87 | | -async def test_get_product_name( |
88 | | - product_name: ProductName, |
89 | | - fake_request: web.Request, |
| 61 | +async def test_get_credit_amount( |
| 62 | + app: web.Application, default_product_name: ProductName |
90 | 63 | ): |
91 | | - assert products_web.get_product_name(fake_request) == product_name |
92 | | - |
| 64 | + # this feature is currently setup from adminer by an operator |
93 | 65 |
|
94 | | -async def test_get_product_template_path( |
95 | | - product_name: ProductName, |
96 | | - fake_request: web.Request, |
97 | | -): |
98 | | - path = await products_web.get_product_template_path( |
99 | | - fake_request, filename="template_name.jinja" |
100 | | - ) |
101 | | - assert path |
| 66 | + # default is not configured |
| 67 | + with pytest.raises(ProductPriceNotDefinedError): |
| 68 | + await products_service.get_credit_amount( |
| 69 | + app, dollar_amount=1, product_name=default_product_name |
| 70 | + ) |
0 commit comments