Exemplo n.º 1
0
def test_asis():
    row = {'name': NormAsIs('DEFAULT'), 'zipcode': 23344}

    i = INSERT('table1', data=[row])
    assert i.query == ('INSERT INTO table1 (name, zipcode) '
                       'VALUES (DEFAULT, %(zipcode_0)s);')
    assert i.binds == {'zipcode_0': 23344}
Exemplo n.º 2
0
def test_insert_no_columns():
    i = INSERT('table1', data=[row1, row2], columns=['phone'], default='blah')
    assert i.binds == {'phone_0': 'blah', 'phone_1': '1112223333'}

    assert i.query == ('INSERT INTO table1 '
                       '(phone) '
                       'VALUES (%(phone_0)s),\n'
                       '       (%(phone_1)s);')
Exemplo n.º 3
0
def test_setting_default():
    i = INSERT('table1', data=[row1, row2], default=2)
    assert i.binds == {
        'name_0': 'justin',
        'phone_0': 2,
        'zipcode_0': 23344,
        'name_1': 'nintendo',
        'phone_1': '1112223333',
        'zipcode_1': 2
    }
Exemplo n.º 4
0
def test_insert_on_conflict():
    i = INSERT('table1',
               data={
                   'col1': 'val1',
                   'col2': 'val2'
               },
               on_conflict='(col1) DO NOTHING')

    assert i.binds == dict(col1_0='val1', col2_0='val2')
    assert i.query == ('INSERT INTO table1 '
                       '(col1, col2) '
                       'VALUES (%(col1_0)s, %(col2_0)s)'
                       '\nON CONFLICT (col1) DO NOTHING;')
Exemplo n.º 5
0
def test_multi_insert():
    i = INSERT('table1', data=[row1, row2])
    assert i.binds == {
        'name_0': 'justin',
        'phone_0': None,
        'zipcode_0': 23344,
        'name_1': 'nintendo',
        'phone_1': '1112223333',
        'zipcode_1': None
    }

    assert i.query == ('INSERT INTO table1 '
                       '(name, phone, zipcode) '
                       'VALUES (%(name_0)s, %(phone_0)s, %(zipcode_0)s),\n'
                       '       (%(name_1)s, %(phone_1)s, %(zipcode_1)s);')
Exemplo n.º 6
0
def test_insert_default_values():
    i = INSERT('table1')

    assert i.binds == {}
    assert i.query == ('INSERT INTO table1 ' 'DEFAULT VALUES;')
Exemplo n.º 7
0
def test_setting_columns():
    i = INSERT('table1', data=row1, columns=['name', 'address'])
    assert i.binds == {'name_0': 'justin', 'address_0': None}
    assert i.query == ('INSERT INTO table1 '
                       '(name, address) VALUES (%(name_0)s, %(address_0)s);')
Exemplo n.º 8
0
def test_basic_insert():
    i = INSERT('table1', data=row1)

    assert i.binds == {'name_0': 'justin', 'zipcode_0': 23344}
    assert i.query == ('INSERT INTO table1 '
                       '(name, zipcode) VALUES (%(name_0)s, %(zipcode_0)s);')