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("*****@*****.**")
        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()))
Exemple #2
0
    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("*****@*****.**")
        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()))
Exemple #3
0
    def setUp(self):
        super(TestTaskSuggestionBulkEdit, self).setUp()

        acc = models.Account()
        acc.set_id("0987654321")
        acc.set_email("*****@*****.**")
        acc.save()

        egs = EditorGroupFixtureFactory.make_editor_group_source(
            "1234567890", "0987654321")
        egm = models.EditorGroup(**egs)
        egm.save(blocking=True)

        self.suggestions = []
        for app_src in ApplicationFixtureFactory.make_many_application_sources(
                count=TEST_SUGGESTION_COUNT):
            self.suggestions.append(models.Suggestion(**app_src))
            self.suggestions[-1].set_editor_group("1234567890")
            self.suggestions[-1].set_editor("0987654321")
            self.suggestions[-1].save()

        self.default_eg = EditorGroupFixtureFactory.setup_editor_group_with_editors(
        )

        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()))
    def setUp(self):
        super(TestTaskSuggestionBulkEdit, self).setUp()

        acc = models.Account()
        acc.set_id("0987654321")
        acc.set_email("*****@*****.**")
        acc.save()

        egs = EditorGroupFixtureFactory.make_editor_group_source("1234567890", "0987654321")
        egm = models.EditorGroup(**egs)
        egm.save(blocking=True)

        self.suggestions = []
        for app_src in ApplicationFixtureFactory.make_many_application_sources(count=TEST_SUGGESTION_COUNT):
            self.suggestions.append(models.Suggestion(**app_src))
            self.suggestions[-1].set_editor_group("1234567890")
            self.suggestions[-1].set_editor("0987654321")
            self.suggestions[-1].save()

        self.default_eg = EditorGroupFixtureFactory.setup_editor_group_with_editors()

        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()))
Exemple #5
0
    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() == "*****@*****.**"
Exemple #7
0
 def test_05_editor(self):
     eg = EditorGroupFixtureFactory.setup_editor_group_with_editors()
     self._make_and_push_test_context(acc=models.Account.pull('eddie'))
     newq = query_filters.editor(self.q)
     assert newq.as_dict() == {
         'query': {
             'filtered': {
                 'filter': {
                     'bool': {
                         'must': [{
                             'terms': {
                                 'admin.editor_group.exact': [eg.name]
                             }
                         }]
                     }
                 }
             }
         }
     }, newq.as_dict()
Exemple #8
0
    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
Exemple #10
0
    def test_01_editor_group_successful_assign(self):
        """Bulk assign an editor group to a bunch of suggestions using a background task"""
        new_eg = EditorGroupFixtureFactory.setup_editor_group_with_editors(
            group_name='Test Editor Group')

        # test dry run
        summary = suggestion_manage(
            {"query": {
                "terms": {
                    "_id": [s.id for s in self.suggestions]
                }
            }},
            editor_group=new_eg.name,
            dry_run=True)
        assert summary.as_dict().get("affected", {}).get(
            "applications") == TEST_SUGGESTION_COUNT, summary.as_dict()

        summary = suggestion_manage(
            {"query": {
                "terms": {
                    "_id": [s.id for s in self.suggestions]
                }
            }},
            editor_group=new_eg.name,
            dry_run=False)
        assert summary.as_dict().get("affected", {}).get(
            "applications") == TEST_SUGGESTION_COUNT, summary.as_dict()

        sleep(1)

        job = models.BackgroundJob.all()[0]

        modified_suggestions = [s.pull(s.id) for s in self.suggestions]

        for ix, s in enumerate(modified_suggestions):
            assert s.editor_group == new_eg.name, \
                "modified_suggestions[{}].editor_group is {}\n" \
                "Here is the BackgroundJob audit log:\n{}".format(
                    ix, s.editor_group, 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_01_editor_group_successful_assign(self):
        """Bulk assign an editor group to a bunch of suggestions using a background task"""
        new_eg = EditorGroupFixtureFactory.setup_editor_group_with_editors(group_name='Test Editor Group')

        # test dry run
        summary = suggestion_manage({"query": {"terms": {"_id": [s.id for s in self.suggestions]}}}, editor_group=new_eg.name, dry_run=True)
        assert summary.as_dict().get("affected", {}).get("applications") == TEST_SUGGESTION_COUNT, summary.as_dict()

        summary = suggestion_manage({"query": {"terms": {"_id": [s.id for s in self.suggestions]}}}, editor_group=new_eg.name, dry_run=False)
        assert summary.as_dict().get("affected", {}).get("applications") == TEST_SUGGESTION_COUNT, summary.as_dict()

        sleep(1)

        job = models.BackgroundJob.all()[0]

        modified_suggestions = [s.pull(s.id) for s in self.suggestions]

        for ix, s in enumerate(modified_suggestions):
            assert s.editor_group == new_eg.name, \
                "modified_suggestions[{}].editor_group is {}\n" \
                "Here is the BackgroundJob audit log:\n{}".format(
                    ix, s.editor_group, json.dumps(job.audit, indent=2)
                )
from nose.tools import assert_raises, assert_false

from portality import constants
from doajtest.fixtures import EditorGroupFixtureFactory, AccountFixtureFactory, ApplicationFixtureFactory, JournalFixtureFactory
from doajtest.helpers import DoajTestCase
from portality import models
from portality.background import BackgroundException
from portality.core import app
from portality.tasks import async_workflow_notifications

APPLICATION_SOURCE = ApplicationFixtureFactory.make_application_source()

JOURNAL_SOURCE_TEST_1 = JournalFixtureFactory.make_journal_source()
JOURNAL_SOURCE_TEST_2 = JournalFixtureFactory.make_journal_source()

EDITOR_GROUP_SOURCE = EditorGroupFixtureFactory.make_editor_group_source()
EDITOR_SOURCE = AccountFixtureFactory.make_editor_source()
ASSED1_SOURCE = AccountFixtureFactory.make_assed1_source()
ASSED2_SOURCE = AccountFixtureFactory.make_assed2_source()
ASSED3_SOURCE = AccountFixtureFactory.make_assed3_source()

#####################################################################
# Mocks required to make some of the lookups work
#####################################################################

@classmethod
def editor_group_pull_by_key(cls, field, value):
    eg = models.EditorGroup(**EDITOR_GROUP_SOURCE)
    return eg

@classmethod
Exemple #14
0
    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() == "*****@*****.**"
Exemple #15
0
 def test_05_editor(self):
     eg = EditorGroupFixtureFactory.setup_editor_group_with_editors()
     self._make_and_push_test_context(acc=models.Account.pull('eddie'))
     newq = query_filters.editor(self.q)
     assert newq.as_dict() == {'query': {'filtered': {'filter': {'bool': {'must': [{'terms': {'admin.editor_group.exact': [eg.name]}}]}}}}}, newq.as_dict()