Skip to content

Commit 0ea1dbe

Browse files
authored
Merge branch 'master' into pr-osparc-agent-permissions-bump
2 parents b23a3cc + d17c117 commit 0ea1dbe

File tree

61 files changed

+786
-488
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+786
-488
lines changed

packages/postgres-database/src/simcore_postgres_database/aiopg_errors.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
SEE https://www.postgresql.org/docs/current/errcodes-appendix.html
2222
"""
2323

24+
import warnings
25+
2426
# NOTE: psycopg2.errors are created dynamically
2527
# pylint: disable=no-name-in-module
2628
from psycopg2 import (
@@ -46,6 +48,19 @@
4648

4749
assert issubclass(UniqueViolation, IntegrityError) # nosec
4850

51+
52+
warnings.warn(
53+
(
54+
"DEPRECATED: The aiopg DBAPI exceptions in this module are no longer used. "
55+
"Please use exceptions from the `sqlalchemy.exc` module instead. "
56+
"See https://docs.sqlalchemy.org/en/21/core/exceptions.html for details. "
57+
"This change is part of the migration to SQLAlchemy async support with asyncpg. "
58+
"See migration issue: https://github.com/ITISFoundation/osparc-simcore/issues/4529"
59+
),
60+
DeprecationWarning,
61+
stacklevel=2,
62+
)
63+
4964
__all__: tuple[str, ...] = (
5065
"CheckViolation",
5166
"DatabaseError",

packages/pytest-simcore/src/pytest_simcore/helpers/httpx_assert_checks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,5 @@ def _do_assert_error(
8585

8686
for msg in list_expected_msg:
8787
assert any(
88-
re.search(msg, e) for e in details
88+
msg == e or re.search(msg, e) for e in details
8989
), f"could not find {msg=} in {details=}"

services/api-server/Makefile

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,5 @@ test-api: ## Runs schemathesis against development server (NOTE: make up-devel f
9595
"$(APP_URL)/api/v0/openapi.json"
9696

9797

98-
test-pacts: guard-PACT_BROKER_USERNAME guard-PACT_BROKER_PASSWORD guard-PACT_BROKER_URL _check_venv_active ## Test pacts
98+
test-pacts: guard-PACT_BROKER_USERNAME guard-PACT_BROKER_PASSWORD guard-PACT_BROKER_URL _check_venv_active ## Test pacts. Usage: PACT_BROKER_USERNAME=your_username PACT_BROKER_PASSWORD=your_password PACT_BROKER_URL=your_broker_url make test-pacts
9999
pytest tests/unit/pact_broker/test*
100-
101-
# Usage:
102-
# PACT_BROKER_USERNAME=your_username \
103-
# PACT_BROKER_PASSWORD=your_password \
104-
# PACT_BROKER_URL=your_broker_url \
105-
# make test-pacts

services/api-server/tests/unit/conftest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -683,11 +683,11 @@ def mocked_catalog_rpc_api(
683683
"""
684684
Mocks the catalog's simcore service RPC API for testing purposes.
685685
"""
686-
from servicelib.rabbitmq.rpc_interfaces.catalog import (
687-
services as catalog_rpc, # keep import here
686+
from servicelib.rabbitmq.rpc_interfaces.catalog import ( # noqa: PLC0415; keep import here
687+
services as catalog_rpc,
688688
)
689689

690-
mocks = {}
690+
mocks: dict[str, MockType] = {}
691691

692692
# Get all callable methods from the side effects class that are not built-ins
693693
side_effect_methods = [
@@ -726,8 +726,8 @@ def mocked_directorv2_rpc_api(
726726
"""
727727
Mocks the director-v2's simcore service RPC API for testing purposes.
728728
"""
729-
from servicelib.rabbitmq.rpc_interfaces.director_v2 import (
730-
computations_tasks as directorv2_rpc, # keep import here
729+
from servicelib.rabbitmq.rpc_interfaces.director_v2 import ( # noqa: PLC0415; keep import here
730+
computations_tasks as directorv2_rpc,
731731
)
732732

733733
mocks = {}
Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
11
# Contract testing (PACT)
22

3-
Maintainer @matusdrobuliak66
3+
- Maintainer @matusdrobuliak66
4+
5+
## How to run this test as a provider?
46

57
```bash
6-
PACT_BROKER_URL=<fill-broker-url> PACT_BROKER_USERNAME=<fill-username> PACT_BROKER_PASSWORD=<fill-secret> make test-pacts
8+
PACT_BROKER_URL=<fill-broker-url> PACT_BROKER_USERNAME=<fill-username> PACT_BROKER_PASSWORD=<fill-secret>
9+
10+
make test-pacts
711
```
812

9-
## Install and Publish new contract to Broker
13+
## How to run this test locally?
14+
15+
- Still not implemented
16+
- The idea would be use local copies of the pacts (see services/api-server/tests/unit/pact_broker/pacts/*.json) instead of reaching the pact server for them.
17+
18+
## How to install and Publish new contract to Broker?
19+
1020
Contracts are generated by Consumer (ex. Sim4Life)
11-
TODO: add reference to Sim4life repo where they can be generated
12-
#### Install
21+
22+
### Install
23+
1324
```bash
1425
npm install @pact-foundation/pact-cli
1526
```
27+
1628
#### Publish
29+
1730
```bash
1831
pact-broker publish ./pacts/05_licensed_items.json --tag licensed_items --consumer-app-version 8.2.1 --broker-base-url=<fill-broker-url> --broker-username=<fill-username> --broker-password=<fill-secret>
1932
```

services/api-server/tests/unit/pact_broker/conftest.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ def pytest_addoption(parser: pytest.Parser) -> None:
3737
)
3838

3939

40-
@pytest.fixture()
40+
@pytest.fixture
4141
def pact_broker_credentials(
4242
request: pytest.FixtureRequest,
43-
):
43+
) -> tuple[str, str, str]:
4444
# Get credentials from either CLI arguments or environment variables
4545
broker_url = request.config.getoption("--broker-url", None) or os.getenv(
4646
"PACT_BROKER_URL"
@@ -64,18 +64,20 @@ def pact_broker_credentials(
6464
]
6565

6666
if missing:
67-
pytest.fail(
68-
f"Missing Pact Broker credentials: {', '.join(missing)}. Set them as environment variables or pass them as CLI arguments."
67+
pytest.skip(
68+
reason="This test runs only if pact broker credentials are provided. "
69+
f"Missing Pact Broker credentials: {', '.join(missing)}. "
70+
"Set them as environment variables or pass them as CLI arguments. "
6971
)
7072

71-
return broker_url, broker_username, broker_password
72-
73+
assert broker_url
74+
assert broker_username
75+
assert broker_password
7376

74-
def mock_get_current_identity() -> Identity:
75-
return Identity(user_id=1, product_name="osparc", email="[email protected]")
77+
return broker_url, broker_username, broker_password
7678

7779

78-
@pytest.fixture()
80+
@pytest.fixture
7981
def running_test_server_url(
8082
app: FastAPI,
8183
):
@@ -84,8 +86,12 @@ def running_test_server_url(
8486
The 'mocked_catalog_service' fixture ensures the function is already
8587
patched by the time we start the server.
8688
"""
89+
8790
# Override
88-
app.dependency_overrides[get_current_identity] = mock_get_current_identity
91+
def _mock_get_current_identity() -> Identity:
92+
return Identity(user_id=1, product_name="osparc", email="[email protected]")
93+
94+
app.dependency_overrides[get_current_identity] = _mock_get_current_identity
8995

9096
port = unused_port()
9197
base_url = f"http://localhost:{port}"
@@ -106,5 +112,6 @@ def running_test_server_url(
106112

107113
yield base_url # , before_server_start
108114

115+
app.dependency_overrides.pop(get_current_identity, None)
109116
server.should_exit = True
110117
thread.join()

services/api-server/tests/unit/pact_broker/test_pact_checkout_release.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# pylint: disable=too-many-arguments
55

66

7-
import os
7+
from collections.abc import Iterable
88

99
import pytest
1010
from fastapi import FastAPI
@@ -18,13 +18,9 @@
1818
from simcore_service_api_server.api.dependencies.resource_usage_tracker_rpc import (
1919
get_resource_usage_tracker_client,
2020
)
21-
from simcore_service_api_server.api.dependencies.webserver_rpc import (
22-
get_wb_api_rpc_client,
23-
)
2421
from simcore_service_api_server.services_rpc.resource_usage_tracker import (
2522
ResourceUsageTrackerClient,
2623
)
27-
from simcore_service_api_server.services_rpc.wb_api_server import WbApiRpcClient
2824

2925
# Fake response based on values from 01_checkout_release.json
3026
EXPECTED_CHECKOUT = LicensedItemCheckoutRpcGet.model_validate(
@@ -64,14 +60,9 @@
6460
@pytest.fixture
6561
async def mock_wb_api_server_rpc(
6662
app: FastAPI,
67-
mocker: MockerFixture,
63+
mocked_app_rpc_dependencies: None,
6864
mock_handler_in_licenses_rpc_interface: HandlerMockFactory,
6965
) -> None:
70-
from servicelib.rabbitmq.rpc_interfaces.webserver.v1 import WebServerRpcClient
71-
72-
app.dependency_overrides[get_wb_api_rpc_client] = lambda: WbApiRpcClient(
73-
_rpc_client=mocker.MagicMock(spec=WebServerRpcClient),
74-
)
7566

7667
mock_handler_in_licenses_rpc_interface(
7768
"checkout_licensed_item_for_wallet", return_value=EXPECTED_CHECKOUT
@@ -83,26 +74,28 @@ async def mock_wb_api_server_rpc(
8374

8475

8576
@pytest.fixture
86-
async def mock_rut_server_rpc(app: FastAPI, mocker: MockerFixture) -> None:
87-
from servicelib.rabbitmq import RabbitMQRPCClient
77+
def mock_rut_server_rpc(app: FastAPI, mocker: MockerFixture) -> Iterable[None]:
78+
import simcore_service_api_server.services_rpc.resource_usage_tracker # noqa: PLC0415
79+
from servicelib.rabbitmq import RabbitMQRPCClient # noqa: PLC0415
8880

8981
app.dependency_overrides[get_resource_usage_tracker_client] = (
9082
lambda: ResourceUsageTrackerClient(
9183
_client=mocker.MagicMock(spec=RabbitMQRPCClient)
9284
)
9385
)
9486

95-
mocker.patch(
96-
"simcore_service_api_server.services_rpc.resource_usage_tracker._get_licensed_item_checkout",
87+
mocker.patch.object(
88+
simcore_service_api_server.services_rpc.resource_usage_tracker,
89+
"_get_licensed_item_checkout",
9790
return_value=EXPECTED_CHECKOUT,
9891
)
9992

93+
yield None
10094

101-
@pytest.mark.skipif(
102-
not os.getenv("PACT_BROKER_URL"),
103-
reason="This test runs only if PACT_BROKER_URL is provided",
104-
)
105-
def test_provider_against_pact(
95+
app.dependency_overrides.pop(get_resource_usage_tracker_client, None)
96+
97+
98+
def test_osparc_api_server_checkout_release_pact(
10699
pact_broker_credentials: tuple[str, str, str],
107100
mock_wb_api_server_rpc: None,
108101
mock_rut_server_rpc: None,
@@ -127,7 +120,7 @@ def test_provider_against_pact(
127120

128121
# NOTE: If you want to filter/test against specific contract use tags
129122
verifier = broker_builder.consumer_tags(
130-
"checkout_release" # <-- Here you define which pact to verify
123+
"checkout_release" # NOTE: Here you define which pact to verify
131124
).build()
132125

133126
# Set API version and run verification

services/api-server/tests/unit/pact_broker/test_pact_licensed_items.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# pylint: disable=unused-variable
44
# pylint: disable=too-many-arguments
55

6-
import os
76

87
import pytest
98
from fastapi import FastAPI
@@ -146,11 +145,7 @@ async def mock_wb_api_server_rpc(
146145
)
147146

148147

149-
@pytest.mark.skipif(
150-
not os.getenv("PACT_BROKER_URL"),
151-
reason="This test runs only if PACT_BROKER_URL is provided",
152-
)
153-
def test_provider_against_pact(
148+
def test_osparc_api_server_licensed_items_pact(
154149
pact_broker_credentials: tuple[str, str, str],
155150
mock_wb_api_server_rpc: None,
156151
running_test_server_url: str,
@@ -174,7 +169,7 @@ def test_provider_against_pact(
174169

175170
# NOTE: If you want to filter/test against specific contract use tags
176171
verifier = broker_builder.consumer_tags(
177-
"licensed_items" # <-- Here you define which pact to verify
172+
"licensed_items" # NOTE: Here you define which pact to verify
178173
).build()
179174

180175
# Set API version and run verification

services/payments/src/simcore_service_payments/db/payments_methods_repo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import datetime
22

3-
import simcore_postgres_database.aiopg_errors as db_errors
43
import sqlalchemy as sa
54
from arrow import utcnow
65
from models_library.api_schemas_payments.errors import (
@@ -16,6 +15,7 @@
1615
InitPromptAckFlowState,
1716
payments_methods,
1817
)
18+
from sqlalchemy.exc import IntegrityError
1919

2020
from ..models.db import PaymentsMethodsDB
2121
from .base import BaseRepository
@@ -42,7 +42,7 @@ async def insert_init_payment_method(
4242
)
4343
return payment_method_id
4444

45-
except db_errors.UniqueViolation as err:
45+
except IntegrityError as err:
4646
raise PaymentMethodUniqueViolationError(
4747
payment_method_id=payment_method_id
4848
) from err

services/payments/src/simcore_service_payments/db/payments_transactions_repo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
from models_library.users import UserID
1414
from models_library.wallets import WalletID
1515
from pydantic import HttpUrl, PositiveInt, TypeAdapter
16-
from simcore_postgres_database import aiopg_errors as pg_errors
1716
from simcore_postgres_database.models.payments_transactions import (
1817
PaymentTransactionState,
1918
payments_transactions,
2019
)
20+
from sqlalchemy.exc import IntegrityError
2121

2222
from ..models.db import PaymentsTransactionsDB
2323
from .base import BaseRepository
@@ -58,7 +58,7 @@ async def insert_init_payment_transaction(
5858
)
5959
)
6060
return payment_id
61-
except pg_errors.UniqueViolation as exc:
61+
except IntegrityError as exc:
6262
raise PaymentAlreadyExistsError(payment_id=f"{payment_id}") from exc
6363

6464
async def update_ack_payment_transaction(

0 commit comments

Comments
 (0)