From 4f06ec139f77a229af73a176ad06552e260adcfd Mon Sep 17 00:00:00 2001 From: Kien Dang Date: Wed, 18 Oct 2023 15:38:52 +0800 Subject: [PATCH] Fix tests Co-authored-by: Shubham Gupta --- packages/syft/src/syft/client/client.py | 2 +- packages/syft/tests/syft/api_test.py | 4 ++-- packages/syft/tests/syft/client_test.py | 10 +++++----- packages/syft/tests/syft/gateways/gateway_test.py | 14 ++++++++++---- .../tests/syft/settings/settings_service_test.py | 5 +++-- packages/syft/tests/syft/users/user_code_test.py | 2 +- packages/syft/tests/syft/users/user_test.py | 2 +- 7 files changed, 23 insertions(+), 16 deletions(-) diff --git a/packages/syft/src/syft/client/client.py b/packages/syft/src/syft/client/client.py index 4f6b6823886..f559755103e 100644 --- a/packages/syft/src/syft/client/client.py +++ b/packages/syft/src/syft/client/client.py @@ -933,7 +933,7 @@ def login( _client = _client_cache if not _client.authed and login_credentials: - _client.login( + _client = _client.login( email=login_credentials.email, password=login_credentials.password, cache=cache, diff --git a/packages/syft/tests/syft/api_test.py b/packages/syft/tests/syft/api_test.py index 42b98584f69..66ba36fafe6 100644 --- a/packages/syft/tests/syft/api_test.py +++ b/packages/syft/tests/syft/api_test.py @@ -49,7 +49,7 @@ def test_api_cache_invalidation_login(root_verify_key, worker): assert guest_client.register( name="q", email="a@b.org", password="aaa", password_verify="aaa" ) - guest_client.login(email="a@b.org", password="aaa") + guest_client = guest_client.login(email="a@b.org", password="aaa") user_id = worker.document_store.partitions["User"].all(root_verify_key).value[-1].id def get_role(verify_key): @@ -75,6 +75,6 @@ def get_role(verify_key): assert get_role(guest_client.credentials.verify_key) == ServiceRole.DATA_OWNER - guest_client.login(email="a@b.org", password="aaa") + guest_client = guest_client.login(email="a@b.org", password="aaa") assert guest_client.upload_dataset(dataset) diff --git a/packages/syft/tests/syft/client_test.py b/packages/syft/tests/syft/client_test.py index 89e5374c850..b1d7f475948 100644 --- a/packages/syft/tests/syft/client_test.py +++ b/packages/syft/tests/syft/client_test.py @@ -2,16 +2,16 @@ def test_client_logged_in_user(worker): guest_client = worker.guest_client assert guest_client.logged_in_user == "" - guest_client.login(email="info@openmined.org", password="changethis") - assert guest_client.logged_in_user == "info@openmined.org" + client = guest_client.login(email="info@openmined.org", password="changethis") + assert client.logged_in_user == "info@openmined.org" - guest_client.register( + client.register( name="sheldon", email="sheldon@caltech.edu", password="bazinga", password_verify="bazinga", ) - guest_client.login(email="sheldon@caltech.edu", password="bazinga") + client = client.login(email="sheldon@caltech.edu", password="bazinga") - assert guest_client.logged_in_user == "sheldon@caltech.edu" + assert client.logged_in_user == "sheldon@caltech.edu" diff --git a/packages/syft/tests/syft/gateways/gateway_test.py b/packages/syft/tests/syft/gateways/gateway_test.py index 1bc1f04146f..ca379ec61b1 100644 --- a/packages/syft/tests/syft/gateways/gateway_test.py +++ b/packages/syft/tests/syft/gateways/gateway_test.py @@ -76,8 +76,12 @@ def test_domain_connect_to_gateway(faker: Faker): assert proxy_domain_client.metadata == domain_client.metadata assert proxy_domain_client.user_role == ServiceRole.NONE - domain_client.login(email="info@openmined.org", password="changethis") - proxy_domain_client.login(email="info@openmined.org", password="changethis") + domain_client = domain_client.login( + email="info@openmined.org", password="changethis" + ) + proxy_domain_client = proxy_domain_client.login( + email="info@openmined.org", password="changethis" + ) assert proxy_domain_client.logged_in_user == "info@openmined.org" assert proxy_domain_client.user_role == ServiceRole.ADMIN @@ -129,8 +133,10 @@ def test_enclave_connect_to_gateway(faker: Faker): password_verify=password, ) - enclave_client.login(email=user_email, password=password) - proxy_enclave_client.login(email=user_email, password=password) + enclave_client = enclave_client.login(email=user_email, password=password) + proxy_enclave_client = proxy_enclave_client.login( + email=user_email, password=password + ) assert proxy_enclave_client.logged_in_user == user_email assert proxy_enclave_client.user_role == enclave_client.user_role diff --git a/packages/syft/tests/syft/settings/settings_service_test.py b/packages/syft/tests/syft/settings/settings_service_test.py index a8ba4d0da68..596e5cec17b 100644 --- a/packages/syft/tests/syft/settings/settings_service_test.py +++ b/packages/syft/tests/syft/settings/settings_service_test.py @@ -305,8 +305,9 @@ def get_mock_client(faker, root_client, role): assert not isinstance(result, SyftError) guest_client = root_client.guest() - guest_client.login(email=user_create.email, password=user_create.password) - return guest_client + return guest_client.login( + email=user_create.email, password=user_create.password + ) verify_key = SyftSigningKey.generate().verify_key mock_node_metadata = NodeMetadata( diff --git a/packages/syft/tests/syft/users/user_code_test.py b/packages/syft/tests/syft/users/user_code_test.py index f24dc8f3c59..9fe191e25ea 100644 --- a/packages/syft/tests/syft/users/user_code_test.py +++ b/packages/syft/tests/syft/users/user_code_test.py @@ -64,7 +64,7 @@ def test_scientist_can_list_code_assets(worker: sy.Worker, faker: Faker) -> None guest_client = root_client.guest() credentials.pop("name") - guest_client.login(**credentials) + guest_client = guest_client.login(**credentials) root_client.upload_dataset(dataset=dataset) diff --git a/packages/syft/tests/syft/users/user_test.py b/packages/syft/tests/syft/users/user_test.py index 63d581926b2..3b56ca54a9e 100644 --- a/packages/syft/tests/syft/users/user_test.py +++ b/packages/syft/tests/syft/users/user_test.py @@ -46,7 +46,7 @@ def get_mock_client(root_client, role) -> DomainClient: assert worker.root_client.api.services.user.update( user_id, UserUpdate(user_id=user_id, role=role) ) - client.login(email=mail, password=password) + client = client.login(email=mail, password=password) client._fetch_api(client.credentials) # hacky, but useful for testing: patch user id and role on client client.user_id = user_id