Skip to content

Commit

Permalink
tests: add tests to permissions.
Browse files Browse the repository at this point in the history
Update pytest-asyncio because it was unable to find the event loop for new tests, see pytest-dev/pytest-asyncio#862
  • Loading branch information
UpstreamData authored and b-rowan committed Aug 28, 2024
1 parent d7ad5c9 commit f03d3a0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ mkdocs-material = "^9.5.29"

[tool.poetry.group.tests.dependencies]
pytest = "^8.3.1"
pytest-asyncio = "^0.23.8"
pytest-asyncio = "^0.24.0"
pytest-md-report = "^0.6.2"

[tool.pytest]
asyncio_mode = "auto"

[tool.isort]
profile = "black"

Expand Down
Empty file added tests/auth/__init__.py
Empty file.
51 changes: 51 additions & 0 deletions tests/auth/test_permissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from goosebit.auth import compare_permission, compare_permissions


def test_compare_single_permission():
assert compare_permission("home.read", "home.read")


def test_compare_inverted_single_permission():
assert not compare_permission("home.read", "!home.read")


def test_compare_wildcard_sub_permission():
assert compare_permission("home.read", "home.*")


def test_compare_inverted_wildcard_sub_permission():
assert not compare_permission("home.read", "!home.*")


def test_compare_root_permission():
assert compare_permission("home.read", "home")


def test_compare_inverted_root_permission():
assert not compare_permission("home.read", "!home")


def test_compare_root_wildcard_permission():
assert compare_permission("home.read", "*")


def test_compare_inverted_root_wildcard_permission():
assert not compare_permission("home.read", "!*")


def test_compare_multiple_single_permissions():
assert compare_permissions(["home.read", "device.write"], ["home.read", "device.write"])


def test_compare_invalid_multiple_single_permissions():
assert not compare_permissions(["home.read", "device.write"], ["home.read", "device.read"])


def test_compare_inverted_multiple_permissions():
assert not compare_permissions(["home.read", "device.write"], ["home.read", "device", "!device.write"])


def test_compare_multiple_root_wildcard_permissions():
assert compare_permissions(
["home.read", "device.write", "device.read", "software.read"], ["*.read", "device.write"]
)

0 comments on commit f03d3a0

Please sign in to comment.