def test_task_create_empty_response(self, mock_create): with self.assertRaises(CLIError) as context: create(self, test_id=device_test_id, wait=False) self.assertTrue( "Failed to create device test task - please ensure a device test exists with Id {}" .format(device_test_id), context.exception, )
def test_sdk_task_create_wait(self, fixture_cmd, service_client_create_wait): result = create(fixture_cmd, test_id=device_test_id, wait=True, poll_interval=1) reqs = list(map(lambda call: call.request, service_client_create_wait.calls)) # Call 0 - create test task assert reqs[0].method == "POST" assert json.loads(reqs[0].body)["taskType"] == "QueueTestRun" url = reqs[0].url assert "deviceTests/{}/tasks".format(device_test_id) in url # Call 1 - get task status assert reqs[1].method == "GET" url = reqs[1].url assert ( "deviceTests/{}/tasks/{}".format(device_test_id, device_test_task_id) in url ) # Call 2 - get run results assert reqs[2].method == "GET" url = reqs[2].url assert ( "deviceTests/{}/testRuns/{}".format(device_test_id, device_test_run_id) in url ) # awaiting a queued test run should yield a test run object assert isinstance(result, TestRun) assert result.id == device_test_run_id assert result.status == "Completed"
def test_sdk_task_create(self, fixture_cmd, service_client_create): result = create(fixture_cmd, test_id=device_test_id) req = service_client_create.calls[0].request assert req.method == "POST" assert json.loads(req.body)["taskType"] == "QueueTestRun" assert result.id == device_test_task_id assert result.device_test_id == device_test_id
def test_task_create_no_wait(self, mock_get, mock_create): result = create(self, test_id=device_test_id, wait=False, poll_interval=1) # one call to create mock_create.assert_called_with( device_test_id=device_test_id, task_type=TaskType.QueueTestRun.value ) assert mock_create.call_count == 1 # no calls to 'get' since wait==Falce mock_get.assert_not_called() # initial create response returned assert result == queued_task
def test_task_create_wait(self, mock_sleep, mock_get, mock_create): result = create(self, test_id=device_test_id, wait=True, poll_interval=1) # one call to create mock_create.assert_called_with( device_test_id=device_test_id, task_type=TaskType.QueueTestRun.value ) assert mock_create.call_count == 1 # three calls to 'get' until status is 'Completed' mock_get.assert_called_with( task_id=device_test_task_id, device_test_id=device_test_id ) assert mock_get.call_count == 3 # make sure we get the last result back assert result.status == "Completed"
def test_task_create(self, mock_create): create(self, test_id=device_test_id) mock_create.assert_called_with( device_test_id=device_test_id, task_type=TaskType.QueueTestRun.value )
def test_task_create_failure(self, mock_create): with self.assertRaises(CLIError) as context: create(self, test_id=device_test_id, wait=False) self.assertTrue({"error": "task currently running"}, context)