Last active
May 22, 2022 07:02
-
-
Save sats17/007f2a04c70bad18819b7b631ffe9817 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
import boto3 | |
import os | |
from moto import mock_dynamodb | |
from unittest.mock import patch | |
@mock_dynamodb # Decorator applied to whole class. This will provides mock for each dynamodb calls which creates inside this class. | |
@patch.dict(os.environ, { | |
"AWS_REGION": "us-east-1", | |
"anime_table_name": 'anime_info'}) | |
class LambdaFunctionTest(unittest.TestCase): | |
def setUp(self) -> None: | |
print("Setup invoked for testing suite") | |
self.dynamodb = boto3.resource('dynamodb', 'us-east-1') | |
anime_table_name = 'anime_info' | |
self.dynamodb.create_table(TableName=anime_table_name, | |
KeySchema=anime_table_data['KeySchema'], | |
AttributeDefinitions=anime_table_data['AttributeDefinitions'], | |
ProvisionedThroughput=anime_table_data['ProvisionedThroughput'] | |
) | |
self.registration_status_table = self.dynamodb.Table(anime_table_name) | |
def tearDown(self) -> None: | |
print("Tearing down resources") | |
self.registration_status_table.delete() | |
anime_table_data = { | |
'KeySchema': [{ | |
'AttributeName': 'anime_name', | |
'KeyType': 'HASH' | |
} | |
], | |
'AttributeDefinitions': [ | |
{ | |
'AttributeName': 'anime_name', | |
'AttributeType': 'S' | |
} | |
], | |
'ProvisionedThroughput': { | |
'ReadCapacityUnits': 1, | |
'WriteCapacityUnits': 1 | |
} | |
} | |
user_table_data = { | |
'KeySchema': [{ | |
'AttributeName': 'user_id', | |
'KeyType': 'HASH' | |
}, | |
{ | |
'AttributeName': 'registration_id', | |
'KeyType': 'RANGE' | |
} | |
], | |
'AttributeDefinitions': [ | |
{ | |
'AttributeName': 'user_id', | |
'AttributeType': 'S' | |
}, | |
{ | |
'AttributeName': 'registration_id', | |
'AttributeType': 'S' | |
} | |
], | |
'ProvisionedThroughput': { | |
'ReadCapacityUnits': 1, | |
'WriteCapacityUnits': 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment