-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more general development on annotations and annotation testing
- Loading branch information
1 parent
4f736c8
commit 99e71d1
Showing
23 changed files
with
703 additions
and
342 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from portality.annotation.annotator import Annotator | ||
|
||
class AnnotatorsMockFactory(object): | ||
@classmethod | ||
def mock_annotator(cls): | ||
return MockAnnotator | ||
|
||
|
||
class MockAnnotator(Annotator): | ||
__identity__ = "mock_annotator" | ||
|
||
def annotate(self, form, | ||
jla, | ||
annotations, | ||
resources, | ||
logger): | ||
annotations.add_annotation(field="pissn", | ||
original_value="1234-5678", | ||
suggested_value="9876-5432", | ||
advice="Change the issn", | ||
reference_url="http://example.com/9876-5432") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,34 @@ | ||
from doajtest.fixtures.resources import ResourcesFixtureFactory | ||
|
||
from portality.annotation.resource_bundle import ResourceUnavailable | ||
|
||
|
||
class ResourceBundleResourceMockFactory(object): | ||
@classmethod | ||
def no_contact_resource_fetch(cls): | ||
def no_contact_resource_fetch(cls, version=None): | ||
def mock(self, *args, **kwargs): | ||
if self.__identity__ == "issn_org": | ||
issn = None | ||
if "issn" in kwargs: | ||
issn = kwargs["issn"] | ||
if len(args) > 0: | ||
issn = args[0] | ||
return ResourcesFixtureFactory.issn_org(issn=issn) | ||
return ResourcesFixtureFactory.issn_org(issn=issn, version=version) | ||
|
||
return None | ||
|
||
return mock | ||
|
||
@classmethod | ||
def fail_fetch(cls): | ||
def mock(self, *args, **kwargs): | ||
raise ResourceUnavailable() | ||
|
||
return mock | ||
|
||
@classmethod | ||
def not_found_fetch(cls): | ||
def mock(self, *args, **kwargs): | ||
return None | ||
|
||
return mock |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from doajtest.helpers import DoajTestCase | ||
from doajtest.fixtures import ApplicationFixtureFactory | ||
from doajtest.mocks.annotation_resource_bundle_Resource import ResourceBundleResourceMockFactory | ||
|
||
from portality.annotation.annotators.issn_active import ISSNActive | ||
from portality import models | ||
from portality.annotation.resource_bundle import Resource, ResourceBundle | ||
|
||
import responses # mocks for the requests library | ||
|
||
|
||
class TestISSNOrg(DoajTestCase): | ||
def setUp(self): | ||
super(TestISSNOrg, self).setUp() | ||
|
||
def tearDown(self): | ||
super(TestISSNOrg, self).tearDown() | ||
|
||
@responses.activate | ||
def test_01_issn_fetch_fail(self): | ||
Resource.fetch = ResourceBundleResourceMockFactory.fail_fetch() | ||
|
||
issn_active = ISSNActive() | ||
|
||
form = { | ||
"pissn": "1234-5678", | ||
"eissn": "9876-5432" | ||
} | ||
|
||
source = ApplicationFixtureFactory.make_application_source() | ||
app = models.Application(**source) | ||
|
||
annotations = models.Annotation() | ||
resources = ResourceBundle() | ||
|
||
issn_active.annotate(form, app, annotations, resources, logger=lambda x: x) | ||
|
||
assert len(annotations.annotations) == 2 | ||
for anno in annotations.annotations: | ||
assert anno.get("advice") == issn_active.UNABLE_TO_ACCESS |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
from doajtest.helpers import DoajTestCase | ||
from doajtest.fixtures import ApplicationFixtureFactory | ||
from doajtest.mocks.annotation_resource_bundle_Resource import ResourceBundleResourceMockFactory | ||
|
||
from portality.annotation.annotators.issn_active import ISSNActive | ||
from portality import models | ||
from portality.annotation.resource_bundle import Resource, ResourceBundle | ||
|
||
|
||
class TestISSNActive(DoajTestCase): | ||
def setUp(self): | ||
self.old_fetch = Resource.fetch | ||
super(TestISSNActive, self).setUp() | ||
|
||
def tearDown(self): | ||
Resource.fetch = self.old_fetch | ||
super(TestISSNActive, self).tearDown() | ||
|
||
def test_01_issn_fetch_fail(self): | ||
Resource.fetch = ResourceBundleResourceMockFactory.fail_fetch() | ||
|
||
issn_active = ISSNActive() | ||
|
||
form = { | ||
"pissn": "1234-5678", | ||
"eissn": "9876-5432" | ||
} | ||
|
||
source = ApplicationFixtureFactory.make_application_source() | ||
app = models.Application(**source) | ||
|
||
annotations = models.Annotation() | ||
resources = ResourceBundle() | ||
|
||
issn_active.annotate(form, app, annotations, resources, logger=lambda x: x) | ||
|
||
assert len(annotations.annotations) == 2 | ||
for anno in annotations.annotations: | ||
assert anno.get("advice") == issn_active.UNABLE_TO_ACCESS | ||
|
||
def test_02_not_found(self): | ||
Resource.fetch = ResourceBundleResourceMockFactory.not_found_fetch() | ||
|
||
issn_active = ISSNActive() | ||
|
||
form = { | ||
"pissn": "1234-5678", | ||
"eissn": "9876-5432" | ||
} | ||
|
||
source = ApplicationFixtureFactory.make_application_source() | ||
app = models.Application(**source) | ||
|
||
annotations = models.Annotation() | ||
resources = ResourceBundle() | ||
|
||
issn_active.annotate(form, app, annotations, resources, logger=lambda x: x) | ||
|
||
assert len(annotations.annotations) == 2 | ||
for anno in annotations.annotations: | ||
assert anno.get("advice") == issn_active.NOT_FOUND | ||
|
||
def test_03_fully_validated(self): | ||
Resource.fetch = ResourceBundleResourceMockFactory.no_contact_resource_fetch(version="Register") | ||
|
||
issn_active = ISSNActive() | ||
|
||
form = { | ||
"pissn": "1234-5678", | ||
"eissn": "9876-5432" | ||
} | ||
|
||
source = ApplicationFixtureFactory.make_application_source() | ||
app = models.Application(**source) | ||
|
||
annotations = models.Annotation() | ||
resources = ResourceBundle() | ||
|
||
issn_active.annotate(form, app, annotations, resources, logger=lambda x: x) | ||
|
||
assert len(annotations.annotations) == 2 | ||
for anno in annotations.annotations: | ||
assert anno.get("advice") == issn_active.FULLY_VALIDATED | ||
|
||
def test_04_not_validated(self): | ||
Resource.fetch = ResourceBundleResourceMockFactory.no_contact_resource_fetch(version="Pending") | ||
|
||
issn_active = ISSNActive() | ||
|
||
form = { | ||
"pissn": "1234-5678", | ||
"eissn": "9876-5432" | ||
} | ||
|
||
source = ApplicationFixtureFactory.make_application_source() | ||
app = models.Application(**source) | ||
|
||
annotations = models.Annotation() | ||
resources = ResourceBundle() | ||
|
||
issn_active.annotate(form, app, annotations, resources, logger=lambda x: x) | ||
|
||
assert len(annotations.annotations) == 2 | ||
for anno in annotations.annotations: | ||
assert anno.get("advice") == issn_active.NOT_VALIDATED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import time | ||
|
||
from portality import constants | ||
from doajtest.helpers import DoajTestCase | ||
from portality.core import app | ||
from portality import models | ||
from portality.tasks.application_annotations import ApplicationAnnotations | ||
from portality.background import BackgroundApi | ||
from portality.bll import DOAJ | ||
|
||
from doajtest.fixtures import ApplicationFixtureFactory, JournalFixtureFactory | ||
from doajtest.mocks.annotation_resource_bundle_Resource import ResourceBundleResourceMockFactory | ||
from doajtest.mocks.annotation_annotators import AnnotatorsMockFactory | ||
|
||
from portality.annotation.resource_bundle import Resource | ||
|
||
|
||
class TestBLLAnnotations(DoajTestCase): | ||
|
||
def setUp(self): | ||
mock_fetch = ResourceBundleResourceMockFactory.no_contact_resource_fetch() | ||
self.old_fetch = Resource.fetch | ||
Resource.fetch = mock_fetch | ||
|
||
super(TestBLLAnnotations, self).setUp() | ||
|
||
def tearDown(self): | ||
Resource.fetch = self.old_fetch | ||
super(TestBLLAnnotations, self).tearDown() | ||
|
||
def test_01_annotate_application(self): | ||
source = ApplicationFixtureFactory.make_application_source() | ||
application = models.Application(**source) | ||
application.save(blocking=True) | ||
|
||
ma = AnnotatorsMockFactory.mock_annotator() | ||
anno_svc = DOAJ.annotationsService([(True, True, ma)]) | ||
anno_svc.annotate_application(application) | ||
|
||
time.sleep(2) | ||
|
||
application = models.Application.pull(application.id) | ||
annotation = models.Annotation.for_application(application.id) | ||
|
||
# assert application.application_status == constants.APPLICATION_STATUS_PENDING | ||
assert annotation is not None | ||
assert annotation.application == application.id | ||
assert len(annotation.annotations) == 1 | ||
|
||
def test_01_annotate_journal(self): | ||
source = JournalFixtureFactory.make_journal_source() | ||
journal = models.Journal(**source) | ||
journal.save(blocking=True) | ||
|
||
ma = AnnotatorsMockFactory.mock_annotator() | ||
anno_svc = DOAJ.annotationsService([(True, True, ma)]) | ||
anno_svc.annotate_journal(journal) | ||
|
||
time.sleep(2) | ||
|
||
journal = models.Journal.pull(journal.id) | ||
annotation = models.Annotation.for_journal(journal.id) | ||
|
||
# assert application.application_status == constants.APPLICATION_STATUS_PENDING | ||
assert annotation is not None | ||
assert annotation.journal == journal.id | ||
assert len(annotation.annotations) == 1 | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.