Example #1
0
def test_LocalSecondaryIndexes_result():
    mock_request = immutable(
        hash_key={
            'name': 'main_hash_key',
            'type': 'S'
        },
        lsi=[dict(
            name='gs_index',
            range_key={
                'name': 'type',
                'type': 'S'
            },
        )])

    expected = [{
        'IndexName':
        'gs_index',
        'KeySchema': [{
            'AttributeName': 'main_hash_key',
            'KeyType': 'HASH'
        }, {
            'AttributeName': 'type',
            'KeyType': 'RANGE'
        }],
        'Projection': {
            'ProjectionType': 'ALL'
        }
    }]

    result = args.LocalSecondaryIndexes(mock_request)

    assertObjectsEqual(result, expected)
Example #2
0
def test_query_builds_basic_description():
    result = query(table_name='users',
                   conditions=attr('username').equals('sunshie'))
    expected = {
        'TableName': 'users',
        'KeyConditionExpression': 'username = :username',
        'ExpressionAttributeValues': {
            ':username': {
                'S': 'sunshie'
            }
        }
    }
    assertObjectsEqual(result.description, expected)
Example #3
0
def test_deep_strip_Decimals():

    result = strip_Decimals({
        'a': decimal.Decimal(30),
        'b': None,
        'c': [decimal.Decimal(30), 'x'],
        'd': {
            'r': decimal.Decimal(30.30)
        }
    })

    expected = {'a': 30, 'b': None, 'c': [30, 'x'], 'd': {'r': 30.30}}

    assertObjectsEqual(result, expected)
Example #4
0
def test_query_builds_aliased_attr_description():
    result = query(table_name='users', conditions=attr('item').equals('carl'))
    expected = {
        'TableName': 'users',
        'KeyConditionExpression': '#item = :item',
        'ExpressionAttributeNames': {
            '#item': 'item'
        },
        'ExpressionAttributeValues': {
            ':item': {
                'S': 'carl'
            }
        }
    }
    assertObjectsEqual(result.description, expected)
Example #5
0
def test_KeySchema_uses_hash_and_range():
    mock_request = immutable(hash_key={
        'name': 'id',
        'type': 'S'
    },
                             range_key={
                                 'name': 'type',
                                 'type': 'S'
                             })

    expected = [{
        'AttributeName': 'id',
        'KeyType': 'HASH'
    }, {
        'AttributeName': 'type',
        'KeyType': 'RANGE'
    }]

    result = args.KeySchema(mock_request)

    assertObjectsEqual(result, expected)
Example #6
0
def test_GlobalSecondaryIndexes_result():
    mock_request = immutable(gsi=[
        dict(
            name='gs_index',
            hash_key={
                'name': 'other',
                'type': 'S'
            },
            range_key={
                'name': 'type',
                'type': 'S'
            },
        )
    ])

    expected = [{
        'IndexName':
        'gs_index',
        'KeySchema': [{
            'AttributeName': 'other',
            'KeyType': 'HASH'
        }, {
            'AttributeName': 'type',
            'KeyType': 'RANGE'
        }],
        'Projection': {
            'ProjectionType': 'ALL'
        },
        'ProvisionedThroughput': {
            'ReadCapacityUnits': 10,
            'WriteCapacityUnits': 10
        }
    }]

    result = args.GlobalSecondaryIndexes(mock_request)

    assertObjectsEqual(result, expected)
Example #7
0
def test_description_builds_correct_description():
    result = describe(table_name='users')
    expected = {
        'TableName': 'users'
    }
    assertObjectsEqual(result.description, expected)
Example #8
0
def test_scan_builds_basic_description():
    result = scan(table_name='users')
    expected = {
        'TableName': 'users'
    }
    assertObjectsEqual(result.description, expected)