7
7
import pytest
8
8
from aiohttp import web
9
9
from aiohttp .test_utils import TestServer
10
+ from models_library .groups import GroupID
10
11
from models_library .products import ProductName
11
- from simcore_service_webserver .products import products_service
12
+ from pydantic import ValidationError
13
+ from servicelib .exceptions import InvalidConfig
14
+ from simcore_postgres_database .utils_products_prices import ProductPriceInfo
15
+ from simcore_service_webserver .products import _service , products_service
12
16
from simcore_service_webserver .products ._repository import ProductRepository
13
17
from simcore_service_webserver .products .errors import (
14
18
MissingStripeConfigError ,
15
19
ProductPriceNotDefinedError ,
20
+ ProductTemplateNotFoundError ,
16
21
)
22
+ from simcore_service_webserver .products .models import Product
17
23
18
24
19
25
@pytest .fixture
@@ -25,6 +31,27 @@ def app(
25
31
return web_server .app
26
32
27
33
34
+ async def test_load_products (app : web .Application ):
35
+ products = await _service .load_products (app )
36
+ assert isinstance (products , list )
37
+ assert all (isinstance (product , Product ) for product in products )
38
+
39
+
40
+ async def test_load_products_validation_error (app : web .Application , mocker ):
41
+ mock_repo = mocker .patch (
42
+ "simcore_service_webserver.products._service.ProductRepository.create_from_app"
43
+ )
44
+ mock_repo .return_value .list_products .side_effect = ValidationError ("Invalid data" )
45
+
46
+ with pytest .raises (InvalidConfig , match = "Invalid product configuration in db" ):
47
+ await _service .load_products (app )
48
+
49
+
50
+ async def test_get_default_product_name (app : web .Application ):
51
+ default_product_name = await _service .get_default_product_name (app )
52
+ assert isinstance (default_product_name , ProductName )
53
+
54
+
28
55
async def test_get_product (app : web .Application , default_product_name : ProductName ):
29
56
30
57
product = products_service .get_product (app , product_name = default_product_name )
@@ -65,3 +92,31 @@ async def test_get_credit_amount(
65
92
await products_service .get_credit_amount (
66
93
app , dollar_amount = 1 , product_name = default_product_name
67
94
)
95
+
96
+
97
+ async def test_list_products_names (app : web .Application ):
98
+ product_names = await products_service .list_products_names (app )
99
+ assert isinstance (product_names , list )
100
+ assert all (isinstance (name , ProductName ) for name in product_names )
101
+
102
+
103
+ async def test_get_credit_price_info (
104
+ app : web .Application , default_product_name : ProductName
105
+ ):
106
+ price_info = await _service .get_credit_price_info (
107
+ app , product_name = default_product_name
108
+ )
109
+ assert price_info is None or isinstance (price_info , ProductPriceInfo )
110
+
111
+
112
+ async def test_get_template_content (app : web .Application ):
113
+ template_name = "some_template"
114
+ with pytest .raises (ProductTemplateNotFoundError ):
115
+ await _service .get_template_content (app , template_name = template_name )
116
+
117
+
118
+ async def test_auto_create_products_groups (app : web .Application ):
119
+ groups = await _service .auto_create_products_groups (app )
120
+ assert isinstance (groups , dict )
121
+ assert all (isinstance (name , ProductName ) for name in groups .keys ())
122
+ assert all (isinstance (group_id , GroupID ) for group_id in groups .values ())
0 commit comments