Skip to content

Commit

Permalink
Added method for Connect subscriptions [ch4617] (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
hassansin authored Dec 20, 2018
1 parent 2f8d968 commit ee21db8
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ chartmogul.Customer.modify(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4c
'into': {'customer_uuid': 'cus_2123290f-09c8-4628-a205-db5596bd58f7'}
})
chartmogul.Customer.destroy(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb')
chartmogul.Customer.connectSubscriptions(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb', data={
'subscriptions': [
{
"data_source_uuid": "ds_ade45e52-47a4-231a-1ed2-eb6b9e541213",
"external_id": "d1c0c885-add0-48db-8fa9-0bdf5017d6b0"
},
{
"data_source_uuid": "ds_ade45e52-47a4-231a-1ed2-eb6b9e541213",
"external_id": "9db5f4a1-1695-44c0-8bd4-de7ce4d0f1d4"
}
]
})
```

#### [Customer Attributes](https://dev.chartmogul.com/docs/customer-attributes)
Expand Down
1 change: 1 addition & 0 deletions chartmogul/api/customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ def make(self, data):

Customer.search = Customer._method('all', 'get', '/customers/search')
Customer.merge = Customer._method('merge', 'post', '/customers/merges')
Customer.connectSubscriptions = Customer._method('create', 'post', '/customers/{uuid}/connect_subscriptions')
2 changes: 1 addition & 1 deletion chartmogul/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _load(cls, response):
(immutable, therefore all set on creation by generator)
"""
response.raise_for_status()
if response.status_code == 204:
if response.status_code == 204 or response.status_code == 202:
return None
try:
jsonObj = response.json()
Expand Down
26 changes: 26 additions & 0 deletions test/api/test_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,29 @@ def test_merge(self, mock_requests):
self.assertEqual(mock_requests.last_request.qs, {})
self.assertEqual(mock_requests.last_request.json(), jsonRequest)
self.assertEqual(result, None)
@requests_mock.mock()
def test_connectSubscriptions(self, mock_requests):
mock_requests.register_uri(
'POST',
"https://api.chartmogul.com/v1/customers/cus_5915ee5a-babd-406b-b8ce-d207133fb4cb/connect_subscriptions",
status_code=202
)

jsonRequest = {
'subscriptions': [
{
"data_source_uuid": "ds_ade45e52-47a4-231a-1ed2-eb6b9e541213",
"external_id": "d1c0c885-add0-48db-8fa9-0bdf5017d6b0"
},
{
"data_source_uuid": "ds_ade45e52-47a4-231a-1ed2-eb6b9e541213",
"external_id": "9db5f4a1-1695-44c0-8bd4-de7ce4d0f1d4"
}
]
}
config = Config("token", "secret")
result = Customer.connectSubscriptions(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb', data=jsonRequest).get()
self.assertEqual(mock_requests.call_count, 1, "expected call")
self.assertEqual(mock_requests.last_request.qs, {})
self.assertEqual(mock_requests.last_request.json(), jsonRequest)
self.assertEqual(result, None)

0 comments on commit ee21db8

Please sign in to comment.