Exemplo n.º 1
0
def setup_test_tables():
    print('####################################')
    print('Creating tables for integration test')
    print('####################################')
    db_func(create(
        table_name='users',
        hash_key='username'))
Exemplo n.º 2
0
def test_scan_gets_all_items(db):

    db(create(table_name='it_companies', hash_key='name'))

    add_company = lambda name: db(
        add(table_name='it_companies', item={'name': name}))

    scanners = ['Apple', 'Microsoft', 'Google', 'Tesla', 'IBM', 'GM']

    for x in scanners:
        add_company(x)

    results = db(scan(table_name='it_companies')).items()

    assert len(results) == len(scanners)
Exemplo n.º 3
0
def test_update_list_by_append(db):

    db(create(table_name='funcs', hash_key='id'))

    db(add(table_name='funcs', item={'id': 'aaa', 'items': ['a', 'b', 'c']}))

    db(
        update(table_name='funcs',
               key={'id': 'aaa'},
               attributes={'items': attr.append('D')}))

    record = db(find(table_name='funcs', key={'id': 'aaa'}))

    items = record.item().get('items')

    assert isinstance(items, list)
    assert 'D' in items
Exemplo n.º 4
0
def test_numbers_are_not_changed(db):
    """Asserts that numbers inserted into dynamo are not converted
    to another type - **namely Decimals**. See https://github.com/boto/boto3/issues/369
    This test is to assert that dynofunc correctly handles this by converting
    any Decimals that dynamo returns back to a default json parsable property.
    """

    db(create(table_name='data_const', hash_key='id'))

    db(
        add(table_name='data_const',
            item={
                'id': 'aaaaaa',
                'prefrences': {
                    'volume': 9
                }
            }))

    user = db(find(table_name='data_const', key={'id': 'aaaaaa'}))

    volume = user.item().get('prefrences').get('volume')

    assert volume == 9
    assert isinstance(volume, int)
Exemplo n.º 5
0
def test_conditions(db):

    ##
    ##  POPULATE TEST DATA
    ##

    db(create(
        table_name='ownership',
        hash_key='id:int',
        range_key='owner'))

    db(add(table_name='ownership', item=_owner_item('ray-x28h')))
    db(add(table_name='ownership', item=_owner_item('ray-934x')))
    db(add(table_name='ownership', item=_owner_item('carl-28hx')))
    db(add(table_name='ownership', item=_owner_item('kobe-oi28')))

    db(create(
        table_name='analytics',
        hash_key='id:int',
        range_key='state:int'))

    db(add(table_name='analytics', item=_analytic_item(1)))
    db(add(table_name='analytics', item=_analytic_item(2)))
    db(add(table_name='analytics', item=_analytic_item(3)))
    db(add(table_name='analytics', item=_analytic_item(4)))
    db(add(table_name='analytics', item=_analytic_item(5)))
    db(add(table_name='analytics', item=_analytic_item(6)))
    db(add(table_name='analytics', item=_analytic_item(7)))
    db(add(table_name='analytics', item=_analytic_item(8)))
    db(add(table_name='analytics', item=_analytic_item(9)))
    db(add(table_name='analytics', item=_analytic_item(10)))

    ##
    ##  RUN TESTS
    ##

    ## TEST == EQUALS
    result = db(query(
        table_name='analytics',
        conditions=attr('id').equals(1)))
    assert len(result.items()) == 10

    ## TEST > GREATER THAN
    result = db(query(
        table_name='analytics',
        conditions=cand(
            attr('id').equals(1),
            attr('state').gt(7))))
    assert len(result.items()) == 3

    ## TEST < LESS THAN
    result = db(query(
        table_name='analytics',
        conditions=cand(
            attr('id').equals(1),
            attr('state').lt(7))))
    assert len(result.items()) == 6

    ## TEST >= GREATER THEAN OR EQUAL TO
    result = db(query(
        table_name='analytics',
        conditions=cand(
            attr('id').equals(1),
            attr('state').gt_or_eq(7))))
    assert len(result.items()) == 4

    ## TEST <= LESS THEAN OR EQUAL TO
    result = db(query(
        table_name='analytics',
        conditions=cand(
            attr('id').equals(1),
            attr('state').lt_or_eq(7))))
    assert len(result.items()) == 7

    ## TEST BETWEEN b AND c
    result = db(query(
        table_name='analytics',
        conditions=cand(
            attr('id').equals(1),
            attr('state').between(6, 8))))
    assert len(result.items()) == 3

    ## TEST begins_with
    result = db(query(
        table_name='ownership',
        conditions=cand(
            attr('id').equals(1),
            attr('owner').begins_with('ray-'))))
    assert len(result.items()) == 2