Skip to content

Commit fa70d08

Browse files
committed
Force autospec=True in tests and fix unit tests
Enabling and enforcing autospec=True check in pep8 tests, and fixing unit tests as a consequence. Change-Id: Id9e98f26ecfc314c7f3e69fd518abfebedc39b1a
1 parent 518742a commit fa70d08

22 files changed

Lines changed: 471 additions & 303 deletions

networking_generic_switch/tests/unit/netmiko/test_arista_eos.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,34 @@ def test_constants(self):
2828
self.assertIsNone(self.switch.SAVE_CONFIGURATION)
2929

3030
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
31-
'NetmikoSwitch.send_commands_to_device')
31+
'NetmikoSwitch.send_commands_to_device', autospec=True)
3232
def test_add_network(self, m_exec):
3333
self.switch.add_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
3434
m_exec.assert_called_with(
35+
self.switch,
3536
['vlan 33', 'name 0ae071f55be943e480eae41fefe85b21'])
3637

3738
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
38-
'NetmikoSwitch.send_commands_to_device')
39+
'NetmikoSwitch.send_commands_to_device', autospec=True)
3940
def test_del_network(self, mock_exec):
4041
self.switch.del_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
41-
mock_exec.assert_called_with(['no vlan 33'])
42+
mock_exec.assert_called_with(self.switch, ['no vlan 33'])
4243

4344
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
44-
'NetmikoSwitch.send_commands_to_device')
45+
'NetmikoSwitch.send_commands_to_device', autospec=True)
4546
def test_plug_port_to_network(self, mock_exec):
4647
self.switch.plug_port_to_network(3333, 33)
4748
mock_exec.assert_called_with(
49+
self.switch,
4850
['interface 3333', 'switchport mode access',
4951
'switchport access vlan 33'])
5052

5153
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
52-
'NetmikoSwitch.send_commands_to_device')
54+
'NetmikoSwitch.send_commands_to_device', autospec=True)
5355
def test_delete_port(self, mock_exec):
5456
self.switch.delete_port(3333, 33)
5557
mock_exec.assert_called_with(
58+
self.switch,
5659
['interface 3333', 'no switchport access vlan 33',
5760
'no switchport mode trunk',
5861
'switchport trunk allowed vlan none'])

networking_generic_switch/tests/unit/netmiko/test_aruba.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,68 +29,75 @@ def test_constants(self):
2929
self.assertIsNone(self.switch.SAVE_CONFIGURATION)
3030

3131
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
32-
'NetmikoSwitch.send_commands_to_device')
32+
'NetmikoSwitch.send_commands_to_device', autospec=True)
3333
def test_add_network(self, m_exec):
3434
self.switch.add_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
3535
m_exec.assert_called_with(
36+
self.switch,
3637
['vlan 33', 'name 0ae071f55be943e480eae41fefe85b21'])
3738

3839
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
39-
'NetmikoSwitch.send_commands_to_device')
40+
'NetmikoSwitch.send_commands_to_device', autospec=True)
4041
def test_del_network(self, mock_exec):
4142
self.switch.del_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
42-
mock_exec.assert_called_with(['no vlan 33'])
43+
mock_exec.assert_called_with(self.switch, ['no vlan 33'])
4344

4445
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
45-
'NetmikoSwitch.send_commands_to_device')
46+
'NetmikoSwitch.send_commands_to_device', autospec=True)
4647
def test_plug_port_to_network(self, mock_exec):
4748
self.switch.plug_port_to_network(3333, 33)
4849
mock_exec.assert_called_with(
50+
self.switch,
4951
['interface 3333', 'no routing', 'vlan access 33'])
5052

5153
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
52-
'NetmikoSwitch.send_commands_to_device')
54+
'NetmikoSwitch.send_commands_to_device', autospec=True)
5355
def test_plug_port_to_network_disable_inactive(self, m_sctd):
5456
switch = self._make_switch_device(
5557
{'ngs_disable_inactive_ports': 'true'})
5658
switch.plug_port_to_network(3333, 33)
5759
m_sctd.assert_called_with(
60+
switch,
5861
['interface 3333', 'no shutdown',
5962
'interface 3333', 'no routing', 'vlan access 33'])
6063

6164
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
62-
'NetmikoSwitch.send_commands_to_device')
65+
'NetmikoSwitch.send_commands_to_device', autospec=True)
6366
def test_delete_port(self, mock_exec):
6467
self.switch.delete_port(3333, 33)
65-
mock_exec.assert_called_with(['interface 3333', 'no vlan access 33'])
68+
mock_exec.assert_called_with(
69+
self.switch, ['interface 3333', 'no vlan access 33'])
6670

6771
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
68-
'NetmikoSwitch.send_commands_to_device')
72+
'NetmikoSwitch.send_commands_to_device', autospec=True)
6973
def test_delete_port_disable_inactive(self, m_sctd):
7074
switch = self._make_switch_device(
7175
{'ngs_disable_inactive_ports': 'true'})
7276
switch.delete_port(3333, 33)
7377
m_sctd.assert_called_with(
78+
switch,
7479
['interface 3333', 'no vlan access 33',
7580
'interface 3333', 'shutdown'])
7681

7782
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
78-
'NetmikoSwitch.send_commands_to_device')
83+
'NetmikoSwitch.send_commands_to_device', autospec=True)
7984
def test_add_network_with_trunk_ports(self, mock_exec):
8085
switch = self._make_switch_device({'ngs_trunk_ports': 'port1, port2'})
8186
switch.add_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
8287
mock_exec.assert_called_with(
88+
switch,
8389
['vlan 33',
8490
'name 0ae071f55be943e480eae41fefe85b21',
8591
'interface port1', 'no routing', 'vlan trunk allowed 33',
8692
'interface port2', 'no routing', 'vlan trunk allowed 33'])
8793

8894
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
89-
'NetmikoSwitch.send_commands_to_device')
95+
'NetmikoSwitch.send_commands_to_device', autospec=True)
9096
def test_del_network_with_trunk_ports(self, mock_exec):
9197
switch = self._make_switch_device({'ngs_trunk_ports': 'port1, port2'})
9298
switch.del_network(33, '0ae071f55be943e480eae41fefe85b21')
9399
mock_exec.assert_called_with(
100+
switch,
94101
['interface port1', 'no vlan trunk allowed 33',
95102
'interface port2', 'no vlan trunk allowed 33',
96103
'no vlan 33'])

networking_generic_switch/tests/unit/netmiko/test_brocade_fastiron.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,43 +30,49 @@ def test_constants(self):
3030
self.assertIsNone(self.switch.SAVE_CONFIGURATION)
3131

3232
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
33-
'NetmikoSwitch.send_commands_to_device')
33+
'NetmikoSwitch.send_commands_to_device', autospec=True)
3434
def test_add_network(self, m_exec):
3535
self.switch.add_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
3636
m_exec.assert_called_with(
37+
self.switch,
3738
['vlan 33 by port', 'name 0ae071f55be943e480eae41fefe85b21'])
3839

3940
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
40-
'NetmikoSwitch.send_commands_to_device')
41+
'NetmikoSwitch.send_commands_to_device', autospec=True)
4142
def test_del_network(self, mock_exec):
4243
self.switch.del_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
43-
mock_exec.assert_called_with(['no vlan 33'])
44+
mock_exec.assert_called_with(self.switch, ['no vlan 33'])
4445

4546
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
46-
'NetmikoSwitch.send_commands_to_device')
47+
'NetmikoSwitch.send_commands_to_device', autospec=True)
4748
def test_plug_port_to_network(self, mock_exec):
4849
self.switch.plug_port_to_network(3333, 33)
4950
mock_exec.assert_called_with(
51+
self.switch,
5052
['vlan 33 by port', 'untagged ether 3333'])
5153

5254
def test_plug_port_to_network_with_cleaning(self):
5355
with mock.patch(
5456
'networking_generic_switch.devices.netmiko_devices.'
55-
'NetmikoSwitch.send_commands_to_device'
57+
'NetmikoSwitch.send_commands_to_device', autospec=True
5658
) as m_exec:
5759
m_exec.return_value = "Member of L2 VLAN ID 22, port is untagged."
5860
self.switch.plug_port_to_network(3333, 33)
5961
m_exec.assert_has_calls([
60-
mock.call(['show interfaces ether 3333 | include VLAN']),
61-
mock.call(['vlan 22 by port', 'no untagged ether 3333']),
62-
mock.call(['vlan 33 by port', 'untagged ether 3333']),
62+
mock.call(self.switch,
63+
['show interfaces ether 3333 | include VLAN']),
64+
mock.call(self.switch,
65+
['vlan 22 by port', 'no untagged ether 3333']),
66+
mock.call(self.switch,
67+
['vlan 33 by port', 'untagged ether 3333']),
6368
])
6469

6570
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
66-
'NetmikoSwitch.send_commands_to_device')
71+
'NetmikoSwitch.send_commands_to_device', autospec=True)
6772
def test_delete_port(self, mock_exec):
6873
self.switch.delete_port(3333, 33)
6974
mock_exec.assert_called_with(
75+
self.switch,
7076
['vlan 33 by port', 'no untagged ether 3333'])
7177

7278
def test__format_commands(self):

networking_generic_switch/tests/unit/netmiko/test_cisco_300.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,34 @@ def test_constants(self):
2828
self.assertIsNone(self.switch.SAVE_CONFIGURATION)
2929

3030
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
31-
'NetmikoSwitch.send_commands_to_device')
31+
'NetmikoSwitch.send_commands_to_device', autospec=True)
3232
def test_add_network(self, m_exec):
3333
self.switch.add_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
3434
m_exec.assert_called_with(
35+
self.switch,
3536
['vlan 33'])
3637

3738
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
38-
'NetmikoSwitch.send_commands_to_device')
39+
'NetmikoSwitch.send_commands_to_device', autospec=True)
3940
def test_del_network(self, mock_exec):
4041
self.switch.del_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
41-
mock_exec.assert_called_with(['no vlan 33'])
42+
mock_exec.assert_called_with(self.switch, ['no vlan 33'])
4243

4344
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
44-
'NetmikoSwitch.send_commands_to_device')
45+
'NetmikoSwitch.send_commands_to_device', autospec=True)
4546
def test_plug_port_to_network(self, mock_exec):
4647
self.switch.plug_port_to_network(3333, 33)
4748
mock_exec.assert_called_with(
49+
self.switch,
4850
['interface 3333', 'switchport mode access',
4951
'switchport access vlan 33'])
5052

5153
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
52-
'NetmikoSwitch.send_commands_to_device')
54+
'NetmikoSwitch.send_commands_to_device', autospec=True)
5355
def test_delete_port(self, mock_exec):
5456
self.switch.delete_port(3333, 33)
5557
mock_exec.assert_called_with(
58+
self.switch,
5659
['interface 3333', 'no switchport access vlan',
5760
'switchport trunk allowed vlan remove all'])
5861

networking_generic_switch/tests/unit/netmiko/test_cisco_ios.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,34 @@ def test_constants(self):
2828
self.assertIsNone(self.switch.SAVE_CONFIGURATION)
2929

3030
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
31-
'NetmikoSwitch.send_commands_to_device')
31+
'NetmikoSwitch.send_commands_to_device', autospec=True)
3232
def test_add_network(self, m_exec):
3333
self.switch.add_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
3434
m_exec.assert_called_with(
35+
self.switch,
3536
['vlan 33', 'name 0ae071f55be943e480eae41fefe85b21'])
3637

3738
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
38-
'NetmikoSwitch.send_commands_to_device')
39+
'NetmikoSwitch.send_commands_to_device', autospec=True)
3940
def test_del_network(self, mock_exec):
4041
self.switch.del_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
41-
mock_exec.assert_called_with(['no vlan 33'])
42+
mock_exec.assert_called_with(self. switch, ['no vlan 33'])
4243

4344
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
44-
'NetmikoSwitch.send_commands_to_device')
45+
'NetmikoSwitch.send_commands_to_device', autospec=True)
4546
def test_plug_port_to_network(self, mock_exec):
4647
self.switch.plug_port_to_network(3333, 33)
4748
mock_exec.assert_called_with(
49+
self.switch,
4850
['interface 3333', 'switchport mode access',
4951
'switchport access vlan 33'])
5052

5153
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
52-
'NetmikoSwitch.send_commands_to_device')
54+
'NetmikoSwitch.send_commands_to_device', autospec=True)
5355
def test_delete_port(self, mock_exec):
5456
self.switch.delete_port(3333, 33)
5557
mock_exec.assert_called_with(
58+
self.switch,
5659
['interface 3333', 'no switchport access vlan 33',
5760
'no switchport mode trunk', 'switchport trunk allowed vlan none'])
5861

networking_generic_switch/tests/unit/netmiko/test_cisco_nxos.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,34 @@ def test_constants(self):
2828
self.assertIsNone(self.switch.SAVE_CONFIGURATION)
2929

3030
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
31-
'NetmikoSwitch.send_commands_to_device')
31+
'NetmikoSwitch.send_commands_to_device', autospec=True)
3232
def test_add_network(self, m_exec):
3333
self.switch.add_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
3434
m_exec.assert_called_with(
35+
self.switch,
3536
['vlan 33', 'name 0ae071f55be943e480eae41fefe85b21', 'exit'])
3637

3738
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
38-
'NetmikoSwitch.send_commands_to_device')
39+
'NetmikoSwitch.send_commands_to_device', autospec=True)
3940
def test_del_network(self, mock_exec):
4041
self.switch.del_network(33, '0ae071f5-5be9-43e4-80ea-e41fefe85b21')
41-
mock_exec.assert_called_with(['no vlan 33'])
42+
mock_exec.assert_called_with(self.switch, ['no vlan 33'])
4243

4344
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
44-
'NetmikoSwitch.send_commands_to_device')
45+
'NetmikoSwitch.send_commands_to_device', autospec=True)
4546
def test_plug_port_to_network(self, mock_exec):
4647
self.switch.plug_port_to_network(3333, 33)
4748
mock_exec.assert_called_with(
49+
self.switch,
4850
['interface 3333', 'switchport mode access',
4951
'switchport access vlan 33', 'exit'])
5052

5153
@mock.patch('networking_generic_switch.devices.netmiko_devices.'
52-
'NetmikoSwitch.send_commands_to_device')
54+
'NetmikoSwitch.send_commands_to_device', autospec=True)
5355
def test_delete_port(self, mock_exec):
5456
self.switch.delete_port(3333, 33)
5557
mock_exec.assert_called_with(
58+
self.switch,
5659
['interface 3333', 'no switchport access vlan', 'exit'])
5760

5861
def test__format_commands(self):

0 commit comments

Comments
 (0)