TestNappsParser.test_parse_napps__all()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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