1- """Configuration for unit testing with a postgress fixture
2-
3- - Unit testing of webserver app with a postgress service as fixture
4- - Starts test session by running a postgres container as a fixture (see postgress_service)
5-
6- IMPORTANT: remember that these are still unit-tests!
7- """
8-
9- # nopycln: file
101# pylint: disable=redefined-outer-name
112# pylint: disable=unused-argument
123# pylint: disable=unused-variable
4+ # pylint: disable=too-many-arguments
135
146import asyncio
157import random
3628from aiohttp import web
3729from aiohttp .test_utils import TestClient , TestServer
3830from aiopg .sa import create_engine
39- from aiopg .sa .connection import SAConnection
4031from faker import Faker
4132from models_library .api_schemas_directorv2 .dynamic_services import DynamicServiceGet
4233from models_library .products import ProductName
@@ -716,7 +707,7 @@ async def with_permitted_override_services_specifications(
716707
717708
718709@pytest .fixture
719- async def all_products_names (
710+ async def app_products_names (
720711 asyncpg_engine : AsyncEngine ,
721712) -> AsyncIterable [list [ProductName ]]:
722713 async with asyncpg_engine .connect () as conn :
@@ -767,7 +758,7 @@ async def all_products_names(
767758@pytest .fixture
768759async def all_product_prices (
769760 asyncpg_engine : AsyncEngine ,
770- all_products_names : list [ProductName ],
761+ app_products_names : list [ProductName ],
771762 faker : Faker ,
772763) -> dict [ProductName , Decimal | None ]:
773764 """Initial list of prices for all products"""
@@ -783,7 +774,7 @@ async def all_product_prices(
783774 }
784775
785776 result = {}
786- for product_name in all_products_names :
777+ for product_name in app_products_names :
787778 usd_or_none = product_price .get (product_name )
788779 if usd_or_none is not None :
789780 async with asyncpg_engine .begin () as conn :
@@ -806,23 +797,23 @@ async def all_product_prices(
806797@pytest .fixture
807798async def latest_osparc_price (
808799 all_product_prices : dict [ProductName , Decimal ],
809- _pre_connection : SAConnection ,
800+ asyncpg_engine : AsyncEngine ,
810801) -> Decimal :
811802 """This inserts a new price for osparc in the history
812803 (i.e. the old price of osparc is still in the database)
813804 """
814-
815- usd = await _pre_connection .scalar (
816- products_prices .insert ()
817- .values (
818- product_name = "osparc" ,
819- usd_per_credit = all_product_prices ["osparc" ] + 5 ,
820- comment = "New price for osparc" ,
821- stripe_price_id = "stripe-price-id" ,
822- stripe_tax_rate_id = "stripe-tax-rate-id" ,
805+ async with asyncpg_engine .begin () as conn :
806+ usd = await conn .scalar (
807+ products_prices .insert ()
808+ .values (
809+ product_name = "osparc" ,
810+ usd_per_credit = all_product_prices ["osparc" ] + 5 ,
811+ comment = "New price for osparc" ,
812+ stripe_price_id = "stripe-price-id" ,
813+ stripe_tax_rate_id = "stripe-tax-rate-id" ,
814+ )
815+ .returning (products_prices .c .usd_per_credit )
823816 )
824- .returning (products_prices .c .usd_per_credit )
825- )
826817 assert usd is not None
827818 assert usd != all_product_prices ["osparc" ]
828819 return Decimal (usd )
0 commit comments