예제 #1
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, ])
예제 #2
0
파일: tests.py 프로젝트: ebhoren/eruditorg
 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, ])
예제 #3
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, ])
예제 #4
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)
예제 #5
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, ])
예제 #6
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)
예제 #7
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}))
예제 #8
0
파일: base.py 프로젝트: ebhoren/eruditorg
    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()
예제 #9
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)
예제 #10
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)
예제 #11
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, ])