def mock_dynamodb()

in api/conftest.py [0:0]


def mock_dynamodb():

    ddb_mock().start()

    session = Session(aws_access_key_id='<ACCESS_KEY_ID>', aws_secret_access_key='<SECRET_KEY>')
    dynamodb = session.resource('dynamodb')

    wheel_table = dynamodb.create_table(
        TableName=WHEEL_TABLE_NAME,
        KeySchema=[
            {
                'AttributeName': 'id',
                'KeyType': 'HASH'
            }
        ],
        AttributeDefinitions=[
            {
                'AttributeName': 'id',
                'AttributeType': 'S'
            },
            {
                'AttributeName': 'name',
                'AttributeType': 'S'
            }
        ],
        BillingMode='PAY_PER_REQUEST',
        GlobalSecondaryIndexes=[{
            'IndexName': 'name_index',
            'KeySchema': [{
                'AttributeName': 'name',
                'KeyType': 'HASH'
            }],
            'Projection': {
                'ProjectionType': 'ALL'
            }
          }]
    )

    participant_table = dynamodb.create_table(
        TableName=PARTICIPANT_TABLE_NAME,
        KeySchema=[
            {
                'AttributeName': 'wheel_id',
                'KeyType': 'HASH'
            },
            {
                'AttributeName': 'id',
                'KeyType': 'RANGE'
            }
        ],
        AttributeDefinitions=[
            {
                'AttributeName': 'wheel_id',
                'AttributeType': 'S'
            },
            {
                'AttributeName': 'id',
                'AttributeType': 'S'
            }
        ],
        BillingMode='PAY_PER_REQUEST'
    )

    #  Wait on table creation
    wheel_table.meta.client.get_waiter('table_exists').wait(TableName=WHEEL_TABLE_NAME)
    participant_table.meta.client.get_waiter('table_exists').wait(TableName=PARTICIPANT_TABLE_NAME)

    yield dynamodb

    ddb_mock().stop()