def test_run_show(self, mock_get, mock_get_latest):
        show(self, test_id=device_test_id, run_id=device_test_run_id)

        # one call to get
        mock_get.assert_called_with(device_test_id=device_test_id,
                                    test_run_id=device_test_run_id)

        # does not call get_latest
        mock_get_latest.assert_not_called()
    def test_sdk_run_show_error(self, fixture_cmd):
        with self.assertRaises(CLIError) as context:
            show(fixture_cmd,
                 test_id=device_test_id,
                 run_id=device_test_run_id)

        self.assertEqual(
            "No test run found for test ID '{}' with run ID '{}'".format(
                device_test_id, device_test_run_id),
            str(context.exception),
        )
    def test_run_show_latest_wait(self, mock_get, mock_get_latest):
        result = show(self, test_id=device_test_id, wait=True, poll_interval=1)
        assert mock_get_latest.call_count == 1

        # three calls to 'get' until status is 'Completed', using run-id from get_latest call
        mock_get.assert_called_with(
            test_run_id=mock_get_latest.return_value.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_sdk_run_show(self, fixture_cmd, service_client_get):
        # get latest run
        result = show(fixture_cmd, test_id=device_test_id)
        req = service_client_get.calls[0].request

        assert "deviceTests/{}/testRuns/latest".format(
            device_test_id) in req.url
        assert req.method == "GET"
        assert result.id == device_test_run_id

        # specific run
        result = show(fixture_cmd,
                      test_id=device_test_id,
                      run_id=device_test_run_id)
        req = service_client_get.calls[1].request

        assert ("deviceTests/{}/testRuns/{}".format(device_test_id,
                                                    device_test_run_id)
                in req.url)
        assert req.method == "GET"
        assert result.id == device_test_run_id
    def test_sdk_run_show_wait(self, fixture_cmd, service_client_get):
        result = show(fixture_cmd,
                      test_id=device_test_id,
                      wait=True,
                      poll_interval=1)
        reqs = list(map(lambda call: call.request, service_client_get.calls))
        assert reqs[0].method == "GET"
        url = reqs[0].url
        assert "deviceTests/{}/testRuns/latest".format(device_test_id) in url

        assert reqs[1].method == "GET"
        url = reqs[1].url
        assert ("deviceTests/{}/testRuns/{}".format(device_test_id,
                                                    device_test_run_id) in url)

        assert result.id == device_test_run_id
        assert result.status == "Completed"
    def test_run_show_latest(self, mock_get, mock_get_latest):
        show(self, test_id=device_test_id)

        # no run_id, so should call get_latest
        mock_get_latest.assert_called_with(device_test_id=device_test_id)
        mock_get.assert_not_called()