-
Notifications
You must be signed in to change notification settings - Fork 7
/
test_licensing.py
75 lines (52 loc) · 3.02 KB
/
test_licensing.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
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
from unittest import TestCase
from unittest.mock import MagicMock, patch
from grafana_api.model import APIModel
from grafana_api.licensing import Licensing
class LicenseTestCase(TestCase):
@patch("grafana_api.api.Api.call_the_api")
def test_check_license_availability(self, call_the_api_mock):
model: APIModel = APIModel(host=MagicMock(), token=MagicMock())
licensing: Licensing = Licensing(grafana_api_model=model)
call_the_api_mock.return_value.status = 200
call_the_api_mock.return_value.data = b"true"
self.assertEqual(True, licensing.check_license_availability())
@patch("grafana_api.api.Api.call_the_api")
def test_check_license_availability_no_result(self, call_the_api_mock):
model: APIModel = APIModel(host=MagicMock(), token=MagicMock())
licensing: Licensing = Licensing(grafana_api_model=model)
call_the_api_mock.return_value.status = 400
with self.assertRaises(Exception):
licensing.check_license_availability()
@patch("grafana_api.api.Api.call_the_api")
def test_manually_force_license_refresh(self, call_the_api_mock):
model: APIModel = APIModel(host=MagicMock(), token=MagicMock())
licensing: Licensing = Licensing(grafana_api_model=model)
call_the_api_mock.return_value = dict({"jti": "2"})
self.assertEqual(dict({"jti": "2"}), licensing.manually_force_license_refresh())
@patch("grafana_api.api.Api.call_the_api")
def test_manually_force_license_refresh_no_result(self, call_the_api_mock):
model: APIModel = APIModel(host=MagicMock(), token=MagicMock())
licensing: Licensing = Licensing(grafana_api_model=model)
call_the_api_mock.return_value = dict()
with self.assertRaises(Exception):
licensing.manually_force_license_refresh()
@patch("grafana_api.api.Api.call_the_api")
def test_remove_license_from_database(self, call_the_api_mock):
model: APIModel = APIModel(host=MagicMock(), token=MagicMock())
licensing: Licensing = Licensing(grafana_api_model=model)
call_the_api_mock.return_value = dict({"status": 200})
self.assertEqual(None, licensing.remove_license_from_database())
@patch("grafana_api.api.Api.call_the_api")
def test_remove_license_from_database_no_result(self, call_the_api_mock):
model: APIModel = APIModel(host=MagicMock(), token=MagicMock())
licensing: Licensing = Licensing(grafana_api_model=model)
call_the_api_mock.return_value = dict()
with self.assertRaises(Exception):
licensing.remove_license_from_database()
@patch("grafana_api.api.Api.call_the_api")
def test_remove_license_from_database_remove_not_possible(self, call_the_api_mock):
model: APIModel = APIModel(host=MagicMock(), token=MagicMock())
licensing: Licensing = Licensing(grafana_api_model=model)
call_the_api_mock.return_value = dict({"status": 404})
with self.assertRaises(Exception):
licensing.remove_license_from_database()