def test_update_data(self): """Test update_data method.""" backend_mock = BackendMock() with mock.patch('bimmer_connected.account.requests', new=backend_mock): account = ConnectedDriveAccount(TEST_USERNAME, TEST_PASSWORD, TEST_COUNTRY) vehicle = account.get_vehicle(G31_VIN) with self.assertRaises(IOError): vehicle.state.update_data() backend_mock.add_response( '.*/api/vehicle/dynamic/v1/{vin}'.format(vin=G31_VIN), data_files=['G31_NBTevo/dynamic.json']) vehicle.state.update_data() self.assertEqual(2201, vehicle.state.mileage)
def test_get_remote_service_status(self): """Test get_remove_service_status method.""" backend_mock = BackendMock() with mock.patch('bimmer_connected.account.requests', new=backend_mock): account = ConnectedDriveAccount(TEST_USERNAME, TEST_PASSWORD, TEST_REGION) vehicle = account.get_vehicle(G31_VIN) with self.assertRaises(IOError): vehicle.remote_services._get_remote_service_status(remote_services._Services.REMOTE_LIGHT_FLASH) backend_mock.add_response( r'https://.+/webapi/v1/user/vehicles/{vin}/serviceExecutionStatus\?.+'.format(vin=G31_VIN), data_files=['G31_NBTevo/flash_executed.json']) status = vehicle.remote_services._get_remote_service_status(remote_services._Services.REMOTE_LIGHT_FLASH) self.assertEqual(ExecutionState.EXECUTED, status.state)
def test_get_remote_service_status(self): """Test get_remove_service_status method.""" backend_mock = BackendMock() with mock.patch('bimmer_connected.account.requests', new=backend_mock): account = ConnectedDriveAccount(TEST_USERNAME, TEST_PASSWORD, TEST_COUNTRY) vehicle = account.get_vehicle(G31_VIN) with self.assertRaises(IOError): vehicle.remote_services._get_remote_service_status() backend_mock.add_response( '.*/api/vehicle/remoteservices/v1/{vin}/state/execution'. format(vin=G31_VIN), data_files=['G31_NBTevo/RLF_EXECUTED.json']) status = vehicle.remote_services._get_remote_service_status() self.assertEqual(ExecutionState.EXECUTED, status.state)
def test_trigger_remote_services(self): """Test executing a remote light flash.""" remote_services._POLLING_CYCLE = 0 remote_services._UPDATE_AFTER_REMOTE_SERVICE_DELAY = 0 services = [('RLF', 'trigger_remote_light_flash', False), ('RDL', 'trigger_remote_door_lock', True), ('RDU', 'trigger_remote_door_unlock', True), ('RCN', 'trigger_remote_air_conditioning', True), ('RHB', 'trigger_remote_horn', False)] for service, call, triggers_update in services: backend_mock = BackendMock() backend_mock.setup_default_vehicles() backend_mock.add_response( r'.*/api/vehicle/remoteservices/v1/{vin}/{service}'.format( vin=G31_VIN, service=service), data_files=['G31_NBTevo/RLF_INITIAL_RESPONSE.json']) backend_mock.add_response( '.*/api/vehicle/remoteservices/v1/{vin}/state/execution'. format(vin=G31_VIN), data_files=[ 'G31_NBTevo/RLF_PENDING.json', 'G31_NBTevo/RLF_DELIVERED.json', 'G31_NBTevo/RLF_EXECUTED.json' ]) with mock.patch('bimmer_connected.account.requests', new=backend_mock): account = ConnectedDriveAccount(TEST_USERNAME, TEST_PASSWORD, TEST_COUNTRY) mock_listener = mock.Mock(return_value=None) account.add_update_listener(mock_listener) vehicle = account.get_vehicle(G31_VIN) response = getattr(vehicle.remote_services, call)() self.assertEqual(ExecutionState.EXECUTED, response.state) if triggers_update: mock_listener.assert_called_once_with() else: mock_listener.assert_not_called()
def test_trigger_remote_services(self): """Test executing a remote light flash.""" remote_services._POLLING_CYCLE = 0 remote_services._UPDATE_AFTER_REMOTE_SERVICE_DELAY = 0 services = [ ('LIGHT_FLASH', 'trigger_remote_light_flash', False), ('DOOR_LOCK', 'trigger_remote_door_lock', True), ('DOOR_UNLOCK', 'trigger_remote_door_unlock', True), ('CLIMATE_NOW', 'trigger_remote_air_conditioning', True), ('HORN_BLOW', 'trigger_remote_horn', False) ] for service, call, triggers_update in services: backend_mock = BackendMock() backend_mock.setup_default_vehicles() backend_mock.add_response('https://.+/webapi/v1/user/vehicles/{vin}/executeService'.format(vin=G31_VIN), data_files=[_RESPONSE_INITIATED]) backend_mock.add_response( r'https://.+/webapi/v1/user/vehicles/{vin}/serviceExecutionStatus\?serviceType={service_type}'.format( vin=G31_VIN, service_type=service), data_files=[ _RESPONSE_PENDING, _RESPONSE_PENDING, _RESPONSE_DELIVERED, _RESPONSE_DELIVERED, _RESPONSE_EXECUTED]) with mock.patch('bimmer_connected.account.requests', new=backend_mock): account = ConnectedDriveAccount(TEST_USERNAME, TEST_PASSWORD, TEST_REGION) mock_listener = mock.Mock(return_value=None) account.add_update_listener(mock_listener) vehicle = account.get_vehicle(G31_VIN) response = getattr(vehicle.remote_services, call)() self.assertEqual(ExecutionState.EXECUTED, response.state) if triggers_update: mock_listener.assert_called_once_with() else: mock_listener.assert_not_called()