Skip to content

Commit

Permalink
modified python tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pjdotson committed Sep 24, 2024
1 parent a473de8 commit f93f9f8
Showing 1 changed file with 7 additions and 47 deletions.
54 changes: 7 additions & 47 deletions client/py/tests/test_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import pytest

import synnax as sy
from synnax.channel.client import CHANNEL_ONTOLOGY_TYPE
from synnax.user.payload import ontology_type as USER_ONTOLOGY_TYPE
from synnax.ontology.payload import ID


Expand Down Expand Up @@ -79,22 +79,14 @@ def test_create_from_kwargs(self, client: sy.Synnax):
ID(type="label", key=resource_id),
]

def test_retrieve_by_subject(
self, two_policies: list[sy.Policy], client: sy.Synnax
) -> None:
p = client.access.retrieve(subjects=[two_policies[0].subjects[0]])
assert len(p) == 1
assert p[0].actions == ["create"]
assert (p[0].objects[0].type, p[0].objects[1].type) == ("channel", "label")

def test_retrieve_by_subject_not_found(self, client: sy.Synnax):
res = client.access.retrieve(subjects=[ID(type="channel", key="hehe")])
assert res is None

def test_delete_by_key(self, two_policies: list[sy.Policy], client: sy.Synnax):
client.access.delete(two_policies[0].key)
p = client.access.retrieve(subjects=[two_policies[0].subjects[0]])
assert p is None
with pytest.raises(sy.NotFoundError):
client.access.retrieve(keys=[two_policies[0].key])


@pytest.mark.access
Expand All @@ -105,7 +97,7 @@ def test_create_user(
):
host, port, _, _ = login_info
username = str(uuid.uuid4())
client.user.create(username, "pwd2")
client.user.create(username=username, password="pwd2")
client2 = sy.Synnax(
host=host,
port=port,
Expand All @@ -114,14 +106,14 @@ def test_create_user(
)

with pytest.raises(sy.AuthError):
client2.user.create(str(uuid.uuid4()), "pwd3")
client2.user.create(username=str(uuid.uuid4()), password="pwd3")

def test_user_privileges(
self, client: sy.Synnax, login_info: tuple[str, int, str, str]
):
host, port, _, _ = login_info
username = str(uuid.uuid4())
usr = client.user.create(username, "pwd3")
usr = client.user.create(username=username, password="pwd3")
client2 = sy.Synnax(
host=host,
port=port,
Expand All @@ -130,36 +122,4 @@ def test_user_privileges(
)

with pytest.raises(sy.AuthError):
client2.channels.create(
sy.Channel(
name="new_channel",
data_type=sy.DataType.FLOAT32,
rate=1 * sy.Rate.HZ,
)
)

p = client.access.create(
subjects=[usr.ontology_id()],
objects=[CHANNEL_ONTOLOGY_TYPE],
actions=["create"],
)

client2.channels.create(
sy.Channel(
name="new_channel",
data_type=sy.DataType.FLOAT32,
rate=1 * sy.Rate.HZ,
)
)

# revoke the policy
client.access.delete(p.key)

with pytest.raises(sy.AuthError):
client2.channels.create(
sy.Channel(
name="new_channel",
data_type=sy.DataType.FLOAT32,
rate=1 * sy.Rate.HZ,
)
)
client2.user.create(username=str(uuid.uuid4()), password="pwd3")

0 comments on commit f93f9f8

Please sign in to comment.