Skip to content

Commit

Permalink
Skip enterprise-only endpoints if there is no license set
Browse files Browse the repository at this point in the history
  • Loading branch information
jadolg committed Jan 14, 2024
1 parent c633f1f commit 88bf2ac
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 2 deletions.
7 changes: 7 additions & 0 deletions rocketchat_API/APISections/licenses.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions rocketchat_API/rocketchat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -41,5 +42,6 @@ class RocketChat(
RocketChatTeams,
RocketChatRoles,
RocketChatBanners,
RocketChatLicenses,
):
pass
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Check warning on line 65 in tests/conftest.py

View check run for this annotation

Codecov / codecov/patch

tests/conftest.py#L65

Added line #L65 was not covered by tests
if "licenses" in licenses_get and len(licenses_get.get("licenses")) > 0:
return
pytest.skip("No license available")

Check warning on line 68 in tests/conftest.py

View check run for this annotation

Codecov / codecov/patch

tests/conftest.py#L68

Added line #L68 was not covered by tests
3 changes: 2 additions & 1 deletion tests/test_chat.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions tests/test_licenses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def test_licenses_get(logged_rocket):
licenses_get = logged_rocket.licenses_get().json()
assert licenses_get.get("success")
2 changes: 1 addition & 1 deletion tests/test_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 88bf2ac

Please sign in to comment.