def testEnumerateInterfaces(self): replies = [] enumif = windows.EnumerateInterfaces() enumif.SendReply = replies.append enumif.Run(None) self.assertNotEmpty(replies) found_address = False for interface in replies: for address in interface.addresses: self.assertNotEmpty(address.human_readable_address) found_address = True if not found_address: self.fail("Not a single address found in EnumerateInterfaces {}".format( replies))
def testEnumerateInterfacesMock(self): # Stub out wmi.WMI().Win32_NetworkAdapterConfiguration() wmi = mock.MagicMock() wmi.Win32_NetworkAdapterConfiguration.return_value = [ client_test_lib.WMIWin32NetworkAdapterConfigurationMock() ] replies = [] with mock.patch.object(windows.wmi, "WMI", return_value=wmi): enumif = windows.EnumerateInterfaces() enumif.SendReply = replies.append enumif.Run(None) self.assertLen(replies, 1) interface = replies[0] self.assertLen(interface.addresses, 4) addresses = [x.human_readable_address for x in interface.addresses] self.assertCountEqual(addresses, [ "192.168.1.20", "ffff::ffff:aaaa:1111:aaaa", "dddd:0:8888:6666:bbbb:aaaa:eeee:bbbb", "dddd:0:8888:6666:bbbb:aaaa:ffff:bbbb" ])