1
|
|
|
"""Test kytos.core.exceptions module.""" |
2
|
|
|
from unittest import TestCase |
3
|
|
|
from unittest.mock import MagicMock |
4
|
|
|
|
5
|
|
|
from kytos.core.exceptions import (KytosCoreException, KytosEventException, |
6
|
|
|
KytosNAppException, |
7
|
|
|
KytosNoTagAvailableError, |
8
|
|
|
KytosSwitchOfflineException) |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
class TestExceptions(TestCase): |
12
|
|
|
"""Exceptions tests.""" |
13
|
|
|
|
14
|
|
|
def test_kytos_core_exception(self): |
15
|
|
|
"""Test KytosCoreException exception.""" |
16
|
|
|
with self.assertRaises(Exception) as exc: |
17
|
|
|
raise KytosCoreException('msg') |
18
|
|
|
|
19
|
|
|
expected_msg = 'KytosCore exception: msg' |
20
|
|
|
self.assertEqual(str(exc.exception), expected_msg) |
21
|
|
|
|
22
|
|
|
def test_kytos_switch_offline_exception(self): |
23
|
|
|
"""Test KytosSwitchOfflineException exception.""" |
24
|
|
|
with self.assertRaises(Exception) as exc: |
25
|
|
|
switch = MagicMock() |
26
|
|
|
switch.dpid = '00:00:00:00:00:00:00:01' |
27
|
|
|
raise KytosSwitchOfflineException(switch) |
28
|
|
|
|
29
|
|
|
expected_msg = 'The switch 00:00:00:00:00:00:00:01 is not reachable. ' |
30
|
|
|
expected_msg += 'Please check the connection between the switch and ' |
31
|
|
|
expected_msg += 'the controller.' |
32
|
|
|
|
33
|
|
|
self.assertEqual(str(exc.exception), expected_msg) |
34
|
|
|
|
35
|
|
|
def test_kytos_event_exception(self): |
36
|
|
|
"""Test KytosEventException exception.""" |
37
|
|
|
with self.assertRaises(Exception) as exc: |
38
|
|
|
raise KytosEventException |
39
|
|
|
|
40
|
|
|
expected_msg = 'KytosEvent exception' |
41
|
|
|
self.assertEqual(str(exc.exception), expected_msg) |
42
|
|
|
|
43
|
|
|
def test_kytos_no_tag_avaible_error(self): |
44
|
|
|
"""Test KytosNoTagAvailableError exception.""" |
45
|
|
|
with self.assertRaises(Exception) as exc: |
46
|
|
|
link = MagicMock() |
47
|
|
|
link.id = '123' |
48
|
|
|
raise KytosNoTagAvailableError(link) |
49
|
|
|
|
50
|
|
|
expected_msg = 'Link 123 has no vlan available.' |
51
|
|
|
self.assertEqual(str(exc.exception), expected_msg) |
52
|
|
|
|
53
|
|
|
def test_kytos_napp_exception(self): |
54
|
|
|
"""Test KytosNAppException exception.""" |
55
|
|
|
with self.assertRaises(Exception) as exc: |
56
|
|
|
raise KytosNAppException() |
57
|
|
|
|
58
|
|
|
expected_msg = 'KytosNApp exception' |
59
|
|
|
self.assertEqual(str(exc.exception), expected_msg) |
60
|
|
|
|