Skip to content

Commit bde5201

Browse files
committed
Add tests for adjustment create
1 parent 976d8e0 commit bde5201

6 files changed

Lines changed: 203 additions & 0 deletions

File tree

recurly/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,20 @@ def __getattr__(self, name):
948948
else:
949949
return super(Adjustment, self).__getattr__(name)
950950

951+
def credit_adjustments(self):
952+
"""A list of credit adjustments that were issued against this adjustment"""
953+
url = recurly.base_uri() + (self.member_path % self.uuid) + '/credit_adjustments'
954+
955+
response = self.http_request(url, 'GET')
956+
if response.status not in (200, 201):
957+
self.raise_http_error(response)
958+
response_xml = response.read()
959+
960+
# This can't be defined at the class level because it is a circular reference
961+
Adjustment._classes_for_nodename['adjustment'] = Adjustment
962+
elem = ElementTree.fromstring(response_xml)
963+
return Adjustment.value_for_element(elem)
964+
951965
class Invoice(Resource):
952966

953967
"""A payable charge to an account for the customer's charges and

tests/fixtures/adjustment/account-has-adjustments.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,15 @@ X-Records: 1
3737
<start_date type="datetime">2009-11-03T23:27:46Z</start_date>
3838
<end_date nil="nil" type="datetime"></end_date>
3939
<created_at type="datetime">2009-11-03T23:27:46Z</created_at>
40+
<custom_fields type="array">
41+
<custom_field>
42+
<name>size</name>
43+
<value>small</value>
44+
</custom_field>
45+
<custom_field>
46+
<name>color</name>
47+
<value>blue</value>
48+
</custom_field>
49+
</custom_fields>
4050
</adjustment>
4151
</adjustments>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
POST https://api.recurly.com/v2/accounts/chargemock/adjustments HTTP/1.1
2+
X-Api-Version: {api-version}
3+
Accept: application/xml
4+
Authorization: Basic YXBpa2V5Og==
5+
User-Agent: {user-agent}
6+
Content-Type: application/xml; charset=utf-8
7+
8+
<?xml version="1.0" encoding="UTF-8"?>
9+
<adjustment type="charge">
10+
<currency>USD</currency>
11+
<custom_fields>
12+
<custom_field>
13+
<name>size</name>
14+
<value>small</value>
15+
</custom_field>
16+
<custom_field>
17+
<name>color</name>
18+
<value>blue</value>
19+
</custom_field>
20+
</custom_fields>
21+
<description>test charge</description>
22+
<unit_amount_in_cents type="integer">1000</unit_amount_in_cents>
23+
</adjustment>
24+

25+
HTTP/1.1 201 Created
26+
Content-Type: application/xml; charset=utf-8
27+
Location: https://api.recurly.com/v2/adjustments/4ba1531325014b4f969cd13676f514d8
28+
29+
<?xml version="1.0" encoding="UTF-8"?>
30+
<adjustment>
31+
<uuid>4ba1531325014b4f969cd13676f514d8</uuid>
32+
<account_code>chargemock</account_code>
33+
<unit_amount_in_cents type="integer">1000</unit_amount_in_cents>
34+
<currency>
35+
USD</currency>
36+
<start_date type="datetime">2009-11-03T23:27:46-08:00</start_date>
37+
<end_date type="datetime"></end_date>
38+
<description>test charge</description>
39+
<custom_fields type="array">
40+
<custom_field>
41+
<name>size</name>
42+
<value>small</value>
43+
</custom_field>
44+
<custom_field>
45+
<name>color</name>
46+
<value>blue</value>
47+
</custom_field>
48+
</custom_fields>
49+
<created_at type="datetime">
50+
2009-11-03T23:27:46-08:00</created_at>
51+
</adjustment>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
GET https://api.recurly.com/v2/adjustments/4ba1531325014b4f969cd13676f514d8/credit_adjustments HTTP/1.1
2+
X-Api-Version: {api-version}
3+
Accept: application/xml
4+
Authorization: Basic YXBpa2V5Og==
5+
User-Agent: {user-agent}
6+
7+

8+
HTTP/1.1 200 OK
9+
Content-Type: application/xml; charset=utf-8
10+
X-Records: 1
11+
12+
<adjustments type="array">
13+
<adjustment type="charge">
14+
<uuid>4ba1531325014b4f969cd13676f514d9</uuid>
15+
<description>test charge</description>
16+
<account_code>chargemock</account_code>
17+
<tax_in_cents type="integer">5000</tax_in_cents>
18+
<tax_type>usst</tax_type>
19+
<tax_region>CA</tax_region>
20+
<tax_rate type="float">0.0875</tax_rate>
21+
<unit_amount_in_cents type="integer">1000</unit_amount_in_cents>
22+
<currency>USD</currency>
23+
<tax_details type="array">
24+
<tax_detail>
25+
<name>california</name>
26+
<type>state</type>
27+
<tax_rate type="float">0.065</tax_rate>
28+
<tax_in_cents type="integer">3000</tax_in_cents>
29+
</tax_detail>
30+
<tax_detail>
31+
<name>san francisco</name>
32+
<type>county</type>
33+
<tax_rate type="float">0.02</tax_rate>
34+
<tax_in_cents type="integer">2000</tax_in_cents>
35+
</tax_detail>
36+
</tax_details>
37+
<start_date type="datetime"> 2009-11-03T23:27:46Z</start_date>
38+
<end_date nil="nil" type="datetime"></end_date>
39+
<created_at type="datetime">2009-11-03T23:27:46Z</created_at>
40+
<custom_fields type="array">
41+
<custom_field>
42+
<name>size</name>
43+
<value>small</value>
44+
</custom_field>
45+
<custom_field>
46+
<name>color</name>
47+
<value>blue</value>
48+
</custom_field>
49+
</custom_fields>
50+
</adjustment>
51+
</adjustments>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
GET https://api.recurly.com/v2/adjustments/4ba1531325014b4f969cd13676f514d8 HTTP/1.1
2+
X-Api-Version: {api-version}
3+
Accept: application/xml
4+
Authorization: Basic YXBpa2V5Og==
5+
User-Agent: {user-agent}
6+
7+

8+
HTTP/1.1 200 OK
9+
Content-Type: application/xml; charset=utf-8
10+
11+
<adjustment type="charge">
12+
<uuid>4ba1531325014b4f969cd13676f514d8</uuid>
13+
<description>test charge</description>
14+
<account_code>chargemock</account_code>
15+
<tax_in_cents type="integer">5000</tax_in_cents>
16+
<tax_type>usst</tax_type>
17+
<tax_region>CA</tax_region>
18+
<tax_rate type="float">0.0875</tax_rate>
19+
<unit_amount_in_cents type="integer">1000</unit_amount_in_cents>
20+
<currency>USD</currency>
21+
<tax_details type="array">
22+
<tax_detail>
23+
<name>california</name>
24+
<type>state</type>
25+
<tax_rate type="float">0.065</tax_rate>
26+
<tax_in_cents type="integer">3000</tax_in_cents>
27+
</tax_detail>
28+
<tax_detail>
29+
<name>san francisco</name>
30+
<type>county</type>
31+
<tax_rate type="float">0.02</tax_rate>
32+
<tax_in_cents type="integer">2000</tax_in_cents>
33+
</tax_detail>
34+
</tax_details>
35+
<start_date type="datetime">2009-11-03T23:27:46Z</start_date>
36+
<end_date nil="nil" type="datetime"></end_date>
37+
<created_at type="datetime">2009-11-03T23:27:46Z</created_at>
38+
<custom_fields type="array">
39+
<custom_field>
40+
<name>size</name>
41+
<value>small</value>
42+
</custom_field>
43+
<custom_field>
44+
<name>
45+
color</name>
46+
<value>blue</value>
47+
</custom_field>
48+
</custom_fields>
49+
</adjustment>

tests/test_resources.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,34 @@ def test_charge(self):
11071107
credits = account.adjustments(type='credit')
11081108
self.assertEqual(len(credits), 0)
11091109

1110+
"""Test custom_fields"""
1111+
with self.mock_request('adjustment/charged-with-custom-fields.xml'):
1112+
# account = Account.get('chargemock')
1113+
charge = Adjustment(
1114+
unit_amount_in_cents=1000,
1115+
currency='USD',
1116+
description='test charge',
1117+
type='charge',
1118+
custom_fields=[
1119+
CustomField(name='size', value='small'),
1120+
CustomField(name='color', value='blue'),
1121+
],
1122+
)
1123+
account.charge(charge)
1124+
self.assertEqual(charge.custom_fields[0].value, 'small')
1125+
self.assertEqual(charge.custom_fields[1].value, 'blue')
1126+
1127+
with self.mock_request('adjustment/account-has-adjustments.xml'):
1128+
adjustments = account.adjustments()
1129+
with self.mock_request('adjustment/lookup.xml'):
1130+
adjustment = Adjustment.get(adjustments[0].uuid)
1131+
self.assertEqual(adjustment.custom_fields[0].value, 'small')
1132+
self.assertEqual(adjustment.custom_fields[1].value, 'blue')
1133+
1134+
with self.mock_request('adjustment/credit-adjustments.xml'):
1135+
credits = adjustment.credit_adjustments()
1136+
self.assertEqual(len(credits), 1)
1137+
11101138
finally:
11111139
with self.mock_request('adjustment/account-deleted.xml'):
11121140
account.delete()

0 commit comments

Comments
 (0)