def test_only_main_collections_are_shown_by_default(self): collection = CollectionFactory.create() main_collection = CollectionFactory.create(is_main_collection=True) journal1 = JournalFactory.create_with_issue(collection=collection) journal2 = JournalFactory.create_with_issue(collection=main_collection) url = reverse('public:journal:journal_list') response = self.client.get(url) assert list(response.context['journals']) == [journal2]
def test_only_main_collections_are_shown_by_default(self): collection = CollectionFactory.create() main_collection = CollectionFactory.create(is_main_collection=True) journal1 = JournalFactory.create(collection=collection) journal2 = JournalFactory.create(collection=main_collection) url = reverse('public:journal:journal_list') response = self.client.get(url) assert list(response.context['journals']) == [journal2]
def test_returns_only_collections_associated_with_theses(self): # Setup author = AuthorFactory.create() collection_1 = CollectionFactory.create(localidentifier='col1') collection_2 = CollectionFactory.create(localidentifier='col2') CollectionFactory.create(localidentifier='col3') ThesisFactory.create(localidentifier='thesis1', collection=collection_1, author=author) ThesisFactory.create(localidentifier='thesis2', collection=collection_2, author=author) # Run & check assert list(get_thesis_collections()) == [collection_1, collection_2, ]
def setup(self): author_1 = AuthorFactory.create(lastname='Abc', firstname='Def') author_2 = AuthorFactory.create(lastname='Def', firstname='ghi') JournalType.objects.create(code='S') JournalType.objects.create(code='C') self.collection_1 = CollectionFactory.create() self.thesis_1 = ThesisFactory.create( localidentifier='t1', collection=self.collection_1, author=author_1, title='Thesis A', publication_year=2014) self.thesis_2 = ThesisFactory.create( localidentifier='t2', collection=self.collection_1, author=author_2, title='Thesis B', publication_year=2011) author_3 = AuthorFactory.create(lastname='Ghi', firstname='Jkl') author_4 = AuthorFactory.create(lastname='Jkl', firstname='mno') self.journal_1 = JournalFactory.create( collection=self.collection, type=JournalType.objects.get(code='S')) self.journal_2 = JournalFactory.create( collection=self.collection, type=JournalType.objects.get(code='C')) self.issue_1 = IssueFactory.create(journal=self.journal_1, year=2012) self.issue_2 = IssueFactory.create(journal=self.journal_2, year=2013) self.article_1 = ArticleFactory.create(title='Title A', issue=self.issue_1) self.article_2 = ArticleFactory.create(title='Title B', issue=self.issue_1) self.article_3 = ArticleFactory.create(title='Title C', issue=self.issue_2) self.article_1.authors.add(author_3) self.article_2.authors.add(author_4) self.article_3.authors.add(author_3) clist = SavedCitationListFactory.create(user=self.user) clist.documents.add(self.thesis_1) clist.documents.add(self.thesis_2) clist.documents.add(self.article_1) clist.documents.add(self.article_2) clist.documents.add(self.article_3)
def test_cannot_return_organisations_with_non_ongoing_subscriptions(self): # Setup now_dt = dt.datetime.now() collection = CollectionFactory.create() journal = JournalFactory(collection=collection) org_1 = OrganisationFactory.create() org_2 = OrganisationFactory.create() org_3 = OrganisationFactory.create() OrganisationFactory.create() subscription_1 = JournalAccessSubscriptionFactory.create( organisation=org_1, journal=journal) JournalAccessSubscriptionPeriodFactory.create( subscription=subscription_1, start=now_dt - dt.timedelta(days=10), end=now_dt + dt.timedelta(days=8)) subscription_2 = JournalAccessSubscriptionFactory.create( organisation=org_2, collection=journal.collection) JournalAccessSubscriptionPeriodFactory.create( subscription=subscription_2, start=now_dt - dt.timedelta(days=10), end=now_dt - dt.timedelta(days=5)) subscription_3 = JournalAccessSubscriptionFactory.create(organisation=org_3) subscription_3.journals.add(journal) JournalAccessSubscriptionPeriodFactory.create( subscription=subscription_3, start=now_dt - dt.timedelta(days=10), end=now_dt + dt.timedelta(days=8)) # Run & check assert set(get_journal_organisation_subscribers(journal)) == set([org_1, org_3, ])
def test_returns_only_theses_for_a_given_author_first_letter(self): # Setup author_1 = AuthorFactory.create(lastname='Aname') author_2 = AuthorFactory.create(lastname='Bname') author_3 = AuthorFactory.create(lastname='Cname') author_4 = AuthorFactory.create(lastname='Dname') collection = CollectionFactory.create() thesis_1 = ThesisFactory.create( # noqa localidentifier='thesis-1', collection=collection, author=author_1, publication_year=2010) thesis_2 = ThesisFactory.create( # noqa localidentifier='thesis-2', collection=collection, author=author_2, publication_year=2012) thesis_3 = ThesisFactory.create( # noqa localidentifier='thesis-3', collection=collection, author=author_3, publication_year=2013) thesis_4 = ThesisFactory.create( # noqa localidentifier='thesis-4', collection=collection, author=author_4, publication_year=2014) thesis_5 = ThesisFactory.create( # noqa localidentifier='thesis-5', collection=collection, author=author_2, publication_year=2012) thesis_6 = ThesisFactory.create( # noqa localidentifier='thesis-6', collection=collection, author=author_2, publication_year=2012) thesis_7 = ThesisFactory.create( # noqa localidentifier='thesis-7', collection=collection, author=author_4, publication_year=2014) url = reverse('public:thesis:collection_list_per_author_name', args=(collection.code, 'B')) # Run response = self.client.get(url) # Check assert response.status_code == 200 assert list(response.context['theses']) == [thesis_2, thesis_5, thesis_6, ]
def test_returns_only_theses_for_a_given_author_first_letter(self): # Setup author_1 = AuthorFactory.create(lastname='Aname') author_2 = AuthorFactory.create(lastname='Bname') author_3 = AuthorFactory.create(lastname='Cname') author_4 = AuthorFactory.create(lastname='Dname') collection = CollectionFactory.create() thesis_1 = ThesisFactory.create( # noqa localidentifier='thesis-1', collection=collection, author=author_1, publication_year=2010) thesis_2 = ThesisFactory.create( # noqa localidentifier='thesis-2', collection=collection, author=author_2, publication_year=2012) thesis_3 = ThesisFactory.create( # noqa localidentifier='thesis-3', collection=collection, author=author_3, publication_year=2013) thesis_4 = ThesisFactory.create( # noqa localidentifier='thesis-4', collection=collection, author=author_4, publication_year=2014) thesis_5 = ThesisFactory.create( # noqa localidentifier='thesis-5', collection=collection, author=author_2, publication_year=2012) thesis_6 = ThesisFactory.create( # noqa localidentifier='thesis-6', collection=collection, author=author_2, publication_year=2012) thesis_7 = ThesisFactory.create( # noqa localidentifier='thesis-7', collection=collection, author=author_4, publication_year=2014) url = reverse('public:thesis:collection_list_per_author_name', args=(collection.id, 'B')) # Run response = self.client.get(url) # Check assert response.status_code == 200 assert list(response.context['theses']) == [thesis_2, thesis_5, thesis_6, ]
def test_can_sort_journals_by_disciplines(self): # Setup collection = CollectionFactory.create() discipline_1 = DisciplineFactory.create(code='abc-discipline', name='ABC') discipline_2 = DisciplineFactory.create(code='def-discipline', name='DEF') discipline_3 = DisciplineFactory.create(code='ghi-discipline', name='GHI') journal_1 = JournalFactory.create(collection=collection) journal_1.disciplines.add(discipline_1) journal_2 = JournalFactory.create(collection=collection) journal_2.disciplines.add(discipline_1) journal_3 = JournalFactory.create(collection=collection) journal_3.disciplines.add(discipline_2) journal_4 = JournalFactory.create(collection=collection) journal_4.disciplines.add(discipline_3) journal_5 = JournalFactory.create(collection=collection) journal_5.disciplines.add(discipline_3) journal_6 = JournalFactory.create(collection=collection) journal_6.disciplines.add(discipline_3) url = reverse('public:journal:journal_list') # Run response = self.client.get(url, {'sorting': 'disciplines'}) # Check assert response.status_code == 200 assert len(response.context['sorted_objects']) == 3 assert response.context['sorted_objects'][0]['key'] == discipline_1.code assert response.context['sorted_objects'][0]['collections'][0]['key'] == collection assert response.context['sorted_objects'][0]['collections'][0]['objects'] == [ journal_1, journal_2, ] assert response.context['sorted_objects'][1]['key'] == discipline_2.code assert response.context['sorted_objects'][1]['collections'][0]['key'] == collection assert response.context['sorted_objects'][1]['collections'][0]['objects'] == [journal_3, ] assert response.context['sorted_objects'][2]['key'] == discipline_3.code assert response.context['sorted_objects'][2]['collections'][0]['key'] == collection assert set(response.context['sorted_objects'][2]['collections'][0]['objects']) == set([ journal_4, journal_5, journal_6, ])
def test_can_determine_the_thesis_counts_per_author_firstletter(self): # Setup author_1 = AuthorFactory.create(lastname='Aname') author_2 = AuthorFactory.create(lastname='Bname') author_3 = AuthorFactory.create(lastname='Cname') author_4 = AuthorFactory.create(lastname='Dname') collection = CollectionFactory.create() thesis_1 = ThesisFactory.create( # noqa localidentifier='thesis-1', collection=collection, author=author_1, publication_year=2010) thesis_2 = ThesisFactory.create( # noqa localidentifier='thesis-2', collection=collection, author=author_2, publication_year=2012) thesis_3 = ThesisFactory.create( # noqa localidentifier='thesis-3', collection=collection, author=author_3, publication_year=2013) thesis_4 = ThesisFactory.create( # noqa localidentifier='thesis-4', collection=collection, author=author_4, publication_year=2014) thesis_5 = ThesisFactory.create( # noqa localidentifier='thesis-5', collection=collection, author=author_2, publication_year=2012) thesis_6 = ThesisFactory.create( # noqa localidentifier='thesis-6', collection=collection, author=author_2, publication_year=2012) thesis_7 = ThesisFactory.create( # noqa localidentifier='thesis-7', collection=collection, author=author_4, publication_year=2014) # Run aggs = get_thesis_counts_per_author_first_letter(Thesis.objects.all()) # Check assert aggs[0] == {'author_firstletter': 'A', 'total': 1} assert aggs[1] == {'author_firstletter': 'B', 'total': 3} assert aggs[2] == {'author_firstletter': 'C', 'total': 1} assert aggs[3] == {'author_firstletter': 'D', 'total': 2}
def test_can_determine_the_thesis_counts_per_publication_year(self): # Setup author = AuthorFactory.create() collection = CollectionFactory.create() thesis_1 = ThesisFactory.create( # noqa localidentifier='thesis-1', collection=collection, author=author, publication_year=2010) thesis_2 = ThesisFactory.create( # noqa localidentifier='thesis-2', collection=collection, author=author, publication_year=2012) thesis_3 = ThesisFactory.create( # noqa localidentifier='thesis-3', collection=collection, author=author, publication_year=2013) thesis_4 = ThesisFactory.create( # noqa localidentifier='thesis-4', collection=collection, author=author, publication_year=2014) thesis_5 = ThesisFactory.create( # noqa localidentifier='thesis-5', collection=collection, author=author, publication_year=2012) thesis_6 = ThesisFactory.create( # noqa localidentifier='thesis-6', collection=collection, author=author, publication_year=2012) thesis_7 = ThesisFactory.create( # noqa localidentifier='thesis-7', collection=collection, author=author, publication_year=2014) # Run aggs = get_thesis_counts_per_publication_year(Thesis.objects.all()) # Check assert aggs[0] == {'publication_year': 2014, 'total': 2} assert aggs[1] == {'publication_year': 2013, 'total': 1} assert aggs[2] == {'publication_year': 2012, 'total': 3} assert aggs[3] == {'publication_year': 2010, 'total': 1}
def test_cannot_return_organisations_with_non_ongoing_subscriptions(self): # Setup now_dt = dt.datetime.now() collection = CollectionFactory.create() journal = JournalFactory(collection=collection) org_1 = OrganisationFactory.create() org_2 = OrganisationFactory.create() org_3 = OrganisationFactory.create() OrganisationFactory.create() subscription_1 = JournalAccessSubscriptionFactory.create( organisation=org_1, journal=journal) JournalAccessSubscriptionPeriodFactory.create( subscription=subscription_1, start=now_dt - dt.timedelta(days=10), end=now_dt + dt.timedelta(days=8)) subscription_2 = JournalAccessSubscriptionFactory.create( organisation=org_2, collection=journal.collection) JournalAccessSubscriptionPeriodFactory.create( subscription=subscription_2, start=now_dt - dt.timedelta(days=10), end=now_dt - dt.timedelta(days=5)) subscription_3 = JournalAccessSubscriptionFactory.create( organisation=org_3) subscription_3.journals.add(journal) JournalAccessSubscriptionPeriodFactory.create( subscription=subscription_3, start=now_dt - dt.timedelta(days=10), end=now_dt + dt.timedelta(days=8)) # Run & check assert set(get_journal_organisation_subscribers(journal)) == set([ org_1, org_3, ])
def test_returns_only_collections_associated_with_theses(self): # Setup author = AuthorFactory.create() collection_1 = CollectionFactory.create(localidentifier='col1') collection_2 = CollectionFactory.create(localidentifier='col2') CollectionFactory.create(localidentifier='col3') ThesisFactory.create(localidentifier='thesis1', collection=collection_1, author=author) ThesisFactory.create(localidentifier='thesis2', collection=collection_2, author=author) # Run & check assert list(get_thesis_collections()) == [ collection_1, collection_2, ]
def test_inserts_collection_information_into_the_context(self): # Setup author = AuthorFactory.create() collection_1 = CollectionFactory.create() collection_2 = CollectionFactory.create() thesis_1 = ThesisFactory.create( # noqa localidentifier='thesis-1', collection=collection_1, author=author, publication_year=2010) thesis_2 = ThesisFactory.create( localidentifier='thesis-2', collection=collection_1, author=author, publication_year=2012) thesis_3 = ThesisFactory.create( localidentifier='thesis-3', collection=collection_1, author=author, publication_year=2013) thesis_4 = ThesisFactory.create( localidentifier='thesis-4', collection=collection_1, author=author, publication_year=2014) thesis_5 = ThesisFactory.create( # noqa localidentifier='thesis-5', collection=collection_2, author=author, publication_year=2010) thesis_6 = ThesisFactory.create( localidentifier='thesis-6', collection=collection_2, author=author, publication_year=2012) thesis_7 = ThesisFactory.create( localidentifier='thesis-7', collection=collection_2, author=author, publication_year=2013) thesis_8 = ThesisFactory.create( localidentifier='thesis-8', collection=collection_2, author=author, publication_year=2014) url = reverse('public:thesis:home') # Run response = self.client.get(url) # Check assert response.status_code == 200 assert 'collections_dict' in response.context assert len(response.context['collections_dict']) == 2 assert collection_1.id in response.context['collections_dict'] assert collection_2.id in response.context['collections_dict'] assert response.context['collections_dict'][collection_1.id]['thesis_count'] == 4 assert response.context['collections_dict'][collection_2.id]['thesis_count'] == 4 assert response.context['collections_dict'][collection_1.id]['recent_theses'] == \ [thesis_4, thesis_3, thesis_2, ] assert response.context['collections_dict'][collection_2.id]['recent_theses'] == \ [thesis_8, thesis_7, thesis_6, ]
def test_can_filter_the_journals_by_open_access(self): # Setup collection = CollectionFactory.create() journal_1 = JournalFactory.create(collection=collection, open_access=True) JournalFactory.create(collection=collection, open_access=False) url = reverse('public:journal:journal_list') # Run response = self.client.get(url, data={'open_access': True}) # Check assert list(response.context['journals']) == [journal_1, ]
def test_can_sort_journals_by_disciplines(self): # Setup collection = CollectionFactory.create() discipline_1 = DisciplineFactory.create(code='abc-discipline', name='ABC') discipline_2 = DisciplineFactory.create(code='def-discipline', name='DEF') discipline_3 = DisciplineFactory.create(code='ghi-discipline', name='GHI') journal_1 = JournalFactory.create_with_issue(collection=collection) journal_1.disciplines.add(discipline_1) journal_2 = JournalFactory.create_with_issue(collection=collection) journal_2.disciplines.add(discipline_1) journal_3 = JournalFactory.create_with_issue(collection=collection) journal_3.disciplines.add(discipline_2) journal_4 = JournalFactory.create_with_issue(collection=collection) journal_4.disciplines.add(discipline_3) journal_5 = JournalFactory.create_with_issue(collection=collection) journal_5.disciplines.add(discipline_3) journal_6 = JournalFactory.create_with_issue(collection=collection) journal_6.disciplines.add(discipline_3) url = reverse('public:journal:journal_list') # Run response = self.client.get(url, {'sorting': 'disciplines'}) # Check assert response.status_code == 200 assert len(response.context['sorted_objects']) == 3 assert response.context['sorted_objects'][0][ 'key'] == discipline_1.code assert response.context['sorted_objects'][0]['collections'][0][ 'key'] == collection assert response.context['sorted_objects'][0]['collections'][0][ 'objects'] == [ journal_1, journal_2, ] assert response.context['sorted_objects'][1][ 'key'] == discipline_2.code assert response.context['sorted_objects'][1]['collections'][0][ 'key'] == collection assert response.context['sorted_objects'][1]['collections'][0][ 'objects'] == [ journal_3, ] assert response.context['sorted_objects'][2][ 'key'] == discipline_3.code assert response.context['sorted_objects'][2]['collections'][0][ 'key'] == collection assert set(response.context['sorted_objects'][2]['collections'][0] ['objects']) == set([ journal_4, journal_5, journal_6, ])
def test_can_filter_the_journals_by_types(self): # Setup collection = CollectionFactory.create() jtype_1 = JournalType.objects.create(code='T1', name='T1') jtype_2 = JournalType.objects.create(code='T2', name='T2') JournalFactory.create(collection=collection, type=jtype_1) journal_2 = JournalFactory.create(collection=collection, type=jtype_2) url = reverse('public:journal:journal_list') # Run response = self.client.get(url, data={'types': ['T2', ]}) # Check assert list(response.context['journals']) == [journal_2, ]
def test_can_filter_the_journals_by_open_access(self): # Setup collection = CollectionFactory.create() journal_1 = JournalFactory.create_with_issue(collection=collection, open_access=True) JournalFactory.create(collection=collection, open_access=False) url = reverse('public:journal:journal_list') # Run response = self.client.get(url, data={'open_access': True}) # Check assert list(response.context['journals']) == [ journal_1, ]
def test_can_embed_the_journal_information_in_the_context_if_available(self): # Setup collection = CollectionFactory.create() journal_1 = JournalFactory.create(collection=collection) journal_2 = JournalFactory.create(collection=collection) journal_info = JournalInformationFactory.create(journal=journal_1) url_1 = reverse('public:journal:journal_detail', kwargs={'code': journal_1.code}) url_2 = reverse('public:journal:journal_detail', kwargs={'code': journal_2.code}) # Run response_1 = self.client.get(url_1) response_2 = self.client.get(url_2) # Check self.assertEqual(response_1.status_code, 200) self.assertEqual(response_2.status_code, 200) self.assertEqual(response_1.context['journal_info'], journal_info) self.assertTrue('journal_info' not in response_2.context)
def _setup_erudit(self): # Setup a User instance self.user = UserFactory.create(username='******', email='*****@*****.**') self.user.set_password('notreallysecret') self.user.save() # Setup a basic publisher self.publisher = PublisherFactory.create(name='Test publisher') # Setup a basic collection self.collection = CollectionFactory.create( code='erudit', localidentifier='erudit', name='Érudit') # Add a journal with a single member self.journal = JournalFactory.create( collection=self.collection, publishers=[self.publisher]) self.journal.members.add(self.user)
def test_can_filter_the_journals_by_types(self): # Setup collection = CollectionFactory.create() jtype_1 = JournalType.objects.create(code='T1', name='T1') jtype_2 = JournalType.objects.create(code='T2', name='T2') JournalFactory.create(collection=collection, type=jtype_1) journal_2 = JournalFactory.create_with_issue(collection=collection, type=jtype_2) url = reverse('public:journal:journal_list') # Run response = self.client.get(url, data={'types': [ 'T2', ]}) # Check assert list(response.context['journals']) == [ journal_2, ]
def test_can_embed_the_latest_issue_in_the_context(self): # Setup collection = CollectionFactory.create(localidentifier='erudit') journal = JournalFactory.create(collection=collection) JournalInformationFactory.create(journal=journal) IssueFactory.create( journal=journal, year=2010, date_published=dt.datetime.now() - dt.timedelta(days=1)) issue_2 = IssueFactory.create(journal=journal, year=2010, date_published=dt.datetime.now()) IssueFactory.create( journal=journal, year=dt.datetime.now().year + 1, date_published=dt.datetime.now() + dt.timedelta(days=30)) url = reverse('public:journal:journal_detail', kwargs={'code': journal.code}) # Run response = self.client.get(url) # Check self.assertEqual(response.status_code, 200) self.assertEqual(response.context['latest_issue'], issue_2)
def test_can_embed_the_journal_information_in_the_context_if_available( self): # Setup collection = CollectionFactory.create() journal_1 = JournalFactory.create(collection=collection) journal_2 = JournalFactory.create(collection=collection) journal_info = JournalInformationFactory.create(journal=journal_1) url_1 = reverse('public:journal:journal_detail', kwargs={'code': journal_1.code}) url_2 = reverse('public:journal:journal_detail', kwargs={'code': journal_2.code}) # Run response_1 = self.client.get(url_1) response_2 = self.client.get(url_2) # Check self.assertEqual(response_1.status_code, 200) self.assertEqual(response_2.status_code, 200) self.assertEqual(response_1.context['journal_info'], journal_info) self.assertTrue('journal_info' not in response_2.context)
def test_can_sort_theses_by_descending_title(self): # Setup author = AuthorFactory.create(lastname='Bname') collection = CollectionFactory.create() thesis_1 = ThesisFactory.create( # noqa localidentifier='thesis-1', collection=collection, author=author, publication_year=2012, title='Atitle') thesis_2 = ThesisFactory.create( # noqa localidentifier='thesis-2', collection=collection, author=author, publication_year=2012, title='Btitle') thesis_3 = ThesisFactory.create( # noqa localidentifier='thesis-3', collection=collection, author=author, publication_year=2012, title='Ctitle') url = reverse('public:thesis:collection_list_per_author_name', args=(collection.code, 'B')) # Run response = self.client.get(url, {'sort_by': 'title_desc'}) # Check assert response.status_code == 200 assert list(response.context['theses']) == [thesis_3, thesis_2, thesis_1, ]
def test_can_sort_theses_by_descending_title(self): # Setup author = AuthorFactory.create(lastname='Bname') collection = CollectionFactory.create() thesis_1 = ThesisFactory.create( # noqa localidentifier='thesis-1', collection=collection, author=author, publication_year=2012, title='Atitle') thesis_2 = ThesisFactory.create( # noqa localidentifier='thesis-2', collection=collection, author=author, publication_year=2012, title='Btitle') thesis_3 = ThesisFactory.create( # noqa localidentifier='thesis-3', collection=collection, author=author, publication_year=2012, title='Ctitle') url = reverse('public:thesis:collection_list_per_author_name', args=(collection.id, 'B')) # Run response = self.client.get(url, {'sort_by': 'title_desc'}) # Check assert response.status_code == 200 assert list(response.context['theses']) == [thesis_3, thesis_2, thesis_1, ]
def _setup_erudit(self): # Setup a User instance self.user = UserFactory.create(username='******', email='*****@*****.**') self.user.set_password('notreallysecret') self.user.save() # Setup a basic publisher self.publisher = PublisherFactory.create(name='Test publisher') # Setup a basic collection self.collection = CollectionFactory.create(code='erudit', localidentifier='erudit', name='Érudit') # Add a journal with a single member self.journal = JournalFactory.create(collection=self.collection, publishers=[self.publisher]) self.journal.members.add(self.user)
def test_embeds_the_other_author_first_letter_aggregation_results_into_the_context(self): # Setup cache.clear() author_1 = AuthorFactory.create(lastname='Aname') author_2 = AuthorFactory.create(lastname='Bname') author_3 = AuthorFactory.create(lastname='Cname') author_4 = AuthorFactory.create(lastname='Dname') collection = CollectionFactory.create() thesis_1 = ThesisFactory.create( # noqa localidentifier='thesis-1', collection=collection, author=author_1, publication_year=2010) thesis_2 = ThesisFactory.create( # noqa localidentifier='thesis-2', collection=collection, author=author_2, publication_year=2012) thesis_3 = ThesisFactory.create( # noqa localidentifier='thesis-3', collection=collection, author=author_3, publication_year=2013) thesis_4 = ThesisFactory.create( # noqa localidentifier='thesis-4', collection=collection, author=author_4, publication_year=2014) thesis_5 = ThesisFactory.create( # noqa localidentifier='thesis-5', collection=collection, author=author_2, publication_year=2012) thesis_6 = ThesisFactory.create( # noqa localidentifier='thesis-6', collection=collection, author=author_2, publication_year=2012) thesis_7 = ThesisFactory.create( # noqa localidentifier='thesis-7', collection=collection, author=author_4, publication_year=2014) url = reverse('public:thesis:collection_list_per_author_name', args=(collection.id, 'B')) # Run response = self.client.get(url) # Check assert response.status_code == 200 assert response.context['other_author_letters'][0] == \ {'author_firstletter': 'A', 'total': 1} assert response.context['other_author_letters'][1] == \ {'author_firstletter': 'B', 'total': 3} assert response.context['other_author_letters'][2] == \ {'author_firstletter': 'C', 'total': 1} assert response.context['other_author_letters'][3] == \ {'author_firstletter': 'D', 'total': 2}
def test_embeds_the_other_author_first_letter_aggregation_results_into_the_context(self): # Setup cache.clear() author_1 = AuthorFactory.create(lastname='Aname') author_2 = AuthorFactory.create(lastname='Bname') author_3 = AuthorFactory.create(lastname='Cname') author_4 = AuthorFactory.create(lastname='Dname') collection = CollectionFactory.create() thesis_1 = ThesisFactory.create( # noqa localidentifier='thesis-1', collection=collection, author=author_1, publication_year=2010) thesis_2 = ThesisFactory.create( # noqa localidentifier='thesis-2', collection=collection, author=author_2, publication_year=2012) thesis_3 = ThesisFactory.create( # noqa localidentifier='thesis-3', collection=collection, author=author_3, publication_year=2013) thesis_4 = ThesisFactory.create( # noqa localidentifier='thesis-4', collection=collection, author=author_4, publication_year=2014) thesis_5 = ThesisFactory.create( # noqa localidentifier='thesis-5', collection=collection, author=author_2, publication_year=2012) thesis_6 = ThesisFactory.create( # noqa localidentifier='thesis-6', collection=collection, author=author_2, publication_year=2012) thesis_7 = ThesisFactory.create( # noqa localidentifier='thesis-7', collection=collection, author=author_4, publication_year=2014) url = reverse('public:thesis:collection_list_per_author_name', args=(collection.code, 'B')) # Run response = self.client.get(url) # Check assert response.status_code == 200 assert response.context['other_author_letters'][0] == \ {'author_firstletter': 'A', 'total': 1} assert response.context['other_author_letters'][1] == \ {'author_firstletter': 'B', 'total': 3} assert response.context['other_author_letters'][2] == \ {'author_firstletter': 'C', 'total': 1} assert response.context['other_author_letters'][3] == \ {'author_firstletter': 'D', 'total': 2}
def test_can_sort_theses_by_descending_date(self): # Setup dt_now = dt.datetime.now() author = AuthorFactory.create(lastname='Bname') collection = CollectionFactory.create() thesis_1 = ThesisFactory.create( # noqa localidentifier='thesis-1', collection=collection, author=author, publication_year=2012, oai_datestamp=(dt_now - dt.timedelta(days=3)).date()) thesis_2 = ThesisFactory.create( # noqa localidentifier='thesis-2', collection=collection, author=author, publication_year=2012, oai_datestamp=(dt_now - dt.timedelta(days=2)).date()) thesis_3 = ThesisFactory.create( # noqa localidentifier='thesis-3', collection=collection, author=author, publication_year=2012, oai_datestamp=(dt_now - dt.timedelta(days=1)).date()) url = reverse('public:thesis:collection_list_per_author_name', args=(collection.id, 'B')) # Run response = self.client.get(url, {'sort_by': 'date_desc'}) # Check assert response.status_code == 200 assert list(response.context['theses']) == [thesis_3, thesis_2, thesis_1, ]
def test_can_sort_theses_by_descending_date(self): # Setup dt_now = dt.datetime.now() author = AuthorFactory.create(lastname='Bname') collection = CollectionFactory.create() thesis_1 = ThesisFactory.create( # noqa localidentifier='thesis-1', collection=collection, author=author, publication_year=2012, oai_datestamp=(dt_now - dt.timedelta(days=3)).date()) thesis_2 = ThesisFactory.create( # noqa localidentifier='thesis-2', collection=collection, author=author, publication_year=2012, oai_datestamp=(dt_now - dt.timedelta(days=2)).date()) thesis_3 = ThesisFactory.create( # noqa localidentifier='thesis-3', collection=collection, author=author, publication_year=2012, oai_datestamp=(dt_now - dt.timedelta(days=1)).date()) url = reverse('public:thesis:collection_list_per_author_name', args=(collection.code, 'B')) # Run response = self.client.get(url, {'sort_by': 'date_desc'}) # Check assert response.status_code == 200 assert list(response.context['theses']) == [thesis_3, thesis_2, thesis_1, ]
def test_only_has_full_identifier_if_complete(self): c1 = CollectionFactory.create(localidentifier=None) j1 = JournalFactory.create(collection=c1, localidentifier=None) i1 = IssueFactory.create(journal=j1) article_1 = ArticleFactory.create(issue=i1) assert article_1.get_full_identifier() is None i1.localidentifier = 'issue1' i1.save() assert article_1.get_full_identifier() is None j1.localidentifier = 'journal1' j1.save() assert article_1.get_full_identifier() is None c1.localidentifier = 'c1' c1.save() assert article_1.get_full_identifier() is not None
def test_inserts_the_thesis_counts_grouped_by_author_name(self): # Setup author_1 = AuthorFactory.create(lastname='Aname') author_2 = AuthorFactory.create(lastname='Bname') author_3 = AuthorFactory.create(lastname='Cname') author_4 = AuthorFactory.create(lastname='Dname') collection = CollectionFactory.create() thesis_1 = ThesisFactory.create( # noqa localidentifier='thesis-1', collection=collection, author=author_1, publication_year=2010) thesis_2 = ThesisFactory.create( # noqa localidentifier='thesis-2', collection=collection, author=author_2, publication_year=2012) thesis_3 = ThesisFactory.create( # noqa localidentifier='thesis-3', collection=collection, author=author_3, publication_year=2013) thesis_4 = ThesisFactory.create( # noqa localidentifier='thesis-4', collection=collection, author=author_4, publication_year=2014) thesis_5 = ThesisFactory.create( # noqa localidentifier='thesis-5', collection=collection, author=author_2, publication_year=2012) thesis_6 = ThesisFactory.create( # noqa localidentifier='thesis-6', collection=collection, author=author_2, publication_year=2012) thesis_7 = ThesisFactory.create( # noqa localidentifier='thesis-7', collection=collection, author=author_4, publication_year=2014) url = reverse('public:thesis:collection_home', args=(collection.id, )) # Run response = self.client.get(url) # Check assert response.status_code == 200 assert response.context['thesis_groups']['by_author_name'][0] == \ {'author_firstletter': 'A', 'total': 1} assert response.context['thesis_groups']['by_author_name'][1] == \ {'author_firstletter': 'B', 'total': 3} assert response.context['thesis_groups']['by_author_name'][2] == \ {'author_firstletter': 'C', 'total': 1} assert response.context['thesis_groups']['by_author_name'][3] == \ {'author_firstletter': 'D', 'total': 2}
def test_inserts_the_thesis_counts_grouped_by_publication_years(self): # Setup cache.clear() author = AuthorFactory.create() collection = CollectionFactory.create() thesis_1 = ThesisFactory.create( # noqa localidentifier='thesis-1', collection=collection, author=author, publication_year=2010) thesis_2 = ThesisFactory.create( # noqa localidentifier='thesis-2', collection=collection, author=author, publication_year=2012) thesis_3 = ThesisFactory.create( # noqa localidentifier='thesis-3', collection=collection, author=author, publication_year=2013) thesis_4 = ThesisFactory.create( # noqa localidentifier='thesis-4', collection=collection, author=author, publication_year=2014) thesis_5 = ThesisFactory.create( # noqa localidentifier='thesis-5', collection=collection, author=author, publication_year=2012) thesis_6 = ThesisFactory.create( # noqa localidentifier='thesis-6', collection=collection, author=author, publication_year=2012) thesis_7 = ThesisFactory.create( # noqa localidentifier='thesis-7', collection=collection, author=author, publication_year=2014) url = reverse('public:thesis:collection_home', args=(collection.id, )) # Run response = self.client.get(url) # Check assert response.status_code == 200 assert response.context['thesis_groups']['by_publication_year'][0] == \ {'publication_year': 2014, 'total': 2} assert response.context['thesis_groups']['by_publication_year'][1] == \ {'publication_year': 2013, 'total': 1} assert response.context['thesis_groups']['by_publication_year'][2] == \ {'publication_year': 2012, 'total': 3} assert response.context['thesis_groups']['by_publication_year'][3] == \ {'publication_year': 2010, 'total': 1}
def test_embeds_the_other_publication_years_aggregation_results_into_the_context(self): # Setup cache.clear() author = AuthorFactory.create() collection = CollectionFactory.create() thesis_1 = ThesisFactory.create( # noqa localidentifier='thesis-1', collection=collection, author=author, publication_year=2010) thesis_2 = ThesisFactory.create( # noqa localidentifier='thesis-2', collection=collection, author=author, publication_year=2012) thesis_3 = ThesisFactory.create( # noqa localidentifier='thesis-3', collection=collection, author=author, publication_year=2013) thesis_4 = ThesisFactory.create( # noqa localidentifier='thesis-4', collection=collection, author=author, publication_year=2014) thesis_5 = ThesisFactory.create( # noqa localidentifier='thesis-5', collection=collection, author=author, publication_year=2012) thesis_6 = ThesisFactory.create( # noqa localidentifier='thesis-6', collection=collection, author=author, publication_year=2012) thesis_7 = ThesisFactory.create( # noqa localidentifier='thesis-7', collection=collection, author=author, publication_year=2014) url = reverse('public:thesis:collection_list_per_year', args=(collection.id, 2012)) # Run response = self.client.get(url) # Check assert response.status_code == 200 assert response.context['other_publication_years'][0] == \ {'publication_year': 2014, 'total': 2} assert response.context['other_publication_years'][1] == \ {'publication_year': 2013, 'total': 1} assert response.context['other_publication_years'][2] == \ {'publication_year': 2012, 'total': 3} assert response.context['other_publication_years'][3] == \ {'publication_year': 2010, 'total': 1}
def test_inserts_the_thesis_counts_grouped_by_publication_years(self): # Setup cache.clear() author = AuthorFactory.create() collection = CollectionFactory.create() thesis_1 = ThesisFactory.create( # noqa localidentifier='thesis-1', collection=collection, author=author, publication_year=2010) thesis_2 = ThesisFactory.create( # noqa localidentifier='thesis-2', collection=collection, author=author, publication_year=2012) thesis_3 = ThesisFactory.create( # noqa localidentifier='thesis-3', collection=collection, author=author, publication_year=2013) thesis_4 = ThesisFactory.create( # noqa localidentifier='thesis-4', collection=collection, author=author, publication_year=2014) thesis_5 = ThesisFactory.create( # noqa localidentifier='thesis-5', collection=collection, author=author, publication_year=2012) thesis_6 = ThesisFactory.create( # noqa localidentifier='thesis-6', collection=collection, author=author, publication_year=2012) thesis_7 = ThesisFactory.create( # noqa localidentifier='thesis-7', collection=collection, author=author, publication_year=2014) url = reverse('public:thesis:collection_home', args=(collection.code, )) # Run response = self.client.get(url) # Check assert response.status_code == 200 assert response.context['thesis_groups']['by_publication_year'][0] == \ {'publication_year': 2014, 'total': 2} assert response.context['thesis_groups']['by_publication_year'][1] == \ {'publication_year': 2013, 'total': 1} assert response.context['thesis_groups']['by_publication_year'][2] == \ {'publication_year': 2012, 'total': 3} assert response.context['thesis_groups']['by_publication_year'][3] == \ {'publication_year': 2010, 'total': 1}
def test_embeds_the_other_publication_years_aggregation_results_into_the_context(self): # Setup cache.clear() author = AuthorFactory.create() collection = CollectionFactory.create() thesis_1 = ThesisFactory.create( # noqa localidentifier='thesis-1', collection=collection, author=author, publication_year=2010) thesis_2 = ThesisFactory.create( # noqa localidentifier='thesis-2', collection=collection, author=author, publication_year=2012) thesis_3 = ThesisFactory.create( # noqa localidentifier='thesis-3', collection=collection, author=author, publication_year=2013) thesis_4 = ThesisFactory.create( # noqa localidentifier='thesis-4', collection=collection, author=author, publication_year=2014) thesis_5 = ThesisFactory.create( # noqa localidentifier='thesis-5', collection=collection, author=author, publication_year=2012) thesis_6 = ThesisFactory.create( # noqa localidentifier='thesis-6', collection=collection, author=author, publication_year=2012) thesis_7 = ThesisFactory.create( # noqa localidentifier='thesis-7', collection=collection, author=author, publication_year=2014) url = reverse('public:thesis:collection_list_per_year', args=(collection.code, 2012)) # Run response = self.client.get(url) # Check assert response.status_code == 200 assert response.context['other_publication_years'][0] == \ {'publication_year': 2014, 'total': 2} assert response.context['other_publication_years'][1] == \ {'publication_year': 2013, 'total': 1} assert response.context['other_publication_years'][2] == \ {'publication_year': 2012, 'total': 3} assert response.context['other_publication_years'][3] == \ {'publication_year': 2010, 'total': 1}
def test_inserts_the_recent_theses_into_the_context(self): # Setup author = AuthorFactory.create() collection = CollectionFactory.create() thesis_1 = ThesisFactory.create( # noqa localidentifier='thesis-1', collection=collection, author=author, publication_year=2010) thesis_2 = ThesisFactory.create( localidentifier='thesis-2', collection=collection, author=author, publication_year=2012) thesis_3 = ThesisFactory.create( localidentifier='thesis-3', collection=collection, author=author, publication_year=2013) thesis_4 = ThesisFactory.create( localidentifier='thesis-4', collection=collection, author=author, publication_year=2014) url = reverse('public:thesis:collection_home', args=(collection.code, )) # Run response = self.client.get(url) # Check assert response.status_code == 200 assert response.context['recent_theses'] == [thesis_4, thesis_3, thesis_2, ]
def test_inserts_the_recent_theses_into_the_context(self): # Setup author = AuthorFactory.create() collection = CollectionFactory.create() thesis_1 = ThesisFactory.create( # noqa localidentifier='thesis-1', collection=collection, author=author, publication_year=2010) thesis_2 = ThesisFactory.create( localidentifier='thesis-2', collection=collection, author=author, publication_year=2012) thesis_3 = ThesisFactory.create( localidentifier='thesis-3', collection=collection, author=author, publication_year=2013) thesis_4 = ThesisFactory.create( localidentifier='thesis-4', collection=collection, author=author, publication_year=2014) url = reverse('public:thesis:collection_home', args=(collection.id, )) # Run response = self.client.get(url) # Check assert response.status_code == 200 assert response.context['recent_theses'] == [thesis_4, thesis_3, thesis_2, ]
def test_can_sort_journals_by_name(self): # Setup collection = CollectionFactory.create() journal_1 = JournalFactory.create(collection=collection, name='ABC journal') journal_2 = JournalFactory.create(collection=collection, name='ACD journal') journal_3 = JournalFactory.create(collection=collection, name='DEF journal') journal_4 = JournalFactory.create(collection=collection, name='GHI journal') journal_5 = JournalFactory.create(collection=collection, name='GIJ journal') journal_6 = JournalFactory.create(collection=collection, name='GJK journal') url = reverse('public:journal:journal_list') # Run response = self.client.get(url) # Check assert response.status_code == 200 assert len(response.context['sorted_objects']) == 3 assert response.context['sorted_objects'][0]['key'] == 'A' assert response.context['sorted_objects'][0]['objects'] == [ journal_1, journal_2, ] assert response.context['sorted_objects'][1]['key'] == 'D' assert response.context['sorted_objects'][1]['objects'] == [journal_3, ] assert response.context['sorted_objects'][2]['key'] == 'G' assert response.context['sorted_objects'][2]['objects'] == [ journal_4, journal_5, journal_6, ]
def setup(self): author_1 = AuthorFactory.create(lastname='Abc', firstname='Def') author_2 = AuthorFactory.create(lastname='Def', firstname='ghi') JournalType.objects.create(code='S') JournalType.objects.create(code='C') self.collection_1 = CollectionFactory.create() self.thesis_1 = ThesisFactory.create(localidentifier='t1', collection=self.collection_1, author=author_1, title='Thesis A', publication_year=2014) self.thesis_2 = ThesisFactory.create(localidentifier='t2', collection=self.collection_1, author=author_2, title='Thesis B', publication_year=2011) author_3 = AuthorFactory.create(lastname='Ghi', firstname='Jkl') author_4 = AuthorFactory.create(lastname='Jkl', firstname='mno') self.journal_1 = JournalFactory.create( collection=self.collection, type=JournalType.objects.get(code='S')) self.journal_2 = JournalFactory.create( collection=self.collection, type=JournalType.objects.get(code='C')) self.issue_1 = IssueFactory.create(journal=self.journal_1, year=2012) self.issue_2 = IssueFactory.create(journal=self.journal_2, year=2013) self.article_1 = ArticleFactory.create(issue=self.issue_1) self.article_2 = ArticleFactory.create(issue=self.issue_1) self.article_3 = ArticleFactory.create(issue=self.issue_2) self.article_1.authors.add(author_3) self.article_2.authors.add(author_4) self.article_3.authors.add(author_3) clist = SavedCitationListFactory.create(user=self.user) clist.documents.add(self.thesis_1) clist.documents.add(self.thesis_2) clist.documents.add(self.article_1) clist.documents.add(self.article_2) clist.documents.add(self.article_3)
def test_can_embed_the_latest_issue_in_the_context(self): # Setup collection = CollectionFactory.create(localidentifier='erudit') journal = JournalFactory.create(collection=collection) JournalInformationFactory.create(journal=journal) IssueFactory.create(journal=journal, year=2010, date_published=dt.datetime.now() - dt.timedelta(days=1)) issue_2 = IssueFactory.create(journal=journal, year=2010, date_published=dt.datetime.now()) issue_3 = IssueFactory.create(is_published=False, journal=journal, year=dt.datetime.now().year + 1, date_published=dt.datetime.now() + dt.timedelta(days=30)) url = reverse('public:journal:journal_detail', kwargs={'code': journal.code}) # Run response = self.client.get(url) # Check self.assertEqual(response.status_code, 200) self.assertEqual(response.context['latest_issue'], issue_2)
def test_can_sort_journals_by_name(self): # Setup collection = CollectionFactory.create() journal_1 = JournalFactory.create_with_issue(collection=collection, name='ABC journal') journal_2 = JournalFactory.create_with_issue(collection=collection, name='ACD journal') journal_3 = JournalFactory.create_with_issue(collection=collection, name='DEF journal') journal_4 = JournalFactory.create_with_issue(collection=collection, name='GHI journal') journal_5 = JournalFactory.create_with_issue(collection=collection, name='GIJ journal') journal_6 = JournalFactory.create_with_issue(collection=collection, name='GJK journal') url = reverse('public:journal:journal_list') # Run response = self.client.get(url) # Check assert response.status_code == 200 assert len(response.context['sorted_objects']) == 3 assert response.context['sorted_objects'][0]['key'] == 'A' assert response.context['sorted_objects'][0]['objects'] == [ journal_1, journal_2, ] assert response.context['sorted_objects'][1]['key'] == 'D' assert response.context['sorted_objects'][1]['objects'] == [ journal_3, ] assert response.context['sorted_objects'][2]['key'] == 'G' assert response.context['sorted_objects'][2]['objects'] == [ journal_4, journal_5, journal_6, ]
def test_only_has_fedora_object_if_collection_has_localidentifier(self): c1 = CollectionFactory.create(localidentifier=None) j1 = JournalFactory.create(collection=c1) issue_1 = IssueFactory.create(journal=j1) article_1 = ArticleFactory.create(issue=issue_1) assert article_1.fedora_object is None