From a53e6ec8f32e23354dfe9b1d7c472a0aeff87f6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Alberto=20D=C3=ADaz=20Orozco=20=28Akiel=29?= Date: Thu, 5 Dec 2024 13:50:01 +0100 Subject: [PATCH 1/7] Add new license method and skip the deprecated one when testing v7 --- rocketchat_API/APISections/licenses.py | 9 +++++++++ tests/conftest.py | 15 ++++++++++++--- tests/test_licenses.py | 9 ++++++++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/rocketchat_API/APISections/licenses.py b/rocketchat_API/APISections/licenses.py index ec6b192..8562c1b 100644 --- a/rocketchat_API/APISections/licenses.py +++ b/rocketchat_API/APISections/licenses.py @@ -1,7 +1,16 @@ +from warnings import deprecated + from rocketchat_API.APISections.base import RocketChatBase class RocketChatLicenses(RocketChatBase): + @deprecated("Use licenses_info instead") 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) + + diff --git a/tests/conftest.py b/tests/conftest.py index cd99e48..058037b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ import pytest +from semver import Version from rocketchat_API.rocketchat import RocketChat @@ -58,11 +59,19 @@ 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") diff --git a/tests/test_licenses.py b/tests/test_licenses.py index 66793ac..cdbd662 100644 --- a/tests/test_licenses.py +++ b/tests/test_licenses.py @@ -1,3 +1,10 @@ -def test_licenses_get(logged_rocket): +from unittest import skipIf + + +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") From aa807805edff754fbc05f4ca0e53f246612a1a6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Alberto=20D=C3=ADaz=20Orozco=20=28Akiel=29?= Date: Thu, 5 Dec 2024 13:50:28 +0100 Subject: [PATCH 2/7] Temporarily skip channels_online (broken on v7) --- tests/test_channels.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_channels.py b/tests/test_channels.py index c31478b..cb3a09f 100644 --- a/tests/test_channels.py +++ b/tests/test_channels.py @@ -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 From 2f223d46c4b373b94f17ecccd4fec5866f553692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Alberto=20D=C3=ADaz=20Orozco=20=28Akiel=29?= Date: Thu, 5 Dec 2024 13:51:04 +0100 Subject: [PATCH 3/7] Add semver to testing dependencies --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4548715..094aa22 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 From 3d37fc17b059eff6174239390d4838aee3c39b98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Alberto=20D=C3=ADaz=20Orozco=20=28Akiel=29?= Date: Thu, 5 Dec 2024 13:54:13 +0100 Subject: [PATCH 4/7] Fix linting --- rocketchat_API/APISections/licenses.py | 2 -- tests/conftest.py | 4 +++- tests/test_licenses.py | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/rocketchat_API/APISections/licenses.py b/rocketchat_API/APISections/licenses.py index 8562c1b..4bc3b7f 100644 --- a/rocketchat_API/APISections/licenses.py +++ b/rocketchat_API/APISections/licenses.py @@ -12,5 +12,3 @@ def licenses_get(self, **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) - - diff --git a/tests/conftest.py b/tests/conftest.py index 058037b..e3a8f1c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -72,6 +72,8 @@ def skip_if_no_license(logged_rocket): licenses_info = logged_rocket.licenses_info().json() if not licenses_info.get("success"): pytest.fail("License endpoint not available") - if "license" in licenses_info and licenses_info.get("license").get("license").get("information").get("offline"): + if "license" in licenses_info and licenses_info.get("license").get("license").get( + "information" + ).get("offline"): return pytest.skip("No license available") diff --git a/tests/test_licenses.py b/tests/test_licenses.py index cdbd662..1d6fe51 100644 --- a/tests/test_licenses.py +++ b/tests/test_licenses.py @@ -5,6 +5,7 @@ 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") From 3160abcd5046eb595dce1df6717b3391cf1b6450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Alberto=20D=C3=ADaz=20Orozco=20=28Akiel=29?= Date: Thu, 5 Dec 2024 13:59:27 +0100 Subject: [PATCH 5/7] Remove deprecation warning the decorator is only available in the latest python version --- rocketchat_API/APISections/licenses.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/rocketchat_API/APISections/licenses.py b/rocketchat_API/APISections/licenses.py index 4bc3b7f..585803e 100644 --- a/rocketchat_API/APISections/licenses.py +++ b/rocketchat_API/APISections/licenses.py @@ -1,10 +1,7 @@ -from warnings import deprecated - from rocketchat_API.APISections.base import RocketChatBase class RocketChatLicenses(RocketChatBase): - @deprecated("Use licenses_info instead") def licenses_get(self, **kwargs): """Retrieves a list of all registered licenses in the workspace.""" return self.call_api_get("licenses.get", kwargs=kwargs) From af19a8927defe671c3fe421f8046c87828ec3465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Alberto=20D=C3=ADaz=20Orozco=20=28Akiel=29?= Date: Thu, 5 Dec 2024 14:03:14 +0100 Subject: [PATCH 6/7] Fix version comparison --- tests/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index e3a8f1c..39bb0f1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -63,7 +63,7 @@ def secondary_user(logged_rocket): 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"): + if version and Version.parse(version) >= Version.parse("7.0.0"): pytest.skip("Endpoint not available in this version") From eb3ce92cb59631f040f5b833c968db334ba63842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Alberto=20D=C3=ADaz=20Orozco=20=28Akiel=29?= Date: Thu, 5 Dec 2024 14:05:27 +0100 Subject: [PATCH 7/7] Remove unused import --- tests/test_licenses.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/test_licenses.py b/tests/test_licenses.py index 1d6fe51..cd15d9a 100644 --- a/tests/test_licenses.py +++ b/tests/test_licenses.py @@ -1,6 +1,3 @@ -from unittest import skipIf - - def test_licenses_get(logged_rocket, skip_v7): licenses_get = logged_rocket.licenses_get().json() assert licenses_get.get("success")