Skip to content

Commit

Permalink
Better example coverage and fix bug with metric points get
Browse files Browse the repository at this point in the history
  • Loading branch information
David Moreau-Simard committed Jul 27, 2016
1 parent 658305d commit 7d6345a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
8 changes: 2 additions & 6 deletions cachetclient/cachet.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,11 @@ def __init__(self, **kwargs):
def delete(self, metric_id, point_id):
return self._delete('metrics/%s/points/%s' % (metric_id, point_id))

def get(self, metric_id=None, point_id=None, **kwargs):
def get(self, metric_id=None, **kwargs):
if metric_id is None:
raise AttributeError('metric_id is required to get metric points.')

if point_id is not None:
return self._get('metrics/%s/points' % metric_id, data=kwargs)
else:
return self._get('metrics/%s/points/%s' % (metric_id, point_id),
data=kwargs)
return self._get('metrics/%s/points' % metric_id, data=kwargs)

@api_token_required
def post(self, **kwargs):
Expand Down
16 changes: 11 additions & 5 deletions contrib/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,41 +29,47 @@

# /components
components = cachet.Components(endpoint=ENDPOINT, api_token=API_TOKEN)
print(components.get())
new_component = json.loads(components.post(name='Test component',
status=1,
description='Test component'))
components.put(id=new_component['id'], description='Updated component')
print(components.get(id=new_component['id']))
print(components.put(id=new_component['id'], description='Updated component'))
components.delete(id=new_component['id'])

# /components/groups
groups = cachet.Groups(endpoint=ENDPOINT, api_token=API_TOKEN)
print(groups.get())
new_group = json.loads(groups.post(name='Test group'))
groups.put(id=new_group['id'], name='Updated group')
print(groups.get(id=new_group['id']))
print(groups.put(id=new_group['id'], name='Updated group'))
groups.delete(new_group['id'])

# /incidents
incidents = cachet.Incidents(endpoint=ENDPOINT, api_token=API_TOKEN)
print(incidents.get())
new_incident = json.loads(incidents.post(name='Test incident',
message='Houston, we have a problem.',
status=1))
incidents.put(id=new_incident['id'],
message="There's another problem, Houston.")
print(incidents.get(id=new_incident['id']))
print(incidents.put(id=new_incident['id'],
message="There's another problem, Houston."))
incidents.delete(id=new_incident['id'])

# /metrics
# /metrics/points
metrics = cachet.Metrics(endpoint=ENDPOINT, api_token=API_TOKEN)
print(metrics.get())
new_metric = json.loads(metrics.post(name='Test metric',
suffix='Numbers per hour',
description='How many numbers per hour',
default_value=0))
print(metrics.get(id=new_metric['id']))

points = cachet.Points(endpoint=ENDPOINT, api_token=API_TOKEN)
new_point = json.loads(points.post(id=new_metric['id'], value=5))
print(points.get(metric_id=new_metric['id'], point_id=new_point['id']))
print(points.get(metric_id=new_metric['id']))

points.delete(metric_id=new_metric['id'], point_id=new_point['id'])
metrics.delete(id=new_metric['id'])

Expand Down

0 comments on commit 7d6345a

Please sign in to comment.