diff --git a/mollie/api/objects/capture.py b/mollie/api/objects/capture.py index 5ebc62c8..d43ac65f 100644 --- a/mollie/api/objects/capture.py +++ b/mollie/api/objects/capture.py @@ -40,14 +40,12 @@ def settlement_id(self): def created_at(self): return self._get_property("createdAt") - @property - def payment(self): + def get_payment(self): """Return the payment for this capture.""" - # TODO Use the embedded payment data, if avalable. + # TODO Use the embedded payment data, if available. return self.client.payments.get(self.payment_id) - @property - def shipment(self): + def get_shipment(self): """Return the shipment for this capture.""" url = self._get_link("shipment") if url: @@ -56,7 +54,6 @@ def shipment(self): # We fake the order object here, since it is not used by from_url() return OrderShipments(self.client, order=None).from_url(url) - @property - def settlement(self): + def get_settlement(self): """Return the settlement for this capture.""" return self.client.settlements.get(self.settlement_id) diff --git a/mollie/api/objects/chargeback.py b/mollie/api/objects/chargeback.py index 188e2b9f..2e86f05f 100644 --- a/mollie/api/objects/chargeback.py +++ b/mollie/api/objects/chargeback.py @@ -1,6 +1,5 @@ import re -from ..error import DataConsistencyError from .base import ObjectBase @@ -40,22 +39,27 @@ def payment_id(self): return self._get_property("paymentId") @property - def payment(self): - """Return the Payment object related to this chargeback.""" - # TODO Use the embedded payment data, if available. - return self.client.payments.get(self.payment_id) + def settlement_id(self): + """ + Return the settlement ID. - @property - def settlement(self): - """Return the Settlement object related to this chargeback, if available.""" + It is extracted from the settlement link, since the id is not available as a real property. + """ url = self._get_link("settlement") if not url: return None - match = re.search(r"settlements/(stl_[a-zA-Z0-9]+)$", url) - if not match: - # This should never happen - raise DataConsistencyError("Unable to extract the settlementId from settlement URL.") # pragma: no cover + match = re.findall(r"/settlements/(stl_\w+)$", url) + if match: + return match[0] - settlement_id = match.group(1) - return self.client.settlements.get(settlement_id) + def get_payment(self): + """Return the Payment object related to this chargeback.""" + # TODO Use the embedded payment data, if available. + return self.client.payments.get(self.payment_id) + + def get_settlement(self): + """Return the Settlement object related to this chargeback, if available.""" + settlement_id = self.settlement_id + if settlement_id is not None: + return self.client.settlements.get(settlement_id) diff --git a/mollie/api/objects/client.py b/mollie/api/objects/client.py index a0642cbc..e9908eb8 100644 --- a/mollie/api/objects/client.py +++ b/mollie/api/objects/client.py @@ -24,8 +24,7 @@ def organisation_created_at(self): # documented _links - @property - def organization(self): + def get_organization(self): """Return the client’s organization. Only available when the include could have been used.""" url = self._get_link("organization") if url: @@ -33,8 +32,7 @@ def organization(self): else: return None - @property - def onboarding(self): + def get_onboarding(self): """Return the client’s onboarding status. Only available when the include could have been used.""" url = self._get_link("onboarding") if url: diff --git a/mollie/api/objects/mandate.py b/mollie/api/objects/mandate.py index 8c78c2f8..58da2e2f 100644 --- a/mollie/api/objects/mandate.py +++ b/mollie/api/objects/mandate.py @@ -56,8 +56,7 @@ def is_invalid(self): """Check if the mandate is invalid.""" return self.status == self.STATUS_INVALID - @property - def customer(self): + def get_customer(self): """Return the customer for this mandate.""" url = self._get_link("customer") if url: diff --git a/mollie/api/objects/onboarding.py b/mollie/api/objects/onboarding.py index af4b8877..da9f5646 100644 --- a/mollie/api/objects/onboarding.py +++ b/mollie/api/objects/onboarding.py @@ -36,13 +36,6 @@ def can_receive_payments(self): def can_receive_settlements(self): return self._get_property("canReceiveSettlements") - @property - def organization(self): - """Retrieve organization for an onboarding.""" - url = self._get_link("organization") - if url: - return self.client.organizations.from_url(url) - def is_needs_data(self): return self.status == self.STATUS_NEEDS_DATA @@ -51,3 +44,9 @@ def is_in_review(self): def is_completed(self): return self.status == self.STATUS_COMPLETED + + def get_organization(self): + """Retrieve the related organization.""" + url = self._get_link("organization") + if url: + return self.client.organizations.from_url(url) diff --git a/mollie/api/objects/payment.py b/mollie/api/objects/payment.py index 0df67bea..00df3563 100644 --- a/mollie/api/objects/payment.py +++ b/mollie/api/objects/payment.py @@ -191,22 +191,19 @@ def captures(self): """Return the captures related to this payment""" return PaymentCaptures(self.client, self) - @property - def settlement(self): + def get_settlement(self): """Return the settlement for this payment.""" if self.settlement_id: return self.client.settlements.get(self.settlement_id) - @property - def mandate(self): + def get_mandate(self): """Return the mandate for this payment.""" if self.customer_id and self.mandate_id: # Setup a minimal Customer object without querying the API. customer = Customer({"id": self.customer_id}, self.client) return customer.mandates.get(self.mandate_id) - @property - def subscription(self): + def get_subscription(self): """ Return the subscription for this payment. @@ -218,14 +215,12 @@ def subscription(self): return CustomerSubscriptions(self.client, customer=None).from_url(url) - @property - def customer(self): + def get_customer(self): """Return the customer for this payment.""" if self.customer_id: return self.client.customers.get(self.customer_id) - @property - def order(self): + def get_order(self): """Return the order for this payment.""" url = self._get_link("order") if url: diff --git a/mollie/api/objects/refund.py b/mollie/api/objects/refund.py index 14352069..56ca1e30 100644 --- a/mollie/api/objects/refund.py +++ b/mollie/api/objects/refund.py @@ -75,20 +75,17 @@ def metadata(self): # documented _links - @property - def payment(self): + def get_payment(self): """Return the payment for this refund.""" return self.client.payments.get(self.payment_id) - @property - def settlement(self): + def get_settlement(self): """Return the settlement for this refund.""" if self.settlement_id: return self.client.settlements.get(self.settlement_id) return None - @property - def order(self): + def get_order(self): """Return the order for this refund.""" if self.order_id: return self.client.orders.get(self.order_id) diff --git a/mollie/api/objects/settlement.py b/mollie/api/objects/settlement.py index 820fc110..70ccee39 100644 --- a/mollie/api/objects/settlement.py +++ b/mollie/api/objects/settlement.py @@ -90,8 +90,7 @@ def captures(self): """Return the captures related to this settlement.""" return SettlementCaptures(self.client, self) - @property - def invoice(self): + def get_invoice(self): """Return the invoice related to this settlement.""" url = self._get_link("invoice") return self.client.invoices.from_url(url) diff --git a/mollie/api/objects/shipment.py b/mollie/api/objects/shipment.py index 38af9fa1..1f807b24 100644 --- a/mollie/api/objects/shipment.py +++ b/mollie/api/objects/shipment.py @@ -40,8 +40,7 @@ def lines(self): } return ObjectList(result, OrderLine, self.client) - @property - def order(self): + def get_order(self): """Return the order of this shipment.""" return self.client.orders.get(self.order_id) diff --git a/mollie/api/objects/subscription.py b/mollie/api/objects/subscription.py index d5636632..1c13a0f8 100644 --- a/mollie/api/objects/subscription.py +++ b/mollie/api/objects/subscription.py @@ -104,8 +104,7 @@ def metadata(self): def application_fee(self): return self._get_property("applicationFee") - @property - def customer(self): + def get_customer(self): """Return the customer for this subscription.""" url = self._get_link("customer") return self.client.customers.from_url(url) @@ -124,28 +123,25 @@ def customer_id(self): if matches: return matches[0] - @property - def profile(self): + def get_profile(self): """Return the profile related to this subscription.""" url = self._get_link("profile") if not url: return None return self.client.profiles.from_url(url) + def get_mandate(self): + if self.mandate_id and self.customer_id: + from ..resources import CustomerMandates + + customer = Customer({"id": self.customer_id}, self.client) + return CustomerMandates(self.client, customer).get(self.mandate_id) + @property def payments(self): # We could also have implemented this using the "payments" entry from the _links, but then we would not have # the explicit interface using .payments.list() from ..resources import SubscriptionPayments - # Create a fake customer object with minimal payload customer = Customer({"id": self.customer_id}, self.client) return SubscriptionPayments(self.client, customer=customer, subscription=self) - - @property - def mandate(self): - if self.mandate_id and self.customer_id: - from ..resources import CustomerMandates - - customer = Customer({"id": self.customer_id}, self.client) - return CustomerMandates(self.client, customer).get(self.mandate_id) diff --git a/tests/responses/settlement_single.json b/tests/responses/settlement_single.json index 1686a9a1..2597a87f 100644 --- a/tests/responses/settlement_single.json +++ b/tests/responses/settlement_single.json @@ -92,11 +92,11 @@ } } ], - "invoiceId": "inv_FrvewDA3Pr" + "invoiceId": "inv_xBEbP9rvAq" } } }, - "invoiceId": "inv_FrvewDA3Pr", + "invoiceId": "inv_xBEbP9rvAq", "_links": { "self": { "href": "https://api.mollie.com/v2/settlements/next", @@ -119,7 +119,7 @@ "type": "application/hal+json" }, "invoice": { - "href": "https://api.mollie.com/v2/invoices/inv_FrvewDA3Pr", + "href": "https://api.mollie.com/v2/invoices/inv_xBEbP9rvAq", "type": "application/hal+json" }, "documentation": { diff --git a/tests/test_clients.py b/tests/test_clients.py index ebbd241b..0af1312a 100644 --- a/tests/test_clients.py +++ b/tests/test_clients.py @@ -40,7 +40,7 @@ def test_client_get_organization(oauth_client, response): response.get(f"https://api.mollie.com/v2/organizations/{CLIENT_ID}", "organization_single") client = oauth_client.clients.get(CLIENT_ID) - organization = client.organization + organization = client.get_organization() assert isinstance(organization, Organization) @@ -49,5 +49,5 @@ def test_client_get_onboarding(oauth_client, response): response.get(f"https://api.mollie.com/v2/onboarding/{CLIENT_ID}", "onboarding_single") client = oauth_client.clients.get(CLIENT_ID) - onboarding = client.onboarding + onboarding = client.get_onboarding() assert isinstance(onboarding, Onboarding) diff --git a/tests/test_customer_mandates.py b/tests/test_customer_mandates.py index d3f1d3a6..aab14e9a 100644 --- a/tests/test_customer_mandates.py +++ b/tests/test_customer_mandates.py @@ -45,7 +45,6 @@ def test_get_customer_mandate(client, response): assert mandate.is_pending() is False assert mandate.is_valid() is True assert mandate.is_invalid() is False - assert mandate.customer is not None def test_get_customer_mandate_invalid_id(client, response): @@ -67,8 +66,9 @@ def test_customer_mandate_get_related_customer(client, response): customer = client.customers.get(CUSTOMER_ID) mandate = customer.mandates.get(MANDATE_ID) - assert isinstance(mandate.customer, Customer) - assert mandate.customer.id == CUSTOMER_ID + customer = mandate.get_customer() + assert isinstance(customer, Customer) + assert customer.id == CUSTOMER_ID def test_create_customer_mandate(client, response): diff --git a/tests/test_customer_subscriptions.py b/tests/test_customer_subscriptions.py index be2d1ad9..ac77a7c2 100644 --- a/tests/test_customer_subscriptions.py +++ b/tests/test_customer_subscriptions.py @@ -32,7 +32,6 @@ def test_get_customer_subscription(client, response): f"https://api.mollie.com/v2/customers/{CUSTOMER_ID}/subscriptions/{SUBSCRIPTION_ID}", "subscription_single", ) - response.get(f"https://api.mollie.com/v2/customers/{CUSTOMER_ID}/mandates/{MANDATE_ID}", "customer_mandate_single") customer = client.customers.get(CUSTOMER_ID) subscription = customer.subscriptions.get(SUBSCRIPTION_ID) @@ -52,8 +51,6 @@ def test_get_customer_subscription(client, response): assert subscription.start_date == "2016-06-01" assert subscription.next_payment_date == "2016-09-01" assert subscription.canceled_at is None - assert subscription.customer is not None - assert subscription.mandate is not None assert subscription.metadata == {"order_id": 1337} assert subscription.application_fee is None assert subscription.is_active() is True @@ -82,8 +79,9 @@ def test_customer_subscription_get_related_customer(client, response): customer = client.customers.get(CUSTOMER_ID) subscription = customer.subscriptions.get(SUBSCRIPTION_ID) - assert isinstance(subscription.customer, Customer) - assert subscription.customer.id == CUSTOMER_ID + related_customer = subscription.get_customer() + assert isinstance(related_customer, Customer) + assert related_customer.id == CUSTOMER_ID == customer.id def test_customer_subscription_get_related_profile(client, response): @@ -96,7 +94,7 @@ def test_customer_subscription_get_related_profile(client, response): customer = client.customers.get(CUSTOMER_ID) subscription = customer.subscriptions.get(SUBSCRIPTION_ID) - profile = subscription.profile + profile = subscription.get_profile() assert isinstance(profile, Profile) assert profile.id == PROFILE_ID @@ -111,7 +109,7 @@ def test_customer_subscription_get_related_mandate(client, response): customer = client.customers.get(CUSTOMER_ID) subscription = customer.subscriptions.get(SUBSCRIPTION_ID) - mandate = subscription.mandate + mandate = subscription.get_mandate() assert isinstance(mandate, Mandate) assert mandate.id == MANDATE_ID diff --git a/tests/test_onboarding.py b/tests/test_onboarding.py index 8dabad31..0ec1e57a 100644 --- a/tests/test_onboarding.py +++ b/tests/test_onboarding.py @@ -51,6 +51,6 @@ def test_onboarding_get_organization(oauth_client, response): ) onboarding = oauth_client.onboarding.get("me") - organization = onboarding.organization + organization = onboarding.get_organization() assert isinstance(organization, Organization) assert organization.id == ORGANIZATION_ID diff --git a/tests/test_payment_captures.py b/tests/test_payment_captures.py index c5eb29e4..f28f3177 100644 --- a/tests/test_payment_captures.py +++ b/tests/test_payment_captures.py @@ -58,7 +58,7 @@ def test_capture_get_related_payment(client, response): payment = client.payments.get(PAYMENT_ID) capture = payment.captures.get(CAPTURE_ID) - payment = capture.payment + payment = capture.get_payment() assert isinstance(payment, Payment) assert payment.id == PAYMENT_ID @@ -71,7 +71,7 @@ def test_capture_get_related_shipment(client, response): payment = client.payments.get(PAYMENT_ID) capture = payment.captures.get(CAPTURE_ID) - shipment = capture.shipment + shipment = capture.get_shipment() assert isinstance(shipment, Shipment) assert shipment.id == SHIPMENT_ID @@ -84,5 +84,5 @@ def test_capture_get_related_settlement(client, response): payment = client.payments.get(PAYMENT_ID) capture = payment.captures.get(CAPTURE_ID) - settlement = capture.settlement + settlement = capture.get_settlement() assert isinstance(settlement, Settlement) diff --git a/tests/test_payment_chargebacks.py b/tests/test_payment_chargebacks.py index 384889ac..a42dbb86 100644 --- a/tests/test_payment_chargebacks.py +++ b/tests/test_payment_chargebacks.py @@ -22,11 +22,10 @@ def test_list_payment_chargebacks(client, response): assert_list_object(chargebacks, Chargeback) -def test_get_single_payment_chargeback(client, response): +def test_get_payment_chargeback(client, response): """Get a single chargeback relevant to a payment.""" response.get(f"https://api.mollie.com/v2/payments/{PAYMENT_ID}", "payment_single") response.get(f"https://api.mollie.com/v2/payments/{PAYMENT_ID}/chargebacks/{CHARGEBACK_ID}", "chargeback_single") - response.get(f"https://api.mollie.com/v2/settlements/{SETTLEMENT_ID}", "settlement_single") payment = client.payments.get(PAYMENT_ID) chargeback = payment.chargebacks.get(CHARGEBACK_ID) @@ -38,8 +37,6 @@ def test_get_single_payment_chargeback(client, response): assert chargeback.reason is None assert chargeback.reversed_at == "2018-03-14T17:00:55.0Z" assert chargeback.payment_id == PAYMENT_ID - assert isinstance(chargeback.payment, Payment) - assert isinstance(chargeback.settlement, Settlement) def test_get_payment_chargeback_invalid_id(client, response): @@ -49,3 +46,26 @@ def test_get_payment_chargeback_invalid_id(client, response): with pytest.raises(IdentifierError) as excinfo: payment.chargebacks.get("invalid") assert str(excinfo.value) == "Invalid chargeback ID 'invalid', it should start with 'chb_'." + + +def test_payment_chargeback_get_related_payment(client, response): + response.get(f"https://api.mollie.com/v2/payments/{PAYMENT_ID}", "payment_single") + response.get(f"https://api.mollie.com/v2/payments/{PAYMENT_ID}/chargebacks/{CHARGEBACK_ID}", "chargeback_single") + + payment = client.payments.get(PAYMENT_ID) + chargeback = payment.chargebacks.get(CHARGEBACK_ID) + related_payment = chargeback.get_payment() + assert isinstance(related_payment, Payment) + assert related_payment.id == payment.id == PAYMENT_ID + + +def test_payment_chargeback_get_related_settlement(client, response): + response.get(f"https://api.mollie.com/v2/payments/{PAYMENT_ID}", "payment_single") + response.get(f"https://api.mollie.com/v2/payments/{PAYMENT_ID}/chargebacks/{CHARGEBACK_ID}", "chargeback_single") + response.get(f"https://api.mollie.com/v2/settlements/{SETTLEMENT_ID}", "settlement_single") + + payment = client.payments.get(PAYMENT_ID) + chargeback = payment.chargebacks.get(CHARGEBACK_ID) + related_settlement = chargeback.get_settlement() + assert isinstance(related_settlement, Settlement) + assert related_settlement.id == SETTLEMENT_ID diff --git a/tests/test_payment_refunds.py b/tests/test_payment_refunds.py index 86c4d285..63e35f72 100644 --- a/tests/test_payment_refunds.py +++ b/tests/test_payment_refunds.py @@ -47,11 +47,6 @@ def test_get_payment_refund(client, response): assert refund.payment_id == PAYMENT_ID assert refund.order_id is None assert refund.created_at == "2018-03-14T17:09:02.0Z" - # properties from _links - assert refund.payment is not None - assert refund.settlement is None - assert refund.order is None - # additional methods assert refund.is_queued() is False assert refund.is_pending() is True @@ -106,7 +101,7 @@ def test_payment_refund_get_related_payment(refund, response): response.get(f"https://api.mollie.com/v2/payments/{PAYMENT_ID}", "payment_single") assert refund.payment_id == PAYMENT_ID - payment = refund.payment + payment = refund.get_payment() assert isinstance(payment, Payment) assert payment.id == PAYMENT_ID @@ -116,7 +111,7 @@ def test_payment_refund_get_related_settlement(refund, response): assert refund.settlement_id == SETTLEMENT_ID assert refund.settlement_amount == {"currency": "EUR", "value": "10.00"} - settlement = refund.settlement + settlement = refund.get_settlement() assert isinstance(settlement, Settlement) assert settlement.id == SETTLEMENT_ID @@ -125,7 +120,7 @@ def test_payment_refund_get_related_order(refund, response): response.get(f"https://api.mollie.com/v2/orders/{ORDER_ID}", "order_single") assert refund.order_id == ORDER_ID - order = refund.order + order = refund.get_order() assert isinstance(order, Order) assert order.id == ORDER_ID diff --git a/tests/test_payments.py b/tests/test_payments.py index a5479bd3..10044eb4 100644 --- a/tests/test_payments.py +++ b/tests/test_payments.py @@ -69,7 +69,6 @@ def test_cancel_payment_invalid_id(client): def test_get_single_payment(client, response): """Retrieve a single payment by payment id.""" response.get(f"https://api.mollie.com/v2/payments/{PAYMENT_ID}", "payment_single_no_links") - response.get(f"https://api.mollie.com/v2/customers/{CUSTOMER_ID}", "customer_single") payment = client.payments.get(PAYMENT_ID) assert isinstance(payment, Payment) @@ -110,11 +109,7 @@ def test_get_single_payment(client, response): assert payment.payonline_url is None assert payment.refunds is not None assert payment.chargebacks is not None - assert payment.mandate is None - assert payment.subscription is None - assert payment.customer is not None assert payment.captures is not None - assert payment.order is None # additional methods assert payment.is_open() is True assert payment.is_pending() is False @@ -177,7 +172,7 @@ def test_payment_get_related_settlement(client, response): assert payment.settlement_id == SETTLEMENT_ID assert payment.settlement_amount == {"currency": "EUR", "value": "39.75"} - settlement = payment.settlement + settlement = payment.get_settlement() assert isinstance(settlement, Settlement) assert settlement.id == SETTLEMENT_ID @@ -188,7 +183,7 @@ def test_payment_get_related_mandate(client, response): response.get(f"https://api.mollie.com/v2/customers/{CUSTOMER_ID}/mandates/{MANDATE_ID}", "customer_mandate_single") payment = client.payments.get(PAYMENT_ID) - mandate = payment.mandate + mandate = payment.get_mandate() assert isinstance(mandate, Mandate) assert mandate.id == MANDATE_ID @@ -200,7 +195,7 @@ def test_payment_get_related_subscription(client, response): ) payment = client.payments.get(PAYMENT_ID) - subscription = payment.subscription + subscription = payment.get_subscription() assert isinstance(subscription, Subscription) assert subscription.id == SUBSCRIPTION_ID @@ -211,7 +206,7 @@ def test_payment_get_related_customer(client, response): response.get(f"https://api.mollie.com/v2/customers/{CUSTOMER_ID}", "customer_single") payment = client.payments.get(PAYMENT_ID) - customer = payment.customer + customer = payment.get_customer() assert isinstance(customer, Customer) assert customer.id == CUSTOMER_ID @@ -221,7 +216,7 @@ def test_payment_get_related_order(client, response): response.get(f"https://api.mollie.com/v2/orders/{ORDER_ID}", "order_single") payment = client.payments.get(PAYMENT_ID) - order = payment.order + order = payment.get_order() assert isinstance(order, Order) assert order.id == ORDER_ID diff --git a/tests/test_settlements.py b/tests/test_settlements.py index 5ff06e01..aa790733 100644 --- a/tests/test_settlements.py +++ b/tests/test_settlements.py @@ -9,7 +9,7 @@ from .utils import assert_list_object SETTLEMENT_ID = "stl_jDk30akdN" -INVOICE_ID = "inv_FrvewDA3Pr" +INVOICE_ID = "inv_xBEbP9rvAq" BANK_REFERENCE = "1234567.1804.03" @@ -24,7 +24,6 @@ def test_list_settlements(oauth_client, response): def test_settlement_get(oauth_client, response): """Retrieve a single settlement method by ID.""" response.get(f"https://api.mollie.com/v2/settlements/{SETTLEMENT_ID}", "settlement_single") - response.get(f"https://api.mollie.com/v2/invoices/{INVOICE_ID}", "invoice_single") settlement = oauth_client.settlements.get(SETTLEMENT_ID) assert isinstance(settlement, Settlement) @@ -45,7 +44,6 @@ def test_settlement_get(oauth_client, response): assert isinstance(settlement.payments, SettlementPayments) assert isinstance(settlement.refunds, SettlementRefunds) assert isinstance(settlement.captures, SettlementCaptures) - assert isinstance(settlement.invoice, Invoice) def test_settlement_get_next(oauth_client, response): @@ -105,10 +103,20 @@ def test_settlement_invoice_id_is_deprecated(oauth_client, response): settlement = oauth_client.settlements.get(SETTLEMENT_ID) with pytest.warns(APIDeprecationWarning) as warnings: - assert settlement.invoice_id == "inv_FrvewDA3Pr" + assert settlement.invoice_id == INVOICE_ID assert len(warnings) == 1 assert str(warnings[0].message) == ( "Using Settlement Invoice ID is deprecated, see " "https://docs.mollie.com/reference/v2/settlements-api/get-settlement" ) + + +def test_settlement_get_related_invoice(oauth_client, response): + response.get(f"https://api.mollie.com/v2/settlements/{SETTLEMENT_ID}", "settlement_single") + response.get(f"https://api.mollie.com/v2/invoices/{INVOICE_ID}", "invoice_single") + + settlement = oauth_client.settlements.get(SETTLEMENT_ID) + invoice = settlement.get_invoice() + assert isinstance(invoice, Invoice) + assert invoice.id == INVOICE_ID diff --git a/tests/test_shipments.py b/tests/test_shipments.py index 2bbd2f6d..e1b72fea 100644 --- a/tests/test_shipments.py +++ b/tests/test_shipments.py @@ -34,7 +34,6 @@ def test_get_shipment(client, response): assert shipment.has_tracking_url() is True assert shipment.tracking_url == "http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C" assert_list_object(shipment.lines, OrderLine) - assert isinstance(shipment.order, Order) def test_create_shipment(client, response): @@ -107,3 +106,14 @@ def test_update_shipment_invalid_id(client, response): with pytest.raises(IdentifierError) as excinfo: order.shipments.update("invalid", data) assert str(excinfo.value) == "Invalid shipment ID 'invalid', it should start with 'shp_'." + + +def test_shipment_get_related_order(client, response): + response.get(f"https://api.mollie.com/v2/orders/{ORDER_ID}", "order_single") + response.get(f"https://api.mollie.com/v2/orders/{ORDER_ID}/shipments/{SHIPMENT_ID}", "shipment_single") + + order = client.orders.get(ORDER_ID) + shipment = order.shipments.get(SHIPMENT_ID) + related_order = shipment.get_order() + assert isinstance(related_order, Order) + assert related_order.id == related_order.id