blob: 2dc07b3e8e4461d8bbfe10fc21d3826b78618a1e [file] [log] [blame]
Alex3bc95f62020-03-05 17:00:04 -06001import os
2
3from unittest.mock import patch
4
5from tests.mocks import mocked_salt_post, mocked_salt_get
6from tests.mocks import _res_dir
7from tests.mocks import mocked_shell, _shell_salt_path
8from tests.test_base import CfgCheckerTestBase
9
10from cfg_checker.modules.network.network_errors import NetworkErrors
11
12
13# Fake ErrorIndex
14_ErrorIndex_path = "cfg_checker.helpers.errors.ErrorIndex"
15_NErrors_path = "cfg_checker.modules.network.network_errors.NetworkErrors"
16
17_fake_nerrors = NetworkErrors(folder="tests/res/fakeerrors")
18_fake_nerrors._error_logs_folder_name = "tests/res/fakeerrors"
19
20
21class TestNetworkModule(CfgCheckerTestBase):
22 @patch('requests.get', side_effect=mocked_salt_get)
23 @patch('requests.post', side_effect=mocked_salt_post)
24 @patch(_shell_salt_path, side_effect=mocked_shell)
25 @patch(_NErrors_path, new=_fake_nerrors)
26 def test_network_list(self, m_get, m_post, m_shell):
27 _args = ["list"]
28 _pm = "cfg_checker.modules.network.mapper.NetworkErrors"
29 with patch(_pm, new=_fake_nerrors):
30 _r_code = self.run_cli(
31 "network",
32 _args
33 )
34 self.assertEqual(
35 _r_code,
36 0,
37 "'mcp-net {}' command failed".format(" ".join(_args))
38 )
39
40 @patch('requests.get', side_effect=mocked_salt_get)
41 @patch('requests.post', side_effect=mocked_salt_post)
42 @patch(_shell_salt_path, side_effect=mocked_shell)
43 @patch(_NErrors_path, new=_fake_nerrors)
44 def test_network_map(self, m_get, m_post, m_shell):
45 _args = ["map"]
46 with patch(
47 "cfg_checker.modules.network.mapper.NetworkErrors",
48 new=_fake_nerrors
49 ):
50 _r_code = self.run_cli(
51 "network",
52 _args
53 )
54 self.assertEqual(
55 _r_code,
56 0,
57 "'mcp-net {}' command failed".format(" ".join(_args))
58 )
59
60 @patch('requests.get', side_effect=mocked_salt_get)
61 @patch('requests.post', side_effect=mocked_salt_post)
62 @patch(_shell_salt_path, side_effect=mocked_shell)
63 @patch(_NErrors_path, new=_fake_nerrors)
64 def test_network_check(self, m_get, m_post, m_shell):
65 _args = ["check"]
66 with patch(
67 "cfg_checker.modules.network.checker.NetworkErrors",
68 new=_fake_nerrors
69 ):
70 _r_code = self.run_cli(
71 "network",
72 _args
73 )
74 self.assertEqual(
75 _r_code,
76 0,
77 "'mcp-net {}' command failed".format(" ".join(_args))
78 )
79
80 @patch('requests.get', side_effect=mocked_salt_get)
81 @patch('requests.post', side_effect=mocked_salt_post)
82 @patch(_shell_salt_path, side_effect=mocked_shell)
83 @patch(_NErrors_path, new=_fake_nerrors)
84 def test_network_report_html(self, m_get, m_post, m_shell):
85 _fake_report = os.path.join(_res_dir, "fake.html")
86 _args = ["report", "--html", _fake_report]
87 _pc = "cfg_checker.modules.network.checker.NetworkErrors"
88 with patch(_pc, new=_fake_nerrors):
89 _r_code = self.run_cli(
90 "network",
91 _args
92 )
93 self.assertEqual(
94 _r_code,
95 0,
96 "'mcp-net {}' command failed".format(" ".join(_args))
97 )