def create_story(event): # get nest so we know it exists first nest = Nest.get(event["arguments"]["nestId"], 'NEST') story = Story(event["arguments"]["nestId"], f'STORY.{ulid.new().int >> 64}', title=event["arguments"]["title"], description=event["arguments"].get("descritpion", ''), owner=event["arguments"].get("owner") or (event["identity"] or {}).get("username"), status=event["arguments"].get("status", "TODO") or "TODO", sprint=event["arguments"].get("sprint", -1) or -1) story.save() return nest.to_dict() # Return Nest for UI simplification
class BaseTest(TestCase): """ Base Test class used to set up the Mock DynamoDB table used for unit testing """ def setUp(self): """ Setup mock dynamodb table and base configuration""" # base event config self.event = { "identity": { "username": "******" }, "info": {}, "arguments": {} } # dynamodb table self.dynamodb = boto3.resource('dynamodb', region_name='us-east-1') self.table = self.dynamodb.create_table(TableName='scrumnest-dev', KeySchema=[{ 'AttributeName': 'nestId', 'KeyType': 'HASH' }, { 'AttributeName': 'nestComponent', 'KeyType': 'RANGE' }], AttributeDefinitions=[{ 'AttributeName': 'nestId', 'AttributeType': 'S' }, { 'AttributeName': 'nestComponent', 'AttributeType': 'S' }], ProvisionedThroughput={ 'ReadCapacityUnits': 1, 'WriteCapacityUnits': 1 }) self.table.meta.client.get_waiter('table_exists').wait( TableName='scrumnest-dev') self.nest = Nest('abc123', 'NEST', name='Test Nest', owner='test_admin', users=[{ 'username': '******', 'email': '*****@*****.**' }, { 'username': '******', 'email': '*****@*****.**' }]) self.nest.save() self.story1 = Story('abc123', 'STORY.123', title='test story 1', owner='test_admin') self.story1.save() def tearDown(self): """ Delete database resources and mock table """ self.table.delete() self.dynamodb = None