def test_03_bulk_edit_not_admin(self): for acc_id in self.forbidden_accounts: logout_user() self._make_and_push_test_context(acc=models.Account.pull(acc_id)) with self.assertRaises(BackgroundException): # test dry run r = journal_manage( { "query": { "terms": { "_id": [j.id for j in self.journals] } } }, note="Test note", dry_run=True) with self.assertRaises(BackgroundException): r = journal_manage( { "query": { "terms": { "_id": [j.id for j in self.journals] } } }, note="Test note", dry_run=False)
def test_03_bulk_edit_not_admin(self): for acc_id in self.forbidden_accounts: logout_user() self._make_and_push_test_context(acc=models.Account.pull(acc_id)) with self.assertRaises(BackgroundException): # test dry run r = journal_manage({"query": {"terms": {"_id": [j.id for j in self.journals]}}}, note="Test note", dry_run=True) with self.assertRaises(BackgroundException): r = journal_manage({"query": {"terms": {"_id": [j.id for j in self.journals]}}}, note="Test note", dry_run=False)
def test_07_unmatched_editor(self): """Bulk assign an editor group to a bunch of journals using a background task""" new_eg = EditorGroupFixtureFactory.setup_editor_group_with_editors( group_name='editorgroup') source = JournalFixtureFactory.make_journal_source() source["admin"]["editor"] = "random_editor" journal = models.Journal(**source) journal.save(blocking=True) # test dry run summary = journal_manage({"query": { "terms": { "_id": [journal.id] } }}, doaj_seal=True, dry_run=False) sleep(2) job = models.BackgroundJob.all()[0] assert job.status == "complete", json.dumps(job.data, indent=2) journal2 = models.Journal.pull(journal.id) assert journal2.editor_group == "editorgroup" assert journal2.editor is None
def test_05_edit_metadata(self): """Bulk assign an editor group to a bunch of journals using a background task""" new_eg = EditorGroupFixtureFactory.setup_editor_group_with_editors(group_name='Test Editor Group') # test dry run summary = journal_manage({"query": {"terms": {"_id": [j.id for j in self.journals]}}}, publisher="my replacement publisher", doaj_seal=True, country="AF", owner="test1", platform=u"my platfo®m", # stick in a weird character for good measure contact_name="my contact", contact_email="*****@*****.**", dry_run=True) assert summary.as_dict().get("affected", {}).get("journals") == TEST_JOURNAL_COUNT, summary.as_dict() summary = journal_manage({"query": {"terms": {"_id": [j.id for j in self.journals]}}}, publisher="my replacement publisher", doaj_seal=True, country="AF", owner="test1", platform=u"my platfo®m", # stick in a weird character for good measure contact_name="my contact", contact_email="*****@*****.**", dry_run=False) assert summary.as_dict().get("affected", {}).get("journals") == TEST_JOURNAL_COUNT, summary.as_dict() sleep(1) job = models.BackgroundJob.all()[0] modified_journals = [j.pull(j.id) for j in self.journals] for ix, j in enumerate(modified_journals): assert j.bibjson().publisher == "my replacement publisher", \ "modified_journals[{}].publisher is {}" \ "\nHere is the BackgroundJob audit log:\n{}"\ .format(ix, j.bibjson().publisher, json.dumps(job.audit, indent=2)) assert j.has_seal() assert j.bibjson().country == "AF" assert j.owner == "test1" assert j.bibjson().provider == u"my platfo®m" assert j.get_latest_contact_name() == "my contact" assert j.get_latest_contact_email() == "*****@*****.**"
def test_01_editor_group_successful_assign(self): """Bulk assign an editor group to a bunch of journals using a background task""" new_eg = EditorGroupFixtureFactory.setup_editor_group_with_editors( group_name='Test Editor Group') # test dry run summary = journal_manage( {"query": { "terms": { "_id": [j.id for j in self.journals] } }}, editor_group=new_eg.name, dry_run=True) assert summary.as_dict().get( "affected", {}).get("journals") == TEST_JOURNAL_COUNT, summary.as_dict() summary = journal_manage( {"query": { "terms": { "_id": [j.id for j in self.journals] } }}, editor_group=new_eg.name, dry_run=False) assert summary.as_dict().get( "affected", {}).get("journals") == TEST_JOURNAL_COUNT, summary.as_dict() sleep(1) job = models.BackgroundJob.all()[0] modified_journals = [j.pull(j.id) for j in self.journals] for ix, j in enumerate(modified_journals): assert j.editor_group == new_eg.name, \ "modified_journals[{}].editor_group is {}" \ "\nHere is the BackgroundJob audit log:\n{}"\ .format(ix, j.editor_group, json.dumps(job.audit, indent=2))
def test_02_note_successful_add(self): # test dry run summary = journal_manage( {"query": { "terms": { "_id": [j.id for j in self.journals] } }}, note="Test note", dry_run=True) assert summary.as_dict().get( "affected", {}).get("journals") == TEST_JOURNAL_COUNT, summary.as_dict() summary = journal_manage( {"query": { "terms": { "_id": [j.id for j in self.journals] } }}, note="Test note", dry_run=False) assert summary.as_dict().get( "affected", {}).get("journals") == TEST_JOURNAL_COUNT, summary.as_dict() sleep(1) job = models.BackgroundJob.all()[0] modified_journals = [j.pull(j.id) for j in self.journals] for ix, j in enumerate(modified_journals): assert j, 'modified_journals[{}] is None, does not seem to exist?' assert j.notes, "modified_journals[{}] has no notes. It is \n{}".format( ix, json.dumps(j.data, indent=2)) assert 'note' in j.notes[-1], json.dumps(j.notes[-1], indent=2) assert j.notes[-1]['note'] == 'Test note', \ "The last note on modified_journals[{}] is {}\n" \ "Here is the BackgroundJob audit log:\n{}".format( ix, j.notes[-1]['note'], json.dumps(job.audit, indent=2) )
def test_02_note_successful_add(self): # test dry run summary = journal_manage({"query": {"terms": {"_id": [j.id for j in self.journals]}}}, note="Test note", dry_run=True) assert summary.as_dict().get("affected", {}).get("journals") == TEST_JOURNAL_COUNT, summary.as_dict() summary = journal_manage({"query": {"terms": {"_id": [j.id for j in self.journals]}}}, note="Test note", dry_run=False) assert summary.as_dict().get("affected", {}).get("journals") == TEST_JOURNAL_COUNT, summary.as_dict() sleep(1) job = models.BackgroundJob.all()[0] modified_journals = [j.pull(j.id) for j in self.journals] for ix, j in enumerate(modified_journals): assert j, 'modified_journals[{}] is None, does not seem to exist?' assert j.notes, "modified_journals[{}] has no notes. It is \n{}".format(ix, json.dumps(j.data, indent=2)) assert 'note' in j.notes[-1], json.dumps(j.notes[-1], indent=2) assert j.notes[-1]['note'] == 'Test note', \ "The last note on modified_journals[{}] is {}\n" \ "Here is the BackgroundJob audit log:\n{}".format( ix, j.notes[-1]['note'], json.dumps(job.audit, indent=2) )
def test_01_editor_group_successful_assign(self): """Bulk assign an editor group to a bunch of journals using a background task""" new_eg = EditorGroupFixtureFactory.setup_editor_group_with_editors(group_name='Test Editor Group') # test dry run summary = journal_manage({"query": {"terms": {"_id": [j.id for j in self.journals]}}}, editor_group=new_eg.name, dry_run=True) assert summary.as_dict().get("affected", {}).get("journals") == TEST_JOURNAL_COUNT, summary.as_dict() summary = journal_manage({"query": {"terms": {"_id": [j.id for j in self.journals]}}}, editor_group=new_eg.name, dry_run=False) assert summary.as_dict().get("affected", {}).get("journals") == TEST_JOURNAL_COUNT, summary.as_dict() sleep(1) job = models.BackgroundJob.all()[0] modified_journals = [j.pull(j.id) for j in self.journals] for ix, j in enumerate(modified_journals): assert j.editor_group == new_eg.name, \ "modified_journals[{}].editor_group is {}" \ "\nHere is the BackgroundJob audit log:\n{}"\ .format(ix, j.editor_group, json.dumps(job.audit, indent=2))
def test_07_unmatched_editor(self): """Bulk assign an editor group to a bunch of journals using a background task""" new_eg = EditorGroupFixtureFactory.setup_editor_group_with_editors(group_name='editorgroup') source = JournalFixtureFactory.make_journal_source() source["admin"]["editor"] = "random_editor" journal = models.Journal(**source) journal.save(blocking=True) # test dry run summary = journal_manage({"query": {"terms": {"_id": [journal.id]}}}, doaj_seal=True, dry_run=False) sleep(2) job = models.BackgroundJob.all()[0] assert job.status == "complete", json.dumps(job.data, indent=2) journal2 = models.Journal.pull(journal.id) assert journal2.editor_group == "editorgroup" assert journal2.editor is None
def test_05_edit_metadata(self): """Bulk assign an editor group to a bunch of journals using a background task""" new_eg = EditorGroupFixtureFactory.setup_editor_group_with_editors( group_name='Test Editor Group') # test dry run summary = journal_manage( {"query": { "terms": { "_id": [j.id for j in self.journals] } }}, publisher="my replacement publisher", doaj_seal=True, country="AF", owner="test1", platform= "my platfo®m", # stick in a weird character for good measure contact_name="my contact", contact_email="*****@*****.**", dry_run=True) assert summary.as_dict().get( "affected", {}).get("journals") == TEST_JOURNAL_COUNT, summary.as_dict() summary = journal_manage( {"query": { "terms": { "_id": [j.id for j in self.journals] } }}, publisher="my replacement publisher", doaj_seal=True, country="AF", owner="test1", platform= "my platfo®m", # stick in a weird character for good measure contact_name="my contact", contact_email="*****@*****.**", dry_run=False) assert summary.as_dict().get( "affected", {}).get("journals") == TEST_JOURNAL_COUNT, summary.as_dict() sleep(1) job = models.BackgroundJob.all()[0] modified_journals = [j.pull(j.id) for j in self.journals] for ix, j in enumerate(modified_journals): assert j.bibjson().publisher == "my replacement publisher", \ "modified_journals[{}].publisher is {}" \ "\nHere is the BackgroundJob audit log:\n{}"\ .format(ix, j.bibjson().publisher, json.dumps(job.audit, indent=2)) assert j.has_seal() assert j.bibjson().country == "AF" assert j.owner == "test1" assert j.bibjson().provider == "my platfo®m" assert j.get_latest_contact_name() == "my contact" assert j.get_latest_contact_email() == "*****@*****.**"