Example #1
0
    def test_can_return_an_http_403_error_if_the_journal_has_no_management_subscription(
            self):
        # Setup
        journal = JournalFactory(collection=self.collection)
        journal.members.add(self.user_granted)
        journal.save()

        ct = ContentType.objects.get(app_label="erudit", model="journal")
        Authorization.objects.create(
            content_type=ct,
            user=self.user_granted,
            object_id=journal.id,
            authorization_codename=AC.can_manage_authorizations.codename)

        self.client.login(username=self.user_granted.username, password="******")

        url = reverse('userspace:journal:authorization:create',
                      args=(journal.pk, ))

        # Run
        response = self.client.get(
            url, {'codename': AC.can_manage_individual_subscription.codename})

        # Check
        self.assertEqual(response.status_code, 403)
Example #2
0
 def test_journals_with_published_issues_are_not_upcoming(self):
     # Setup
     JournalFactory.create_with_issue()
     # Run
     journals = Journal.upcoming_objects.all()
     # Check
     assert list(journals) == []
Example #3
0
    def test_shows_the_individual_subscription_authorization_section_with_management(self):
        # Setup
        journal = JournalFactory(collection=self.collection)
        journal.members.add(self.user_granted)
        journal.save()

        ct = ContentType.objects.get(app_label="erudit", model="journal")
        Authorization.objects.create(
            content_type=ct,
            user=self.user_granted,
            object_id=journal.id,
            authorization_codename=AC.can_manage_authorizations.codename)

        plan = JournalManagementPlanFactory.create(max_accounts=10)
        JournalManagementSubscriptionFactory.create(journal=journal, plan=plan)

        self.client.login(username=self.user_granted.username,
                          password="******")

        url = reverse('userspace:journal:authorization:list', args=(journal.pk, ))

        # Run
        response = self.client.get(url, {'codename': AC.can_manage_authorizations.codename})

        # Check
        self.assertEqual(response.status_code, 200)
        self.assertTrue(
            AC.can_manage_individual_subscription.codename
            in response.context['authorizations'])
Example #4
0
 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)
Example #5
0
    def test_permission_delete_restricted(self):
        self.client.login(username=self.user_non_granted.username,
                          password="******")

        journal = JournalFactory(collection=self.collection)
        journal.save()

        self.client.login(username=self.user_granted.username,
                          password="******")

        ct = ContentType.objects.get(app_label="erudit", model="journal")
        authorization = Authorization.objects.create(
            content_type=ct,
            user=self.user_granted,
            object_id=journal.id,
            authorization_codename=AC.can_manage_authorizations.codename)

        url = reverse('userspace:journal:authorization:delete',
                      args=(journal.pk, authorization.pk, ))

        response = self.client.get(url)
        self.assertEqual(response.status_code, 403)

        journal.members.add(self.user_granted)
        journal.save()
        response = self.client.get(url, follow=True)
        self.assertEqual(response.status_code, 200)
Example #6
0
    def test_shows_the_individual_subscription_authorization_section_with_management(
            self):
        # Setup
        journal = JournalFactory(collection=self.collection)
        journal.members.add(self.user_granted)
        journal.save()

        ct = ContentType.objects.get(app_label="erudit", model="journal")
        Authorization.objects.create(
            content_type=ct,
            user=self.user_granted,
            object_id=journal.id,
            authorization_codename=AC.can_manage_authorizations.codename)

        plan = JournalManagementPlanFactory.create(max_accounts=10)
        JournalManagementSubscriptionFactory.create(journal=journal, plan=plan)

        self.client.login(username=self.user_granted.username, password="******")

        url = reverse('userspace:journal:authorization:list',
                      args=(journal.pk, ))

        # Run
        response = self.client.get(
            url, {'codename': AC.can_manage_authorizations.codename})

        # Check
        self.assertEqual(response.status_code, 200)
        self.assertTrue(AC.can_manage_individual_subscription.codename in
                        response.context['authorizations'])
Example #7
0
 def test_embeds_the_latest_journals_into_the_context(self):
     # Setup
     JournalFactory.create(collection=self.collection)
     url = reverse('public:home')
     # Run
     response = self.client.get(url)
     # Check
     self.assertEqual(response.status_code, 200)
Example #8
0
 def test_embeds_the_upcoming_journals_into_the_context(self):
     # Setup
     JournalFactory.create(collection=self.collection, upcoming=False)
     url = reverse('public:home')
     # Run
     response = self.client.get(url)
     # Check
     self.assertEqual(response.status_code, 200)
Example #9
0
    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]
Example #10
0
    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]
Example #11
0
 def test_can_return_its_letter_prefix(self):
     # Setup
     journal_1 = JournalFactory.create(
         name='Test', collection=self.collection, publishers=[self.publisher])
     journal_2 = JournalFactory.create(
         name=None, collection=self.collection, publishers=[self.publisher])
     # Run & check
     self.assertEqual(journal_1.letter_prefix, 'T')
     self.assertIsNone(journal_2.letter_prefix)
Example #12
0
    def test_knows_if_a_user_cannot_manage_authorizations(self):
        user = UserFactory()
        journal = JournalFactory(collection=self.collection)
        is_granted = user.has_perm('authorization.manage_authorizations', journal)
        self.assertEqual(is_granted, False)

        journal.members.add(user)
        journal.save()
        is_granted = user.has_perm('authorization.manage_authorizations', journal)
        self.assertEqual(is_granted, False)
Example #13
0
 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, ]
Example #14
0
 def test_can_filter_the_journals_by_collections(self):
     # Setup
     col_1 = CollectionFactory(code='col1')
     col_2 = CollectionFactory(code='col2')
     JournalFactory.create(collection=col_1)
     journal_2 = JournalFactory.create(collection=col_2)
     url = reverse('public:journal:journal_list')
     # Run
     response = self.client.get(url, data={'collections': ['col2', ]})
     # Check
     assert list(response.context['journals']) == [journal_2, ]
Example #15
0
 def test_knows_that_it_is_in_open_access_if_its_issue_is_in_open_access(self):
     # Setup
     j1 = JournalFactory.create(open_access=True)
     j2 = JournalFactory.create(open_access=False)
     issue_1 = IssueFactory.create(journal=j1)
     article_1 = ArticleFactory.create(issue=issue_1)
     issue_2 = IssueFactory.create(journal=j2)
     article_2 = ArticleFactory.create(issue=issue_2)
     # Run 1 check
     self.assertTrue(article_1.open_access)
     self.assertFalse(article_2.open_access)
Example #16
0
    def test_knows_if_a_user_cannot_manage_authorizations(self):
        user = UserFactory()
        journal = JournalFactory(collection=self.collection)
        is_granted = user.has_perm('authorization.manage_authorizations',
                                   journal)
        self.assertEqual(is_granted, False)

        journal.members.add(user)
        journal.save()
        is_granted = user.has_perm('authorization.manage_authorizations',
                                   journal)
        self.assertEqual(is_granted, False)
Example #17
0
 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, ]
Example #18
0
 def test_returns_only_the_internal_journals(self):
     # Setup
     journal_1 = JournalFactory.create(
         collection=self.collection,
         external_url='http://example.com',
         redirect_to_external_url=True
     )
     JournalFactory.create(collection=self.collection)
     # Run
     journals = Journal.internal_objects.all()
     # Check
     self.assertTrue(journal_1 not in journals)
Example #19
0
 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,
     ]
Example #20
0
 def test_knows_if_a_user_can_manage_authorizations(self):
     user = UserFactory()
     journal = JournalFactory(collection=self.collection)
     journal.members.add(user)
     journal.save()
     ct = ContentType.objects.get(app_label="erudit", model="journal")
     Authorization.objects.create(
         content_type=ct,
         user=user,
         object_id=journal.id,
         authorization_codename=AC.can_manage_authorizations.codename)
     is_granted = user.has_perm('authorization.manage_authorizations', journal)
     self.assertEqual(is_granted, True)
Example #21
0
    def test_permission_list_restricted(self):
        journal = JournalFactory(collection=self.collection)
        journal.members.add(self.user_granted)
        journal.save()

        self.client.login(username=self.user_non_granted.username,
                          password="******")
        url = reverse('userspace:journal:authorization:list', args=(journal.pk, ))

        response = self.client.get(url)
        self.assertEqual(response.status_code, 403)

        response = self.client.get(url)
        self.assertEqual(response.status_code, 403)
Example #22
0
 def test_knows_if_a_user_can_manage_authorizations(self):
     user = UserFactory()
     journal = JournalFactory(collection=self.collection)
     journal.members.add(user)
     journal.save()
     ct = ContentType.objects.get(app_label="erudit", model="journal")
     Authorization.objects.create(
         content_type=ct,
         user=user,
         object_id=journal.id,
         authorization_codename=AC.can_manage_authorizations.codename)
     is_granted = user.has_perm('authorization.manage_authorizations',
                                journal)
     self.assertEqual(is_granted, True)
Example #23
0
    def test_permission_list_restricted(self):
        journal = JournalFactory(collection=self.collection)
        journal.members.add(self.user_granted)
        journal.save()

        self.client.login(username=self.user_non_granted.username,
                          password="******")
        url = reverse('userspace:journal:authorization:list',
                      args=(journal.pk, ))

        response = self.client.get(url)
        self.assertEqual(response.status_code, 403)

        response = self.client.get(url)
        self.assertEqual(response.status_code, 403)
Example #24
0
 def test_can_filter_the_journals_by_collections(self):
     # Setup
     col_1 = CollectionFactory(code='col1')
     col_2 = CollectionFactory(code='col2')
     JournalFactory.create_with_issue(collection=col_1)
     journal_2 = JournalFactory.create_with_issue(collection=col_2)
     url = reverse('public:journal:journal_list')
     # Run
     response = self.client.get(url, data={'collections': [
         'col2',
     ]})
     # Check
     assert list(response.context['journals']) == [
         journal_2,
     ]
Example #25
0
 def test_can_return_a_journal_using_its_localidentifier_or_its_code(self):
     # Setup
     journal = JournalFactory.create(
         collection=self.collection, localidentifier='foobar42', code='foobar')
     # Run & check
     self.assertEqual(Journal.legacy_objects.get_by_id('foobar'), journal)
     self.assertEqual(Journal.legacy_objects.get_by_id('foobar42'), journal)
Example #26
0
    def test_provides_only_subscriptions_associated_with_the_current_journal(self):
        # Setup
        AuthorizationFactory.create(
            content_type=ContentType.objects.get_for_model(self.journal),
            object_id=self.journal.id,
            user=self.user,
            authorization_codename=AC.can_manage_individual_subscription.codename,
        )

        plan = JournalManagementPlanFactory.create(max_accounts=10)
        JournalManagementSubscriptionFactory.create(journal=self.journal, plan=plan)

        other_journal = JournalFactory.create(collection=self.collection)
        subscription_1 = JournalAccessSubscriptionFactory.create(user=self.user, journal=self.journal)
        JournalAccessSubscriptionFactory.create(user=self.user, journal=other_journal)

        self.client.login(username="******", password="******")
        url = reverse("userspace:journal:subscription:list", kwargs={"journal_pk": self.journal.pk})

        # Run
        response = self.client.get(url)

        # Check
        self.assertEqual(response.status_code, 200)
        self.assertEqual(list(response.context["subscriptions"]), [subscription_1])
Example #27
0
 def test_can_redirect_to_journal_external_url(self):
     journal = JournalFactory(code='journal1',
                              external_url='http://www.erudit.org')
     response = self.client.get(
         reverse('public:journal:journal_external_redirect',
                 kwargs={'code': journal.code}))
     assert response.status_code == 302
Example #28
0
 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,
     ])
Example #29
0
    def test_can_return_all_the_journals_if_the_user_is_a_member_of_a_production_team(
            self):
        # Setup
        class MyView(JournalScopeMixin, TemplateView):
            allow_production_team_access = True
            template_name = 'dummy.html'

        user = UserFactory.create()
        group = GroupFactory.create(name='Production team')
        ProductionTeamFactory.create(group=group, identifier='main')
        user.groups.add(group)

        journal = JournalFactory.create(collection=self.collection)
        url = reverse('userspace:journal:information:update',
                      kwargs={'journal_pk': journal.pk})
        request = self.get_request(url)
        request.user = user
        my_view = MyView()
        my_view.request = request

        # Run & check
        journals = my_view.get_user_journals()
        assert journals
        assert list(journals) == list(
            Journal.objects.filter(collection__code='erudit'))
Example #30
0
    def test_provides_only_subscriptions_associated_with_the_current_journal(
            self):
        # Setup
        AuthorizationFactory.create(
            content_type=ContentType.objects.get_for_model(self.journal),
            object_id=self.journal.id,
            user=self.user,
            authorization_codename=AC.can_manage_individual_subscription.
            codename)

        plan = JournalManagementPlanFactory.create(max_accounts=10)
        JournalManagementSubscriptionFactory.create(journal=self.journal,
                                                    plan=plan)

        other_journal = JournalFactory.create(collection=self.collection)
        subscription_1 = JournalAccessSubscriptionFactory.create(
            user=self.user, journal=self.journal)
        JournalAccessSubscriptionFactory.create(user=self.user,
                                                journal=other_journal)

        self.client.login(username='******', password='******')
        url = reverse('userspace:journal:subscription:list',
                      kwargs={
                          'journal_pk': self.journal.pk,
                      })

        # Run
        response = self.client.get(url)

        # Check
        self.assertEqual(response.status_code, 200)
        self.assertEqual(list(response.context['subscriptions']), [
            subscription_1,
        ])
Example #31
0
    def test_user_can_manage(self):
        journal = JournalFactory(collection=self.collection)
        user = UserFactory()
        journal.members.add(user)
        journal.save()
        ct = ContentType.objects.get(app_label="erudit", model="journal")
        Authorization.objects.create(
            content_type=ct,
            user=user,
            object_id=journal.id,
            authorization_codename=AC.can_manage_issuesubmission.codename)
        issue = IssueSubmissionFactory(journal=journal)

        is_granted = user.has_perm('editor.manage_issuesubmission',
                                   issue.journal)
        self.assertEqual(is_granted, True)
Example #32
0
 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)
Example #33
0
    def test_user_can_manage(self):
        journal = JournalFactory(collection=self.collection)
        user = UserFactory()
        journal.members.add(user)
        journal.save()
        ct = ContentType.objects.get(app_label="erudit", model="journal")
        Authorization.objects.create(
            content_type=ct,
            user=user,
            object_id=journal.id,
            authorization_codename=AC.can_manage_issuesubmission.codename)
        issue = IssueSubmissionFactory(journal=journal)

        is_granted = user.has_perm('editor.manage_issuesubmission',
                                   issue.journal)
        self.assertEqual(is_granted, True)
Example #34
0
 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,
     ]
Example #35
0
    def test_permission_list_granted(self):
        journal = JournalFactory(collection=self.collection)
        journal.members.add(self.user_granted)
        journal.save()

        ct = ContentType.objects.get(app_label="erudit", model="journal")
        Authorization.objects.create(
            content_type=ct,
            user=self.user_granted,
            object_id=journal.id,
            authorization_codename=AC.can_manage_authorizations.codename)

        self.client.login(username=self.user_granted.username, password="******")
        url = reverse('userspace:journal:authorization:list',
                      args=(journal.pk, ))
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
Example #36
0
    def test_issuesubmission_add_granted(self):
        journal = JournalFactory(collection=self.collection)
        journal.save()
        journal.members.add(self.user_granted)

        self.client.login(username=self.user_granted.username,
                          password="******")
        url = reverse('userspace:journal:editor:add', kwargs={'journal_pk': journal.pk})
        response = self.client.get(url)
        self.assertEqual(response.status_code, 403)

        ct = ContentType.objects.get(app_label="erudit", model="journal")
        Authorization.objects.create(
            content_type=ct,
            user=self.user_granted,
            object_id=journal.id,
            authorization_codename=AC.can_manage_issuesubmission.codename)
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
Example #37
0
 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)
Example #38
0
    def test_issuesubmission_add_granted(self):
        journal = JournalFactory(collection=self.collection)
        journal.save()
        journal.members.add(self.user_granted)

        self.client.login(username=self.user_granted.username, password="******")
        url = reverse('userspace:journal:editor:add',
                      kwargs={'journal_pk': journal.pk})
        response = self.client.get(url)
        self.assertEqual(response.status_code, 403)

        ct = ContentType.objects.get(app_label="erudit", model="journal")
        Authorization.objects.create(
            content_type=ct,
            user=self.user_granted,
            object_id=journal.id,
            authorization_codename=AC.can_manage_issuesubmission.codename)
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
Example #39
0
 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, ])
Example #40
0
    def test_returns_an_http_404_error_if_the_codename_is_not_known(self):
        # Setup
        journal = JournalFactory(collection=self.collection)
        journal.members.add(self.user_granted)
        journal.save()

        ct = ContentType.objects.get(app_label="erudit", model="journal")
        Authorization.objects.create(
            content_type=ct,
            user=self.user_granted,
            object_id=journal.id,
            authorization_codename=AC.can_manage_authorizations.codename)

        self.client.login(username=self.user_granted.username,
                          password="******")

        url = reverse('userspace:journal:authorization:create', args=(journal.pk, ))

        # Run
        response = self.client.get(url, {'codename': 'dummy'})

        # Check
        self.assertEqual(response.status_code, 404)
Example #41
0
 def test_can_resolve_the_current_url_for_another_journal(self):
     # Setup
     journal_2 = JournalFactory.create(collection=self.collection, publishers=[self.publisher])
     factory = RequestFactory()
     base_url = reverse(
         'userspace:journal:information:update', kwargs={'journal_pk': self.journal.pk})
     request = factory.get(base_url)
     request.resolver_match = resolve(base_url)
     # Run
     url = journal_url({'request': request}, journal_2)
     # Check
     self.assertEqual(
         url,
         reverse('userspace:journal:information:update', kwargs={'journal_pk': journal_2.pk}))
Example #42
0
    def test_upcoming_journals_are_hidden_from_list(self):

        # Create 6 journals
        journals = JournalFactory.create_batch(6)

        # Create an issue for the first 5 journals
        for journal in journals[:5]:
            IssueFactory(journal=journal)

        url = reverse('public:journal:journal_list')
        # Run
        response = self.client.get(url)
        displayed_journals = set(response.context['journals'])
        assert displayed_journals == set(journals[:5])
        assert journals[5] not in displayed_journals
Example #43
0
 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)
Example #44
0
    def test_returns_a_403_error_if_no_journal_can_be_associated_with_the_current_user(self):
        # Setup
        class MyView(JournalScopeMixin, TemplateView):
            template_name = "dummy.html"

        user = UserFactory.create()
        journal = JournalFactory.create(collection=self.collection)
        url = reverse("userspace:journal:information:update", kwargs={"journal_pk": journal.pk})
        request = self.get_request(url)
        request.user = user
        my_view = MyView.as_view()

        # Run & check
        with self.assertRaises(PermissionDenied):
            my_view(request, journal_pk=self.journal.pk)
Example #45
0
    def test_contact_filter(self):
        user = UserFactory()
        user2 = UserFactory()

        journal_in = JournalFactory(collection=self.collection)
        journal_in.members.add(user)
        journal_in.save()

        journal_not_in = JournalFactory(collection=self.collection)
        journal_not_in.members.add(user2)
        journal_not_in.save()

        data = {'user': user, 'journal': journal_in}

        form = IssueSubmissionForm(**data)
        choices = [c[0] for c in form.fields['contact'].choices]
        self.assertTrue(user.id in choices)
        self.assertFalse(user2.id in choices)
Example #46
0
 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,
                ])
Example #47
0
    def test_returns_a_403_error_if_no_journal_can_be_associated_with_the_current_user(
            self):
        # Setup
        class MyView(JournalScopeMixin, TemplateView):
            template_name = 'dummy.html'

        user = UserFactory.create()
        journal = JournalFactory.create(collection=self.collection)
        url = reverse('userspace:journal:information:update',
                      kwargs={'journal_pk': journal.pk})
        request = self.get_request(url)
        request.user = user
        my_view = MyView.as_view()

        # Run & check
        with self.assertRaises(PermissionDenied):
            my_view(request, journal_pk=self.journal.pk)
Example #48
0
 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)
Example #49
0
    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)
Example #50
0
    def test_can_return_articles_written_for_a_given_journal(self):
        # Setup
        other_journal = JournalFactory.create(
            publishers=[self.publisher])
        other_issue = IssueFactory.create(
            journal=other_journal, date_published=dt.datetime.now())
        other_article = ArticleFactory.create(issue=other_issue)

        issue = IssueFactory.create(
            journal=self.journal, date_published=dt.datetime.now())
        article = ArticleFactory.create(issue=issue)

        author = AuthorFactory.create()

        article.authors.add(author)
        other_article.authors.add(author)

        # Run
        self.assertEqual(list(author.articles_in_journal(self.journal)), [article, ])
Example #51
0
    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)
Example #52
0
    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
Example #53
0
 def test_knows_that_issues_with_open_access_are_not_embargoed(self):
     # Setup
     now_dt = dt.datetime.now()
     j2 = JournalFactory.create(open_access=False)
     self.journal.last_publication_year = now_dt.year
     self.journal.open_access = True
     self.journal.type = JournalTypeFactory.create(code='C')
     self.journal.save()
     issue_1 = IssueFactory.create(
         journal=self.journal, year=now_dt.year - 1,
         date_published=dt.date(now_dt.year - 1, 3, 20))
     issue_2 = IssueFactory.create(
         journal=self.journal, year=now_dt.year - 2,
         date_published=dt.date(now_dt.year - 2, 3, 20))
     issue_3 = IssueFactory.create(
         journal=j2, year=now_dt.year,
         date_published=dt.date(now_dt.year, 3, 20))
     # Run & check
     self.assertFalse(issue_1.embargoed)
     self.assertFalse(issue_2.embargoed)
     self.assertFalse(issue_3.embargoed)
Example #54
0
    def test_can_return_all_the_journals_if_the_user_is_a_member_of_a_production_team(self):
        # Setup
        class MyView(JournalScopeMixin, TemplateView):
            allow_production_team_access = True
            template_name = "dummy.html"

        user = UserFactory.create()
        group = GroupFactory.create(name="Production team")
        ProductionTeamFactory.create(group=group, identifier="main")
        user.groups.add(group)

        journal = JournalFactory.create(collection=self.collection)
        url = reverse("userspace:journal:information:update", kwargs={"journal_pk": journal.pk})
        request = self.get_request(url)
        request.user = user
        my_view = MyView()
        my_view.request = request

        # Run & check
        journals = my_view.get_user_journals()
        assert journals
        assert list(journals) == list(Journal.objects.filter(collection__code="erudit"))
Example #55
0
 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)
Example #56
0
 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,
     ]
Example #57
0
 def test_knows_that_a_staff_member_can_manage_authorizations(self):
     user = UserFactory(is_staff=True)
     journal = JournalFactory(collection=self.collection)
     is_granted = user.has_perm('authorization.manage_authorizations',
                                journal)
     self.assertEqual(is_granted, True)