Skip to content

Commit a1af1a8

Browse files
author
Tom Hendrikx
committed
Add test for CustomerSubscription pagination results
1 parent 31e1ef0 commit a1af1a8

File tree

4 files changed

+78
-3
lines changed

4 files changed

+78
-3
lines changed

tests/responses/subscriptions_customer_list.json renamed to tests/responses/customer_subscriptions_list.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
},
9090
"previous": null,
9191
"next": {
92-
"href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/subscriptions?from=sub_mnfbwhMfvo",
92+
"href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/subscriptions?from=sub_rVKGtNd6s6",
9393
"type": "application/hal+json"
9494
},
9595
"documentation": {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"count": 1,
3+
"_embedded": {
4+
"subscriptions": [
5+
{
6+
"resource": "subscription",
7+
"id": "sub_rVKGtNd6s6",
8+
"mode": "live",
9+
"createdAt": "2018-06-01T12:23:34+00:00",
10+
"status": "active",
11+
"amount": {
12+
"value": "35.00",
13+
"currency": "EUR"
14+
},
15+
"times": 4,
16+
"interval": "3 months",
17+
"description": "Quarterly payment",
18+
"method": "ideal",
19+
"webhookUrl": "https://webshop.example.org/subscriptions/webhook",
20+
"_links": {
21+
"self": {
22+
"href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/subscriptions/sub_rVKGtNd6s6",
23+
"type": "application/hal+json"
24+
},
25+
"customer": {
26+
"href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U",
27+
"type": "application/hal+json"
28+
}
29+
}
30+
}
31+
]
32+
},
33+
"_links": {
34+
"self": {
35+
"href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/subscriptions?from=sub_rVKGtNd6s6",
36+
"type": "application/hal+json"
37+
},
38+
"previous": {
39+
"href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/subscriptions",
40+
"type": "application/hal+json"
41+
},
42+
"next": null,
43+
"documentation": {
44+
"href": "https://docs.mollie.com/reference/v2/subscriptions-api/list-subscriptions",
45+
"type": "text/html"
46+
}
47+
}
48+
}

tests/test_customer_subscriptions.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
from responses import matchers
23

34
from mollie.api.error import IdentifierError
45
from mollie.api.objects.customer import Customer
@@ -19,13 +20,39 @@
1920
def test_list_customer_subscriptions(client, response):
2021
"""Retrieve a list of subscriptions."""
2122
response.get(f"https://api.mollie.com/v2/customers/{CUSTOMER_ID}", "customer_single")
22-
response.get(f"https://api.mollie.com/v2/customers/{CUSTOMER_ID}/subscriptions", "subscriptions_customer_list")
23+
response.get(f"https://api.mollie.com/v2/customers/{CUSTOMER_ID}/subscriptions", "customer_subscriptions_list")
2324

2425
customer = client.customers.get(CUSTOMER_ID)
2526
subscriptions = customer.subscriptions.list()
2627
assert_list_object(subscriptions, Subscription)
2728

2829

30+
def test_list_customer_subscription_pagination(client, response):
31+
"""Retrieve a list of paginated subscriptions."""
32+
response.get(f"https://api.mollie.com/v2/customers/{CUSTOMER_ID}", "customer_single")
33+
response.get(
34+
f"https://api.mollie.com/v2/customers/{CUSTOMER_ID}/subscriptions",
35+
"customer_subscriptions_list",
36+
match=[matchers.query_string_matcher("")],
37+
)
38+
response.get(
39+
f"https://api.mollie.com/v2/customers/{CUSTOMER_ID}/subscriptions",
40+
"customer_subscriptions_list_more",
41+
match=[matchers.query_string_matcher("from=sub_rVKGtNd6s6")],
42+
)
43+
44+
customer = client.customers.get(CUSTOMER_ID)
45+
first_subscriptions_page = customer.subscriptions.list()
46+
assert first_subscriptions_page.has_previous() is False
47+
assert first_subscriptions_page.has_next() is True
48+
49+
second_subscriptions_page = first_subscriptions_page.get_next()
50+
assert_list_object(second_subscriptions_page, Subscription)
51+
52+
subscription = next(second_subscriptions_page)
53+
assert subscription.id == "sub_rVKGtNd6s6"
54+
55+
2956
def test_get_customer_subscription(client, response):
3057
response.get(f"https://api.mollie.com/v2/customers/{CUSTOMER_ID}", "customer_single")
3158
response.get(

tests/test_customers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def test_customer_get_related_mandates(client, response):
109109
def test_customer_get_related_subscriptions(client, response):
110110
"""Retrieve related subscriptions for a customer."""
111111
response.get(f"https://api.mollie.com/v2/customers/{CUSTOMER_ID}", "customer_single")
112-
response.get(f"https://api.mollie.com/v2/customers/{CUSTOMER_ID}/subscriptions", "subscriptions_customer_list")
112+
response.get(f"https://api.mollie.com/v2/customers/{CUSTOMER_ID}/subscriptions", "customer_subscriptions_list")
113113

114114
customer = client.customers.get(CUSTOMER_ID)
115115
subscriptions = customer.subscriptions.list()

0 commit comments

Comments
 (0)