本文整理汇总了Python中erudit.test.factories.AuthorFactory类的典型用法代码示例。如果您正苦于以下问题:Python AuthorFactory类的具体用法?Python AuthorFactory怎么用?Python AuthorFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AuthorFactory类的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)
示例2: test_returns_only_theses_for_a_given_author_first_letter
def test_returns_only_theses_for_a_given_author_first_letter(self):
# Setup
author_1 = AuthorFactory.create(lastname='Aname')
author_2 = AuthorFactory.create(lastname='Bname')
author_3 = AuthorFactory.create(lastname='Cname')
author_4 = AuthorFactory.create(lastname='Dname')
collection = CollectionFactory.create()
thesis_1 = ThesisFactory.create( # noqa
localidentifier='thesis-1', collection=collection, author=author_1,
publication_year=2010)
thesis_2 = ThesisFactory.create( # noqa
localidentifier='thesis-2', collection=collection, author=author_2,
publication_year=2012)
thesis_3 = ThesisFactory.create( # noqa
localidentifier='thesis-3', collection=collection, author=author_3,
publication_year=2013)
thesis_4 = ThesisFactory.create( # noqa
localidentifier='thesis-4', collection=collection, author=author_4,
publication_year=2014)
thesis_5 = ThesisFactory.create( # noqa
localidentifier='thesis-5', collection=collection, author=author_2,
publication_year=2012)
thesis_6 = ThesisFactory.create( # noqa
localidentifier='thesis-6', collection=collection, author=author_2,
publication_year=2012)
thesis_7 = ThesisFactory.create( # noqa
localidentifier='thesis-7', collection=collection, author=author_4,
publication_year=2014)
url = reverse('public:thesis:collection_list_per_author_name', args=(collection.id, 'B'))
# Run
response = self.client.get(url)
# Check
assert response.status_code == 200
assert list(response.context['theses']) == [thesis_2, thesis_5, thesis_6, ]
示例3: 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')
示例4: test_can_determine_the_thesis_counts_per_author_firstletter
def test_can_determine_the_thesis_counts_per_author_firstletter(self):
# Setup
author_1 = AuthorFactory.create(lastname='Aname')
author_2 = AuthorFactory.create(lastname='Bname')
author_3 = AuthorFactory.create(lastname='Cname')
author_4 = AuthorFactory.create(lastname='Dname')
collection = CollectionFactory.create()
thesis_1 = ThesisFactory.create( # noqa
localidentifier='thesis-1', collection=collection, author=author_1,
publication_year=2010)
thesis_2 = ThesisFactory.create( # noqa
localidentifier='thesis-2', collection=collection, author=author_2,
publication_year=2012)
thesis_3 = ThesisFactory.create( # noqa
localidentifier='thesis-3', collection=collection, author=author_3,
publication_year=2013)
thesis_4 = ThesisFactory.create( # noqa
localidentifier='thesis-4', collection=collection, author=author_4,
publication_year=2014)
thesis_5 = ThesisFactory.create( # noqa
localidentifier='thesis-5', collection=collection, author=author_2,
publication_year=2012)
thesis_6 = ThesisFactory.create( # noqa
localidentifier='thesis-6', collection=collection, author=author_2,
publication_year=2012)
thesis_7 = ThesisFactory.create( # noqa
localidentifier='thesis-7', collection=collection, author=author_4,
publication_year=2014)
# Run
aggs = get_thesis_counts_per_author_first_letter(Thesis.objects.all())
# Check
assert aggs[0] == {'author_firstletter': 'A', 'total': 1}
assert aggs[1] == {'author_firstletter': 'B', 'total': 3}
assert aggs[2] == {'author_firstletter': 'C', 'total': 1}
assert aggs[3] == {'author_firstletter': 'D', 'total': 2}
示例5: test_can_return_its_name
def test_can_return_its_name(self):
author_1 = AuthorFactory()
assert str(author_1) == "{lastname}, {firstname}".format(
lastname=author_1.lastname, firstname=author_1.firstname
)
author_1.suffix = 'PhD'
assert str(author_1) == "{suffix} {firstname} {lastname}".format(
suffix=author_1.suffix, firstname=author_1.firstname, lastname=author_1.lastname
)
示例6: test_can_return_its_letter_prefix
def test_can_return_its_letter_prefix(self):
# Setup
author_1 = AuthorFactory.create(lastname='Abc', firstname='Def')
author_2 = AuthorFactory.create(lastname=None, firstname='Def')
author_3 = AuthorFactory.create(lastname=None, firstname='Def', othername='Ghi')
author_4 = AuthorFactory.create(lastname=':', firstname='Def')
author_5 = AuthorFactory.create(lastname=':', firstname=None)
# Run & check
assert author_1.letter_prefix == 'A'
assert author_2.letter_prefix == 'D'
assert author_3.letter_prefix == 'G'
assert author_4.letter_prefix == 'D'
assert author_5.letter_prefix is None
示例7: test_can_determine_the_thesis_counts_per_publication_year
def test_can_determine_the_thesis_counts_per_publication_year(self):
# Setup
author = AuthorFactory.create()
collection = CollectionFactory.create()
thesis_1 = ThesisFactory.create( # noqa
localidentifier='thesis-1', collection=collection, author=author,
publication_year=2010)
thesis_2 = ThesisFactory.create( # noqa
localidentifier='thesis-2', collection=collection, author=author,
publication_year=2012)
thesis_3 = ThesisFactory.create( # noqa
localidentifier='thesis-3', collection=collection, author=author,
publication_year=2013)
thesis_4 = ThesisFactory.create( # noqa
localidentifier='thesis-4', collection=collection, author=author,
publication_year=2014)
thesis_5 = ThesisFactory.create( # noqa
localidentifier='thesis-5', collection=collection, author=author,
publication_year=2012)
thesis_6 = ThesisFactory.create( # noqa
localidentifier='thesis-6', collection=collection, author=author,
publication_year=2012)
thesis_7 = ThesisFactory.create( # noqa
localidentifier='thesis-7', collection=collection, author=author,
publication_year=2014)
# Run
aggs = get_thesis_counts_per_publication_year(Thesis.objects.all())
# Check
assert aggs[0] == {'publication_year': 2014, 'total': 2}
assert aggs[1] == {'publication_year': 2013, 'total': 1}
assert aggs[2] == {'publication_year': 2012, 'total': 3}
assert aggs[3] == {'publication_year': 2010, 'total': 1}
示例8: test_returns_only_collections_associated_with_theses
def test_returns_only_collections_associated_with_theses(self):
# Setup
author = AuthorFactory.create()
collection_1 = CollectionFactory.create(localidentifier='col1')
collection_2 = CollectionFactory.create(localidentifier='col2')
CollectionFactory.create(localidentifier='col3')
ThesisFactory.create(localidentifier='thesis1', collection=collection_1, author=author)
ThesisFactory.create(localidentifier='thesis2', collection=collection_2, author=author)
# Run & check
assert list(get_thesis_collections()) == [collection_1, collection_2, ]
示例9: test_embeds_the_other_author_first_letter_aggregation_results_into_the_context
def test_embeds_the_other_author_first_letter_aggregation_results_into_the_context(self):
# Setup
cache.clear()
author_1 = AuthorFactory.create(lastname='Aname')
author_2 = AuthorFactory.create(lastname='Bname')
author_3 = AuthorFactory.create(lastname='Cname')
author_4 = AuthorFactory.create(lastname='Dname')
collection = CollectionFactory.create()
thesis_1 = ThesisFactory.create( # noqa
localidentifier='thesis-1', collection=collection, author=author_1,
publication_year=2010)
thesis_2 = ThesisFactory.create( # noqa
localidentifier='thesis-2', collection=collection, author=author_2,
publication_year=2012)
thesis_3 = ThesisFactory.create( # noqa
localidentifier='thesis-3', collection=collection, author=author_3,
publication_year=2013)
thesis_4 = ThesisFactory.create( # noqa
localidentifier='thesis-4', collection=collection, author=author_4,
publication_year=2014)
thesis_5 = ThesisFactory.create( # noqa
localidentifier='thesis-5', collection=collection, author=author_2,
publication_year=2012)
thesis_6 = ThesisFactory.create( # noqa
localidentifier='thesis-6', collection=collection, author=author_2,
publication_year=2012)
thesis_7 = ThesisFactory.create( # noqa
localidentifier='thesis-7', collection=collection, author=author_4,
publication_year=2014)
url = reverse('public:thesis:collection_list_per_author_name', args=(collection.id, 'B'))
# Run
response = self.client.get(url)
# Check
assert response.status_code == 200
assert response.context['other_author_letters'][0] == \
{'author_firstletter': 'A', 'total': 1}
assert response.context['other_author_letters'][1] == \
{'author_firstletter': 'B', 'total': 3}
assert response.context['other_author_letters'][2] == \
{'author_firstletter': 'C', 'total': 1}
assert response.context['other_author_letters'][3] == \
{'author_firstletter': 'D', 'total': 2}
示例10: test_provides_only_authors_for_the_first_available_letter_by_default
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, ])
示例11: test_inserts_the_thesis_counts_grouped_by_author_name
def test_inserts_the_thesis_counts_grouped_by_author_name(self):
# Setup
author_1 = AuthorFactory.create(lastname='Aname')
author_2 = AuthorFactory.create(lastname='Bname')
author_3 = AuthorFactory.create(lastname='Cname')
author_4 = AuthorFactory.create(lastname='Dname')
collection = CollectionFactory.create()
thesis_1 = ThesisFactory.create( # noqa
localidentifier='thesis-1', collection=collection, author=author_1,
publication_year=2010)
thesis_2 = ThesisFactory.create( # noqa
localidentifier='thesis-2', collection=collection, author=author_2,
publication_year=2012)
thesis_3 = ThesisFactory.create( # noqa
localidentifier='thesis-3', collection=collection, author=author_3,
publication_year=2013)
thesis_4 = ThesisFactory.create( # noqa
localidentifier='thesis-4', collection=collection, author=author_4,
publication_year=2014)
thesis_5 = ThesisFactory.create( # noqa
localidentifier='thesis-5', collection=collection, author=author_2,
publication_year=2012)
thesis_6 = ThesisFactory.create( # noqa
localidentifier='thesis-6', collection=collection, author=author_2,
publication_year=2012)
thesis_7 = ThesisFactory.create( # noqa
localidentifier='thesis-7', collection=collection, author=author_4,
publication_year=2014)
url = reverse('public:thesis:collection_home', args=(collection.id, ))
# Run
response = self.client.get(url)
# Check
assert response.status_code == 200
assert response.context['thesis_groups']['by_author_name'][0] == \
{'author_firstletter': 'A', 'total': 1}
assert response.context['thesis_groups']['by_author_name'][1] == \
{'author_firstletter': 'B', 'total': 3}
assert response.context['thesis_groups']['by_author_name'][2] == \
{'author_firstletter': 'C', 'total': 1}
assert response.context['thesis_groups']['by_author_name'][3] == \
{'author_firstletter': 'D', 'total': 2}
示例12: test_can_sort_theses_by_descending_author_name
def test_can_sort_theses_by_descending_author_name(self):
# Setup
author_1 = AuthorFactory.create(lastname='BAname')
author_2 = AuthorFactory.create(lastname='BBname')
author_3 = AuthorFactory.create(lastname='BCname')
collection = CollectionFactory.create()
thesis_1 = ThesisFactory.create( # noqa
localidentifier='thesis-1', collection=collection, author=author_1,
publication_year=2012)
thesis_2 = ThesisFactory.create( # noqa
localidentifier='thesis-2', collection=collection, author=author_2,
publication_year=2012)
thesis_3 = ThesisFactory.create( # noqa
localidentifier='thesis-3', collection=collection, author=author_3,
publication_year=2012)
url = reverse('public:thesis:collection_list_per_author_name', args=(collection.id, 'B'))
# Run
response = self.client.get(url, {'sort_by': 'author_desc'})
# Check
assert response.status_code == 200
assert list(response.context['theses']) == [thesis_3, thesis_2, thesis_1, ]
示例13: test_can_filter_by_article_type_when_no_article_of_type
def test_can_filter_by_article_type_when_no_article_of_type(self):
issue_1 = IssueFactory.create(journal=self.journal, date_published=dt.datetime.now())
article_1 = ArticleFactory.create( issue=issue_1, type='article')
author_1 = AuthorFactory.create(lastname='atest')
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": 'compterendu'})
# Check
self.assertEqual(response.status_code, 200)
示例14: test_only_provides_authors_for_the_given_letter
def test_only_provides_authors_for_the_given_letter(self):
# Seetup
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')
article_1.authors.add(author_1)
article_1.authors.add(author_2)
article_1.save()
url = reverse('public:journal:journal_authors_list', kwargs={'code': self.journal.code})
# Run
response = self.client.get(url, letter='b')
# Check
self.assertEqual(response.status_code, 200)
authors_dicts = response.context['authors_dicts']
assert len(authors_dicts) == 1
assert authors_dicts[0]['author'] == author_1
示例15: test_do_not_fail_when_user_requests_a_letter_with_no_articles
def test_do_not_fail_when_user_requests_a_letter_with_no_articles(self):
# Setup
issue_1 = IssueFactory.create(journal=self.journal, date_published=dt.datetime.now())
article_1 = ArticleFactory.create(issue=issue_1, type='article')
author_1 = AuthorFactory.create(lastname='btest')
article_1.authors.add(author_1)
url = reverse('public:journal:journal_authors_list', kwargs={'code': self.journal.code})
response = self.client.get(url, {"article_type": 'compterendu', 'letter': 'A'})
# Check
self.assertEqual(response.status_code, 200)