def testSetUnattendTimeZoneRun(self, dhcp, edit, build_info, timezone): build_info.NetInterfaces.return_value = [ mock.Mock(ip_address='127.0.0.1', mac_address='11:22:33:44:55:66', dhcp_server=None), mock.Mock(ip_address='127.0.0.2', mac_address=None, dhcp_server=None), mock.Mock(ip_address=None, mac_address='22:11:33:44:55:66', dhcp_server=None), mock.Mock(ip_address='10.1.10.1', mac_address='AA:BB:CC:DD:EE:FF', dhcp_server='192.168.1.1') ] st = sysprep.SetUnattendTimeZone([], build_info) # Normal Run timezone.return_value.TranslateZone.return_value = ( 'New Zealand Standard Time') dhcp.side_effect = iter([None, None, 'Antarctica/McMurdo']) st.Run() dhcp.assert_has_calls([ mock.call(client_addr='127.0.0.1', client_mac='11:22:33:44:55:66', option=101, server_addr='255.255.255.255'), mock.call(client_addr='10.1.10.1', client_mac='AA:BB:CC:DD:EE:FF', option=101, server_addr='192.168.1.1'), mock.call(client_addr='10.1.10.1', client_mac='AA:BB:CC:DD:EE:FF', option=101, server_addr='255.255.255.255') ]) edit.assert_called_with(st, u'New Zealand Standard Time') timezone.assert_called_with(load_map=True) timezone.return_value.TranslateZone.assert_called_with( 'Antarctica/McMurdo') timezone.reset_mock() # Failed Mapping dhcp.side_effect = None dhcp.return_value = 'Antarctica/NorthPole' timezone.return_value.TranslateZone.return_value = '' st.Run() edit.assert_called_with(st, u'Pacific Standard Time') timezone.assert_called_with(load_map=True) timezone.return_value.TranslateZone.assert_called_with( 'Antarctica/NorthPole') timezone.reset_mock() # No Result dhcp.return_value = None st.Run() edit.assert_called_with(st, u'Pacific Standard Time') self.assertFalse(timezone.called)
def testSetUnattendTimeZoneEditUnattend(self, build_info): st = sysprep.SetUnattendTimeZone([], build_info) st._EditUnattend( 'Yakutsk Standard Time', unattend_path='/windows/panther/unattend.xml') with self.fake_open('/windows/panther/unattend.xml') as handle: result = [line.strip() for line in handle.readlines()] self.assertIn('<TimeZone>Yakutsk Standard Time</TimeZone>', result) # IOError self.assertRaises(sysprep.ActionError, st._EditUnattend, 'Yakutsk Standard Time', '/windows/panther/noneattend.xml')