Example #1
0
    def test_permission_delete_restricted(self):
        self.client.login(username=self.user_non_granted.username,
                          password="******")

        journal = JournalFactory()
        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 #2
0
 def test_returns_only_the_upcoming_journals(self):
     # Setup
     journal_1 = JournalFactory.create(upcoming=True)
     JournalFactory.create(upcoming=False)
     # Run
     journals = Journal.upcoming_objects.all()
     # Check
     self.assertEqual(list(journals), [journal_1, ])
Example #3
0
    def test_user_cant_manage(self):
        user = UserFactory()
        journal = JournalFactory()
        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 #4
0
 def test_embeds_the_upcoming_journals_into_the_context(self):
     # Setup
     journal_1 = JournalFactory.create(upcoming=True)
     JournalFactory.create(upcoming=False)
     url = reverse('public:home')
     # Run
     response = self.client.get(url)
     # Check
     self.assertEqual(response.status_code, 200)
     self.assertEqual(list(response.context['upcoming_journals']), [journal_1, ])
Example #5
0
 def test_includes_only_journals_that_can_be_edited_by_the_current_user(self):
     # Setup
     for _ in range(6):
         JournalFactory.create(publishers=[self.publisher])
     self.client.login(username='******', password='******')
     url = reverse('userspace:journal:journal-information-list')
     # Run
     response = self.client.get(url)
     # Check
     self.assertEqual(response.status_code, 200)
     self.assertEqual(list(response.context['journals']), [self.journal, ])
Example #6
0
 def test_user_can_manage(self):
     user = UserFactory()
     journal = JournalFactory()
     journal.members.add(user)
     journal.save()
     ct = ContentType.objects.get(app_label="erudit", model="journal")
     Rule.objects.create(content_type=ct,
                         user=user,
                         object_id=journal.id,
                         permission="userspace.manage_permissions")
     is_granted = user.has_perm('userspace.manage_permissions', journal)
     self.assertEqual(is_granted, True)
Example #7
0
    def test_permission_create_restricted(self):
        self.client.login(username=self.user_non_granted.username,
                          password="******")
        url = reverse('userspace:permissions:perm_create')

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

        journal = JournalFactory()
        journal.members.add(self.user_granted)
        journal.save()
        response = self.client.get(url)
        self.assertEqual(response.status_code, 302)
Example #8
0
 def test_user_can_manage(self):
     user = UserFactory()
     journal = JournalFactory()
     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 #9
0
    def test_journal_filter(self):
        user = UserFactory()
        data = {'user': user}

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

        journal_not_in = JournalFactory()
        form = AuthorizationForm(**data)
        choices = [c[0] for c in form.fields['journal'].choices]
        self.assertTrue(journal_in.id in choices)
        self.assertFalse(journal_not_in.id in choices)
Example #10
0
    def test_permission_create_restricted(self):
        journal = JournalFactory()
        journal.members.add(self.user_granted)
        journal.save()

        self.client.login(username=self.user_non_granted.username,
                          password="******")
        url = reverse('userspace:journal:authorization:create', 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 #11
0
    def test_user_can_manage(self):
        journal = JournalFactory()
        user = UserFactory()
        journal.members.add(user)
        journal.save()
        ct = ContentType.objects.get(app_label="erudit", model="journal")
        Rule.objects.create(content_type=ct,
                            user=user,
                            object_id=journal.id,
                            permission="editor.manage_issuesubmission")
        issue = IssueSubmissionFactory(journal=journal)

        is_granted = user.has_perm('editor.manage_issuesubmission',
                                   issue.journal)
        self.assertEqual(is_granted, True)
Example #12
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 #13
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()
        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 #14
0
    def test_permission_create_granted(self):
        journal = JournalFactory()
        journal.members.add(self.user_granted)
        journal.save()

        ct = ContentType.objects.get(app_label="erudit", model="journal")
        Rule.objects.create(content_type=ct,
                            user=self.user_granted,
                            object_id=journal.id,
                            permission='userspace.manage_permissions')

        self.client.login(username=self.user_granted.username,
                          password="******")
        url = reverse('userspace:permissions:perm_create')
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
Example #15
0
    def test_menu_permission_presence(self):
        journal = JournalFactory()
        user = UserFactory(username="******")
        user.set_password("user")
        user.save()
        journal.members.add(user)
        journal.save()

        ct = ContentType.objects.get(app_label="erudit", model="journal")
        Rule.objects.create(content_type=ct,
                            user=user,
                            object_id=journal.id,
                            permission="userspace.manage_permissions")

        url = reverse('userspace:permissions:perm_list')
        self.client.login(username="******", password="******")
        response = self.client.get(reverse('userspace:dashboard'))
        self.assertContains(response, url)
Example #16
0
    def test_user_filter(self):
        user = UserFactory()
        data = {'user': user}

        user_in = UserFactory()
        user_not_in = UserFactory()
        journal_in = JournalFactory()
        journal_in.members.add(user)
        journal_in.members.add(user_in)
        journal_in.save()

        journal_not_in = JournalFactory()
        journal_not_in.members.add(user_not_in)
        form = RuleForm(**data)
        choices = [c[0] for c in form.fields['user'].choices]
        self.assertTrue(user.id in choices)
        self.assertTrue(user_in.id in choices)
        self.assertFalse(user_not_in.id in choices)
Example #17
0
    def test_issuesubmission_update_granted(self):
        journal = JournalFactory()
        journal.members.add(self.user_granted)
        journal.save()
        issue = IssueSubmissionFactory(journal=journal)

        self.client.login(username=self.user_granted.username,
                          password="******")
        url = reverse('userspace:editor:update', args=(issue.pk, ))
        response = self.client.get(url)
        self.assertEqual(response.status_code, 404)

        ct = ContentType.objects.get(app_label="erudit", model="journal")
        Rule.objects.create(content_type=ct,
                            user=self.user_granted,
                            object_id=journal.id,
                            permission="editor.manage_issuesubmission")
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
Example #18
0
    def test_cannot_create_journal_if_nonedinum_journal_exists(self):
        """ Cannot create a journal if a non edinum journal with the same shortname exists """
        publisher = PublisherFactory.create()

        journal = JournalFactory.create(code='testj', edinum_id="123", publishers=[publisher])

        journal = create_or_update_journal(
            publisher, "123", "test", "testj", "", "", None
        )

        self.assertIsNone(journal)
Example #19
0
    def test_journal_contact_invalid(self):
        user = UserFactory()
        user2 = UserFactory()
        data = {'user': user}

        journal_in1 = JournalFactory()
        journal_in1.members.add(user)
        journal_in1.save()
        self.authorize_user_on_journal(user, journal_in1)

        journal_in2 = JournalFactory()
        journal_in2.members.add(user)
        journal_in2.members.add(user2)
        journal_in2.save()
        self.authorize_user_on_journal(user, journal_in2)

        form = IssueSubmissionForm(**data)
        choices = [c[0] for c in form.fields['contact'].choices]
        self.assertTrue(user.id in choices)
        self.assertTrue(user2.id in choices)

        data.update({'data': {
            'journal': journal_in1.id,
            'contact': user2.id,
            'year': '2016',
            'number': '123', }
        })
        form = IssueSubmissionForm(**data)
        self.assertFalse(form.is_valid())
Example #20
0
 def test_can_resolve_the_current_url_for_another_journal(self):
     # Setup
     journal_2 = JournalFactory.create(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 #21
0
    def setUp(self):

        self.factory = RequestFactory()

        self.user = User.objects.create_user(
            username='******',
            email='*****@*****.**',
            password='******'
        )

        self.other_user = User.objects.create_user(
            username='******',
            email='*****@*****.**',
            password='******'
        )

        self.publisher = Publisher.objects.create(
            name='Éditeur de test',
        )

        self.other_publisher = Publisher.objects.create(
            name='Autre éditeur de test',
        )

        erudit = Collection(code="erudit", name="Érudit")
        erudit.save()

        # Add a journal with a member
        self.journal = JournalFactory.create(publishers=[self.publisher])
        self.journal.members.add(self.user)
        self.journal.collection = erudit
        self.journal.save()

        # Add a second journal with another member
        self.other_journal = JournalFactory.create(publishers=[self.other_publisher])
        self.other_journal.members.add(self.other_user)
        self.other_journal.save()
Example #22
0
 def test_can_embed_the_latest_issue_in_the_context(self):
     # Setup
     collection = CollectionFactory.create()
     journal = JournalFactory.create(collection=collection)
     JournalInformationFactory.create(journal=journal)
     IssueFactory.create(
         journal=journal, date_published=dt.datetime.now() - dt.timedelta(days=1))
     issue_2 = IssueFactory.create(journal=journal, date_published=dt.datetime.now())
     IssueFactory.create(journal=journal, date_published=None)
     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 #23
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()
        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 #24
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 #25
0
    def test_contact_filter(self):
        user = UserFactory()
        user2 = UserFactory()
        data = {'user': user}

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

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

        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)