Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Co-authored-by: Shubham Gupta <[email protected]>
  • Loading branch information
kiendang and shubham3121 committed Oct 18, 2023
1 parent 8482d51 commit 4f06ec1
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/syft/src/syft/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/syft/tests/syft/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_api_cache_invalidation_login(root_verify_key, worker):
assert guest_client.register(
name="q", email="[email protected]", password="aaa", password_verify="aaa"
)
guest_client.login(email="[email protected]", password="aaa")
guest_client = guest_client.login(email="[email protected]", password="aaa")
user_id = worker.document_store.partitions["User"].all(root_verify_key).value[-1].id

def get_role(verify_key):
Expand All @@ -75,6 +75,6 @@ def get_role(verify_key):

assert get_role(guest_client.credentials.verify_key) == ServiceRole.DATA_OWNER

guest_client.login(email="[email protected]", password="aaa")
guest_client = guest_client.login(email="[email protected]", password="aaa")

assert guest_client.upload_dataset(dataset)
10 changes: 5 additions & 5 deletions packages/syft/tests/syft/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]", password="changethis")
assert guest_client.logged_in_user == "[email protected]"
client = guest_client.login(email="[email protected]", password="changethis")
assert client.logged_in_user == "[email protected]"

guest_client.register(
client.register(
name="sheldon",
email="[email protected]",
password="bazinga",
password_verify="bazinga",
)

guest_client.login(email="[email protected]", password="bazinga")
client = client.login(email="[email protected]", password="bazinga")

assert guest_client.logged_in_user == "[email protected]"
assert client.logged_in_user == "[email protected]"
14 changes: 10 additions & 4 deletions packages/syft/tests/syft/gateways/gateway_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]", password="changethis")
proxy_domain_client.login(email="[email protected]", password="changethis")
domain_client = domain_client.login(
email="[email protected]", password="changethis"
)
proxy_domain_client = proxy_domain_client.login(
email="[email protected]", password="changethis"
)

assert proxy_domain_client.logged_in_user == "[email protected]"
assert proxy_domain_client.user_role == ServiceRole.ADMIN
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions packages/syft/tests/syft/settings/settings_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion packages/syft/tests/syft/users/user_code_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion packages/syft/tests/syft/users/user_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4f06ec1

Please sign in to comment.