Completed
Push — master ( 8c7e23...a5eeed )
by Beraldo
15s queued 11s
created

tests.test_core.test_link   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 35
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A TestLink._get_v0x04_ifaces() 0 14 1
A TestLink.test_init_with_null_endpoints() 0 4 2
A TestLink.test_init() 0 6 1
A TestLink.setUp() 0 3 1
A TestLink.test_link_id() 0 4 1
1
"""Link tests."""
2
import logging
3
import unittest
4
from unittest.mock import Mock
5
6
from kytos.core.interface import Interface
7
from kytos.core.link import Link
8
from kytos.core.switch import Switch
9
10
logging.basicConfig(level=logging.CRITICAL)
11
12
13
class TestLink(unittest.TestCase):
14
    """Test Links."""
15
16
    def setUp(self):
17
        """Create interface objects."""
18
        self.iface1, self.iface2 = self._get_v0x04_ifaces()
19
20
    @staticmethod
21
    def _get_v0x04_ifaces(*args, **kwargs):
22
        """Create a pair of v0x04 interfaces with optional extra arguments."""
23
        switch1 = Switch('dpid1')
24
        switch1.connection = Mock()
25
        switch1.connection.protocol.version = 0x04
26
        iface1 = Interface('interface1', 41, switch1, *args, **kwargs)
27
28
        switch2 = Switch('dpid2')
29
        switch2.connection = Mock()
30
        switch2.connection.protocol.version = 0x04
31
        iface2 = Interface('interface2', 42, switch2, *args, **kwargs)
32
33
        return iface1, iface2
34
35
    def test_init(self):
36
        """Test normal Link initialization."""
37
        link = Link(self.iface1, self.iface2)
38
        self.assertIsInstance(link, Link)
39
        self.assertIs(link.is_active(), True)
40
        self.assertIs(link.is_enabled(), False)
41
42
    def test_init_with_null_endpoints(self):
43
        """Test initialization with None as endpoints."""
44
        with self.assertRaises(ValueError):
45
            Link(None, None)
46
47
    def test_link_id(self):
48
        link1 = Link(self.iface1, self.iface2)
49
        link2 = Link(self.iface2, self.iface1)
50
        self.assertEqual(link1.id, link2.id)
51