Skip to content

Commit

Permalink
fixes with query params
Browse files Browse the repository at this point in the history
  • Loading branch information
jaddek committed Feb 14, 2025
1 parent 3363211 commit fc3f0c2
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 72 deletions.
14 changes: 6 additions & 8 deletions src/jpy_tillo_sdk/domain/brand/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ class QueryParams(QP):
category: Optional[str] = None

@property
def query(self) -> QueryParams:
return self.QueryParams(**(self._query or {}))

def query(self) -> QueryParams|None:
return self._query

class TemplateListEndpoint(Endpoint):
_method = "GET"
Expand All @@ -35,9 +34,8 @@ def get_sign_attrs(self) -> tuple:
return (self.brand,) if self.brand is not None else ()

@property
def query(self) -> QueryParams:
return self.QueryParams(**(self._query or {}))

def query(self) -> QueryParams|None:
return self._query

class TemplateEndpoint(Endpoint):
_method = "GET"
Expand All @@ -53,5 +51,5 @@ def get_sign_attrs(self) -> tuple:
return (self.brand,) if self.brand else ()

@property
def query(self) -> QueryParams:
return self.QueryParams(**(self._query or {}))
def query(self) -> QueryParams|None:
return self._query
8 changes: 7 additions & 1 deletion src/jpy_tillo_sdk/domain/digital_card/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class FulfilmentParametersForRewardPassUsingUrl:
personalisation: Optional[Union[Personalisation, PersonalisationExtended]] = None

def get_sign_attrs(self) -> tuple:

if self.client_request_id and self.brand and self.face_value:
return (
self.client_request_id,
Expand Down Expand Up @@ -122,6 +121,9 @@ class QueryParams(QP):
def get_sign_attrs(self) -> tuple:
return (self.brand,) if self.brand is not None else ()

@property
def query(self) -> QueryParams|None:
return self._query

class CancelDigitalCodeEndpoint(Endpoint):
_method: str = "DELETE"
Expand Down Expand Up @@ -284,3 +286,7 @@ class QueryParams(QP):

def get_sign_attrs(self) -> tuple:
return ()

@property
def query(self) -> QueryParams|None:
return self._query
4 changes: 4 additions & 0 deletions src/jpy_tillo_sdk/domain/float/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ class CheckFloatsEndpoint(Endpoint):
@dataclass(frozen=True)
class QueryParams(QP):
currency: Optional[Currency] = None

@property
def query(self) -> QueryParams|None:
return self._query
2 changes: 1 addition & 1 deletion src/jpy_tillo_sdk/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def sign_attrs(self) -> Optional[tuple]:
return self._sign_attrs

@property
def query(self) -> QP:
def query(self) -> QP|None:
return self._query

@property
Expand Down
101 changes: 39 additions & 62 deletions tests/domain/brand/test_brand_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,21 @@
TemplateListEndpoint,
TemplateEndpoint,
)
from jpy_tillo_sdk.endpoint import QP
from jpy_tillo_sdk.enums import Domains
from jpy_tillo_sdk.http_methods import HttpMethods


@pytest.fixture
def brand_endpoint():
return BrandEndpoint()
def test_brand_endpoint():
endpoint = BrandEndpoint()


@pytest.fixture
def brand_endpoint_query_params():
return BrandEndpoint.QueryParams()


@pytest.fixture
def template_list_endpoint():
return TemplateListEndpoint()


@pytest.fixture
def template_endpoint():
return TemplateEndpoint()


def test_brand_endpoint(brand_endpoint):
assert brand_endpoint.method == HttpMethods.GET.value
assert brand_endpoint.endpoint == Domains.BRANDS.value
assert brand_endpoint.route == "/api/v2/" + Domains.BRANDS.value
assert isinstance(brand_endpoint.query, QP)
assert brand_endpoint.body == {}
assert brand_endpoint.sign_attrs is None
assert brand_endpoint.is_body_not_empty() is False
assert brand_endpoint.params == {}
assert endpoint.method == HttpMethods.GET.value
assert endpoint.endpoint == Domains.BRANDS.value
assert endpoint.route == "/api/v2/" + Domains.BRANDS.value
assert endpoint.query is None
assert endpoint.body == {}
assert endpoint.sign_attrs is None
assert endpoint.is_body_not_empty() is False
assert endpoint.params == {}


@pytest.mark.parametrize(
Expand All @@ -59,20 +40,13 @@ def test_brand_endpoint(brand_endpoint):
"detail": False
}),
({}),
(None),
],
)
def test_brand_endpoint_query(query):
endpoint_class = BrandEndpoint(query=query)

assert isinstance(endpoint_class.query, BrandEndpoint.QueryParams)
endpoint_class = BrandEndpoint(query=BrandEndpoint.QueryParams(**query))

if query is None:
assert endpoint_class.query.brand is None
assert endpoint_class.query.category is None
assert endpoint_class.query.country is None
assert endpoint_class.query.currency is None
assert endpoint_class.query.detail is None
assert endpoint_class.query is None
else:
assert endpoint_class.query.brand == query.get("brand")
assert endpoint_class.query.category == query.get("category")
Expand Down Expand Up @@ -151,15 +125,17 @@ def test_brand_endpoint_query_params(query, not_empty_values, sign_attrs):
assert qp.get_sign_attrs() is None


def test_template_list_endpoint(template_list_endpoint):
assert template_list_endpoint.method == HttpMethods.GET.value
assert template_list_endpoint.endpoint == Domains.TEMPLATES.value
assert template_list_endpoint.route == "/api/v2/" + Domains.TEMPLATES.value
assert isinstance(template_list_endpoint.query, QP)
assert template_list_endpoint.body == {}
assert template_list_endpoint.sign_attrs is None
assert template_list_endpoint.is_body_not_empty() is False
assert template_list_endpoint.params == {}
def test_template_list_endpoint():
endpoint = TemplateListEndpoint()

assert endpoint.method == HttpMethods.GET.value
assert endpoint.endpoint == Domains.TEMPLATES.value
assert endpoint.route == "/api/v2/" + Domains.TEMPLATES.value
assert endpoint.query is None
assert endpoint.body == {}
assert endpoint.sign_attrs is None
assert endpoint.is_body_not_empty() is False
assert endpoint.params == {}


@pytest.mark.parametrize(
Expand Down Expand Up @@ -217,11 +193,10 @@ def test_template_list_endpoint_query_params(query, not_empty_values, sign_attrs
"brand": "brand",
}),
({}),
(None),
],
)
def test_template_list_endpoint_query(query):
endpoint_class = TemplateListEndpoint(query=query)
endpoint_class = TemplateListEndpoint(query=TemplateListEndpoint.QueryParams(**query))

assert isinstance(endpoint_class.query, TemplateListEndpoint.QueryParams)

Expand All @@ -231,15 +206,17 @@ def test_template_list_endpoint_query(query):
assert endpoint_class.query.brand == query.get("brand")


def test_template_endpoint(template_endpoint):
assert template_endpoint.method == HttpMethods.GET.value
assert template_endpoint.endpoint == Domains.TEMPLATE.value
assert template_endpoint.route == "/api/v2/" + Domains.TEMPLATE.value
assert isinstance(template_endpoint.query, QP)
assert template_endpoint.body == {}
assert template_endpoint.sign_attrs is None
assert template_endpoint.is_body_not_empty() is False
assert template_endpoint.params == {}
def test_endpoint():
endpoint = TemplateEndpoint()

assert endpoint.method == HttpMethods.GET.value
assert endpoint.endpoint == Domains.TEMPLATE.value
assert endpoint.route == "/api/v2/" + Domains.TEMPLATE.value
assert endpoint.query is None
assert endpoint.body == {}
assert endpoint.sign_attrs is None
assert endpoint.is_body_not_empty() is False
assert endpoint.params == {}


@pytest.mark.parametrize(
Expand All @@ -254,18 +231,18 @@ def test_template_endpoint(template_endpoint):
"template": "template",
}),
({}),
(None),
],
)
def test_template_endpoint_query(query):
endpoint_class = TemplateEndpoint(query=query)
def test_endpoint_query(query):
endpoint_class = TemplateEndpoint(query=TemplateEndpoint.QueryParams(**query))

assert isinstance(endpoint_class.query, TemplateEndpoint.QueryParams)

if query is None:
assert endpoint_class.query.brand is None
assert endpoint_class.query.template is None
else:

assert endpoint_class.query.brand == query.get("brand")
assert endpoint_class.query.template == query.get("template")

Expand Down Expand Up @@ -311,7 +288,7 @@ def test_template_endpoint_query(query):
),
],
)
def test_template_endpoint_query_params(query, not_empty_values, sign_attrs):
def test_endpoint_query_params(query, not_empty_values, sign_attrs):
brand_value = query.get("brand") if query is not None else None
template_value = query.get("template") if query is not None else None

Expand Down

0 comments on commit fc3f0c2

Please # to comment.