Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new entity NotificationRecipients #1118

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = {
pnovotny marked this conversation as resolved.
Show resolved Hide resolved
'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()))
Loading