本文整理汇总了Python中doajtest.fixtures.JournalFixtureFactory类的典型用法代码示例。如果您正苦于以下问题:Python JournalFixtureFactory类的具体用法?Python JournalFixtureFactory怎么用?Python JournalFixtureFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JournalFixtureFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_03_create_articles_fail
def test_03_create_articles_fail(self):
# if the account is dud
with self.assertRaises(Api401Error):
data = ArticleFixtureFactory.make_incoming_api_article()
dataset = [data] * 10
ids = ArticlesBulkApi.create(dataset, None)
# check that the index is empty, as none of them should have been made
all = [x for x in models.Article.iterall()]
assert len(all) == 0
# if the data is bust
with self.assertRaises(Api400Error):
account = models.Account()
account.set_id("test")
account.set_name("Tester")
account.set_email("[email protected]")
# add a journal to the account
journal = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True))
journal.set_owner(account.id)
journal.save()
time.sleep(1)
dataset = dataset[:5] + [{"some" : {"junk" : "data"}}] + dataset[5:]
ids = ArticlesBulkApi.create(dataset, account)
# check that the index is empty, as none of them should have been made
all = [x for x in models.Article.iterall()]
assert len(all) == 0
示例2: test_02_create_duplicate_articles
def test_02_create_duplicate_articles(self):
# set up all the bits we need - 10 articles
data = ArticleFixtureFactory.make_incoming_api_article()
dataset = [data] * 10
# create an account that we'll do the create as
account = models.Account()
account.set_id("test")
account.set_name("Tester")
account.set_email("[email protected]")
# add a journal to the account
journal = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True))
journal.set_owner(account.id)
journal.save()
time.sleep(2)
# call create on the object (which will save it to the index)
with self.assertRaises(Api400Error):
ids = ArticlesBulkApi.create(dataset, account)
time.sleep(2)
with self.assertRaises(ESMappingMissingError):
all_articles = models.Article.all()
示例3: test_11_delete_article_fail
def test_11_delete_article_fail(self):
# set up all the bits we need
account = models.Account()
account.set_id('test')
account.set_name("Tester")
account.set_email("[email protected]")
journal = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True))
journal.set_owner(account.id)
journal.save()
time.sleep(1)
data = ArticleFixtureFactory.make_article_source()
# call create on the object (which will save it to the index)
a = ArticlesCrudApi.create(data, account)
# let the index catch up
time.sleep(1)
# call delete on the object in various context that will fail
# without an account
with self.assertRaises(Api401Error):
ArticlesCrudApi.delete(a.id, None)
# with the wrong account
account.set_id("other")
with self.assertRaises(Api404Error):
ArticlesCrudApi.delete(a.id, account)
# on the wrong id
account.set_id("test")
with self.assertRaises(Api404Error):
ArticlesCrudApi.delete("adfasdfhwefwef", account)
示例4: test_06_anonymise_admin_empty_notes
def test_06_anonymise_admin_empty_notes(self):
journal_src = JournalFixtureFactory.make_journal_source()
journal_src['admin'] = {
'owner': 'testuser',
'editor': 'testeditor',
'contact': [{
'email': '[email protected]',
'name': 'Tester Tester'
}],
'notes': []
}
journal = models.Journal(**journal_src)
with freeze_time("2017-02-23"):
ar = anon_export._anonymise_admin(journal)
assert ar.data['admin'] == {
'owner': 'testuser',
'editor': 'testeditor',
'contact': [{
'email': '5[email protected]example.com',
'name': 'Ryan Gallagher'
}],
'notes': []
}, ar['admin']
示例5: test_15_create_application_update_request_dryrun
def test_15_create_application_update_request_dryrun(self):
# set up all the bits we need
data = ApplicationFixtureFactory.incoming_application()
account = models.Account()
account.set_id("test")
account.set_name("Tester")
account.set_email("[email protected]")
account.add_role("publisher")
journal = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True))
journal.bibjson().remove_identifiers()
journal.bibjson().add_identifier(journal.bibjson().E_ISSN, "9999-8888")
journal.bibjson().add_identifier(journal.bibjson().P_ISSN, "7777-6666")
journal.bibjson().title = "not changed"
journal.set_id(data["admin"]["current_journal"])
journal.set_owner(account.id)
journal.save(blocking=True)
# call create on the object, with the dry_run flag set
a = ApplicationsCrudApi.create(data, account, dry_run=True)
time.sleep(2)
# now check that the application index remains empty
ss = [x for x in models.Suggestion.iterall()]
assert len(ss) == 0
示例6: setUp
def setUp(self):
super(TestTaskJournalBulkEdit, self).setUp()
self.default_eg = EditorGroupFixtureFactory.setup_editor_group_with_editors()
acc = models.Account()
acc.set_id("0987654321")
acc.set_email("[email protected]")
acc.save()
egs = EditorGroupFixtureFactory.make_editor_group_source("1234567890", "0987654321")
egm = models.EditorGroup(**egs)
egm.save(blocking=True)
self.journals = []
for j_src in JournalFixtureFactory.make_many_journal_sources(count=TEST_JOURNAL_COUNT):
self.journals.append(models.Journal(**j_src))
self.journals[-1].set_editor_group("1234567890")
self.journals[-1].set_editor("0987654321")
self.journals[-1].save(blocking=True)
self.forbidden_accounts = [
AccountFixtureFactory.make_editor_source()['id'],
AccountFixtureFactory.make_assed1_source()['id'],
AccountFixtureFactory.make_assed2_source()['id'],
AccountFixtureFactory.make_assed3_source()['id']
]
self._make_and_push_test_context(acc=models.Account(**AccountFixtureFactory.make_managing_editor_source()))
示例7: test_02_retrieve_public_journal_success
def test_02_retrieve_public_journal_success(self):
# set up all the bits we need
data = JournalFixtureFactory.make_journal_source(in_doaj=True, include_obsolete_fields=True)
j = models.Journal(**data)
j.save()
time.sleep(2)
a = JournalsCrudApi.retrieve(j.id, account=None)
# check that we got back the object we expected
assert isinstance(a, OutgoingJournal)
assert a.id == j.id
# it should also work if we're logged in with the owner or another user
# owner first
account = models.Account()
account.set_id(j.owner)
account.set_name("Tester")
account.set_email("[email protected]")
a = JournalsCrudApi.retrieve(j.id, account)
assert isinstance(a, OutgoingJournal)
assert a.id == j.id
# try with another account
not_owner = models.Account()
not_owner.set_id("asdklfjaioefwe")
a = JournalsCrudApi.retrieve(j.id, not_owner)
assert isinstance(a, OutgoingJournal)
assert a.id == j.id
示例8: get_journal
def get_journal(cls, specs):
journals = []
for spec in specs:
source = JournalFixtureFactory.make_journal_source(in_doaj=True)
j = Journal(**source)
bj = j.bibjson()
bj.title = spec.get("title", "Journal Title")
bj.remove_identifiers()
if "pissn" in spec:
bj.add_identifier(bj.P_ISSN, spec.get("pissn"))
if "eissn" in spec:
bj.add_identifier(bj.E_ISSN, spec.get("eissn"))
spec["instance"] = j
journals.append(spec)
def mock(self):
bibjson = self.bibjson()
# first, get the ISSNs associated with the record
pissns = bibjson.get_identifiers(bibjson.P_ISSN)
eissns = bibjson.get_identifiers(bibjson.E_ISSN)
for j in journals:
if j["pissn"] in pissns and j["eissn"] in eissns:
return j["instance"]
return mock
示例9: test_03_withdraw
def test_03_withdraw(self):
acc = models.Account()
acc.set_name("testuser")
ctx = self._make_and_push_test_context(acc=acc)
sources = JournalFixtureFactory.make_many_journal_sources(10, in_doaj=True)
ids = []
articles = []
for source in sources:
j = models.Journal(**source)
j.save()
ids.append(j.id)
pissn = j.bibjson().get_identifiers(j.bibjson().P_ISSN)
eissn = j.bibjson().get_identifiers(j.bibjson().E_ISSN)
asource = ArticleFixtureFactory.make_article_source(pissn=pissn[0], eissn=eissn[0], with_id=False)
a = models.Article(**asource)
a.save()
articles.append(a.id)
time.sleep(2)
change_in_doaj(ids, False)
time.sleep(2)
for id in ids:
j = models.Journal.pull(id)
assert j.is_in_doaj() is False
for id in articles:
a = models.Article.pull(id)
assert a.is_in_doaj() is False
ctx.pop()
示例10: test_02_reinstate_task
def test_02_reinstate_task(self):
sources = JournalFixtureFactory.make_many_journal_sources(10, in_doaj=False)
ids = []
articles = []
for source in sources:
j = models.Journal(**source)
j.save()
ids.append(j.id)
pissn = j.bibjson().get_identifiers(j.bibjson().P_ISSN)
eissn = j.bibjson().get_identifiers(j.bibjson().E_ISSN)
asource = ArticleFixtureFactory.make_article_source(pissn=pissn[0], eissn=eissn[0], with_id=False, in_doaj=False)
a = models.Article(**asource)
a.save()
articles.append(a.id)
time.sleep(2)
job = SetInDOAJBackgroundTask.prepare("testuser", journal_ids=ids, in_doaj=True)
SetInDOAJBackgroundTask.submit(job)
time.sleep(2)
for id in ids:
j = models.Journal.pull(id)
assert j.is_in_doaj() is True
for id in articles:
a = models.Article.pull(id)
assert a.is_in_doaj() is True
示例11: test_10_delete_article_success
def test_10_delete_article_success(self):
# set up all the bits we need
account = models.Account()
account.set_id('test')
account.set_name("Tester")
account.set_email("[email protected]")
journal = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True))
journal.set_owner(account.id)
journal.save()
time.sleep(1)
data = ArticleFixtureFactory.make_article_source()
# call create on the object (which will save it to the index)
a = ArticlesCrudApi.create(data, account)
# let the index catch up
time.sleep(1)
# now delete it
ArticlesCrudApi.delete(a.id, account)
# let the index catch up
time.sleep(1)
ap = models.Article.pull(a.id)
assert ap is None
示例12: test_07_retrieve_article_fail
def test_07_retrieve_article_fail(self):
# set up all the bits we need
# add a journal to the account
account = models.Account()
account.set_id('test')
account.set_name("Tester")
account.set_email("[email protected]")
journal = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True))
journal.set_owner(account.id)
journal.save()
time.sleep(1)
data = ArticleFixtureFactory.make_article_source()
data['admin']['in_doaj'] = False
ap = models.Article(**data)
ap.save()
time.sleep(1)
# should fail when no user and in_doaj is False
with self.assertRaises(Api401Error):
a = ArticlesCrudApi.retrieve(ap.id, None)
# wrong user
account = models.Account()
account.set_id("asdklfjaioefwe")
with self.assertRaises(Api404Error):
a = ArticlesCrudApi.retrieve(ap.id, account)
# non-existant article
account = models.Account()
account.set_id(ap.id)
with self.assertRaises(Api404Error):
a = ArticlesCrudApi.retrieve("ijsidfawefwefw", account)
示例13: test_03_oai_resumption_token
def test_03_oai_resumption_token(self):
""" Test the behaviour of the ResumptionToken in the OAI interface"""
# Set the OAI interface to only return two identifiers at a time
app.config['OAIPMH_LIST_IDENTIFIERS_PAGE_SIZE'] = 2
[j0, j1, j2, j3, j4] = JournalFixtureFactory.make_many_journal_sources(5, in_doaj=True)
# Save a single journal in the index
jm0 = models.Journal(**j0)
jm0.save(blocking=True)
# ListIdentifiers - we expect no resumptionToken because all results are returned
with app.test_client() as t_client:
resp = t_client.get('/oai?verb=ListIdentifiers&metadataPrefix=oai_dc')
t = etree.fromstring(resp.data)
assert t.xpath('//oai:identifier', namespaces=self.oai_ns)[0].text == 'oai:doaj.org/journal:journalid0'
assert t.xpath('//oai:resumptionToken', namespaces=self.oai_ns) == []
# Populate index with 4 more journals
for j in [j1, j2, j3, j4]:
jm = models.Journal(**j)
jm.save(blocking=True)
# ListIdentifiers - we expect 5 total results and a resumptionToken to fetch the rest
with app.test_client() as t_client:
resp = t_client.get('/oai?verb=ListIdentifiers&metadataPrefix=oai_dc')
t = etree.fromstring(resp.data)
#print etree.tostring(t, pretty_print=True)
rt = t.xpath('//oai:resumptionToken', namespaces=self.oai_ns)[0]
assert rt.get('completeListSize') == '5'
assert rt.get('cursor') == '2'
# Get the next result
resp2 = t_client.get('/oai?verb=ListIdentifiers&resumptionToken={0}'.format(rt.text))
t = etree.fromstring(resp2.data)
#print etree.tostring(t, pretty_print=True)
rt2 = t.xpath('//oai:resumptionToken', namespaces=self.oai_ns)[0]
assert rt2.get('completeListSize') == '5'
assert rt2.get('cursor') == '4'
# And the final result - check we get an empty resumptionToken
resp3 = t_client.get('/oai?verb=ListIdentifiers&resumptionToken={0}'.format(rt2.text))
t = etree.fromstring(resp3.data)
#print etree.tostring(t, pretty_print=True)
rt3 = t.xpath('//oai:resumptionToken', namespaces=self.oai_ns)[0]
assert rt3.get('completeListSize') == '5'
assert rt3.get('cursor') == '5'
assert rt3.text is None
# We should get an error if we request again with an empty resumptionToken
resp4 = t_client.get('/oai?verb=ListIdentifiers&resumptionToken={0}'.format(rt3.text))
assert resp4.status_code == 200 # fixme: should this be a real error code?
t = etree.fromstring(resp4.data)
#print etree.tostring(t, pretty_print=True)
err = t.xpath('//oai:error', namespaces=self.oai_ns)[0]
assert 'the resumptionToken argument is invalid or expired' in err.text
示例14: test_03b_create_update_request_fail
def test_03b_create_update_request_fail(self):
# update request target not found
with self.assertRaises(Api404Error):
data = ApplicationFixtureFactory.incoming_application()
publisher = models.Account(**AccountFixtureFactory.make_publisher_source())
try:
a = ApplicationsCrudApi.create(data, publisher)
except Api404Error as e:
raise
# if a formcontext exception is raised on finalise
publisher = models.Account(**AccountFixtureFactory.make_publisher_source())
journal = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True))
journal.set_id(journal.makeid())
journal.set_owner(publisher.id)
journal.save(blocking=True)
formcontext.FormContext.finalise = mock_finalise_exception
with self.assertRaises(Api400Error):
data = ApplicationFixtureFactory.incoming_application()
data["admin"]["current_journal"] = journal.id
try:
a = ApplicationsCrudApi.create(data, publisher)
except Api400Error as e:
assert e.message == "test exception"
raise
formcontext.FormContext.finalise = self.old_finalise
# validation fails on the formcontext
publisher = models.Account(**AccountFixtureFactory.make_publisher_source())
journal = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True))
journal.set_id(journal.makeid())
journal.set_owner(publisher.id)
journal.save(blocking=True)
IncomingApplication.custom_validate = mock_custom_validate_always_pass
with self.assertRaises(Api400Error):
data = ApplicationFixtureFactory.incoming_application()
# duff submission charges url should trip the validator
data["bibjson"]["submission_charges_url"] = "not a url!"
data["admin"]["current_journal"] = journal.id
try:
a = ApplicationsCrudApi.create(data, publisher)
except Api400Error as e:
raise
示例15: test_13_create_application_update_request_success
def test_13_create_application_update_request_success(self):
# set up all the bits we need
data = ApplicationFixtureFactory.incoming_application()
account = models.Account()
account.set_id("test")
account.set_name("Tester")
account.set_email("[email protected]")
account.add_role("publisher")
account.save(blocking=True)
journal = models.Journal(**JournalFixtureFactory.make_journal_source(in_doaj=True))
journal.bibjson().remove_identifiers()
journal.bibjson().add_identifier(journal.bibjson().E_ISSN, "9999-8888")
journal.bibjson().add_identifier(journal.bibjson().P_ISSN, "7777-6666")
journal.bibjson().title = "not changed"
journal.set_id(data["admin"]["current_journal"])
journal.set_owner(account.id)
journal.save(blocking=True)
# call create on the object (which will save it to the index)
a = ApplicationsCrudApi.create(data, account)
# check that it got created with the right properties
assert isinstance(a, models.Suggestion)
assert a.id != "ignore_me"
assert a.created_date != "2001-01-01T00:00:00Z"
assert a.last_updated != "2001-01-01T00:00:00Z"
assert a.suggester.get("name") == "Tester" # The suggester should be the owner of the existing journal
assert a.suggester.get("email") == "[email protected]"
assert a.owner == "test"
assert a.suggested_on is not None
assert a.bibjson().issns() == ["9999-8888", "7777-6666"] or a.bibjson().issns() == ["7777-6666", "9999-8888"]
assert a.bibjson().title == "not changed"
# also, because it's a special case, check the archiving_policy
archiving_policy = a.bibjson().archiving_policy
assert len(archiving_policy.get("policy")) == 4
lcount = 0
scount = 0
for ap in archiving_policy.get("policy"):
if isinstance(ap, list):
lcount += 1
assert ap[0] in ["A national library", "Other"]
assert ap[1] in ["Trinity", "A safe place"]
else:
scount += 1
assert lcount == 2
assert scount == 2
assert "CLOCKSS" in archiving_policy.get("policy")
assert "LOCKSS" in archiving_policy.get("policy")
time.sleep(2)
s = models.Suggestion.pull(a.id)
assert s is not None