tests.unit.commands.test_napps_parser   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 50
dl 0
loc 75
ccs 48
cts 48
cp 1
rs 10
c 0
b 0
f 0
wmc 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A TestNappsParser.test_parse__error() 0 12 2
A TestNappsParser.test_parse_napps__all() 0 6 1
A TestNappsParser.test_call() 0 10 1
A TestNappsParser.test_parse() 0 10 2
A TestNappsParser.test_parse_napps__any() 0 6 1
A TestNappsParser.test_parse_napp__success() 0 6 1
A TestNappsParser.test_parse_napp__error() 0 5 2
1
"""kytos.cli.commands.napps.parser tests."""
2 1
import sys
3 1
import unittest
4 1
from unittest.mock import patch
5
6 1
from kytos.cli.commands.napps.parser import (call, parse, parse_napp,
7
                                             parse_napps)
8 1
from kytos.utils.exceptions import KytosException
9
10
11 1
class TestNappsParser(unittest.TestCase):
12
    """Test the NappsAPI parser methods."""
13
14 1
    @staticmethod
15 1
    @patch('kytos.cli.commands.napps.parser.call')
16 1
    @patch('kytos.cli.commands.napps.parser.docopt', return_value='args')
17 1
    def test_parse(*args):
18
        """Test parse method."""
19 1
        (_, mock_call) = args
20 1
        with patch.object(sys, 'argv', ['A', 'B', 'C']):
21 1
            parse('argv')
22
23 1
            mock_call.assert_called_with('C', 'args')
24
25 1
    @staticmethod
26 1
    @patch('sys.exit')
27 1
    @patch('kytos.cli.commands.napps.parser.call')
28 1
    @patch('kytos.cli.commands.napps.parser.docopt', return_value='args')
29 1
    def test_parse__error(*args):
30
        """Test parse method to error case."""
31 1
        (_, mock_call, mock_exit) = args
32 1
        mock_call.side_effect = KytosException
33 1
        with patch.object(sys, 'argv', ['A', 'B', 'C']):
34 1
            parse('argv')
35
36 1
            mock_exit.assert_called()
37
38 1
    @staticmethod
39 1
    @patch('kytos.cli.commands.napps.api.NAppsAPI.install')
40 1
    @patch('kytos.utils.config.KytosConfig')
41 1
    def test_call(*args):
42
        """Test call method."""
43 1
        (_, mock_napps_api) = args
44 1
        call_args = {'<napp>': 'all'}
45 1
        call('install', call_args)
46
47 1
        mock_napps_api.assert_called_with(call_args)
48
49 1
    def test_parse_napps__all(self):
50
        """Test parse_napps method to all napps."""
51 1
        napp_ids = ['all']
52 1
        napps = parse_napps(napp_ids)
53
54 1
        self.assertEqual(napps, 'all')
55
56 1
    def test_parse_napps__any(self):
57
        """Test parse_napps method to any napp."""
58 1
        napp_ids = ['user/napp:version']
59 1
        napps = parse_napps(napp_ids)
60
61 1
        self.assertEqual(napps, [('user', 'napp', 'version')])
62
63 1
    def test_parse_napp__success(self):
64
        """Test parse_napp method to success case."""
65 1
        napp = 'user/napp:version'
66 1
        groups = parse_napp(napp)
67
68 1
        self.assertEqual(groups, ('user', 'napp', 'version'))
69
70 1
    def test_parse_napp__error(self):
71
        """Test parse_napp method to error case."""
72 1
        napp = 'usernappversion'
73 1
        with self.assertRaises(KytosException):
74
            parse_napp(napp)
75