From 9de9fb51db737a090c23301084d534e2b2da3d83 Mon Sep 17 00:00:00 2001 From: Ryan Lerch Date: Jan 18 2023 06:24:31 +0000 Subject: [PATCH 1/4] fix failing test_invalidtopic test Signed-off-by: Ryan Lerch --- diff --git a/fedocal_messages/tests/test_object_from_topic.py b/fedocal_messages/tests/test_object_from_topic.py index 71af4e5..0e69bd5 100644 --- a/fedocal_messages/tests/test_object_from_topic.py +++ b/fedocal_messages/tests/test_object_from_topic.py @@ -39,4 +39,4 @@ def test_invalidtopic(): cls = get_message_object_from_topic("fedocal.invalid.topic") assert str(type(cls())) == "" - assert hasattr(cls(), "app_name") is False + assert cls().app_name is None From 548b9f3fdf97652a6242a9f628a4b3ac7ab4896a Mon Sep 17 00:00:00 2001 From: Ryan Lerch Date: Jan 18 2023 06:51:46 +0000 Subject: [PATCH 2/4] deprecate agent for agent_name Signed-off-by: Ryan Lerch --- diff --git a/fedocal_messages/base.py b/fedocal_messages/base.py index dd9fe60..5b8c87a 100644 --- a/fedocal_messages/base.py +++ b/fedocal_messages/base.py @@ -14,6 +14,8 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +import warnings + from fedora_messaging import message from fedora_messaging.schema_utils import user_avatar_url @@ -87,6 +89,15 @@ class FedocalMessage(message.Message): @property def agent(self): + warnings.warn( + "agent property is deprecated, please use agent_name instead", + DeprecationWarning, + stacklevel=2, + ) + return self.agent_name + + @property + def agent_name(self): return self.body.get("agent") @property diff --git a/fedocal_messages/tests/test_common.py b/fedocal_messages/tests/test_common.py index 18f7dc8..b78788f 100644 --- a/fedocal_messages/tests/test_common.py +++ b/fedocal_messages/tests/test_common.py @@ -16,6 +16,8 @@ """Unit tests for common properties of the message schemas.""" +import pytest + from .utils import DUMMY_CALENDAR, DUMMY_MEETING from ..messages import ReminderV1 @@ -27,9 +29,18 @@ def test_properties(): assert message.app_name == "fedocal" assert message.app_icon == "https://apps.fedoraproject.org/img/icons/fedocal.png" - assert message.agent == "dummy_user" + assert message.agent_name == "dummy_user" assert ( message.agent_avatar == "https://seccdn.libravatar.org/avatar/" "b0ec8f140ba7eee8f4bfc7955858bc43c14fdd83edadf7b3819459efcaa5c690?s=64&d=retro" ) assert message.usernames == ["dummy_user"] + + with pytest.warns(DeprecationWarning) as w: + assert message.agent == "dummy_user" + + assert len(w) == 1 + assert ( + w[0].message.args[0] + == "agent property is deprecated, please use agent_name instead" + ) From a4974df1ab86e7ccf283ae01d1b1355615f412b5 Mon Sep 17 00:00:00 2001 From: Ryan Lerch Date: Jan 18 2023 07:25:32 +0000 Subject: [PATCH 3/4] put the meeting managers into the user's property previously, the usernames property was only populated with the agent name if it was in the message. Now we add the usernames listed in the meeting managers list to the usernames property Signed-off-by: Ryan Lerch --- diff --git a/fedocal_messages/base.py b/fedocal_messages/base.py index 5b8c87a..0ac4987 100644 --- a/fedocal_messages/base.py +++ b/fedocal_messages/base.py @@ -106,10 +106,18 @@ class FedocalMessage(message.Message): @property def usernames(self): + users = [] if self.agent: - return [self.agent] - else: - return [] + users.append(self.agent) + + try: + users.extend(self.body["meeting"]["meeting_manager"]) + except KeyError: + pass + + users = list(set(users)) + users.sort() + return users @property def url(self): diff --git a/fedocal_messages/tests/test_common.py b/fedocal_messages/tests/test_common.py index b78788f..ce5b8ee 100644 --- a/fedocal_messages/tests/test_common.py +++ b/fedocal_messages/tests/test_common.py @@ -34,7 +34,7 @@ def test_properties(): message.agent_avatar == "https://seccdn.libravatar.org/avatar/" "b0ec8f140ba7eee8f4bfc7955858bc43c14fdd83edadf7b3819459efcaa5c690?s=64&d=retro" ) - assert message.usernames == ["dummy_user"] + assert message.usernames == ["dummy_user", "ralph"] with pytest.warns(DeprecationWarning) as w: assert message.agent == "dummy_user" From f7a6c1a31aa352421f67d30b581df14e740b36d1 Mon Sep 17 00:00:00 2001 From: Ryan Lerch Date: Jan 18 2023 07:48:57 +0000 Subject: [PATCH 4/4] Add groups property to the messages add the groups prop to the message schemas. It is gereneated from the calendar's groups metadata Signed-off-by: Ryan Lerch --- diff --git a/fedocal_messages/base.py b/fedocal_messages/base.py index 0ac4987..4b601f1 100644 --- a/fedocal_messages/base.py +++ b/fedocal_messages/base.py @@ -120,6 +120,28 @@ class FedocalMessage(message.Message): return users @property + def groups(self): + groupslist = [] + try: + groupslist.append(self.body["calendar"]["calendar_admin_group"]) + except KeyError: + pass + + try: + groupslist.append(self.body["calendar"]["calendar_editor_group"]) + except KeyError: + pass + + # remove duplicates + groupslist = list(set(groupslist)) + + # remove possible empty strings + groupslist = [g for g in groupslist if g] + + groupslist.sort() + return groupslist + + @property def url(self): try: return self.body["thing"]["url"] diff --git a/fedocal_messages/tests/test_common.py b/fedocal_messages/tests/test_common.py index ce5b8ee..da73494 100644 --- a/fedocal_messages/tests/test_common.py +++ b/fedocal_messages/tests/test_common.py @@ -35,6 +35,7 @@ def test_properties(): "b0ec8f140ba7eee8f4bfc7955858bc43c14fdd83edadf7b3819459efcaa5c690?s=64&d=retro" ) assert message.usernames == ["dummy_user", "ralph"] + assert message.groups == ["syadmin", "testers"] with pytest.warns(DeprecationWarning) as w: assert message.agent == "dummy_user" diff --git a/fedocal_messages/tests/utils.py b/fedocal_messages/tests/utils.py index e3c51f1..6cd8177 100644 --- a/fedocal_messages/tests/utils.py +++ b/fedocal_messages/tests/utils.py @@ -21,7 +21,7 @@ DUMMY_CALENDAR = { "calendar_name": "test_calendar", "calendar_contact": "foo@example.com", "calendar_description": "A test calendar", - "calendar_editor_group": None, + "calendar_editor_group": "testers", "calendar_admin_group": "syadmin", "calendar_status": "active", }