Skip to content
4 changes: 2 additions & 2 deletions api/webview/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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'])
Expand Down
16 changes: 16 additions & 0 deletions tests/test_api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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)