Skip to content
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
1 change: 1 addition & 0 deletions complaint_search/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# The default result size matches the front-end default for users.
# The trend_depth default limits display to 5 items in some Trends contexts.
PAGINATION_BATCH = 100
MAX_DOWNLOAD_SIZE = 100000
MAX_PAGINATION_DEPTH = 10000
RESULT_SIZE_DEFAULT = 25
RESULT_SIZE_OPTIONS = [10, 50, 100]
Expand Down
6 changes: 6 additions & 0 deletions complaint_search/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
from io import StringIO

from django.http import StreamingHttpResponse
from django.http.response import Http404

from complaint_search.defaults import MAX_DOWNLOAD_SIZE


class OpenSearchExporter(object):
Expand Down Expand Up @@ -63,6 +66,9 @@ def stream():
# - total_count (int)
# The total number of records to be output
def export_json(self, scanResponse, total_count):
if not total_count or total_count > MAX_DOWNLOAD_SIZE:
return Http404

def stream():
count = 0
# Write JSON
Expand Down
9 changes: 9 additions & 0 deletions complaint_search/tests/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
from collections import OrderedDict

from django.http import StreamingHttpResponse
from django.http.response import Http404
from django.test import TestCase

from parameterized import parameterized

from complaint_search.defaults import MAX_DOWNLOAD_SIZE
from complaint_search.export import OpenSearchExporter


Expand Down Expand Up @@ -76,6 +78,13 @@ def test_export_json_request_response(self, length):
downloaded_file = io.BytesIO(b"".join(res.streaming_content))
self.assertFalse(downloaded_file is None)

def test_json_export_limit(self):
length = MAX_DOWNLOAD_SIZE + 1
es_exporter = OpenSearchExporter()
gen = es_generator(length)
es_exporter.export_json(gen, length)
self.assertRaises(Http404)


class TestCSVExportWithUnicodeCharacters(TestCase):
def test_export_contains_unicode_chacter(self):
Expand Down
Loading