当前位置: 首页>>代码示例>>Python>>正文


Python factories.ArticleFactory类代码示例

本文整理汇总了Python中erudit.test.factories.ArticleFactory的典型用法代码示例。如果您正苦于以下问题:Python ArticleFactory类的具体用法?Python ArticleFactory怎么用?Python ArticleFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ArticleFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setup

 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)
开发者ID:savoirfairelinux,项目名称:eruditorg,代码行数:32,代码来源:test_views.py

示例2: test_can_return_all_the_articles_associated_with_the_last_issue_of_a_journal

 def test_can_return_all_the_articles_associated_with_the_last_issue_of_a_journal(self, mock_erudit_object):  # noqa
     # Setup
     mock_erudit_object.return_value = get_mocked_erudit_object()
     issue1 = IssueFactory.create(
         journal=self.journal, year=2010, date_published=dt.datetime.now())
     article1 = ArticleFactory.create(issue=issue1)
     article2 = ArticleFactory.create(issue=issue1)
     issue2 = IssueFactory.create(
         journal=self.journal, year=2010,
         date_published=dt.datetime.now() - dt.timedelta(days=2))
     ArticleFactory.create(issue=issue2)
     request = self.factory.get('/')
     # Run
     f = LatestJournalArticlesFeed()
     f.get_object(request, self.journal.code)
     feed = f.get_feed(None, request)
     # Check
     self.assertEqual(len(feed.items), 2)
     self.assertIn(
         reverse('public:journal:article_detail',
                 args=[
                     article1.issue.journal.code,
                     article1.issue.volume_slug,
                     article1.issue.localidentifier,
                     article1.localidentifier
                 ]), feed.items[0]['link'])
     self.assertIn(
         reverse('public:journal:article_detail',
                 args=[
                     article2.issue.journal.code,
                     article2.issue.volume_slug,
                     article2.issue.localidentifier,
                     article2.localidentifier
                 ]), feed.items[1]['link'])
开发者ID:erudit,项目名称:eruditorg,代码行数:34,代码来源:test_feeds.py

示例3: test_returns_only_the_internal_articles

 def test_returns_only_the_internal_articles(self):
     # Setup
     issue = IssueFactory.create(journal=self.journal, external_url=None)
     article_1 = ArticleFactory.create(issue=issue, external_url=None)
     article_2 = ArticleFactory.create(issue=issue, external_url='http://example.com')
     # Run
     articles = Article.internal_objects.all()
     # Check
     self.assertTrue(article_1 in articles)
     self.assertTrue(article_2 not in articles)
开发者ID:erudit,项目名称:erudit-core,代码行数:10,代码来源:test_managers.py

示例4: test_knows_that_it_is_in_open_access_if_its_issue_is_in_open_access

 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)
开发者ID:erudit,项目名称:erudit-core,代码行数:11,代码来源:test_models.py

示例5: test_can_add_new_articles

 def test_can_add_new_articles(self):
     # Setup
     issue = IssueFactory.create(journal=self.journal)
     article_1 = ArticleFactory.create(issue=issue)
     article_2 = ArticleFactory.create(issue=issue)
     request = self.factory.get('/')
     middleware = SessionMiddleware()
     middleware.process_request(request)
     citation_list = SavedCitationList(request)
     # Run
     citation_list.add(article_1)
     citation_list.add(article_2)
     # Check
     self.assertTrue(article_1 in citation_list)
     self.assertTrue(article_2.id in citation_list)
开发者ID:erudit,项目名称:eruditorg,代码行数:15,代码来源:test_citations.py

示例6: test_inserts_the_current_letter_in_the_context

    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')
开发者ID:erudit,项目名称:eruditorg,代码行数:26,代码来源:test_views.py

示例7: test_cannot_grant_access_to_an_article_if_it_is_associated_to_an_institutional_account_that_is_not_not_ongoing

    def test_cannot_grant_access_to_an_article_if_it_is_associated_to_an_institutional_account_that_is_not_not_ongoing(
        self
    ):  # noqa
        # Setup
        self.journal.open_access = False
        self.journal.save()
        issue = IssueFactory.create(
            journal=self.journal, year=dt.datetime.now().year, date_published=dt.datetime.now(), localidentifier="test"
        )
        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()
        # FIXME call middleware
        request.subscription = None
        parameters = request.META.copy()
        parameters["HTTP_X_FORWARDED_FOR"] = "192.168.1.3"
        request.META = parameters

        view = MyView()
        view.request = request

        # Run # check
        self.assertFalse(view.has_access())
开发者ID:erudit,项目名称:eruditorg,代码行数:34,代码来源:test_viewmixins.py

示例8: test_cannot_grant_access_to_an_article_if_it_is_associated_to_an_individual_subscription_that_is_not_ongoing

    def test_cannot_grant_access_to_an_article_if_it_is_associated_to_an_individual_subscription_that_is_not_ongoing(
        self
    ):  # noqa
        # Setup
        self.journal.open_access = False
        self.journal.save()
        issue = IssueFactory.create(
            journal=self.journal, year=dt.datetime.now().year, date_published=dt.datetime.now(), localidentifier="test"
        )
        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
        request.subscription = None
        view = MyView()
        view.request = request

        # Run # check
        self.assertFalse(view.has_access())
开发者ID:erudit,项目名称:eruditorg,代码行数:25,代码来源:test_viewmixins.py

示例9: test_can_grant_access_to_an_article_if_it_is_associated_to_an_individual_subscription

    def test_can_grant_access_to_an_article_if_it_is_associated_to_an_individual_subscription(self):
        # Setup
        self.journal.open_access = False
        self.journal.save()
        issue = IssueFactory.create(
            journal=self.journal, year=dt.datetime.now().year, date_published=dt.datetime.now(), localidentifier="test"
        )
        article = ArticleFactory.create(issue=issue)

        now_dt = dt.datetime.now()

        subscription = JournalAccessSubscriptionFactory.create(user=self.user, journal=self.journal)
        JournalAccessSubscriptionPeriodFactory.create(
            subscription=subscription, start=now_dt - dt.timedelta(days=10), end=now_dt + dt.timedelta(days=8)
        )

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

        request = self.factory.get("/")
        request.user = self.user
        view = MyView()
        view.request = request
        middleware.process_request(request)

        # Run # check
        self.assertTrue(view.has_access())
开发者ID:erudit,项目名称:eruditorg,代码行数:28,代码来源:test_viewmixins.py

示例10: test_can_grant_access_to_an_article_has_no_movable_limitation

    def test_can_grant_access_to_an_article_has_no_movable_limitation(self):
        # Setup
        now_dt = dt.datetime.now()

        self.journal.open_access = False
        self.journal.save()
        issue = IssueFactory.create(
            journal=self.journal,
            year=dt.datetime.now().year - 5,
            date_published=dt.date(now_dt.year - 5, 3, 20),
            localidentifier="test",
        )
        article = ArticleFactory.create(issue=issue)

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

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

        # Run # check
        self.assertTrue(view.has_access())
开发者ID:erudit,项目名称:eruditorg,代码行数:25,代码来源:test_viewmixins.py

示例11: test_can_retrieve_xml_of_existing_articles

    def test_can_retrieve_xml_of_existing_articles(self, mock_ds, mock_pdf):

        with open(os.path.join(FIXTURE_ROOT, '1023796ar.xml'), 'r') as f:
            from eulxml.xmlmap import load_xmlobject_from_file
            mock_pdf.content = load_xmlobject_from_file(f)
        mock_ds = ['ERUDITXSD300', ]  # noqa

        issue = IssueFactory.create(
            journal=self.journal, year=2010,
            date_published=dt.datetime.now() - dt.timedelta(days=1000))
        article = ArticleFactory.create(issue=issue)
        journal_id = self.journal.localidentifier
        issue_id = issue.localidentifier
        article_id = article.localidentifier
        url = reverse('public:journal:article_raw_xml', args=(
            journal_id, issue.volume_slug, issue_id, article_id
        ))
        request = self.factory.get(url)
        request.user = AnonymousUser()
        request.subscription = None

        # Run
        response = ArticleXmlView.as_view()(
            request, journal_code=journal_id, issue_slug=issue.volume_slug, issue_localid=issue_id,
            localid=article_id)

        # Check
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['Content-Type'], 'application/xml')
开发者ID:erudit,项目名称:eruditorg,代码行数:29,代码来源:test_views.py

示例12: test_can_retrieve_the_first_page_of_the_pdf_of_existing_articles

    def test_can_retrieve_the_first_page_of_the_pdf_of_existing_articles(self, mock_ds, mock_pdf):
        # Setup
        with open(os.path.join(FIXTURE_ROOT, 'dummy-multipages.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() - dt.timedelta(days=1000))
        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_firstpage', args=(
            journal_id, issue.volume_slug, issue_id, article_id
        ))
        request = self.factory.get(url)
        request.user = AnonymousUser()

        # Run
        response = ArticleRawPdfFirstPageView.as_view()(
            request, journal_code=journal_id, issue_slug=issue.volume_slug,
            issue_localid=issue_id, localid=article_id)

        # Check
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['Content-Type'], 'application/pdf')
        raw_pdf = io.BytesIO()
        raw_pdf.write(response.content)
        pdf = PdfFileReader(raw_pdf)
        self.assertEqual(pdf.numPages, 1)
开发者ID:erudit,项目名称:eruditorg,代码行数:31,代码来源:test_views.py

示例13: test_can_properly_paginate_a_queryset_using_a_list_of_localidentifiers

 def test_can_properly_paginate_a_queryset_using_a_list_of_localidentifiers(self):
     # Setup
     issue = IssueFactory.create(journal=self.journal)
     localidentifiers = []
     for i in range(0, 10):
         lid = 'lid-{0}'.format(i)
         localidentifiers.append(lid)
         ArticleFactory.create(issue=issue, localidentifier=lid)
     request = Request(self.factory.get('/', data={'page': 1}))
     paginator = EruditDocumentPagination()
     # Run
     object_list = paginator.paginate(10, localidentifiers, Article.objects.all(), request)
     # Check
     self.assertEqual(
         object_list,
         list(Article.objects.filter(localidentifier__in=localidentifiers[:10])
              .order_by('localidentifier')))
开发者ID:erudit,项目名称:eruditorg,代码行数:17,代码来源:test_pagination.py

示例14: test_generates_a_pdf_into_a_bytes_stream_by_default

 def test_generates_a_pdf_into_a_bytes_stream_by_default(self):
     # Setup
     issue = IssueFactory.create(journal=self.journal)
     article = ArticleFactory.create(issue=issue)
     # Run & check
     pdf = generate_pdf('public/journal/article_pdf_coverpage.html', context={
         'article': article, 'issue': issue, 'journal': issue.journal})
     self.assertTrue(isinstance(pdf, io.BytesIO))
开发者ID:erudit,项目名称:eruditorg,代码行数:8,代码来源:test_pdf.py

示例15: test_can_filter_by_article_type

    def test_can_filter_by_article_type(self):
        # Setup
        issue_1 = IssueFactory.create(journal=self.journal, date_published=dt.datetime.now())
        article_1 = ArticleFactory.create( issue=issue_1, type='article')
        article_2 = ArticleFactory.create( issue=issue_1, type='compterendu')  # noqa

        author_1 = AuthorFactory.create(lastname='btest')
        article_1.authors.add(author_1)

        url = reverse('public:journal:journal_authors_list', kwargs={'code': self.journal.code})

        # Run
        response = self.client.get(url, article_type='article')

        # Check
        self.assertEqual(response.status_code, 200)
        authors_dicts = response.context['authors_dicts']

        assert len(authors_dicts) == 1
开发者ID:erudit,项目名称:eruditorg,代码行数:19,代码来源:test_views.py


注:本文中的erudit.test.factories.ArticleFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。