def test_query_results(self, monkeypatch): """Tests that the ``_query_results`` method sends a request adhering to the Honeywell API specs.""" dev = HQSDevice(3, machine=DUMMY_MACHINE, user_email=DUMMY_EMAIL, retry_delay=0.1) SOME_ACCESS_TOKEN = "XYZ789" monkeypatch.setattr(dev, "get_valid_access_token", lambda: SOME_ACCESS_TOKEN) # set num_calls=1 as the job was already submitted in cases when we get # the result mock_response = MockResponse(num_calls=1) call_history = [] def wrapper(job_endpoint, headers): call_history.append(tuple([job_endpoint, headers])) return mock_response monkeypatch.setattr(requests, "get", wrapper) SOME_JOB_ID = "JOB123" mock_job_data = {"job": SOME_JOB_ID, "status": "not completed!"} res = dev._query_results(mock_job_data) expected_header = { "Authorization": SOME_ACCESS_TOKEN, } assert len(call_history) == 1 job_endpoint, headers = call_history[0] assert job_endpoint == "/".join([dev.hostname, SOME_JOB_ID]) assert headers == expected_header
def test_query_results_expected_response(self, monkeypatch): """Tests that using the ``_query_results`` method an expected response is gathered.""" dev = HQSDevice(3, machine=DUMMY_MACHINE, user_email=DUMMY_EMAIL, retry_delay=0.01) SOME_ACCESS_TOKEN = "XYZ789" monkeypatch.setattr(dev, "get_valid_access_token", lambda: SOME_ACCESS_TOKEN) mock_response = MockResponse() monkeypatch.setattr(requests, "get", lambda *args, **kwargs: mock_response) SOME_JOB_ID = "JOB123" mock_job_data = {"job": SOME_JOB_ID, "status": "not completed!"} res = dev._query_results(mock_job_data) assert res == mock_response.mock_get_response