Test Failed
Pull Request — master (#277)
by Gleyberson
01:32
created

tests.unit.commands.test_napps_parser   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 40
dl 0
loc 62
rs 10
c 0
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
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
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('kytos.cli.commands.napps.api.NAppsAPI.install')
27
    @patch('kytos.utils.config.KytosConfig')
28
    def test_call(*args):
29
        """Test call method."""
30
        (_, mock_napps_api) = args
31
        call_args = {'<napp>': 'all'}
32
        call('install', call_args)
33
34
        mock_napps_api.assert_called_with(call_args)
35
36
    def test_parse_napps__all(self):
37
        """Test parse_napps method to all napps."""
38
        napp_ids = ['all']
39
        napps = parse_napps(napp_ids)
40
41
        self.assertEqual(napps, 'all')
42
43
    def test_parse_napps__any(self):
44
        """Test parse_napps method to any napp."""
45
        napp_ids = ['user/napp:version']
46
        napps = parse_napps(napp_ids)
47
48
        self.assertEqual(napps, [('user', 'napp', 'version')])
49
50
    def test_parse_napp__success(self):
51
        """Test parse_napp method to success case."""
52
        napp = 'user/napp:version'
53
        groups = parse_napp(napp)
54
55
        self.assertEqual(groups, ('user', 'napp', 'version'))
56
57
    def test_parse_napp__error(self):
58
        """Test parse_napp method to error case."""
59
        napp = 'usernappversion'
60
        with self.assertRaises(KytosException):
61
            parse_napp(napp)
62