-
Notifications
You must be signed in to change notification settings - Fork 8
/
test_short_url.py
36 lines (25 loc) · 1.36 KB
/
test_short_url.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
from unittest import TestCase
from unittest.mock import MagicMock, patch
from grafana_api.model import APIModel
from grafana_api.short_url import ShortUrl
class ShortUrlTestCase(TestCase):
@patch("grafana_api.api.Api.call_the_api")
def test_create_short_url(self, call_the_api_mock):
model: APIModel = APIModel(host=MagicMock(), token=MagicMock())
short_url: ShortUrl = ShortUrl(grafana_api_model=model)
call_the_api_mock.return_value = dict({"url": "test"})
self.assertEqual("test", short_url.create_short_url(path="Test").get("url"))
@patch("grafana_api.api.Api.call_the_api")
def test_create_short_url_invalid_path(self, call_the_api_mock):
model: APIModel = APIModel(host=MagicMock(), token=MagicMock())
short_url: ShortUrl = ShortUrl(grafana_api_model=model)
call_the_api_mock.return_value = dict()
with self.assertRaises(ValueError):
short_url.create_short_url(path="")
@patch("grafana_api.api.Api.call_the_api")
def test_create_short_url_invalid_output(self, call_the_api_mock):
model: APIModel = APIModel(host=MagicMock(), token=MagicMock())
short_url: ShortUrl = ShortUrl(grafana_api_model=model)
call_the_api_mock.return_value = dict({"url": None})
with self.assertRaises(Exception):
short_url.create_short_url(path="test")