Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 65df4f7

Browse files
committed
Set end / start time to current timestamp. Add a few more tests.
1 parent d53b001 commit 65df4f7

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

grafannotate/cli.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
except ImportError:
1111
from urlparse import urlparse
1212

13+
CURRENT_TIMESTAMP = int(time.time())
14+
1315

1416
@click.command()
1517
@click.option('-u', '--uri', 'annotate_uri',
@@ -18,10 +20,10 @@
1820
@click.option('-T', '--title', 'title', default='event', help='Event title. Default: "event".')
1921
@click.option('-t', '--tag', 'tags', multiple=True, help='Event tags (can be used multiple times).')
2022
@click.option('-d', '--description', 'description', help='Event description body. Optional.')
21-
@click.option('-s', '--start', 'start_time',
22-
default=int(time.time()),
23+
@click.option('-s', '--start', 'start_time', default=CURRENT_TIMESTAMP,
2324
help='Start timestamp (unix secs). Default: current timestamp.')
24-
@click.option('-e', '--end', 'end_time', default=0, help='End timestamp (unix secs). Optional.')
25+
@click.option('-e', '--end', 'end_time', default=CURRENT_TIMESTAMP,
26+
help='End timestamp (unix secs). Optional.')
2527
def main(annotate_uri, title, tags, description, start_time, end_time):
2628
""" Send Grafana annotations """
2729

@@ -46,7 +48,7 @@ def main(annotate_uri, title, tags, description, start_time, end_time):
4648
event_data['text'] = '<b>%s</b>\n\n%s' % (title, description)
4749
event_data['tags'] = tags
4850
event_data['time'] = int(round(start_time * 1000))
49-
if end_time > 0:
51+
if end_time != start_time:
5052
if end_time < start_time:
5153
raise Exception('Event end time cannot be before start time.')
5254
event_data['isRegion'] = True

tests/test_cli.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,15 @@ def test_cli_with_tag(runner, caplog):
1818
result = runner.invoke(cli.main, ['--tag', 'event'])
1919
assert result.exit_code == 0
2020
assert 'NewConnectionError' in caplog.text
21+
22+
23+
def test_cli_with_bad_end_time(runner, caplog):
24+
result = runner.invoke(cli.main, ['--tag', 'event', '--end', 0])
25+
assert result.exit_code == 0
26+
assert 'end time cannot be before start time' in caplog.text
27+
28+
29+
def test_cli_with_bad_uri(runner, caplog):
30+
result = runner.invoke(cli.main, ['--tag', 'event', '--uri', 'blob://localhost'])
31+
assert result.exit_code == 0
32+
assert 'Scheme blob not recognised' in caplog.text

0 commit comments

Comments
 (0)