Skip to content

Commit

Permalink
workflows: exclude authors from feature flag
Browse files Browse the repository at this point in the history
Signed-off-by: Harris Tzovanakis <[email protected]>
  • Loading branch information
drjova authored and david-caro committed May 2, 2018
1 parent 65c4c83 commit 90c2063
Show file tree
Hide file tree
Showing 4 changed files with 303 additions and 4 deletions.
3 changes: 2 additions & 1 deletion inspirehep/modules/workflows/tasks/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ def send_robotupload(
@wraps(send_robotupload)
def _send_robotupload(obj, eng):
is_update = obj.extra_data.get('is-update')
is_article = obj.workflow.name == 'article'

if is_update and not current_app.config.get('FEATURE_FLAG_ENABLE_UPDATE_TO_LEGACY', False):
if is_article and is_update and not current_app.config.get('FEATURE_FLAG_ENABLE_UPDATE_TO_LEGACY', False):
obj.log.info(
'skipping upload to legacy, feature flag ``FEATURE_FLAG_ENABLE_UPDATE_TO_LEGACY`` is disabled.')
return
Expand Down
3 changes: 2 additions & 1 deletion inspirehep/modules/workflows/tasks/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ def _get_updated_record(obj):
return updated_record

is_update = obj.extra_data.get('is-update')
is_article = obj.workflow.name == 'article'

if is_update:
if not current_app.config.get('FEATURE_FLAG_ENABLE_MERGER', False):
if is_article and not current_app.config.get('FEATURE_FLAG_ENABLE_MERGER', False):
obj.log.info(
'skipping update record, feature flag ``FEATURE_FLAG_ENABLE_MERGER`` is disabled.'
)
Expand Down
5 changes: 4 additions & 1 deletion tests/integration/workflows/test_workflows_tasks_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
from flask import current_app

from invenio_workflows import workflow_object_class
from invenio_workflows.models import Workflow


# FIXME: otherwise this task is not found by Celery.
from inspirehep.modules.orcid.tasks import orcid_push # noqa: F401
Expand All @@ -40,6 +42,7 @@ def test_store_record_does_not_raise_in_the_orcid_receiver(mock_attempt_push, ap
}

with patch.dict(current_app.config, config):
workflow_obj = Workflow(name='article')
obj = workflow_object_class.create({
'$schema': 'http://localhost:5000/schemas/records/hep.json',
'_collections': [
Expand All @@ -62,6 +65,6 @@ def test_store_record_does_not_raise_in_the_orcid_receiver(mock_attempt_push, ap
'titles': [
{'title': 'title'},
],
})
}, workflow=workflow_obj)

store_record(obj, None) # Does not raise.
296 changes: 295 additions & 1 deletion tests/unit/workflows/test_workflows_tasks_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
wait_webcoll,
)

from mocks import MockEng, MockObj, MockUser
from mocks import MockEng, MockObj, MockUser, MockWorkflow


@patch('inspirehep.modules.workflows.tasks.submission.User')
Expand Down Expand Up @@ -747,3 +747,297 @@ def test_prepare_keywords_does_nothing_if_no_keywords_were_predicted():

assert validate(result['keywords'], subschema) is None
assert expected == result['keywords']


def test_send_robotupload_new_authors_when_feature_flag_is_disabled():
with requests_mock.Mocker() as requests_mocker:
requests_mocker.register_uri(
'POST', 'http://inspirehep.net/batchuploader/robotupload/insert',
text='[INFO] foo bar baz'
)

config = {
'LEGACY_ROBOTUPLOAD_URL': 'http://inspirehep.net',
'PRODUCTION_MODE': True,
'FEATURE_FLAG_ENABLE_UPDATE_TO_LEGACY': False
}

with patch.dict(current_app.config, config), \
patch('inspirehep.modules.workflows.tasks.submission.record2marcxml'):
data = {
'$schema': 'http://localhost:5000/schemas/records/authors.json',
'name': {
'preferred_name': 'Jessica Jones',
'value': 'Jones, Jessica'
}
}
extra_data = {}

obj = MockObj(data, extra_data)
obj.workflow = MockWorkflow('author')
eng = MockEng()

_send_robotupload = send_robotupload(
mode='insert',
)

assert _send_robotupload(obj, eng) is None

expected = (
'Robotupload sent!'
'[INFO] foo bar baz'
'end of upload'
)
result = obj.log._info.getvalue()

assert expected == result


def test_send_robotupload_update_authors_when_feature_flag_is_disabled():
with requests_mock.Mocker() as requests_mocker:
requests_mocker.register_uri(
'POST', 'http://inspirehep.net/batchuploader/robotupload/insert',
text='[INFO] foo bar baz'
)

config = {
'LEGACY_ROBOTUPLOAD_URL': 'http://inspirehep.net',
'PRODUCTION_MODE': True,
'FEATURE_FLAG_ENABLE_UPDATE_TO_LEGACY': False
}

with patch.dict(current_app.config, config), \
patch('inspirehep.modules.workflows.tasks.submission.record2marcxml'):
data = {
'$schema': 'http://localhost:5000/schemas/records/authors.json',
'name': {
'preferred_name': 'Jessica Jones',
'value': 'Jones, Jessica'
}
}
extra_data = {
'is-update': True
}

obj = MockObj(data, extra_data)
obj.workflow = MockWorkflow('author')
eng = MockEng()

_send_robotupload = send_robotupload(
mode='insert',
)

assert _send_robotupload(obj, eng) is None

expected = (
'Robotupload sent!'
'[INFO] foo bar baz'
'end of upload'
)
result = obj.log._info.getvalue()

assert expected == result


def test_send_robotupload_new_authors_when_feature_flag_is_enabled():
with requests_mock.Mocker() as requests_mocker:
requests_mocker.register_uri(
'POST', 'http://inspirehep.net/batchuploader/robotupload/insert',
text='[INFO] foo bar baz'
)

config = {
'LEGACY_ROBOTUPLOAD_URL': 'http://inspirehep.net',
'PRODUCTION_MODE': True,
'FEATURE_FLAG_ENABLE_UPDATE_TO_LEGACY': True
}

with patch.dict(current_app.config, config), \
patch('inspirehep.modules.workflows.tasks.submission.record2marcxml'):
data = {
'$schema': 'http://localhost:5000/schemas/records/authors.json',
'name': {
'preferred_name': 'Jessica Jones',
'value': 'Jones, Jessica'
}
}
extra_data = {
'is-update': True
}

obj = MockObj(data, extra_data)
obj.workflow = MockWorkflow('author')
eng = MockEng()

_send_robotupload = send_robotupload(
mode='insert',
)

assert _send_robotupload(obj, eng) is None

expected = (
'Robotupload sent!'
'[INFO] foo bar baz'
'end of upload'
)
result = obj.log._info.getvalue()

assert expected == result


def test_send_robotupload_update_authors_when_feature_flag_is_enabled():
with requests_mock.Mocker() as requests_mocker:
requests_mocker.register_uri(
'POST', 'http://inspirehep.net/batchuploader/robotupload/insert',
text='[INFO] foo bar baz'
)

config = {
'LEGACY_ROBOTUPLOAD_URL': 'http://inspirehep.net',
'PRODUCTION_MODE': True,
'FEATURE_FLAG_ENABLE_UPDATE_TO_LEGACY': True
}

with patch.dict(current_app.config, config), \
patch('inspirehep.modules.workflows.tasks.submission.record2marcxml'):
data = {
'$schema': 'http://localhost:5000/schemas/records/authors.json',
'name': {
'preferred_name': 'Jessica Jones',
'value': 'Jones, Jessica'
}
}
extra_data = {
'is-update': True
}

obj = MockObj(data, extra_data)
obj.workflow = MockWorkflow('author')
eng = MockEng()

_send_robotupload = send_robotupload(
mode='insert',
)

assert _send_robotupload(obj, eng) is None

expected = (
'Robotupload sent!'
'[INFO] foo bar baz'
'end of upload'
)
result = obj.log._info.getvalue()

assert expected == result


def test_send_robotupload_new_article_when_feature_flag_is_disabled():
with requests_mock.Mocker() as requests_mocker:
requests_mocker.register_uri(
'POST', 'http://inspirehep.net/batchuploader/robotupload/insert',
text='[INFO] foo bar baz'
)

config = {
'LEGACY_ROBOTUPLOAD_URL': 'http://inspirehep.net',
'PRODUCTION_MODE': True,
'FEATURE_FLAG_ENABLE_UPDATE_TO_LEGACY': False
}

with patch.dict(current_app.config, config), \
patch('inspirehep.modules.workflows.tasks.submission.record2marcxml'):
data = {
'$schema': 'http://localhost:5000/schemas/records/hep.json',
}

extra_data = {}

obj = MockObj(data, extra_data)
eng = MockEng()

_send_robotupload = send_robotupload(
mode='insert',
)

assert _send_robotupload(obj, eng) is None

expected = (
'Robotupload sent!'
'[INFO] foo bar baz'
'end of upload'
)
result = obj.log._info.getvalue()

assert expected == result


def test_send_robotupload_update_article_when_feature_flag_is_disabled():
config = {
'LEGACY_ROBOTUPLOAD_URL': 'http://inspirehep.net',
'PRODUCTION_MODE': True,
'FEATURE_FLAG_ENABLE_UPDATE_TO_LEGACY': False
}

with patch.dict(current_app.config, config), \
patch('inspirehep.modules.workflows.tasks.submission.record2marcxml'):
data = {
'$schema': 'http://localhost:5000/schemas/records/hep.json',
}

extra_data = {
'is-update': True
}

obj = MockObj(data, extra_data)
eng = MockEng()

_send_robotupload = send_robotupload(
mode='insert',
)

expected_log = 'skipping upload to legacy, feature flag ``FEATURE_FLAG_ENABLE_UPDATE_TO_LEGACY`` is disabled.'

assert _send_robotupload(obj, eng) is None
assert expected_log in obj.log._info.getvalue()


def test_send_robotupload_update_article_when_feature_flag_is_enabled():
with requests_mock.Mocker() as requests_mocker:
requests_mocker.register_uri(
'POST', 'http://inspirehep.net/batchuploader/robotupload/insert',
text='[INFO] foo bar baz'
)

config = {
'LEGACY_ROBOTUPLOAD_URL': 'http://inspirehep.net',
'PRODUCTION_MODE': True,
'FEATURE_FLAG_ENABLE_UPDATE_TO_LEGACY': True
}

with patch.dict(current_app.config, config), \
patch('inspirehep.modules.workflows.tasks.submission.record2marcxml'):
data = {
'$schema': 'http://localhost:5000/schemas/records/hep.json',
}

extra_data = {
'is-update': True
}

obj = MockObj(data, extra_data)
eng = MockEng()

_send_robotupload = send_robotupload(
mode='insert',
)

assert _send_robotupload(obj, eng) is None

expected = (
'Robotupload sent!'
'[INFO] foo bar baz'
'end of upload'
)
result = obj.log._info.getvalue()

assert expected == result

0 comments on commit 90c2063

Please sign in to comment.