Skip to content

Commit 310a6f0

Browse files
committed
Fix docs, explicit content-type, tests
1 parent 8b2f81c commit 310a6f0

File tree

4 files changed

+56
-13
lines changed

4 files changed

+56
-13
lines changed

README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,22 +179,28 @@ chartmogul.Plan.destroy(config, uuid='')
179179
#### [Invoices](https://dev.chartmogul.com/docs/invoices)
180180

181181
```python
182-
chartmogul.Invoice.create(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb', data={})
183-
chartmogul.Invoice.all(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb', page=2, per_page=10)
182+
import chartmogul.imp
183+
184+
chartmogul.imp.Invoice.create(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb', data={})
185+
chartmogul.imp.Invoice.all(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb', page=2, per_page=10)
184186
```
185187

186188
#### [Transactions](https://dev.chartmogul.com/docs/transactions)
187189

188190
```python
189-
chartmogul.Transaction.create(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb', data={})
191+
import chartmogul.imp
192+
193+
chartmogul.imp.Transaction.create(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb', data={})
190194
```
191195

192196
#### [Subscriptions](https://dev.chartmogul.com/docs/subscriptions)
193197

194198
```python
195-
chartmogul.Subscription.all(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb')
196-
chartmogul.Subscription.cancel(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb' data={'cancelled_at': ''})
197-
chartmogul.Subscription.modify(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb' data={'cancellation_dates': []})
199+
import chartmogul.imp
200+
201+
chartmogul.imp.Subscription.all(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb')
202+
chartmogul.imp.Subscription.cancel(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb' data={'cancelled_at': ''})
203+
chartmogul.imp.Subscription.modify(config, uuid='cus_5915ee5a-babd-406b-b8ce-d207133fb4cb' data={'cancellation_dates': []})
198204
```
199205

200206
### [Metrics API](https://dev.chartmogul.com/docs/introduction-metrics-api)
@@ -203,7 +209,7 @@ Available methods in Metrics API:
203209

204210

205211
```python
206-
chartmogul.metrics.all(config,
212+
chartmogul.Metrics.all(config,
207213
start_date='2015-01-01', # notice the _ here
208214
end_date='2015-11-24',
209215
interval='month',

chartmogul/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"""
2828

2929
__title__ = 'chartmogul'
30-
__version__ = '1.0.0'
30+
__version__ = '1.0.1'
3131
__build__ = 0x000000
3232
__author__ = 'ChartMogul Ltd'
3333
__license__ = 'MIT'

chartmogul/resource.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,13 @@ def _request(cls, config, method, http_verb, path, data=None, **kwargs):
115115
data = dumps(data, default=json_serial)
116116

117117
return Promise(lambda resolve, _:
118-
resolve(getattr(requests, http_verb)(config.uri + path,
119-
data=data,
120-
params=params,
121-
auth=config.auth)
122-
)).then(cls._load).catch(annotateHTTPError)
118+
resolve(getattr(requests, http_verb)(
119+
config.uri + path,
120+
data=data,
121+
headers={'content-type': 'application/json'},
122+
params=params,
123+
auth=config.auth)
124+
)).then(cls._load).catch(annotateHTTPError)
123125

124126
@classmethod
125127
def _expandPath(cls, path, kwargs):

test/api/test_plan.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class PlanTestCase(unittest.TestCase):
99
"""
1010
Tests cursor query parameters & modify (patch a plan).
1111
"""
12+
maxDiff = None
1213

1314
@requests_mock.mock()
1415
def test_cursor_list_plans(self, mock_requests):
@@ -71,3 +72,37 @@ def test_modify_plan(self, mock_requests):
7172
self.assertEqual(mock_requests.last_request.json(),
7273
{"name": u"new_name"})
7374
self.assertEqual(str(plan), str(expected))
75+
76+
@requests_mock.mock()
77+
def test_create_plan(self, mock_requests):
78+
expected_plan_dict = {
79+
"uuid": u"whatever_uuid",
80+
"data_source_uuid": u"some_uuid",
81+
"name": u"new_name",
82+
"interval_count": 2,
83+
"interval_unit": u"moonshines",
84+
"external_id": u"custom_filter"
85+
}
86+
sent = {
87+
"data_source_uuid": "ds_9bb53a1e-edfd-11e6-bf83-af49e978cb11",
88+
"name": "Gold Plan",
89+
"interval_count": 1,
90+
"interval_unit": "month",
91+
"external_id": "plan_0002"
92+
}
93+
mock_requests.register_uri(
94+
'POST',
95+
"https://api.chartmogul.com/v1/plans",
96+
request_headers={'Authorization': 'Basic dG9rZW46c2VjcmV0'},
97+
status_code=200,
98+
json=expected_plan_dict
99+
)
100+
config = Config("token", "secret") # is actually checked in mock
101+
plan = Plan.create(
102+
config,
103+
data=sent).get()
104+
expected = Plan(**expected_plan_dict)
105+
self.assertEqual(mock_requests.call_count, 1, "expected call")
106+
self.assertEqual(mock_requests.last_request.qs, {})
107+
self.assertEqual(mock_requests.last_request.json(), sent)
108+
self.assertEqual(str(plan), str(expected))

0 commit comments

Comments
 (0)