diff --git a/api/webview/views.py b/api/webview/views.py index bc077f54..e55d4f4f 100644 --- a/api/webview/views.py +++ b/api/webview/views.py @@ -28,7 +28,7 @@ def perform_create(self, serializer): def get_queryset(self): """ Return all documents """ - return Document.objects.all() + return Document.objects.all().order_by('providerUpdatedDateTime').exclude(normalized=None) class DocumentsFromSource(generics.ListAPIView): @@ -44,7 +44,7 @@ def perform_create(self, serializer): def get_queryset(self): """ Return queryset based on source """ - return Document.objects.filter(source=self.kwargs['source']) + return Document.objects.filter(source=self.kwargs['source']).order_by('providerUpdatedDateTime').exclude(normalized=None) @api_view(['GET']) diff --git a/tests/test_api_views.py b/tests/test_api_views.py index b903140c..f541dc81 100644 --- a/tests/test_api_views.py +++ b/tests/test_api_views.py @@ -6,6 +6,7 @@ from rest_framework.test import APIRequestFactory from api.webview.views import DocumentList, status, institutions +from api.webview.models import Document django.setup() @@ -61,3 +62,18 @@ def test_institutions(self): response = view(request) self.assertEqual(response.status_code, 200) + def test_exclude_non_normalized_documents(self): + view = DocumentList.as_view() + create_document(source="bad",normalized=None) + create_document(source="good",normalized="This is Normalized") + request = self.factory.get( + '/documents/' + ) + response = view(request) + self.assertNotContains(response, "bad", + status_code=200) + + +def create_document(source,normalized): + return Document.objects.create(source=source, normalized=normalized) +