From f03d3a048a1dbaf000aa0ba625a60d29e86385de Mon Sep 17 00:00:00 2001 From: Upstream Data Date: Tue, 27 Aug 2024 10:19:41 -0600 Subject: [PATCH] tests: add tests to permissions. Update pytest-asyncio because it was unable to find the event loop for new tests, see https://github.com/pytest-dev/pytest-asyncio/issues/862 --- pyproject.toml | 5 +++- tests/auth/__init__.py | 0 tests/auth/test_permissions.py | 51 ++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tests/auth/__init__.py create mode 100644 tests/auth/test_permissions.py diff --git a/pyproject.toml b/pyproject.toml index e502f913..54cfcf15 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/tests/auth/__init__.py b/tests/auth/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/auth/test_permissions.py b/tests/auth/test_permissions.py new file mode 100644 index 00000000..fac70fcb --- /dev/null +++ b/tests/auth/test_permissions.py @@ -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"] + )