Skip to content

Commit

Permalink
Keep test submissions seperate from prod when testing for duplicate s…
Browse files Browse the repository at this point in the history
…ource ID
  • Loading branch information
BenGalewsky committed Jan 9, 2024
1 parent e811b43 commit 44ce70f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
9 changes: 8 additions & 1 deletion aws/submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,16 @@ def lambda_handler(event, context):

#
existing_source_name = metadata.get("mdf", {}).get("source_name", None)
print("++++++++existing_source+++++++", existing_source_name)

is_test = submission_conf["test"]

# Distinguish test sources from prod. Tack -test on the end of the provided
# name
if is_test and existing_source_name:
existing_source_name += "-test"

print("++++++++existing_source+++++++", existing_source_name)

if not existing_source_name:
source_name = str(uuid.uuid4())
existing_record = None
Expand Down
13 changes: 13 additions & 0 deletions aws/tests/submit_dataset.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ Feature: Submit Dataset
And an automate flow started
And I should receive a success result with the generated uuid and version 1.0

Scenario: Submit Test Dataset With Provided source_id
Given I'm authenticated with MDF
And I have a new MDF dataset to submit
And I provide the source_id
And I set the test flag to true
When I submit the dataset

Then a dynamo record should be created with the provided source_id modified to indicate test
And the dynamo record should be version 1.0
And an automate flow started
And I should receive a success result with test source-id, the generated uuid and version 1.0


Scenario: Attempt to update another users record
Given I'm authenticated with MDF
And I have an update to another users record
Expand Down
32 changes: 31 additions & 1 deletion aws/tests/test_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
def test_publish_provided_source_id():
pass

@scenario('submit_dataset.feature', 'Submit Test Dataset With Provided source_id')
def test_publish_provided_source_id_test():
pass

@scenario('submit_dataset.feature', 'Submit Dataset')
def test_submit():
pass
Expand Down Expand Up @@ -72,6 +76,10 @@ def provided_source_id(mdf, mdf_environment):
mdf_environment['source_id'] = 'my dataset'
return mdf.get_submission()

@given("I set the test flag to true", target_fixture='mdf_submission')
def set_test_flag(mdf):
mdf.test=True
return mdf.get_submission()

@given('I have a new MDF dataset to submit for an organization that mints DOIs',
target_fixture='mdf_submission')
Expand Down Expand Up @@ -141,11 +149,21 @@ def no_error(submit_result, mdf_environment):

@then(parsers.parse('I should receive a success result with the generated uuid and version {version}'))
def no_error_with_version(submit_result, mdf_environment, version):
verify_success_result(submit_result, mdf_environment, version, is_test=False)

@then(parsers.parse('I should receive a success result with test source-id, the generated uuid and version {version}'))
def no_error_test_submission_with_version(submit_result, mdf_environment, version):
verify_success_result(submit_result, mdf_environment, version, is_test=True)

def verify_success_result(submit_result, mdf_environment, version, is_test=False):
print("---------->", submit_result)
assert submit_result['statusCode'] == 202
body = json.loads(submit_result['body'])
assert body['success']
assert body['source_id'] == mdf_environment['source_id']
if is_test:
assert body['source_id'] == mdf_environment['source_id']+"-test"
else:
assert body['source_id'] == mdf_environment['source_id']
assert body['version'] == version


Expand Down Expand Up @@ -218,3 +236,15 @@ def previous_versions_field_empty(dynamo_record):
@then("the previous_versions field should be ['my dataset-1.0']")
def previous_versions_after_update(dynamo_record):
assert dynamo_record['previous_versions'] == ['my dataset-1.0']


@then(
"a dynamo record should be created with the provided source_id modified to indicate test", target_fixture="dynamo_record")
def verify_test_source_id(mdf_environment):
dynamo_manager = mdf_environment['dynamo_manager']
dynamo_manager.create_status.assert_called()
dynamo_record = dynamo_manager.create_status.call_args[0][0]
print(dynamo_record)
assert dynamo_record['source_id'] == mdf_environment['source_id']+"-test"
assert dynamo_record['action_id'] == 'action-id-1'
return dynamo_record

0 comments on commit 44ce70f

Please sign in to comment.