Skip to content

Commit

Permalink
new entity for NotificationRecipients
Browse files Browse the repository at this point in the history
Added new entity `NotificationRecipients` for `/notification_recipients` endpoint.
  • Loading branch information
pnovotny authored and pondrejk committed Apr 8, 2024
1 parent b157b63 commit e6e6ec6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
14 changes: 14 additions & 0 deletions nailgun/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -8916,3 +8916,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)
31 changes: 31 additions & 0 deletions tests/test_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3999,3 +3999,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()))

0 comments on commit e6e6ec6

Please sign in to comment.