Skip to content

Commit 7d6345a

Browse files
author
David Moreau-Simard
committed
Better example coverage and fix bug with metric points get
1 parent 658305d commit 7d6345a

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

cachetclient/cachet.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,11 @@ def __init__(self, **kwargs):
201201
def delete(self, metric_id, point_id):
202202
return self._delete('metrics/%s/points/%s' % (metric_id, point_id))
203203

204-
def get(self, metric_id=None, point_id=None, **kwargs):
204+
def get(self, metric_id=None, **kwargs):
205205
if metric_id is None:
206206
raise AttributeError('metric_id is required to get metric points.')
207207

208-
if point_id is not None:
209-
return self._get('metrics/%s/points' % metric_id, data=kwargs)
210-
else:
211-
return self._get('metrics/%s/points/%s' % (metric_id, point_id),
212-
data=kwargs)
208+
return self._get('metrics/%s/points' % metric_id, data=kwargs)
213209

214210
@api_token_required
215211
def post(self, **kwargs):

contrib/example.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,41 +29,47 @@
2929

3030
# /components
3131
components = cachet.Components(endpoint=ENDPOINT, api_token=API_TOKEN)
32+
print(components.get())
3233
new_component = json.loads(components.post(name='Test component',
3334
status=1,
3435
description='Test component'))
36+
components.put(id=new_component['id'], description='Updated component')
3537
print(components.get(id=new_component['id']))
36-
print(components.put(id=new_component['id'], description='Updated component'))
3738
components.delete(id=new_component['id'])
3839

3940
# /components/groups
4041
groups = cachet.Groups(endpoint=ENDPOINT, api_token=API_TOKEN)
42+
print(groups.get())
4143
new_group = json.loads(groups.post(name='Test group'))
44+
groups.put(id=new_group['id'], name='Updated group')
4245
print(groups.get(id=new_group['id']))
43-
print(groups.put(id=new_group['id'], name='Updated group'))
4446
groups.delete(new_group['id'])
4547

4648
# /incidents
4749
incidents = cachet.Incidents(endpoint=ENDPOINT, api_token=API_TOKEN)
50+
print(incidents.get())
4851
new_incident = json.loads(incidents.post(name='Test incident',
4952
message='Houston, we have a problem.',
5053
status=1))
54+
incidents.put(id=new_incident['id'],
55+
message="There's another problem, Houston.")
5156
print(incidents.get(id=new_incident['id']))
52-
print(incidents.put(id=new_incident['id'],
53-
message="There's another problem, Houston."))
5457
incidents.delete(id=new_incident['id'])
5558

5659
# /metrics
5760
# /metrics/points
5861
metrics = cachet.Metrics(endpoint=ENDPOINT, api_token=API_TOKEN)
62+
print(metrics.get())
5963
new_metric = json.loads(metrics.post(name='Test metric',
6064
suffix='Numbers per hour',
6165
description='How many numbers per hour',
6266
default_value=0))
6367
print(metrics.get(id=new_metric['id']))
68+
6469
points = cachet.Points(endpoint=ENDPOINT, api_token=API_TOKEN)
6570
new_point = json.loads(points.post(id=new_metric['id'], value=5))
66-
print(points.get(metric_id=new_metric['id'], point_id=new_point['id']))
71+
print(points.get(metric_id=new_metric['id']))
72+
6773
points.delete(metric_id=new_metric['id'], point_id=new_point['id'])
6874
metrics.delete(id=new_metric['id'])
6975

0 commit comments

Comments
 (0)