Skip to content

Commit f94aa82

Browse files
pnovotnyweb-flow
authored andcommitted
new entity for NotificationRecipients
Added new entity `NotificationRecipients` for `/notification_recipients` endpoint. (cherry picked from commit e6e6ec6)
1 parent 8ca2de2 commit f94aa82

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

nailgun/entities.py

+14
Original file line numberDiff line numberDiff line change
@@ -8876,3 +8876,17 @@ def search(self, fields=None, query=None, filters=None):
88768876
return super().search(
88778877
fields=fields, query=query, filters=filters, path_fields={'user': self.user}
88788878
)
8879+
8880+
8881+
class NotificationRecipients(Entity, EntityReadMixin):
8882+
"""A representation of /notification_recipients endpoint."""
8883+
8884+
def __init__(self, server_config=None, **kwargs):
8885+
self._fields = {
8886+
'notifications': entity_fields.ListField(),
8887+
}
8888+
self._meta = {
8889+
'api_path': '/notification_recipients',
8890+
'read_type': 'base',
8891+
}
8892+
super().__init__(server_config, **kwargs)

tests/test_entities.py

+31
Original file line numberDiff line numberDiff line change
@@ -3993,3 +3993,34 @@ def test_scap_tailoring_file(self):
39933993
_get_required_field_names(entity),
39943994
set(entity.get_values().keys()),
39953995
)
3996+
3997+
3998+
class NotificationRecipientsTestCase(TestCase):
3999+
"""Tests for :class:`nailgun.entities.NotificationRecipients`."""
4000+
4001+
def test_to_json(self):
4002+
"""Check json serialisation on nested entities."""
4003+
notifications_kwargs = {
4004+
"notifications": [
4005+
{
4006+
"id": 28,
4007+
"seen": False,
4008+
"level": "info",
4009+
"text": "The fastest guide to configuring Red Hat Satellite ever",
4010+
"created_at": "2024-03-20T17:24:33.596Z",
4011+
"group": "Community",
4012+
"actions": {
4013+
"links": [
4014+
{
4015+
"href": "https://www.redhat.com/en/blog/fastest-guide-configuring-red-hat-satellite-ever",
4016+
"title": "Open",
4017+
"external": True,
4018+
}
4019+
]
4020+
},
4021+
}
4022+
]
4023+
}
4024+
cfg = config.ServerConfig(url='https://foo.bar', verify=False, auth=('foo', 'bar'))
4025+
notifications = entities.NotificationRecipients(cfg, **notifications_kwargs)
4026+
self.assertDictEqual(notifications_kwargs, json.loads(notifications.to_json()))

0 commit comments

Comments
 (0)