Skip to content

Commit

Permalink
Throw an exception if organization is not valid
Browse files Browse the repository at this point in the history
  • Loading branch information
BenGalewsky committed Feb 6, 2024
1 parent 89e677a commit 599e8d9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
18 changes: 15 additions & 3 deletions aws/submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions aws/tests/submit_dataset.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions aws/tests/test_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 599e8d9

Please sign in to comment.