forked from devopsmakers/python-grafannotate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cli.py
More file actions
88 lines (64 loc) · 2.68 KB
/
test_cli.py
File metadata and controls
88 lines (64 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import pytest
import time
import mock
from click.testing import CliRunner
from grafannotate import cli
CURRENT_TIMESTAMP = int(time.time())
@pytest.fixture
def runner():
return CliRunner()
def test_cli(runner, caplog):
result = runner.invoke(cli.main)
assert result.exit_code == 0
assert 'must have at least one tag' in caplog.text
def test_cli_with_tag(runner, caplog):
result = runner.invoke(cli.main, ['--tag', 'event'])
assert result.exit_code == 0
assert 'NewConnectionError' in caplog.text
@mock.patch('grafannotate.cli.Annotation.send', autospec=True)
def test_cli_with_debug_mock(mock_send, runner, caplog):
return_data = {
'event_data': {
'isRegion': True,
'tags': ['test'],
'text': '<b>event</b>\n\ntesting',
'time': 1559332960000,
'timeEnd': 1559332970000
},
'id': '12345',
'message': 'Annotation added'
}
mock_send.return_value = return_data
caplog.set_level('DEBUG')
result = runner.invoke(cli.main, ['--tag', 'event'])
assert result.exit_code == 0
assert return_data['message'] in caplog.text
assert str(return_data['event_data']) in caplog.text
def test_cli_with_debug(runner, caplog):
result = runner.invoke(cli.main, ['--tag', 'event', '--debug'])
assert result.exit_code == 0
assert 'NewConnectionError' in caplog.text
def test_cli_with_bad_end_time(runner, caplog):
result = runner.invoke(cli.main, ['--tag', 'event', '--end', 0])
assert result.exit_code == 0
assert 'end time cannot be before start time' in caplog.text
def test_cli_with_bad_uri(runner, caplog):
result = runner.invoke(cli.main, ['--tag', 'event', '--uri', 'blob://localhost'])
assert result.exit_code == 0
assert 'Scheme blob not recognised' in caplog.text
def test_cli_with_user_pass(runner, caplog):
result = runner.invoke(cli.main, ['--tag', 'event', '--uri', 'http://user:pass@localhost'])
assert result.exit_code == 0
assert 'NewConnectionError' in caplog.text
def test_cli_with_api_key(runner, caplog):
result = runner.invoke(cli.main, ['--tag', 'event', '--uri', 'http://localhost', '--api-key', 'aTestKey'])
assert result.exit_code == 0
assert 'NewConnectionError' in caplog.text
def test_cli_with_end_time(runner, caplog):
result = runner.invoke(cli.main, ['--tag', 'event', '--end', CURRENT_TIMESTAMP + 600])
assert result.exit_code == 0
assert 'NewConnectionError' in caplog.text
def test_cli_with_influx(runner, caplog):
result = runner.invoke(cli.main, ['--tag', 'event', '--uri', 'influx://localhost:8086'])
assert result.exit_code == 0
assert 'NewConnectionError' in caplog.text