diff --git a/tests/test_iqm_sampler.py b/tests/test_iqm_sampler.py index e04499e4..cd888b5d 100644 --- a/tests/test_iqm_sampler.py +++ b/tests/test_iqm_sampler.py @@ -16,12 +16,13 @@ import uuid import cirq -from mockito import ANY, mock, verify, when +from mockito import ANY, expect, mock, verify, when import numpy as np import pytest import sympy # type: ignore from iqm.cirq_iqm import Adonis +import iqm.cirq_iqm as module_under_test from iqm.cirq_iqm.iqm_sampler import IQMResult, IQMSampler, ResultMetadata from iqm.iqm_client import ( Circuit, @@ -344,17 +345,18 @@ def test_run_iqm_batch_allows_to_override_polling_timeout( np.testing.assert_array_equal(results[1].measurements['some stuff'], np.array([[1]])) +@pytest.mark.usefixtures('unstub') def test_credentials_are_passed_to_client(): user_auth_args = { 'auth_server_url': 'https://fake.auth.server.com', 'username': 'fake-username', 'password': 'fake-password', } - with when(IQMClient)._update_tokens(): - sampler = IQMSampler('http://url', Adonis(), **user_auth_args) - assert sampler._client._credentials.auth_server_url == user_auth_args['auth_server_url'] - assert sampler._client._credentials.username == user_auth_args['username'] - assert sampler._client._credentials.password == user_auth_args['password'] + when(module_under_test.iqm_sampler).IQMClient('http://url', client_signature=ANY, **user_auth_args).thenReturn( + mock(IQMClient) + ) + IQMSampler('http://url', Adonis(), **user_auth_args) + verify(module_under_test.iqm_sampler, times=1).IQMClient('http://url', client_signature=ANY, **user_auth_args) @pytest.mark.usefixtures('unstub') @@ -364,15 +366,14 @@ def test_client_signature_is_passed_to_client(): assert f'cirq-iqm {version("cirq-iqm")}' in sampler._client._signature +@pytest.mark.usefixtures('unstub') def test_close_client(): user_auth_args = { 'auth_server_url': 'https://fake.auth.server.com', 'username': 'fake-username', 'password': 'fake-password', } - with when(IQMClient)._update_tokens(): - sampler = IQMSampler('http://url', Adonis(), **user_auth_args) - try: - sampler.close_client() - except Exception as exc: # pylint: disable=broad-except - assert False, f'sampler created with credentials raised an exception {exc} on .close_client()' + sampler = IQMSampler('http://url', Adonis(), **user_auth_args) + sampler._client = mock(IQMClient) + expect(sampler._client, times=1).close_auth_session().thenReturn(True) + sampler.close_client()