diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7e01c73..cb406d3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks.git rev: v1.4.0 hooks: - - id: autopep8-wrapper - id: check-added-large-files - id: check-ast - id: check-byte-order-marker @@ -23,16 +22,20 @@ repos: args: ['--django'] - id: requirements-txt-fixer - id: trailing-whitespace +- repo: https://github.com/pre-commit/mirrors-autopep8 + rev: v1.5 + hooks: + - id: autopep8 - repo: https://github.com/asottile/pyupgrade - rev: v1.6.1 + rev: v1.26.2 hooks: - id: pyupgrade args: ['--py3-plus'] - repo: https://github.com/asottile/seed-isort-config - rev: v1.2.0 + rev: v1.9.4 hooks: - id: seed-isort-config - repo: https://github.com/pre-commit/mirrors-isort - rev: v4.3.4 + rev: v4.3.21 hooks: - id: isort diff --git a/alertaclient/api.py b/alertaclient/api.py index 48b233a..0979e3b 100644 --- a/alertaclient/api.py +++ b/alertaclient/api.py @@ -1,4 +1,3 @@ - import json import logging import os @@ -200,10 +199,11 @@ def delete_customer(self, id): return self.http.delete('/customer/%s' % id) # Heartbeats - def heartbeat(self, origin, tags=None, timeout=None, customer=None): + def heartbeat(self, origin, tags=None, attributes=None, timeout=None, customer=None): data = { 'origin': origin, 'tags': tags or list(), + 'attributes': attributes or dict(), 'timeout': timeout, 'createTime': datetime.utcnow(), 'customer': customer diff --git a/alertaclient/auth/azure.py b/alertaclient/auth/azure.py index 353f509..eed0b6c 100644 --- a/alertaclient/auth/azure.py +++ b/alertaclient/auth/azure.py @@ -1,4 +1,3 @@ - import webbrowser from uuid import uuid4 diff --git a/alertaclient/auth/github.py b/alertaclient/auth/github.py index 5be8f83..b1c5c95 100644 --- a/alertaclient/auth/github.py +++ b/alertaclient/auth/github.py @@ -1,4 +1,3 @@ - import webbrowser from uuid import uuid4 diff --git a/alertaclient/auth/gitlab.py b/alertaclient/auth/gitlab.py index b1ef412..9603709 100644 --- a/alertaclient/auth/gitlab.py +++ b/alertaclient/auth/gitlab.py @@ -1,4 +1,3 @@ - import webbrowser from uuid import uuid4 diff --git a/alertaclient/auth/google.py b/alertaclient/auth/google.py index e36e00a..33f7d0e 100644 --- a/alertaclient/auth/google.py +++ b/alertaclient/auth/google.py @@ -1,4 +1,3 @@ - import webbrowser from uuid import uuid4 diff --git a/alertaclient/auth/oidc.py b/alertaclient/auth/oidc.py index dc311b5..2968a3a 100644 --- a/alertaclient/auth/oidc.py +++ b/alertaclient/auth/oidc.py @@ -1,4 +1,3 @@ - import webbrowser from uuid import uuid4 diff --git a/alertaclient/auth/token.py b/alertaclient/auth/token.py index 69de0d0..53d7602 100644 --- a/alertaclient/auth/token.py +++ b/alertaclient/auth/token.py @@ -1,4 +1,3 @@ - import base64 import json from http.server import BaseHTTPRequestHandler, HTTPServer diff --git a/alertaclient/auth/utils.py b/alertaclient/auth/utils.py index 68445a9..057159d 100644 --- a/alertaclient/auth/utils.py +++ b/alertaclient/auth/utils.py @@ -1,4 +1,3 @@ - import os from netrc import netrc from urllib.parse import urlparse diff --git a/alertaclient/commands/cmd_blackouts.py b/alertaclient/commands/cmd_blackouts.py index 1644e60..70c2af2 100644 --- a/alertaclient/commands/cmd_blackouts.py +++ b/alertaclient/commands/cmd_blackouts.py @@ -1,4 +1,3 @@ - import json import click diff --git a/alertaclient/commands/cmd_config.py b/alertaclient/commands/cmd_config.py index 264fdfd..f458601 100644 --- a/alertaclient/commands/cmd_config.py +++ b/alertaclient/commands/cmd_config.py @@ -1,4 +1,3 @@ - import click diff --git a/alertaclient/commands/cmd_customers.py b/alertaclient/commands/cmd_customers.py index bed8a62..9602698 100644 --- a/alertaclient/commands/cmd_customers.py +++ b/alertaclient/commands/cmd_customers.py @@ -1,4 +1,3 @@ - import json import click diff --git a/alertaclient/commands/cmd_groups.py b/alertaclient/commands/cmd_groups.py index 1753626..61348e2 100644 --- a/alertaclient/commands/cmd_groups.py +++ b/alertaclient/commands/cmd_groups.py @@ -1,4 +1,3 @@ - import json import click diff --git a/alertaclient/commands/cmd_heartbeat.py b/alertaclient/commands/cmd_heartbeat.py index f689e29..6226241 100644 --- a/alertaclient/commands/cmd_heartbeat.py +++ b/alertaclient/commands/cmd_heartbeat.py @@ -1,27 +1,47 @@ -import os -import platform import sys import click -prog = os.path.basename(sys.argv[0]) +from alertaclient.utils import origin @click.command('heartbeat', short_help='Send a heartbeat') -@click.option('--origin', '-O', metavar='ORIGIN', default='{}/{}'.format(prog, platform.uname()[1]), help='Origin of heartbeat.') +@click.option('--origin', '-O', metavar='ORIGIN', default=origin, help='Origin of heartbeat.') +@click.option('--environment', '-E', metavar='ENVIRONMENT', help='Environment eg. Production, Development') +@click.option('--severity', '-s', metavar='SEVERITY', help='Severity eg. critical, major, minor, warning') +@click.option('--service', '-S', metavar='SERVICE', multiple=True, help='List of affected services eg. app name, Web, Network, Storage, Database, Security') +@click.option('--group', '-g', metavar='GROUP', help='Group event by type eg. OS, Performance') @click.option('--tag', '-T', 'tags', multiple=True, metavar='TAG', help='List of tags eg. London, os:linux, AWS/EC2') @click.option('--timeout', metavar='SECONDS', type=int, help='Seconds before heartbeat is stale') @click.option('--customer', metavar='STRING', help='Customer') @click.option('--delete', '-D', metavar='ID', help='Delete hearbeat using ID') @click.pass_obj -def cli(obj, origin, tags, timeout, customer, delete): - """Send or delete a heartbeat.""" +def cli(obj, origin, environment, severity, service, group, tags, timeout, customer, delete): + """ + Send or delete a heartbeat. + + Note: The "environment", "severity", "service" and "group" values are only + used when heartbeat alerts are generated from slow or stale heartbeats. + """ client = obj['client'] if delete: client.delete_heartbeat(delete) else: + if any(t.startswith('environment') or t.startswith('group') for t in tags): + click.secho('ERROR: Do not use tags for "environment" or "group". See help.', bold=True) + + attributes = dict() + if environment: + attributes['environment'] = environment + if severity: + attributes['severity'] = severity + if service: + attributes['service'] = service + if group: + attributes['group'] = group + try: - heartbeat = client.heartbeat(origin=origin, tags=tags, timeout=timeout, customer=customer) + heartbeat = client.heartbeat(origin=origin, tags=tags, attributes=attributes, timeout=timeout, customer=customer) except Exception as e: click.echo('ERROR: {}'.format(e)) sys.exit(1) diff --git a/alertaclient/commands/cmd_heartbeats.py b/alertaclient/commands/cmd_heartbeats.py index d836e2d..b9964ff 100644 --- a/alertaclient/commands/cmd_heartbeats.py +++ b/alertaclient/commands/cmd_heartbeats.py @@ -1,10 +1,10 @@ - import json import click from tabulate import tabulate from alertaclient.models.heartbeat import Heartbeat +from alertaclient.utils import origin @click.command('heartbeats', short_help='List heartbeats') @@ -29,7 +29,7 @@ def cli(obj, alert, severity, timeout, purge): else: timezone = obj['timezone'] headers = { - 'id': 'ID', 'origin': 'ORIGIN', 'customer': 'CUSTOMER', 'tags': 'TAGS', + 'id': 'ID', 'origin': 'ORIGIN', 'customer': 'CUSTOMER', 'tags': 'TAGS', 'attributes': 'ATTRIBUTES', 'createTime': 'CREATED', 'receiveTime': 'RECEIVED', 'since': 'SINCE', 'timeout': 'TIMEOUT', 'latency': 'LATENCY', 'maxLatency': 'MAX LATENCY', 'status': 'STATUS' } @@ -45,24 +45,20 @@ def cli(obj, alert, severity, timeout, purge): if alert: with click.progressbar(heartbeats, label='Alerting {} heartbeats'.format(len(heartbeats))) as bar: for b in bar: - params = dict(filter(lambda a: len(a) == 2, map(lambda a: a.split(':'), b.tags))) - environment = params.get('environment', 'Production') - group = params.get('group', 'System') - tags = list(filter(lambda a: not a.startswith('environment:') - and not a.startswith('group:'), b.tags)) - if b.status == 'expired': # aka. "stale" client.send_alert( resource=b.origin, event='HeartbeatFail', + environment=b.attributes.get('environment', 'Production'), + severity=b.attributes.get('severity', severity), correlate=['HeartbeatFail', 'HeartbeatSlow', 'HeartbeatOK'], - group=group, - environment=environment, - service=['Alerta'], - severity=severity, + service=b.attributes.get('service', ['Alerta']), + group=b.attributes.get('group', 'System'), value='{}'.format(b.since), text='Heartbeat not received in {} seconds'.format(b.timeout), - tags=tags, + tags=b.tags, + attributes=b.attributes, + origin=origin, type='heartbeatAlert', timeout=timeout, customer=b.customer @@ -71,14 +67,16 @@ def cli(obj, alert, severity, timeout, purge): client.send_alert( resource=b.origin, event='HeartbeatSlow', + environment=b.attributes.get('environment', 'Production'), + severity=b.attributes.get('severity', severity), correlate=['HeartbeatFail', 'HeartbeatSlow', 'HeartbeatOK'], - group=group, - environment=environment, - service=['Alerta'], - severity=severity, + service=b.attributes.get('service', ['Alerta']), + group=b.attributes.get('group', 'System'), value='{}ms'.format(b.latency), text='Heartbeat took more than {}ms to be processed'.format(b.max_latency), - tags=tags, + tags=b.tags, + attributes=b.attributes, + origin=origin, type='heartbeatAlert', timeout=timeout, customer=b.customer @@ -87,14 +85,17 @@ def cli(obj, alert, severity, timeout, purge): client.send_alert( resource=b.origin, event='HeartbeatOK', + environment=b.attributes.get('environment', 'Production'), + severity=b.attributes.get('severity', default_normal_severity), correlate=['HeartbeatFail', 'HeartbeatSlow', 'HeartbeatOK'], - group=group, - environment=environment, - service=['Alerta'], - severity=default_normal_severity, + service=b.attributes.get('service', ['Alerta']), + group=b.attributes.get('group', 'System'), value='', text='Heartbeat OK', - tags=tags, + tags=b.tags, + attributes=b.attributes, + origin=origin, type='heartbeatAlert', + timeout=timeout, customer=b.customer ) diff --git a/alertaclient/commands/cmd_help.py b/alertaclient/commands/cmd_help.py index 05ecadd..6b67545 100644 --- a/alertaclient/commands/cmd_help.py +++ b/alertaclient/commands/cmd_help.py @@ -1,4 +1,3 @@ - import click diff --git a/alertaclient/commands/cmd_history.py b/alertaclient/commands/cmd_history.py index 9b75fcb..a454fdd 100644 --- a/alertaclient/commands/cmd_history.py +++ b/alertaclient/commands/cmd_history.py @@ -1,4 +1,3 @@ - import json import click diff --git a/alertaclient/commands/cmd_keys.py b/alertaclient/commands/cmd_keys.py index f99e767..d740eb1 100644 --- a/alertaclient/commands/cmd_keys.py +++ b/alertaclient/commands/cmd_keys.py @@ -1,4 +1,3 @@ - import json import click diff --git a/alertaclient/commands/cmd_login.py b/alertaclient/commands/cmd_login.py index 48fd9d6..fcfded8 100644 --- a/alertaclient/commands/cmd_login.py +++ b/alertaclient/commands/cmd_login.py @@ -1,4 +1,3 @@ - import sys import click diff --git a/alertaclient/commands/cmd_logout.py b/alertaclient/commands/cmd_logout.py index b6947e3..d6a1eeb 100644 --- a/alertaclient/commands/cmd_logout.py +++ b/alertaclient/commands/cmd_logout.py @@ -1,4 +1,3 @@ - import click from alertaclient.auth.utils import clear_token diff --git a/alertaclient/commands/cmd_perms.py b/alertaclient/commands/cmd_perms.py index cadba4b..2b866fd 100644 --- a/alertaclient/commands/cmd_perms.py +++ b/alertaclient/commands/cmd_perms.py @@ -1,4 +1,3 @@ - import json import click diff --git a/alertaclient/commands/cmd_query.py b/alertaclient/commands/cmd_query.py index fdc4293..9ba95e4 100644 --- a/alertaclient/commands/cmd_query.py +++ b/alertaclient/commands/cmd_query.py @@ -1,4 +1,3 @@ - import json import click @@ -97,7 +96,7 @@ def cli(obj, ids, query, filters, display, from_date=None): DateTime.localtime(alert.receive_time, timezone)), fg=color['fg']) click.secho(' last received | {}'.format( DateTime.localtime(alert.last_receive_time, timezone)), fg=color['fg']) - click.secho(' latency | {}ms'.format((latency.microseconds / 1000)), fg=color['fg']) + click.secho(' latency | {}ms'.format(latency.microseconds / 1000), fg=color['fg']) click.secho(' timeout | {}s'.format(alert.timeout), fg=color['fg']) click.secho(' alert id | {}'.format(alert.id), fg=color['fg']) diff --git a/alertaclient/commands/cmd_raw.py b/alertaclient/commands/cmd_raw.py index 381b2c0..c5b74d8 100644 --- a/alertaclient/commands/cmd_raw.py +++ b/alertaclient/commands/cmd_raw.py @@ -1,4 +1,3 @@ - import click from tabulate import tabulate diff --git a/alertaclient/commands/cmd_send.py b/alertaclient/commands/cmd_send.py index b0f3f96..94600b3 100644 --- a/alertaclient/commands/cmd_send.py +++ b/alertaclient/commands/cmd_send.py @@ -1,4 +1,3 @@ - import json import os import sys @@ -29,6 +28,7 @@ def cli(obj, resource, event, environment, severity, correlate, service, group, client = obj['client'] def send_alert(resource, event, **kwargs): + click.echo('send') try: id, alert, message = client.send_alert( resource=resource, diff --git a/alertaclient/commands/cmd_status.py b/alertaclient/commands/cmd_status.py index c94c6a9..d5e3fef 100644 --- a/alertaclient/commands/cmd_status.py +++ b/alertaclient/commands/cmd_status.py @@ -1,4 +1,3 @@ - import click from tabulate import tabulate diff --git a/alertaclient/commands/cmd_token.py b/alertaclient/commands/cmd_token.py index f315db9..a99e651 100644 --- a/alertaclient/commands/cmd_token.py +++ b/alertaclient/commands/cmd_token.py @@ -1,4 +1,3 @@ - import click from alertaclient.auth.utils import get_token diff --git a/alertaclient/commands/cmd_top.py b/alertaclient/commands/cmd_top.py index 9ef79ce..8bef932 100644 --- a/alertaclient/commands/cmd_top.py +++ b/alertaclient/commands/cmd_top.py @@ -1,4 +1,3 @@ - import click from alertaclient.top import Screen diff --git a/alertaclient/commands/cmd_uptime.py b/alertaclient/commands/cmd_uptime.py index 2ff807e..fb98aaf 100644 --- a/alertaclient/commands/cmd_uptime.py +++ b/alertaclient/commands/cmd_uptime.py @@ -1,4 +1,3 @@ - from datetime import datetime, timedelta import click diff --git a/alertaclient/commands/cmd_users.py b/alertaclient/commands/cmd_users.py index df6da32..ee2ed62 100644 --- a/alertaclient/commands/cmd_users.py +++ b/alertaclient/commands/cmd_users.py @@ -1,4 +1,3 @@ - import json import click diff --git a/alertaclient/commands/cmd_version.py b/alertaclient/commands/cmd_version.py index 679cd0b..b576353 100644 --- a/alertaclient/commands/cmd_version.py +++ b/alertaclient/commands/cmd_version.py @@ -1,4 +1,3 @@ - import click from requests import __version__ as requests_version diff --git a/alertaclient/commands/cmd_watch.py b/alertaclient/commands/cmd_watch.py index 29ae7c2..f9c8e5d 100644 --- a/alertaclient/commands/cmd_watch.py +++ b/alertaclient/commands/cmd_watch.py @@ -1,4 +1,3 @@ - import sys import time diff --git a/alertaclient/commands/cmd_whoami.py b/alertaclient/commands/cmd_whoami.py index 4c939a8..7feef78 100644 --- a/alertaclient/commands/cmd_whoami.py +++ b/alertaclient/commands/cmd_whoami.py @@ -1,4 +1,3 @@ - import click diff --git a/alertaclient/exceptions.py b/alertaclient/exceptions.py index 9d3aa03..d17c798 100644 --- a/alertaclient/exceptions.py +++ b/alertaclient/exceptions.py @@ -1,4 +1,3 @@ - try: from click import ClickException as ClientException # type: ignore except Exception: diff --git a/alertaclient/models/alert.py b/alertaclient/models/alert.py index c31348c..5ea741a 100644 --- a/alertaclient/models/alert.py +++ b/alertaclient/models/alert.py @@ -1,4 +1,3 @@ - from datetime import datetime from alertaclient.utils import DateTime diff --git a/alertaclient/models/blackout.py b/alertaclient/models/blackout.py index fdee437..d1b3716 100644 --- a/alertaclient/models/blackout.py +++ b/alertaclient/models/blackout.py @@ -1,4 +1,3 @@ - from datetime import datetime, timedelta from alertaclient.utils import DateTime diff --git a/alertaclient/models/customer.py b/alertaclient/models/customer.py index ae199a6..0b5d10f 100644 --- a/alertaclient/models/customer.py +++ b/alertaclient/models/customer.py @@ -1,4 +1,3 @@ - class Customer: def __init__(self, match, customer, **kwargs): diff --git a/alertaclient/models/group.py b/alertaclient/models/group.py index b36c887..7657ed5 100644 --- a/alertaclient/models/group.py +++ b/alertaclient/models/group.py @@ -1,4 +1,3 @@ - from typing import Any, Dict from uuid import uuid4 diff --git a/alertaclient/models/heartbeat.py b/alertaclient/models/heartbeat.py index f6340b1..4b8f56f 100644 --- a/alertaclient/models/heartbeat.py +++ b/alertaclient/models/heartbeat.py @@ -1,4 +1,3 @@ - from datetime import datetime, timedelta from alertaclient.utils import DateTime @@ -9,10 +8,15 @@ class Heartbeat: def __init__(self, origin=None, tags=None, create_time=None, timeout=None, customer=None, **kwargs): + if any(['.' in key for key in kwargs.get('attributes', dict()).keys()])\ + or any(['$' in key for key in kwargs.get('attributes', dict()).keys()]): + raise ValueError('Attribute keys must not contain "." or "$"') + self.id = kwargs.get('id', None) self.origin = origin self.status = kwargs.get('status', None) or 'unknown' self.tags = tags or list() + self.attributes = kwargs.get('attributes', None) or dict() self.event_type = kwargs.get('event_type', kwargs.get('type', None)) or 'Heartbeat' self.create_time = create_time self.timeout = timeout @@ -37,6 +41,8 @@ def __repr__(self): def parse(cls, json): if not isinstance(json.get('tags', []), list): raise ValueError('tags must be a list') + if not isinstance(json.get('attributes', {}), dict): + raise ValueError('attributes must be a JSON object') if not isinstance(json.get('timeout', 0), int): raise ValueError('timeout must be an integer') @@ -45,6 +51,7 @@ def parse(cls, json): origin=json.get('origin', None), status=json.get('status', None), tags=json.get('tags', list()), + attributes=json.get('attributes', dict()), event_type=json.get('type', None), create_time=DateTime.parse(json.get('createTime')), timeout=json.get('timeout', None), @@ -59,6 +66,7 @@ def tabular(self, timezone=None): 'origin': self.origin, 'customer': self.customer, 'tags': ','.join(self.tags), + 'attributes': self.attributes, 'createTime': DateTime.localtime(self.create_time, timezone), 'receiveTime': DateTime.localtime(self.receive_time, timezone), 'since': self.since, diff --git a/alertaclient/models/history.py b/alertaclient/models/history.py index e575206..f400f9d 100644 --- a/alertaclient/models/history.py +++ b/alertaclient/models/history.py @@ -1,4 +1,3 @@ - from datetime import datetime from alertaclient.utils import DateTime diff --git a/alertaclient/models/key.py b/alertaclient/models/key.py index b0bd24b..6a6182f 100644 --- a/alertaclient/models/key.py +++ b/alertaclient/models/key.py @@ -1,4 +1,3 @@ - from alertaclient.utils import DateTime diff --git a/alertaclient/models/permission.py b/alertaclient/models/permission.py index b1ee4df..66a5144 100644 --- a/alertaclient/models/permission.py +++ b/alertaclient/models/permission.py @@ -1,5 +1,3 @@ - - class Permission: def __init__(self, match, scopes, **kwargs): diff --git a/alertaclient/models/user.py b/alertaclient/models/user.py index fc1c2d6..0adea57 100644 --- a/alertaclient/models/user.py +++ b/alertaclient/models/user.py @@ -1,4 +1,3 @@ - from alertaclient.utils import DateTime diff --git a/alertaclient/top.py b/alertaclient/top.py index 2cb484a..c3756fe 100644 --- a/alertaclient/top.py +++ b/alertaclient/top.py @@ -1,4 +1,3 @@ - import curses import sys import time diff --git a/alertaclient/utils.py b/alertaclient/utils.py index 25e4273..879b7df 100644 --- a/alertaclient/utils.py +++ b/alertaclient/utils.py @@ -1,6 +1,8 @@ - import datetime import json +import os +import platform +import sys import click import pytz @@ -56,3 +58,8 @@ def show_skipped(id): client.action(id, action=action, text=text or 'status changed using CLI', timeout=timeout) except Exception: skipped += 1 + + +def origin(): + prog = os.path.basename(sys.argv[0]) + return '{}/{}'.format(prog, platform.uname()[1]) diff --git a/tests/test_alerts.py b/tests/test_alerts.py index 0e7f3f6..bc27750 100644 --- a/tests/test_alerts.py +++ b/tests/test_alerts.py @@ -1,4 +1,3 @@ - import unittest import requests_mock diff --git a/tests/test_blackouts.py b/tests/test_blackouts.py index 6ecf2fe..2a841b3 100644 --- a/tests/test_blackouts.py +++ b/tests/test_blackouts.py @@ -1,4 +1,3 @@ - import unittest import requests_mock diff --git a/tests/test_commands.py b/tests/test_commands.py index 3385766..c0de243 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -1,10 +1,12 @@ import unittest +from uuid import UUID import requests_mock from click.testing import CliRunner from alertaclient.api import Client -from alertaclient.commands.cmd_whoami import cli as whoami +from alertaclient.commands.cmd_heartbeat import cli as heartbeat_cmd +from alertaclient.commands.cmd_whoami import cli as whoami_cmd from alertaclient.config import Config @@ -17,7 +19,49 @@ def setUp(self): self.obj = config.options self.obj['client'] = self.client - self.runner = CliRunner() + self.runner = CliRunner(echo_stdin=True) + + @requests_mock.mock() + def test_send_cmd(self, m): + + config_response = """ + {} + """ + m.get('/config', text=config_response) + + send_response = """ + { + "heartbeat": { + "attributes": { + "environment": "Production", + "service": [ + "Web" + ], + "severity": "major" + }, + "createTime": "2020-01-25T12:32:50.223Z", + "customer": null, + "href": "http://api.local.alerta.io:8080/heartbeat/e07d7c02-0b41-418a-b0e6-cd172e06c872", + "id": "e07d7c02-0b41-418a-b0e6-cd172e06c872", + "latency": 14, + "maxLatency": 2000, + "origin": "alerta/macbook.lan", + "receiveTime": "2020-01-25T12:32:50.237Z", + "since": 0, + "status": "ok", + "tags": [], + "timeout": 86400, + "type": "Heartbeat" + }, + "id": "e07d7c02-0b41-418a-b0e6-cd172e06c872", + "status": "ok" + } + """ + + m.post('/heartbeat', text=send_response) + result = self.runner.invoke(heartbeat_cmd, ['-E', 'Production', '-S', 'Web', '-s', 'major'], obj=self.obj) + UUID(result.output.strip()) + self.assertEqual(result.exit_code, 0) @requests_mock.mock() def test_whoami_cmd(self, m): @@ -44,6 +88,6 @@ def test_whoami_cmd(self, m): """ m.get('/userinfo', text=whoami_response) - result = self.runner.invoke(whoami, ['-u'], obj=self.obj) + result = self.runner.invoke(whoami_cmd, ['-u'], obj=self.obj) self.assertIn('preferred_username : admin@alerta.io', result.output) self.assertEqual(result.exit_code, 0) diff --git a/tests/test_customers.py b/tests/test_customers.py index 47996b1..f804dd8 100644 --- a/tests/test_customers.py +++ b/tests/test_customers.py @@ -1,4 +1,3 @@ - import unittest import requests_mock diff --git a/tests/test_groups.py b/tests/test_groups.py index 0a8c80e..5686d8d 100644 --- a/tests/test_groups.py +++ b/tests/test_groups.py @@ -1,4 +1,3 @@ - import unittest import requests_mock diff --git a/tests/test_heartbeats.py b/tests/test_heartbeats.py index db86f56..a113052 100644 --- a/tests/test_heartbeats.py +++ b/tests/test_heartbeats.py @@ -1,4 +1,3 @@ - import unittest import requests_mock diff --git a/tests/test_history.py b/tests/test_history.py index dcabf36..256a743 100644 --- a/tests/test_history.py +++ b/tests/test_history.py @@ -1,4 +1,3 @@ - import unittest import requests_mock diff --git a/tests/test_keys.py b/tests/test_keys.py index 80488a4..dbaa3fd 100644 --- a/tests/test_keys.py +++ b/tests/test_keys.py @@ -1,4 +1,3 @@ - import unittest import requests_mock diff --git a/tests/test_notes.py b/tests/test_notes.py index 9683bc1..7dc90bd 100644 --- a/tests/test_notes.py +++ b/tests/test_notes.py @@ -1,4 +1,3 @@ - import unittest import requests_mock diff --git a/tests/test_permissions.py b/tests/test_permissions.py index 6ce2f30..2b04ed0 100644 --- a/tests/test_permissions.py +++ b/tests/test_permissions.py @@ -1,4 +1,3 @@ - import unittest import requests_mock diff --git a/tests/test_remoteconfig.py b/tests/test_remoteconfig.py index f3349cd..73e8aea 100644 --- a/tests/test_remoteconfig.py +++ b/tests/test_remoteconfig.py @@ -1,4 +1,3 @@ - import unittest import requests diff --git a/tests/test_users.py b/tests/test_users.py index 41044f6..8a25754 100644 --- a/tests/test_users.py +++ b/tests/test_users.py @@ -1,4 +1,3 @@ - import unittest import requests_mock