Skip to content

Commit

Permalink
cleanup network legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
giancarloromeo committed Nov 19, 2024
1 parent dcdc863 commit 9f0a938
Show file tree
Hide file tree
Showing 16 changed files with 39 additions and 99 deletions.

This file was deleted.

39 changes: 0 additions & 39 deletions packages/common-library/tests/test_pydantic_networks_extension.py

This file was deleted.

6 changes: 2 additions & 4 deletions packages/models-library/src/models_library/rest_pagination.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Annotated, Final, Generic, TypeAlias, TypeVar

from common_library.pydantic_networks_extension import AnyHttpUrlLegacy
from pydantic import (
AnyHttpUrl,
BaseModel,
BeforeValidator,
ConfigDict,
Expand Down Expand Up @@ -100,9 +100,7 @@ class PageLinks(
PageRefs[
Annotated[
str,
BeforeValidator(
lambda x: str(TypeAdapter(AnyHttpUrlLegacy).validate_python(x))
),
BeforeValidator(lambda x: str(TypeAdapter(AnyHttpUrl).validate_python(x))),
]
]
):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from math import ceil
from typing import Any, Protocol, runtime_checkable
from typing_extensions import TypedDict

from common_library.pydantic_networks_extension import AnyHttpUrlLegacy
from pydantic import TypeAdapter
from pydantic import AnyHttpUrl, TypeAdapter
from typing_extensions import TypedDict

from .rest_pagination import PageLinks, PageMetaInfoLimitOffset

Expand Down Expand Up @@ -42,7 +41,7 @@ def _replace_query(url: _URLType, query: dict[str, Any]) -> str:
new_url = url.replace_query_params(**query)

new_url_str = f"{new_url}"
return f"{TypeAdapter(AnyHttpUrlLegacy).validate_python(new_url_str)}"
return f"{TypeAdapter(AnyHttpUrl).validate_python(new_url_str)}"


class PageDict(TypedDict):
Expand Down Expand Up @@ -70,7 +69,9 @@ def paginate_data(
"""
last_page = ceil(total / limit) - 1

data = [item.model_dump() if hasattr(item, "model_dump") else item for item in chunk]
data = [
item.model_dump() if hasattr(item, "model_dump") else item for item in chunk
]

return PageDict(
_meta=PageMetaInfoLimitOffset(
Expand Down
7 changes: 2 additions & 5 deletions packages/settings-library/src/settings_library/ssm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Annotated

from common_library.pydantic_networks_extension import AnyHttpUrlLegacy
from pydantic import BeforeValidator, Field, SecretStr, TypeAdapter
from pydantic import AnyHttpUrl, BeforeValidator, Field, SecretStr, TypeAdapter
from pydantic_settings import SettingsConfigDict

from .base import BaseCustomSettings
Expand All @@ -12,9 +11,7 @@ class SSMSettings(BaseCustomSettings):
SSM_ENDPOINT: (
Annotated[
str,
BeforeValidator(
lambda x: str(TypeAdapter(AnyHttpUrlLegacy).validate_python(x))
),
BeforeValidator(lambda x: str(TypeAdapter(AnyHttpUrl).validate_python(x))),
]
| None
) = Field(default=None, description="do not define if using standard AWS")
Expand Down
5 changes: 2 additions & 3 deletions services/agent/src/simcore_service_agent/core/settings.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from datetime import timedelta

from common_library.pydantic_networks_extension import AnyHttpUrlLegacy
from models_library.basic_types import BootModeEnum, LogLevel
from pydantic import AliasChoices, Field, field_validator
from pydantic import AliasChoices, AnyHttpUrl, Field, field_validator
from servicelib.logging_utils_filtering import LoggerName, MessageSubstring
from settings_library.base import BaseCustomSettings
from settings_library.r_clone import S3Provider
Expand Down Expand Up @@ -43,7 +42,7 @@ class ApplicationSettings(BaseCustomSettings, MixinLoggingSettings):
AGENT_VOLUMES_CLEANUP_TARGET_SWARM_STACK_NAME: str = Field(
..., description="Exactly the same as director-v2's `SWARM_STACK_NAME` env var"
)
AGENT_VOLUMES_CLEANUP_S3_ENDPOINT: AnyHttpUrlLegacy
AGENT_VOLUMES_CLEANUP_S3_ENDPOINT: AnyHttpUrl
AGENT_VOLUMES_CLEANUP_S3_ACCESS_KEY: str
AGENT_VOLUMES_CLEANUP_S3_SECRET_KEY: str
AGENT_VOLUMES_CLEANUP_S3_BUCKET: str
Expand Down
6 changes: 3 additions & 3 deletions services/agent/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


import pytest
from common_library.pydantic_networks_extension import HttpUrlLegacy
from common_library.pydantic_networks_extension import HttpUrl
from faker import Faker
from models_library.basic_types import BootModeEnum
from moto.server import ThreadedMotoServer
Expand Down Expand Up @@ -65,8 +65,8 @@ def mock_environment(


@pytest.fixture(scope="module")
def mocked_s3_server_url(mocked_aws_server: ThreadedMotoServer) -> HttpUrlLegacy:
def mocked_s3_server_url(mocked_aws_server: ThreadedMotoServer) -> HttpUrl:
# pylint: disable=protected-access
return TypeAdapter(HttpUrlLegacy).validate_python(
return TypeAdapter(HttpUrl).validate_python(
f"http://{mocked_aws_server._ip_address}:{mocked_aws_server._port}", # noqa: SLF001
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
from collections.abc import Callable

from fastapi import APIRouter, Depends
from pydantic import BaseModel
from common_library.pydantic_networks_extension import HttpUrlLegacy
from pydantic import BaseModel, HttpUrl

from .._meta import API_VERSION, PROJECT_NAME
from ._dependencies import get_reverse_url_mapper
Expand All @@ -21,7 +20,7 @@
class _Meta(BaseModel):
name: str
version: str
docs_url: HttpUrlLegacy
docs_url: HttpUrl


#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import logging
from urllib import parse

from common_library.pydantic_networks_extension import HttpUrlLegacy
from cryptography.fernet import Fernet, InvalidToken
from models_library.invitations import InvitationContent, InvitationInputs
from models_library.products import ProductName
Expand Down Expand Up @@ -67,7 +66,7 @@ def _build_link(
# Adds query to fragment
base_url = f"{base_url}/"
url = URL(base_url).replace(fragment=f"{r}")
return TypeAdapter(HttpUrlLegacy).validate_python(f"{url}")
return TypeAdapter(HttpUrl).validate_python(f"{url}")


def _fernet_encrypt_as_urlsafe_code(
Expand Down
6 changes: 3 additions & 3 deletions services/invitations/tests/unit/api/test_api_invitations.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_check_valid_invitation(
# check invitation_url
response = client.post(
f"/{API_VTAG}/invitations:extract",
json={"invitation_url": invitation_url},
json={"invitation_url": f"{invitation_url}"},
auth=basic_auth,
)
assert response.status_code == 200, f"{response.json()=}"
Expand Down Expand Up @@ -130,7 +130,7 @@ def test_check_invalid_invitation_with_different_secret(
# check invitation_url
response = client.post(
f"/{API_VTAG}/invitations:extract",
json={"invitation_url": invitation_url},
json={"invitation_url": f"{invitation_url}"},
auth=basic_auth,
)
assert (
Expand Down Expand Up @@ -173,7 +173,7 @@ def test_check_invalid_invitation_with_wrong_code(
default_product=default_product,
)

invitation_url_with_invalid_code = invitation_url[:-3]
invitation_url_with_invalid_code = f"{invitation_url}"[:-3]

# check invitation_url
response = client.post(
Expand Down
12 changes: 9 additions & 3 deletions services/invitations/tests/unit/test_invitations.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def test_create_and_decrypt_invitation(
base_url=faker.url(),
default_product=default_product,
)
assert URL(invitation_link).fragment
query_params = dict(parse.parse_qsl((URL(URL(invitation_link).fragment).query)))
assert URL(f"{invitation_link}").fragment
query_params = dict(parse.parse_qsl(URL(URL(f"{invitation_link}").fragment).query))

# will raise TokenError or ValidationError
invitation = decrypt_invitation(
Expand Down Expand Up @@ -196,4 +196,10 @@ class OtherModel(BaseModel):


def test_aliases_uniqueness():
assert not [item for item, count in Counter([field.alias for field in _ContentWithShortNames.model_fields.values()]).items() if count > 1] #nosec
assert not [
item
for item, count in Counter(
[field.alias for field in _ContentWithShortNames.model_fields.values()]
).items()
if count > 1
] # nosec
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from functools import cached_property

from common_library.pydantic_networks_extension import HttpUrlLegacy
from models_library.basic_types import NonNegativeDecimal
from pydantic import (
AliasChoices,
EmailStr,
Field,
HttpUrl,
PositiveFloat,
SecretStr,
TypeAdapter,
Expand Down Expand Up @@ -69,7 +69,7 @@ class ApplicationSettings(_BaseApplicationSettings):
These settings includes extra configuration for the http-API
"""

PAYMENTS_GATEWAY_URL: HttpUrlLegacy = Field(
PAYMENTS_GATEWAY_URL: HttpUrl = Field(
..., description="Base url to the payment gateway"
)

Expand Down Expand Up @@ -134,7 +134,7 @@ class ApplicationSettings(_BaseApplicationSettings):
description="settings for postgres service",
)

PAYMENTS_STRIPE_URL: HttpUrlLegacy = Field(
PAYMENTS_STRIPE_URL: HttpUrl = Field(
..., description="Base url to the payment Stripe"
)
PAYMENTS_STRIPE_API_SECRET: SecretStr = Field(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def setup_payments_gateway(app: FastAPI):

# create
api = PaymentsGatewayApi.from_client_kwargs(
base_url=settings.PAYMENTS_GATEWAY_URL,
base_url=f"{settings.PAYMENTS_GATEWAY_URL}",
headers={"accept": "application/json"},
auth=_GatewayApiAuth(
secret=settings.PAYMENTS_GATEWAY_API_SECRET.get_secret_value()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def setup_stripe(app: FastAPI):
assert app.state # nosec
settings: ApplicationSettings = app.state.settings
api = StripeApi.from_client_kwargs(
base_url=settings.PAYMENTS_STRIPE_URL,
base_url=f"{settings.PAYMENTS_STRIPE_URL}",
auth=_StripeBearerAuth(settings.PAYMENTS_STRIPE_API_SECRET.get_secret_value()),
)
if settings.PAYMENTS_TRACING:
Expand Down
4 changes: 2 additions & 2 deletions services/payments/tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def mock_payments_gateway_service_api_base(app: FastAPI) -> Iterator[MockRouter]
settings: ApplicationSettings = app.state.settings

with respx.mock(
base_url=settings.PAYMENTS_GATEWAY_URL,
base_url=f"{settings.PAYMENTS_GATEWAY_URL}",
assert_all_called=False,
assert_all_mocked=True, # IMPORTANT: KEEP always True!
) as respx_mock:
Expand Down Expand Up @@ -410,7 +410,7 @@ def mock_payments_stripe_api_base(app: FastAPI) -> Iterator[MockRouter]:
settings: ApplicationSettings = app.state.settings

with respx.mock(
base_url=settings.PAYMENTS_STRIPE_URL,
base_url=f"{settings.PAYMENTS_STRIPE_URL}",
assert_all_called=False,
assert_all_mocked=True, # IMPORTANT: KEEP always True!
) as respx_mock:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ async def test_one_time_payment_workflow(
)

app_settings: ApplicationSettings = app.state.settings
assert submission_link.host == URL(app_settings.PAYMENTS_GATEWAY_URL).host
assert submission_link.host == URL(f"{app_settings.PAYMENTS_GATEWAY_URL}").host

# cancel
payment_canceled = await payment_gateway_api.cancel_payment(payment_initiated)
Expand Down Expand Up @@ -160,7 +160,7 @@ async def test_payment_methods_workflow(
)

app_settings: ApplicationSettings = app.state.settings
assert form_link.host == URL(app_settings.PAYMENTS_GATEWAY_URL).host
assert form_link.host == URL(f"{app_settings.PAYMENTS_GATEWAY_URL}").host

# CRUD
payment_method_id = initiated.payment_method_id
Expand Down

0 comments on commit 9f0a938

Please sign in to comment.