-
Notifications
You must be signed in to change notification settings - Fork 8
/
test_search.py
42 lines (29 loc) · 1.44 KB
/
test_search.py
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
from unittest import TestCase
from unittest.mock import MagicMock, Mock, patch
from src.grafana_api.model import APIModel
from src.grafana_api.search import Search
class SearchTestCase(TestCase):
@patch("src.grafana_api.api.Api.call_the_api")
def test_search(self, call_the_api_mock):
model: APIModel = APIModel(host=MagicMock(), token=MagicMock())
search: Search = Search(grafana_api_model=model)
mock: Mock = Mock()
mock.json = Mock(return_value=list(["test"]))
call_the_api_mock.return_value = mock
self.assertEqual(["test"], search.search(search_query="Test"))
@patch("src.grafana_api.api.Api.call_the_api")
def test_search_invalid_empty_list(self, call_the_api_mock):
model: APIModel = APIModel(host=MagicMock(), token=MagicMock())
search: Search = Search(grafana_api_model=model)
mock: Mock = Mock()
mock.json = Mock(return_value=list())
call_the_api_mock.return_value = mock
with self.assertRaises(Exception):
search.search(search_query="test")
@patch("src.grafana_api.api.Api.call_the_api")
def test_search_invalid_output(self, call_the_api_mock):
model: APIModel = APIModel(host=MagicMock(), token=MagicMock())
search: Search = Search(grafana_api_model=model)
call_the_api_mock.side_effect = Exception
with self.assertRaises(Exception):
search.search(search_query=MagicMock())