From 88bf2ac88d2cb126c889ab55833ad6a60c6670a9 Mon Sep 17 00:00:00 2001 From: "Jorge Alberto Diaz Orozco (Akiel)" Date: Sun, 14 Jan 2024 12:41:51 +0100 Subject: [PATCH] Skip enterprise-only endpoints if there is no license set --- rocketchat_API/APISections/licenses.py | 7 +++++++ rocketchat_API/rocketchat.py | 2 ++ tests/conftest.py | 10 ++++++++++ tests/test_chat.py | 3 ++- tests/test_licenses.py | 3 +++ tests/test_roles.py | 2 +- 6 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 rocketchat_API/APISections/licenses.py create mode 100644 tests/test_licenses.py diff --git a/rocketchat_API/APISections/licenses.py b/rocketchat_API/APISections/licenses.py new file mode 100644 index 0000000..ec6b192 --- /dev/null +++ b/rocketchat_API/APISections/licenses.py @@ -0,0 +1,7 @@ +from rocketchat_API.APISections.base import RocketChatBase + + +class RocketChatLicenses(RocketChatBase): + def licenses_get(self, **kwargs): + """Retrieves a list of all registered licenses in the workspace.""" + return self.call_api_get("licenses.get", kwargs=kwargs) diff --git a/rocketchat_API/rocketchat.py b/rocketchat_API/rocketchat.py index feced53..1a0432b 100755 --- a/rocketchat_API/rocketchat.py +++ b/rocketchat_API/rocketchat.py @@ -8,6 +8,7 @@ from rocketchat_API.APISections.im import RocketChatIM from rocketchat_API.APISections.integrations import RocketChatIntegrations from rocketchat_API.APISections.invites import RocketChatInvites +from rocketchat_API.APISections.licenses import RocketChatLicenses from rocketchat_API.APISections.livechat import RocketChatLivechat from rocketchat_API.APISections.miscellaneous import RocketChatMiscellaneous from rocketchat_API.APISections.permissions import RocketChatPermissions @@ -41,5 +42,6 @@ class RocketChat( RocketChatTeams, RocketChatRoles, RocketChatBanners, + RocketChatLicenses, ): pass diff --git a/tests/conftest.py b/tests/conftest.py index d6a88b1..cd99e48 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -56,3 +56,13 @@ def secondary_user(logged_rocket): yield _testuser_id logged_rocket.users_delete(_testuser_id) + + +@pytest.fixture +def skip_if_no_license(logged_rocket): + licenses_get = logged_rocket.licenses_get().json() + if not licenses_get.get("success"): + pytest.fail("License endpoint not available") + if "licenses" in licenses_get and len(licenses_get.get("licenses")) > 0: + return + pytest.skip("No license available") diff --git a/tests/test_chat.py b/tests/test_chat.py index b0818d6..492263a 100644 --- a/tests/test_chat.py +++ b/tests/test_chat.py @@ -1,6 +1,7 @@ import pytest from rocketchat_API.APIExceptions.RocketExceptions import RocketMissingParamException +from tests.conftest import skip_if_no_license def test_chat_post_notext_message(logged_rocket): @@ -135,7 +136,7 @@ def test_chat_search(logged_rocket): assert chat_search.get("success") -def test_chat_get_message_read_receipts(logged_rocket): +def test_chat_get_message_read_receipts(logged_rocket, skip_if_no_license): message_id = ( logged_rocket.chat_post_message("hello", channel="GENERAL") .json() diff --git a/tests/test_licenses.py b/tests/test_licenses.py new file mode 100644 index 0000000..66793ac --- /dev/null +++ b/tests/test_licenses.py @@ -0,0 +1,3 @@ +def test_licenses_get(logged_rocket): + licenses_get = logged_rocket.licenses_get().json() + assert licenses_get.get("success") diff --git a/tests/test_roles.py b/tests/test_roles.py index 4769547..d6c6923 100644 --- a/tests/test_roles.py +++ b/tests/test_roles.py @@ -7,7 +7,7 @@ def test_roles_list(logged_rocket): assert len(roles_list.get("roles")) > 0 -def test_roles_create(logged_rocket): +def test_roles_create(logged_rocket, skip_if_no_license): name = str(uuid.uuid1()) roles_create = logged_rocket.roles_create( name=name, scope="Subscriptions", description="a test role"