def test_open_ports_specified_interface(self): expected_output = { 'eth0': { '80': 'open', '443': 'closed', '32009': 'closed' } } mock_response = mock.Mock() mock_response.side_effect = [ 'open', 'closed', 'closed' ] with mock.patch( 'ae_preflight.profile.get_interface_ip_address' ) as ip: ip.return_value = '1.1.1.1' with mock.patch( 'ae_preflight.profile.check_for_socket', side_effect=mock_response ): returns = profile.check_open_ports('eth0', True) self.assertEquals( expected_output, returns, 'Returned values did not match expected output' )
def test_open_ports_no_ip_addr(self): expected_output = {'eth0': 'No IP address assigned'} with mock.patch('ae_preflight.profile.get_interface_ip_address') as ip: ip.return_value = None returns = profile.check_open_ports('eth0', True) self.assertEquals(expected_output, returns, 'Returned values did not match expected output')
def test_open_ports_failure(self): expected_output = {} with mock.patch('ae_preflight.profile.get_active_interfaces') as iface: iface.side_effect = IOError() returns = profile.check_open_ports(None, True) self.assertEquals(expected_output, returns, 'Returned values did not match expected output')