From b42f8f1ad9ed90f9b4acfa6d5fe0cf8e6985e64b Mon Sep 17 00:00:00 2001 From: Calum Mackervoy Date: Sat, 28 Nov 2020 19:16:29 +0000 Subject: [PATCH] bugfix: fixed issue with InboxView depth, implemented empty_containers setting for inbox --- djangoldp_notification/settings.py | 3 +- .../tests/scripts/generate_inbox_fixture.py | 48 +++++++++++++++++++ djangoldp_notification/views.py | 2 +- 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 djangoldp_notification/tests/scripts/generate_inbox_fixture.py diff --git a/djangoldp_notification/settings.py b/djangoldp_notification/settings.py index a5ed1cc..9adc13d 100644 --- a/djangoldp_notification/settings.py +++ b/djangoldp_notification/settings.py @@ -1 +1,2 @@ -USER_NESTED_FIELDS = ['inbox', 'settings'] \ No newline at end of file +USER_NESTED_FIELDS = ['inbox', 'settings'] +USER_EMPTY_CONTAINERS = ['inbox'] \ No newline at end of file diff --git a/djangoldp_notification/tests/scripts/generate_inbox_fixture.py b/djangoldp_notification/tests/scripts/generate_inbox_fixture.py new file mode 100644 index 0000000..0f12010 --- /dev/null +++ b/djangoldp_notification/tests/scripts/generate_inbox_fixture.py @@ -0,0 +1,48 @@ +import json +import argparse +from pathlib import Path +from copy import deepcopy +from datetime import datetime + +''' +A script which generates and outputs placeholder notifications attached to a parametrised user, output +into a parameterised file (json), which can be used as a Django fixture or imported into a live database +e.g. python manage.py loaddata fixture.json +for help run python generate_inbox_fixture.py -h +''' + +# starting from offset ensures that existing users etc are not disturbed +parser = argparse.ArgumentParser(description='generates and outputs random test data, into a file used by the performance unit tests') +parser.add_argument(dest='count', metavar='N', type=int, help='the number of users (and projects) to generate') +parser.add_argument(dest='user', metavar='U', type=str, help='the primary key of the user whose inbox should store the notifications') +parser.add_argument('--offset', dest='offset', type=int, default=100, help='an offset to start primary keys at (should be larger than the largest pre-existing project/user primary key)') +parser.add_argument('-f', dest='file_dest', type=str, default="../fixtures/inbox.json", help='the file destination to write to') + +args = parser.parse_args() +count = args.count +user = args.user +OFFSET = args.offset + +notification_template = { + 'model': 'djangoldp_notification.notification', + 'pk': 0, + 'fields': { + 'user': user, + 'author': 'Test', + 'object': 'http://localhost:8000/users/admin/', + 'type': 'Update', + 'summary': 'Test', + 'date': str(datetime.date(datetime.now())) + } +} + +fixture = list() +for i in range(count): + notification = deepcopy(notification_template) + notification['pk'] = OFFSET + i + fixture.append(notification) + +with open(Path(__file__).parent / args.file_dest, 'w') as output: + json.dump(fixture, output) + +print(str(count)) diff --git a/djangoldp_notification/views.py b/djangoldp_notification/views.py index a53af15..08b8b3f 100644 --- a/djangoldp_notification/views.py +++ b/djangoldp_notification/views.py @@ -9,4 +9,4 @@ class LDPNotificationsPagination(LDPPagination): class LDPNotificationsViewSet(LDPViewSet): '''overridden LDPViewSet to force pagination''' pagination_class = LDPNotificationsPagination - depth = 1 + depth = 0