Exemplo n.º 1
0
 def test_can_return_its_published_issues(self):
     # Setup
     issue_1 = IssueFactory.create(
         journal=self.journal, date_published=dt.datetime.now() - dt.timedelta(days=1))
     issue_2 = IssueFactory.create(journal=self.journal, date_published=dt.datetime.now())
     IssueFactory.create(journal=self.journal, date_published=None)
     # Run & check
     self.assertEqual(set(self.journal.published_issues), {issue_1, issue_2})
Exemplo n.º 2
0
 def test_can_return_its_last_issue(self):
     # Setup
     IssueFactory.create(
         journal=self.journal, date_published=dt.datetime.now() - dt.timedelta(days=1))
     issue_2 = IssueFactory.create(journal=self.journal, date_published=dt.datetime.now())
     IssueFactory.create(journal=self.journal, date_published=None)
     # Run & check
     self.assertEqual(self.journal.last_issue, issue_2)
Exemplo n.º 3
0
 def test_knows_that_it_is_in_open_access_if_its_issue_is_in_open_access(self):
     # Setup
     issue_1 = IssueFactory.create(journal=self.journal, open_access=True)
     article_1 = ArticleFactory.create(issue=issue_1)
     issue_2 = IssueFactory.create(journal=self.journal, open_access=False)
     article_2 = ArticleFactory.create(issue=issue_2)
     # Run 1 check
     self.assertTrue(article_1.open_access)
     self.assertFalse(article_2.open_access)
Exemplo n.º 4
0
 def test_embeds_the_latest_issues_into_the_context(self):
     # Setup
     issue_1 = IssueFactory.create(
         journal=self.journal, date_published=dt.datetime.now() - dt.timedelta(days=1))
     issue_2 = IssueFactory.create(journal=self.journal, date_published=dt.datetime.now())
     url = reverse('public:home')
     # Run
     response = self.client.get(url)
     # Check
     self.assertEqual(response.status_code, 200)
     self.assertEqual(list(response.context['latest_issues']), [issue_2, issue_1, ])
Exemplo n.º 5
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)
Exemplo n.º 6
0
    def test_can_grant_access_to_an_article_if_it_is_associatd_to_an_institutional_account(self):
        # Setup
        issue = IssueFactory.create(
            journal=self.journal, date_published=dt.datetime.now(), localidentifier='test',
            open_access=True)
        article = ArticleFactory.create(issue=issue)

        policy = PolicyFactory.create(max_accounts=2)
        policy.access_journal.add(self.journal)
        organisation = OrganisationFactory.create()
        institutional_account = InstitutionalAccountFactory(
            institution=organisation, policy=policy)
        InstitutionIPAddressRangeFactory.build(
            institutional_account=institutional_account,
            ip_start='192.168.1.2', ip_end='192.168.1.4')

        class MyView(ArticleAccessCheckMixin):
            def get_article(self):
                return article

        request = self.factory.get('/')
        parameters = request.META.copy()
        parameters['HTTP_X_FORWARDED_FOR'] = '192.168.1.3'
        request.META = parameters

        view = MyView()
        view.request = request

        # Run # check
        self.assertTrue(view.has_access())
Exemplo n.º 7
0
    def test_inserts_the_current_letter_in_the_context(self):
        # Setup
        issue_1 = IssueFactory.create(journal=self.journal, date_published=dt.datetime.now())
        article_1 = ArticleFactory.create(issue=issue_1)

        author_1 = AuthorFactory.create(lastname='btest')
        author_2 = AuthorFactory.create(lastname='ctest1')
        author_3 = AuthorFactory.create(lastname='ctest2')

        article_1.authors.add(author_1)
        article_1.authors.add(author_2)
        article_1.authors.add(author_3)
        url = reverse('public:journal:journal-authors-list', kwargs={'code': self.journal.code})

        # Run
        response_1 = self.client.get(url)
        response_2 = self.client.get(url, {'letter': 'c'})
        response_3 = self.client.get(url, {'letter': 'invalid'})

        # Check
        self.assertEqual(response_1.status_code, 200)
        self.assertEqual(response_2.status_code, 200)
        self.assertEqual(response_3.status_code, 200)
        self.assertEqual(response_1.context['letter'], 'b')
        self.assertEqual(response_2.context['letter'], 'c')
        self.assertEqual(response_3.context['letter'], 'b')
Exemplo n.º 8
0
    def test_can_grant_access_to_an_article_if_it_is_associated_to_an_institutional_account(self):
        # Setup
        issue = IssueFactory.create(
            journal=self.journal, date_published=dt.datetime.now(), localidentifier='test',
            open_access=False)
        article = ArticleFactory.create(issue=issue)

        organisation = OrganisationFactory.create()
        subscription = JournalAccessSubscriptionFactory.create(
            journal=self.journal, organisation=organisation)
        InstitutionIPAddressRangeFactory.create(
            subscription=subscription,
            ip_start='192.168.1.2', ip_end='192.168.1.4')

        class MyView(ArticleAccessCheckMixin):
            def get_article(self):
                return article

        request = self.factory.get('/')
        request.user = AnonymousUser()
        parameters = request.META.copy()
        parameters['HTTP_X_FORWARDED_FOR'] = '192.168.1.3'
        request.META = parameters

        view = MyView()
        view.request = request

        # Run # check
        self.assertTrue(view.has_access())
Exemplo n.º 9
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, ])
Exemplo n.º 10
0
 def test_works_with_pks(self):
     # Setup
     issue = IssueFactory.create(journal=self.journal, date_published=dt.datetime.now())
     url = reverse('public:journal:issue-detail', kwargs={
         'journal_code': self.journal.code, 'pk': issue.pk})
     # Run
     response = self.client.get(url)
     # Check
     self.assertEqual(response.status_code, 200)
Exemplo n.º 11
0
 def test_can_return_its_last_issue_with_open_access(self):
     # Setup
     IssueFactory.create(
         journal=self.journal, date_published=dt.datetime.now() - dt.timedelta(days=2))
     issue_2 = IssueFactory.create(
         journal=self.journal, date_published=dt.datetime.now() - dt.timedelta(days=1),
         open_access=True)
     IssueFactory.create(
         journal=self.journal, date_published=dt.datetime.now(), open_access=False)
     IssueFactory.create(journal=self.journal, date_published=None, open_access=True)
     # Run & check
     self.assertEqual(self.journal.last_oa_issue, issue_2)
Exemplo n.º 12
0
 def test_works_with_pks(self):
     # Setup
     issue = IssueFactory.create(
         journal=self.journal, date_published=dt.datetime.now(), open_access=True)
     article = ArticleFactory.create(issue=issue)
     url = reverse('public:journal:article-detail', kwargs={
         'journal_code': self.journal.code, 'issue_localid': issue.localidentifier,
         'pk': article.pk})
     request = self.factory.get(url)
     # Run
     response = ArticleDetailView.as_view()(
         request, localid=article.localidentifier)
     # Check
     self.assertEqual(response.status_code, 200)
Exemplo n.º 13
0
    def test_can_grant_access_to_an_article_if_it_is_in_open_access(self):
        # Setup
        issue = IssueFactory.create(
            journal=self.journal, date_published=dt.datetime.now(), localidentifier='test',
            open_access=True)
        article = ArticleFactory.create(issue=issue)

        class MyView(ArticleAccessCheckMixin):
            def get_article(self):
                return article

        view = MyView()

        # Run # check
        self.assertTrue(view.has_access())
Exemplo n.º 14
0
 def test_can_transform_article_xml_to_html(self, mock_ds, mock_xsd300):
     # Setup
     with open(FIXTURE_ROOT + '/article.xml', mode='r') as fp:
         xml = fp.read()
     mock_ds.return_value = ['ERUDITXSD300', ]  # noqa
     mock_xsd300.content = unittest.mock.MagicMock()
     mock_xsd300.content.serialize = unittest.mock.MagicMock(return_value=xml)
     issue = IssueFactory.create(
         journal=self.journal, date_published=dt.datetime.now(), localidentifier='test')
     article = ArticleFactory.create(issue=issue)
     # Run
     ret = render_article(Context({}), article)
     # Check
     self.assertTrue(ret is not None)
     self.assertTrue(ret.startswith('<div class="article-wrapper">'))
Exemplo n.º 15
0
    def test_do_not_grant_access_by_default(self):
        # Setup
        issue = IssueFactory.create(
            journal=self.journal, date_published=dt.datetime.now(), localidentifier='test',
            open_access=False)
        article = ArticleFactory.create(issue=issue)

        class MyView(ArticleAccessCheckMixin):
            def get_article(self):
                return article

        request = self.factory.get('/')

        view = MyView()
        view.request = request

        # Run # check
        self.assertFalse(view.has_access())
Exemplo n.º 16
0
    def test_can_grant_access_to_an_article_if_it_is_associated_to_an_individual_subscription(self):
        # Setup
        issue = IssueFactory.create(
            journal=self.journal, date_published=dt.datetime.now(), localidentifier='test',
            open_access=False)
        article = ArticleFactory.create(issue=issue)

        JournalAccessSubscriptionFactory.create(user=self.user, journal=self.journal)

        class MyView(ArticleAccessCheckMixin):
            def get_article(self):
                return article

        request = self.factory.get('/')
        request.user = self.user
        view = MyView()
        view.request = request

        # Run # check
        self.assertTrue(view.has_access())
Exemplo n.º 17
0
    def test_provides_only_authors_for_the_first_available_letter_by_default(self):
        # Setup
        issue_1 = IssueFactory.create(journal=self.journal, date_published=dt.datetime.now())
        article_1 = ArticleFactory.create(issue=issue_1)

        author_1 = AuthorFactory.create(lastname='btest')
        author_2 = AuthorFactory.create(lastname='ctest1')
        author_3 = AuthorFactory.create(lastname='ctest2')

        article_1.authors.add(author_1)
        article_1.authors.add(author_2)
        article_1.authors.add(author_3)
        url = reverse('public:journal:journal-authors-list', kwargs={'code': self.journal.code})

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

        # Check
        self.assertEqual(response.status_code, 200)
        self.assertEqual(list(response.context['authors']), [author_1, ])
Exemplo n.º 18
0
    def test_inserts_a_flag_into_the_context(self):
        # Setup
        issue = IssueFactory.create(
            journal=self.journal, date_published=dt.datetime.now(), localidentifier='test',
            open_access=True)
        article = ArticleFactory.create(issue=issue)

        class MyViewAncestor(object):
            def get_context_data(self, **kwargs):
                return {}

        class MyView(ArticleAccessCheckMixin, MyViewAncestor):
            def get_article(self):
                return article

        view = MyView()

        # Run # check
        self.assertTrue(view.has_access())
        self.assertTrue(view.get_context_data()['article_access_granted'])
Exemplo n.º 19
0
    def test_can_retrieve_the_pdf_of_existing_articles(self, mock_ds, mock_pdf):
        # Setup
        with open(os.path.join(FIXTURE_ROOT, 'dummy.pdf'), 'rb') as f:
            mock_pdf.content = io.BytesIO()
            mock_pdf.content.write(f.read())
        mock_ds = ['ERUDITXSD300', ]  # noqa

        issue = IssueFactory.create(journal=self.journal, date_published=dt.datetime.now())
        article = ArticleFactory.create(issue=issue)
        journal_id = self.journal.localidentifier
        issue_id = issue.localidentifier
        article_id = article.localidentifier
        url = reverse('public:journal:article-raw-pdf', args=(
            journal_id, issue_id, article_id
        ))
        request = self.factory.get(url)

        # Run
        response = ArticleRawPdfView.as_view()(
            request, journalid=journal_id, issueid=issue_id, articleid=article_id)

        # Check
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['Content-Type'], 'application/pdf')
Exemplo n.º 20
0
    def test_inserts_a_dict_with_the_letters_counts_in_the_context(self):
        # Setup
        issue_1 = IssueFactory.create(journal=self.journal, date_published=dt.datetime.now())
        article_1 = ArticleFactory.create(issue=issue_1)

        author_1 = AuthorFactory.create(lastname='btest')
        author_2 = AuthorFactory.create(lastname='ctest1')
        author_3 = AuthorFactory.create(lastname='ctest2')

        article_1.authors.add(author_1)
        article_1.authors.add(author_2)
        article_1.authors.add(author_3)
        url = reverse('public:journal:journal-authors-list', kwargs={'code': self.journal.code})

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

        # Check
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.context['letters_counts']), 26)
        self.assertEqual(response.context['letters_counts']['b'], 1)
        self.assertEqual(response.context['letters_counts']['c'], 2)
        for letter in 'adefghijklmnopqrstuvwxyz':
            self.assertEqual(response.context['letters_counts'][letter], 0)
Exemplo n.º 21
0
 def setUp(self):
     super(TestIssue, self).setUp()
     self.issue = IssueFactory.create(journal=self.journal)
Exemplo n.º 22
0
 def setUp(self):
     super(TestArticle, self).setUp()
     self.issue = IssueFactory.create(journal=self.journal)
     self.article = ArticleFactory.create(issue=self.issue)