Skip to content

Commit

Permalink
Merge pull request #275 from jadolg/fix-license-method-v7
Browse files Browse the repository at this point in the history
Fix license method issues
  • Loading branch information
jadolg authored Dec 5, 2024
2 parents 694e4f0 + eb3ce92 commit 5a2280f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install pytest-cov requests
run: pip install pytest-cov requests semver
- name: Wait for rocket.chat server to be online
run: until curl --silent http://localhost:3000/api/info/; do sleep 15; echo "waiting for Rocket.Chat server to start"; done;
timeout-minutes: 5
Expand Down
4 changes: 4 additions & 0 deletions rocketchat_API/APISections/licenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ 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)

def licenses_info(self, **kwargs):
"""Retrieves a list of all registered licenses in the workspace."""
return self.call_api_get("licenses.info", kwargs=kwargs)
17 changes: 14 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from semver import Version

from rocketchat_API.rocketchat import RocketChat

Expand Down Expand Up @@ -58,11 +59,21 @@ def secondary_user(logged_rocket):
logged_rocket.users_delete(_testuser_id)


@pytest.fixture
def skip_v7(logged_rocket):
"""Skip test if chat version is > 7.0.0"""
version = logged_rocket.info().json().get("info").get("version")
if version and Version.parse(version) >= Version.parse("7.0.0"):
pytest.skip("Endpoint not available in this version")


@pytest.fixture
def skip_if_no_license(logged_rocket):
licenses_get = logged_rocket.licenses_get().json()
if not licenses_get.get("success"):
licenses_info = logged_rocket.licenses_info().json()
if not licenses_info.get("success"):
pytest.fail("License endpoint not available")
if "licenses" in licenses_get and len(licenses_get.get("licenses")) > 0:
if "license" in licenses_info and licenses_info.get("license").get("license").get(
"information"
).get("offline"):
return
pytest.skip("No license available")
2 changes: 1 addition & 1 deletion tests/test_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def test_channels_counters(logged_rocket):
logged_rocket.channels_counters()


def test_channels_online(logged_rocket):
def test_channels_online(logged_rocket, skip_v7):
channels_online = logged_rocket.channels_online(query={"_id": "GENERAL"}).json()
assert channels_online.get("success")
assert len(channels_online.get("online")) >= 1
Expand Down
7 changes: 6 additions & 1 deletion tests/test_licenses.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
def test_licenses_get(logged_rocket):
def test_licenses_get(logged_rocket, skip_v7):
licenses_get = logged_rocket.licenses_get().json()
assert licenses_get.get("success")


def test_licenses_info(logged_rocket):
licenses_info = logged_rocket.licenses_info().json()
assert licenses_info.get("success")

0 comments on commit 5a2280f

Please sign in to comment.