Passed
Pull Request — master (#452)
by Valessio Soares de
02:56
created

  A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 49
rs 10
wmc 4

5 Methods

Rating   Name   Duplication   Size   Complexity  
B estController.setUp() 0 25 1
A estController.test_register_configuration_endpoint() 0 5 1
A ustomOption.__init__() 0 3 1
A estController.test_configuration_endpoint() 0 5 1
A estController.test_register_kytos_endpoints() 0 8 1
1
"""Controller tests."""
2
3
import json
4
import unittest
5
6
from kytos.core.controller import Controller
7
8
9
class TestController(unittest.TestCase):
10
    """Test the class Controller."""
11
12
    def setUp(self):
13
        """Instantiate a controller with custom options."""
14
        class CustomOption:
15
            """Class to represent a custom option used by Kytos."""
16
17
            def __init__(self, **kwargs):
18
                """Construtor method of CustomOption."""
19
                self.__dict__.update(kwargs)
20
21
        options_dict = {'api_port': '8181',
22
                        'conf': '/etc/kytos/kytos.conf',
23
                        'daemon': 'False',
24
                        'debug': 'False',
25
                        'foreground': True,
26
                        'installed_napps': '/var/lib/kytos/napps/.installed',
27
                        'listen': '0.0.0.0',
28
                        'logging': '/etc/kytos/logging.ini',
29
                        'napps': '/var/lib/kytos/napps',
30
                        'napps_repositories': ['https://www.sample.com/repo/'],
31
                        'pidfile': '/var/run/kytos/kytosd.pid',
32
                        'port': '6633',
33
                        'workdir': '/var/lib/kytos'}
34
35
        self.options = options_dict
36
        self.controller = Controller(CustomOption(**options_dict))
37
38
    def test_configuration_endpoint(self):
39
        """Should return the attribute options as json."""
40
        expected = json.dumps(self.options)
41
        actual = self.controller.configuration_endpoint()
42
        self.assertEqual(expected, actual)
43
44
    def test_register_configuration_endpoint(self):
45
        """Should register the endpoint '/kytos/config/'."""
46
        expected_endpoint = '/kytos/config/'
47
        actual_endpoints = self.controller.api_server.rest_endpoints
48
        self.assertIn(expected_endpoint, actual_endpoints)
49
50
    def test_register_kytos_endpoints(self):
51
        """Verify all endpoints registered by Controller."""
52
        expected_endpoints = ['/kytos/config/', '/kytos/shutdown/',
53
                              '/kytos/status/', '/index.html', '/',
54
                              '/static/<path:filename>']
55
        actual_endpoints = self.controller.api_server.rest_endpoints
56
        self.assertListEqual(sorted(expected_endpoints),
57
                             sorted(actual_endpoints))
58