Skip to content

Commit

Permalink
Fix failing CollectionDetailView tests
Browse files Browse the repository at this point in the history
  • Loading branch information
blms committed Sep 23, 2024
1 parent b1151c2 commit 2fcc03f
Showing 1 changed file with 54 additions and 15 deletions.
69 changes: 54 additions & 15 deletions apps/readux/tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.test import TestCase, Client
from django.test import RequestFactory
from django.conf import settings

from apps.readux.forms import AllVolumesForm
from ..annotations import Annotations, AnnotationCrud
from django.contrib.auth import get_user_model
from django.urls import reverse
Expand Down Expand Up @@ -417,27 +419,64 @@ def test_user_annotations_on_canvas(self):
assert serialized_canvas['label'] == str(self.canvas.position)
assert len(serialized_canvas['otherContent']) == 1

# TODO are the volumes actually sorted?
def test_collection_detail_view_sort_and_order(self):
view = CollectionDetail()
for sort in view.SORT_OPTIONS:
for order in view.ORDER_OPTIONS:
kwargs = {'sort': sort, 'order': order }
url = reverse('collection', kwargs={ 'collection': self.collection.pid })
response = self.client.get(url, data=kwargs)
context = response.context_data
assert context['sort'] == sort
assert context['order'] == order
assert context['order_url_params'] == urlencode({'sort': sort, 'order': order})
assert context['manifest_query_set'].ordered
descrizione = self.collection.manifests.first()
vol2 = Manifest.objects.create(pid="test1", author="xyz", label="zyx", published_date_edtf="1000")
self.collection.manifests.add(vol2)
url = reverse('collection', kwargs={ 'collection': self.collection.pid })

# test all different sort options: title
kwargs = {'sort': 'title', 'order': 'asc' }
response = self.client.get(url, data=kwargs)
context = response.context_data
assert context['volumes'][0].pid == descrizione.pid
kwargs = {'sort': 'title', 'order': 'desc' }
response = self.client.get(url, data=kwargs)
context = response.context_data
assert context['volumes'][0].pid == vol2.pid

# author
kwargs = {'sort': 'author', 'order': 'asc' }
response = self.client.get(url, data=kwargs)
context = response.context_data
assert context['volumes'][0].pid == descrizione.pid
kwargs = {'sort': 'author', 'order': 'desc' }
response = self.client.get(url, data=kwargs)
context = response.context_data
assert context['volumes'][0].pid == vol2.pid

# edtf date published
kwargs = {'sort': 'date', 'order': 'asc' }
response = self.client.get(url, data=kwargs)
context = response.context_data
assert context['volumes'][0].pid == vol2.pid
# the other one doesn't have an edtf published date, so it should be sorted last
# (nulls last) and therefore vol2 should still be first
kwargs = {'sort': 'date', 'order': 'desc' }
response = self.client.get(url, data=kwargs)
context = response.context_data
assert context['volumes'][0].pid == vol2.pid

# date added
kwargs = {'sort': 'added', 'order': 'asc' }
response = self.client.get(url, data=kwargs)
context = response.context_data
assert context['volumes'][0].pid == descrizione.pid
kwargs = {'sort': 'added', 'order': 'desc' }
response = self.client.get(url, data=kwargs)
context = response.context_data
assert context['volumes'][0].pid == vol2.pid

def test_collection_detail_view_with_no_sort_or_order_specified(self):
descrizione = self.collection.manifests.first()
vol2 = Manifest.objects.create(pid="test1", author="xyz", label="zyx", published_date_edtf="1000")
self.collection.manifests.add(vol2)
url = reverse('collection', kwargs={ 'collection': self.collection.pid })
response = self.client.get(url)
context = response.context_data
assert context['sort'] == 'title'
assert context['order'] == 'asc'
assert context['manifest_query_set'].ordered
# should order by title, asc
assert context['volumes'][0].pid == descrizione.pid
assert context['volumes'][1].pid == vol2.pid

def test_volume_detail_view(self):
url = reverse('volume', kwargs={'volume': self.manifest.pid})
Expand Down

0 comments on commit 2fcc03f

Please sign in to comment.