Skip to content

Commit

Permalink
workflows: feature flag for sending refs to legacy
Browse files Browse the repository at this point in the history
Signed-off-by: Micha Moskovic <michamos@gmail.com>
  • Loading branch information
michamos authored and turtle321 committed May 2, 2018
1 parent 5d5385e commit 3fc85bd
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
1 change: 1 addition & 0 deletions inspirehep/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
FEATURE_FLAG_ENABLE_MERGER = False
FEATURE_FLAG_ENABLE_UPDATE_TO_LEGACY = False
"""This feature flag will prevent to send a ``replace`` update to legacy."""
FEATURE_FLAG_ENABLE_SENDING_REFERENCES_TO_LEGACY = False

# Default language and timezone
# =============================
Expand Down
6 changes: 6 additions & 0 deletions inspirehep/modules/workflows/tasks/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import os
import logging
from copy import copy
from functools import wraps
from pprint import pformat

Expand Down Expand Up @@ -218,6 +219,11 @@ def _send_robotupload(obj, eng):
data = obj.extra_data.get(extra_data_key) or {}
else:
data = obj.data

if not current_app.config.get('FEATURE_FLAG_ENABLE_SENDING_REFERENCES_TO_LEGACY'):
data = copy(data)
data.pop('references', None)

marcxml = record2marcxml(data)

if current_app.debug:
Expand Down
122 changes: 122 additions & 0 deletions tests/unit/workflows/test_workflows_tasks_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,128 @@ def test_send_robotupload_does_nothing_when_not_in_production_mode():
assert _send_robotupload(obj, eng) is None


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

schema = load_schema('hep')
subschema = schema['properties']['references']

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

with patch.dict(current_app.config, config), \
patch('inspirehep.modules.workflows.tasks.submission.record2marcxml') as mock_record2marcxml:
data = {
'$schema': 'http://localhost:5000/schemas/records/hep.json',
'references': [
{
'raw_refs': [
{
'schema': 'text',
'value': '[1] J. Maldacena and A. Strominger, hep-th/9710014.',
},
],
},
]
}
data_without_references = {
'$schema': 'http://localhost:5000/schemas/records/hep.json',
}
extra_data = {}
assert validate(data['references'], subschema) is None

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

_send_robotupload = send_robotupload(
mode='insert',
)

assert _send_robotupload(obj, eng) is None
assert mock_record2marcxml.called_with(data_without_references)


def test_send_robotupload_works_doesnt_fail_when_removing_references_and_no_references():
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,
}

with patch.dict(current_app.config, config), \
patch('inspirehep.modules.workflows.tasks.submission.record2marcxml') as mock_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
assert mock_record2marcxml.called_with(data)


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

schema = load_schema('hep')
subschema = schema['properties']['references']

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

with patch.dict(current_app.config, config), \
patch('inspirehep.modules.workflows.tasks.submission.record2marcxml') as mock_record2marcxml:
data = {
'$schema': 'http://localhost:5000/schemas/records/hep.json',
'references': [
{
'raw_refs': [
{
'schema': 'text',
'value': '[1] J. Maldacena and A. Strominger, hep-th/9710014.',
},
],
},
]
}
extra_data = {}
assert validate(data['references'], subschema) is None

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

_send_robotupload = send_robotupload(
mode='insert',
)

assert _send_robotupload(obj, eng) is None
assert mock_record2marcxml.called_with(data) # includes references


def test_wait_webcoll_halts_the_workflow_engine_when_in_production_mode():
config = {'PRODUCTION_MODE': True}

Expand Down

0 comments on commit 3fc85bd

Please sign in to comment.