Skip to content

Commit f7cd46b

Browse files
authored
[sc-66235] Support disconnecting subscriptions in Python library (#102)
* Add support for disconnecting subscriptions. * Upgrade action/cache. * Bump version number.
1 parent 9d376e3 commit f7cd46b

6 files changed

Lines changed: 50 additions & 4 deletions

File tree

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
with:
1616
python-version: "3.11"
1717
- name: Cache pip
18-
uses: actions/cache@v2
18+
uses: actions/cache@v3
1919
with:
2020
path: ~/.cache/pip
2121
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
@@ -39,7 +39,7 @@ jobs:
3939
with:
4040
python-version: ${{ matrix.python-versions }}
4141
- name: Cache pip
42-
uses: actions/cache@v2
42+
uses: actions/cache@v3
4343
with:
4444
path: ~/.cache/pip
4545
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,18 @@ chartmogul.Customer.connectSubscriptions(config, uuid='cus_5915ee5a-babd-406b-b8
150150
}
151151
]
152152
})
153+
chartmogul.Customer.disconnectSubscriptions(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb', data={
154+
'subscriptions': [
155+
{
156+
"data_source_uuid": "ds_ade45e52-47a4-231a-1ed2-eb6b9e541213",
157+
"external_id": "d1c0c885-add0-48db-8fa9-0bdf5017d6b0"
158+
},
159+
{
160+
"data_source_uuid": "ds_ade45e52-47a4-231a-1ed2-eb6b9e541213",
161+
"external_id": "9db5f4a1-1695-44c0-8bd4-de7ce4d0f1d4"
162+
}
163+
]
164+
})
153165
chartmogul.Customer.contacts(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb', cursor='aabbcc', per_page=20)
154166
chartmogul.Customer.createContact(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb', data={})
155167
chartmogul.Customer.notes(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb', cursor='aabbcc', per_page=20)
@@ -433,7 +445,8 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/chartm
433445
Make sure that:
434446
1. you have prepared `~/.pypirc` with credentials,
435447
2. a higher version has been set in `chartmogul/__init__.py`,
436-
3. Test & build package `python3 setup.py test sdist`
448+
3. Run tests `python3 -m unittest`
449+
4. Build package `python3 setup.py sdist`
437450
4. release works `twine upload --repository-url https://test.pypi.org/legacy/ dist/*`,
438451
5. release to production `twine upload dist/*`,
439452

chartmogul/api/customer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ def make(self, data, **kwargs):
8282
Customer.connectSubscriptions = Customer._method(
8383
"create", "post", "/customers/{uuid}/connect_subscriptions"
8484
)
85+
Customer.disconnectSubscriptions = Customer._method(
86+
"create", "post", "/customers/{uuid}/disconnect_subscriptions"
87+
)
8588
Customer.contacts = Contact._method("all", "get", "/customers/{uuid}/contacts", useCallerClass=True)
8689
Customer.createContact = Contact._method(
8790
"create", "post", "/customers/{uuid}/contacts", useCallerClass=True

chartmogul/api/transaction.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class _Schema(Schema):
1616
date = fields.DateTime()
1717
result = fields.String()
1818
amount_in_cents = fields.Int(allow_none=True)
19+
transaction_fees_in_cents = fields.Int(allow_none=True)
1920

2021
@post_load
2122
def make(self, data, **kwargs):

chartmogul/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "4.4.0"
1+
__version__ = "4.5.0"

test/api/test_customer.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,35 @@ def test_connectSubscriptions(self, mock_requests):
503503
self.assertEqual(mock_requests.last_request.json(), jsonRequest)
504504
self.assertEqual(result, None)
505505

506+
@requests_mock.mock()
507+
def test_disconnectSubscriptions(self, mock_requests):
508+
mock_requests.register_uri(
509+
"POST",
510+
"https://api.chartmogul.com/v1/customers/cus_5915ee5a-babd-406b-b8ce-d207133fb4cb/disconnect_subscriptions",
511+
status_code=202,
512+
)
513+
514+
jsonRequest = {
515+
"subscriptions": [
516+
{
517+
"data_source_uuid": "ds_ade45e52-47a4-231a-1ed2-eb6b9e541213",
518+
"external_id": "d1c0c885-add0-48db-8fa9-0bdf5017d6b0",
519+
},
520+
{
521+
"data_source_uuid": "ds_ade45e52-47a4-231a-1ed2-eb6b9e541213",
522+
"external_id": "9db5f4a1-1695-44c0-8bd4-de7ce4d0f1d4",
523+
},
524+
]
525+
}
526+
config = Config("token")
527+
result = Customer.disconnectSubscriptions(
528+
config, uuid="cus_5915ee5a-babd-406b-b8ce-d207133fb4cb", data=jsonRequest
529+
).get()
530+
self.assertEqual(mock_requests.call_count, 1, "expected call")
531+
self.assertEqual(mock_requests.last_request.qs, {})
532+
self.assertEqual(mock_requests.last_request.json(), jsonRequest)
533+
self.assertEqual(result, None)
534+
506535
@requests_mock.mock()
507536
def test_modify_uuid_missing(self, mock_requests):
508537
mock_requests.register_uri(

0 commit comments

Comments
 (0)