From 599e8d90159a8a4e4e33c8fc8e4008d8ced1577c Mon Sep 17 00:00:00 2001 From: Ben Galewsky Date: Tue, 6 Feb 2024 14:49:43 -0600 Subject: [PATCH] Throw an exception if organization is not valid --- aws/submit.py | 18 +++++++++++++++--- aws/tests/submit_dataset.feature | 7 +++++++ aws/tests/test_submit.py | 8 ++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/aws/submit.py b/aws/submit.py index 5c277ee..2ee72c4 100644 --- a/aws/submit.py +++ b/aws/submit.py @@ -10,7 +10,7 @@ from automate_manager import AutomateManager from dynamo_manager import DynamoManager -from organization import Organization +from organization import Organization, OrganizationException from source_id_manager import SourceIDManager from utils import get_secret @@ -115,13 +115,25 @@ def lambda_handler(event, context): print("+++Metadata+++", metadata) org_cannonical_name = metadata.get("mdf", {}).get("organization", "MDF Open") + # MDF Connect Client needs to only allow one organization. Til then, we just # take the first one if type(org_cannonical_name) == list: org_cannonical_name = org_cannonical_name[0] - organization = Organization.from_schema_repo(org_cannonical_name) - print("######", organization) + try: + organization = Organization.from_schema_repo(org_cannonical_name) + print("######", organization) + except OrganizationException as e: + return { + 'statusCode': 400, + 'body': json.dumps( + { + "success": False, + "error": f"Organization: {org_cannonical_name} not found" + }) + } + # Validate input JSON # resourceType is always going to be Dataset, don't require from user diff --git a/aws/tests/submit_dataset.feature b/aws/tests/submit_dataset.feature index 8d6cca3..d27aba9 100644 --- a/aws/tests/submit_dataset.feature +++ b/aws/tests/submit_dataset.feature @@ -96,3 +96,10 @@ Feature: Submit Dataset And an automate flow started with a true mint DOI flag And the data destination should be the Petrel MDF directory And I should receive a success result with the generated uuid and version 1.0 + + + Scenario: Submit Dataset with invalid organization + Given I'm authenticated with MDF + And I have a new MDF dataset to submit for an organization that does not exist + When I submit the dataset + Then I should receive a failure result \ No newline at end of file diff --git a/aws/tests/test_submit.py b/aws/tests/test_submit.py index 7f68c38..f657cb0 100644 --- a/aws/tests/test_submit.py +++ b/aws/tests/test_submit.py @@ -21,6 +21,10 @@ def test_submit(): def test_update_other_users_record(): pass +@scenario('submit_dataset.feature', 'Submit Dataset with invalid organization') +def test_invalid_organization(): + pass + @scenario('submit_dataset.feature', 'Attempt to add a record with an existing source_id') def test_add_record_with_existing_source_id(): @@ -105,6 +109,10 @@ def mdf_datset(mdf, mdf_environment, mocker): return mdf.get_submission() +@given("I have a new MDF dataset to submit for an organization that does not exist", target_fixture='mdf_submission') +def invalid_org(mdf, mdf_environment): + mdf.set_organization("Not A Valid Organization") + return mdf.get_submission() @given('I have a new MDF dataset to submit with a source_id that already exists', target_fixture='mdf_submission')