Passed
Push — master ( b66520...374a48 )
by Humberto
02:29 queued 11s
created

build.tests.unit.helpers   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 51.11 %

Importance

Changes 0
Metric Value
eloc 23
dl 23
loc 45
rs 10
c 0
b 0
f 0
wmc 6

3 Functions

Rating   Name   Duplication   Size   Complexity  
A get_controller_mock() 0 6 1
A get_app_test_client() 0 4 1
A get_napp_urls() 23 23 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
"""Module to help to create tests."""
2
from unittest.mock import Mock
3
4
from kytos.core.config import KytosConfig
5
from kytos.core import Controller
6
7
8
def get_controller_mock():
9
    """Return a controller mock."""
10
    options = KytosConfig().options['daemon']
11
    controller = Controller(options)
12
    controller.log = Mock()
13
    return controller
14
15
16 View Code Duplication
def get_napp_urls(napp):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
17
    """Return the kytos/topology urls.
18
19
    The urls will be like:
20
21
    urls = [
22
        (options, methods, url)
23
    ]
24
25
    """
26
    controller = napp.controller
27
    controller.api_server.register_napp_endpoints(napp)
28
29
    urls = []
30
    for rule in controller.api_server.app.url_map.iter_rules():
31
        options = {}
32
        for arg in rule.arguments:
33
            options[arg] = "[{0}]".format(arg)
34
35
        if f'{napp.username}/{napp.name}' in str(rule):
36
            urls.append((options, rule.methods, f'{str(rule)}'))
37
38
    return urls
39
40
41
def get_app_test_client(napp):
42
    """Return a flask api test client."""
43
    napp.controller.api_server.register_napp_endpoints(napp)
44
    return napp.controller.api_server.app.test_client()
45