From f94aa82aac48ab3928b5520a1342e605bb7a39fe Mon Sep 17 00:00:00 2001 From: Pavel Novotny Date: Tue, 2 Apr 2024 22:31:49 +0200 Subject: [PATCH] new entity for NotificationRecipients Added new entity `NotificationRecipients` for `/notification_recipients` endpoint. (cherry picked from commit e6e6ec6dcfcd5d258e32587eda95683c4554a049) --- nailgun/entities.py | 14 ++++++++++++++ tests/test_entities.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/nailgun/entities.py b/nailgun/entities.py index 68d55c9a..9ad12f89 100644 --- a/nailgun/entities.py +++ b/nailgun/entities.py @@ -8876,3 +8876,17 @@ def search(self, fields=None, query=None, filters=None): return super().search( fields=fields, query=query, filters=filters, path_fields={'user': self.user} ) + + +class NotificationRecipients(Entity, EntityReadMixin): + """A representation of /notification_recipients endpoint.""" + + def __init__(self, server_config=None, **kwargs): + self._fields = { + 'notifications': entity_fields.ListField(), + } + self._meta = { + 'api_path': '/notification_recipients', + 'read_type': 'base', + } + super().__init__(server_config, **kwargs) diff --git a/tests/test_entities.py b/tests/test_entities.py index 9618d5cd..4f72de36 100644 --- a/tests/test_entities.py +++ b/tests/test_entities.py @@ -3993,3 +3993,34 @@ def test_scap_tailoring_file(self): _get_required_field_names(entity), set(entity.get_values().keys()), ) + + +class NotificationRecipientsTestCase(TestCase): + """Tests for :class:`nailgun.entities.NotificationRecipients`.""" + + def test_to_json(self): + """Check json serialisation on nested entities.""" + notifications_kwargs = { + "notifications": [ + { + "id": 28, + "seen": False, + "level": "info", + "text": "The fastest guide to configuring Red Hat Satellite ever", + "created_at": "2024-03-20T17:24:33.596Z", + "group": "Community", + "actions": { + "links": [ + { + "href": "https://www.redhat.com/en/blog/fastest-guide-configuring-red-hat-satellite-ever", + "title": "Open", + "external": True, + } + ] + }, + } + ] + } + cfg = config.ServerConfig(url='https://foo.bar', verify=False, auth=('foo', 'bar')) + notifications = entities.NotificationRecipients(cfg, **notifications_kwargs) + self.assertDictEqual(notifications_kwargs, json.loads(notifications.to_json()))