Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ac09140

Browse filesBrowse files
mentholigavinballard
authored andcommitted
Fixed RecurringApplicationChrage resources current() method to work correctly and added tests. See issue Shopify#85
1 parent cbe2c3d commit ac09140
Copy full SHA for ac09140

4 files changed

+101-1Lines changed: 101 additions & 1 deletion

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎shopify/resources/recurring_application_charge.py‎

Copy file name to clipboardExpand all lines: shopify/resources/recurring_application_charge.py
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
from ..base import ShopifyResource
22

3+
def _get_first_by_status(resources, status):
4+
for resource in resources:
5+
if resource.status == status:
6+
return resource
7+
return None
8+
39

410
class RecurringApplicationCharge(ShopifyResource):
511

612
@classmethod
713
def current(cls):
8-
return cls.find_first(status="active")
14+
"""
15+
Returns first RecurringApplicationCharge object with status=active.
16+
If not found, None will be returned.
17+
"""
18+
return _get_first_by_status(cls.find(), "active")
919

1020
def cancel(self):
1121
self._load_attributes_from_response(self.destroy)
Collapse file
+38Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"recurring_application_charges": [
3+
{
4+
"activated_on": null,
5+
"api_client_id": 755357713,
6+
"billing_on": "2015-01-15T00:00:00+00:00",
7+
"cancelled_on": null,
8+
"created_at": "2015-01-16T11:45:44-05:00",
9+
"id": 455696195,
10+
"name": "Super Mega Plan",
11+
"price": "15.00",
12+
"return_url": "http://yourapp.com",
13+
"status": "accepted",
14+
"test": null,
15+
"trial_days": 0,
16+
"trial_ends_on": null,
17+
"updated_at": "2015-01-16T11:46:56-05:00",
18+
"decorated_return_url": "http://yourapp.com?charge_id=455696195"
19+
},
20+
{
21+
"activated_on": "2015-01-15T00:00:00+00:00",
22+
"api_client_id": 755357713,
23+
"billing_on": "2015-01-15T00:00:00+00:00",
24+
"cancelled_on": null,
25+
"created_at": "2015-01-16T11:45:44-05:00",
26+
"id": 455696195,
27+
"name": "Super Mega Plan 2",
28+
"price": "15.00",
29+
"return_url": "http://yourapp.com",
30+
"status": "active",
31+
"test": null,
32+
"trial_days": 0,
33+
"trial_ends_on": null,
34+
"updated_at": "2015-01-16T11:46:56-05:00",
35+
"decorated_return_url": "http://yourapp.com?charge_id=455696195"
36+
}
37+
]
38+
}
Collapse file
+38Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"recurring_application_charges": [
3+
{
4+
"activated_on": null,
5+
"api_client_id": 755357713,
6+
"billing_on": "2015-01-15T00:00:00+00:00",
7+
"cancelled_on": null,
8+
"created_at": "2015-01-16T11:45:44-05:00",
9+
"id": 455696195,
10+
"name": "Super Mega Plan",
11+
"price": "15.00",
12+
"return_url": "http://yourapp.com",
13+
"status": "accepted",
14+
"test": null,
15+
"trial_days": 0,
16+
"trial_ends_on": null,
17+
"updated_at": "2015-01-16T11:46:56-05:00",
18+
"decorated_return_url": "http://yourapp.com?charge_id=455696195"
19+
},
20+
{
21+
"activated_on": "2015-01-15T00:00:00+00:00",
22+
"api_client_id": 755357713,
23+
"billing_on": "2015-01-15T00:00:00+00:00",
24+
"cancelled_on": null,
25+
"created_at": "2015-01-16T11:45:44-05:00",
26+
"id": 455696195,
27+
"name": "Super Mega Plan 2",
28+
"price": "15.00",
29+
"return_url": "http://yourapp.com",
30+
"status": "rejected",
31+
"test": null,
32+
"trial_days": 0,
33+
"trial_ends_on": null,
34+
"updated_at": "2015-01-16T11:46:56-05:00",
35+
"decorated_return_url": "http://yourapp.com?charge_id=455696195"
36+
}
37+
]
38+
}
Collapse file

‎test/recurring_charge_test.py‎

Copy file name to clipboardExpand all lines: test/recurring_charge_test.py
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,17 @@ def test_activate_charge(self):
77
self.fake("recurring_application_charges/35463/activate", method='POST',headers={'Content-length':'0', 'Content-type': 'application/json'}, body=" ")
88
charge = shopify.RecurringApplicationCharge({'id': 35463})
99
charge.activate()
10+
11+
def test_current_method_returns_active_charge(self):
12+
# Test that current() class method correctly returns
13+
# first RecurringApplicationCharge with active status
14+
self.fake("recurring_application_charges")
15+
charge = shopify.RecurringApplicationCharge.current()
16+
self.assertEqual(charge.id, 455696195)
17+
18+
def test_current_method_returns_none_if_active_not_found(self):
19+
# Test that current() class method correctly returns
20+
# None if RecurringApplicationCharge with active status not found
21+
self.fake("recurring_application_charges", body=self.load_fixture("recurring_application_charges_no_active"))
22+
charge = shopify.RecurringApplicationCharge.current()
23+
self.assertEqual(charge, None)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.