tests.unit.commands.test_users_parser   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 78.26 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 32
dl 36
loc 46
ccs 31
cts 31
cp 1
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A TestUsersParser.test_parse() 10 10 2
A TestUsersParser.test_parse__error() 12 12 2
A TestUsersParser.test_call() 9 9 1

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
"""kytos.cli.commands.users.parser tests."""
2 1
import sys
3 1
import unittest
4 1
from unittest.mock import patch
5
6 1
from kytos.cli.commands.users.parser import call, parse
7 1
from kytos.utils.exceptions import KytosException
8
9
10 1 View Code Duplication
class TestUsersParser(unittest.TestCase):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
11
    """Test the UsersAPI parser methods."""
12
13 1
    @staticmethod
14 1
    @patch('kytos.cli.commands.users.parser.call')
15 1
    @patch('kytos.cli.commands.users.parser.docopt', return_value='args')
16 1
    def test_parse(*args):
17
        """Test parse method."""
18 1
        (_, mock_call) = args
19 1
        with patch.object(sys, 'argv', ['A', 'B', 'C']):
20 1
            parse('argv')
21
22 1
            mock_call.assert_called_with('C', 'args')
23
24 1
    @staticmethod
25 1
    @patch('sys.exit')
26 1
    @patch('kytos.cli.commands.users.parser.call')
27 1
    @patch('kytos.cli.commands.users.parser.docopt', return_value='args')
28 1
    def test_parse__error(*args):
29
        """Test parse method to error case."""
30 1
        (_, mock_call, mock_exit) = args
31 1
        mock_call.side_effect = KytosException
32 1
        with patch.object(sys, 'argv', ['A', 'B', 'C']):
33 1
            parse('argv')
34
35 1
            mock_exit.assert_called()
36
37 1
    @staticmethod
38 1
    @patch('kytos.cli.commands.users.api.UsersAPI.register')
39 1
    @patch('kytos.utils.config.KytosConfig')
40 1
    def test_call(*args):
41
        """Test call method."""
42 1
        (_, mock_users_api) = args
43 1
        call('register', 'args')
44
45
        mock_users_api.assert_called_with('args')
46