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

Allow for longer linked object IDs, increase page size for event listings #88

Merged
merged 5 commits into from
Jul 7, 2017
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion premis_event_service/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ class EventSearchForm(forms.Form):

linked_object_id = forms.CharField(
widget=forms.TextInput(attrs={'placeholder': 'Linked Object ID', 'class': 'input-medium'}),
max_length=20,
max_length=64,
required=False)
13 changes: 2 additions & 11 deletions premis_event_service/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
EVENT_UPDATE_TRANSLATION_DICT = xpath_map
XML_HEADER = "<?xml version=\"1.0\"?>\n%s"

EVENT_SEARCH_PER_PAGE = 20
EVENT_SEARCH_PER_PAGE = 200


def get_request_body(request):
Expand Down Expand Up @@ -533,7 +533,6 @@ def app_event(request, identifier=None):
elif request.method == 'GET' and not identifier:
# negotiate the details of our feed here
events = Event.objects.all()
startTime = datetime.now()
# parse the request get variables and filter the search
if request.GET.get('start_date'):
start_date = datetime.strptime(
Expand Down Expand Up @@ -575,15 +574,13 @@ def app_event(request, identifier=None):
except FieldError:
# If order_by fails, revert to natural order.
events = unordered_events
debug_list = []
endTime = datetime.now()
if request.GET:
page = int(request.GET['page']) if request.GET.get('page') else 1
else:
page = 1
try:
atomFeed = makeObjectFeed(
paginator=Paginator(events, 20),
paginator=Paginator(events, 200),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this 200 since the 20 was hard coded or do you want to use the constant?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, sorry. It's a mistake. I hard-coded it to make sure the paginator still worked properly, intending to either change it or set it to a new constant w/ the same value. Fix coming momentarily.

objectToXMLFunction=objectToPremisEventXML,
feedId=request.path[1:],
webRoot='http://%s' % request.META.get('HTTP_HOST'),
Expand All @@ -600,12 +597,6 @@ def app_event(request, identifier=None):
status=400,
content_type='text/plain'
)
comment = etree.Comment(
"\n".join(debug_list) +
"\nTime prior to filtering is %s, time after filtering is %s" %
(startTime, endTime)
)
atomFeed.append(comment)
atomFeedText = XML_HEADER % etree.tostring(atomFeed, pretty_print=True)
resp = HttpResponse(atomFeedText, content_type="application/atom+xml")
resp.status_code = 200
Expand Down
11 changes: 6 additions & 5 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def test_head_and_get_headers_match_with_identifier(self, rf):
class TestAppEvent:
"""Tests for views.app_event."""
CONTENT_TYPE = 'application/atom+xml'
RESULTS_PER_PAGE = 20
RESULTS_PER_PAGE = views.EVENT_SEARCH_PER_PAGE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you are using EVENT_SEARCH_PER_PAGE, in app_event you hard code 200. Do we want to switch in one place or the other?


def response_has_event(self, response, event):
"""True if the event is the only event in the response content."""
Expand Down Expand Up @@ -682,7 +682,7 @@ def test_head_and_get_headers_match_with_identifier(self, rf):

class TestEventSearch:
"""Tests for views.event_search."""
RESULTS_PER_PAGE = 20
RESULTS_PER_PAGE = views.EVENT_SEARCH_PER_PAGE

def response_has_event(self, response, event):
"""True if the event is the only Event in the response context."""
Expand Down Expand Up @@ -734,7 +734,7 @@ def test_filtering_results(self, client):

class TestJsonEventSearch:
"""Tests for views.json_event_search."""
RESULTS_PER_PAGE = 20
RESULTS_PER_PAGE = views.EVENT_SEARCH_PER_PAGE
CONTENT_TYPE = 'application/json'
REL_SELF = 'self'
REL_FIRST = 'first'
Expand Down Expand Up @@ -782,11 +782,12 @@ def test_no_results(self, rf):
assert response.status_code == 200

def test_results_per_page(self, rf):
factories.EventFactory.create_batch(30)
per_page = self.RESULTS_PER_PAGE
factories.EventFactory.create_batch(per_page*4)
request = rf.get('/')
response = views.json_event_search(request)
data = json.loads(response.content)
assert len(data['feed']['entry']) == self.RESULTS_PER_PAGE
assert len(data['feed']['entry']) == per_page

def test_opensearch_query(self, rf):
factories.EventFactory.create_batch(10)
Expand Down