Esempio n. 1
0
def test_sm_disconnect():
    """
    Checks that the db is disconnecting properly
    """
    s = SqlManager(db_name)
    s.connect()
    s.disconnect()
    actual = s.con is None
    n_ok(actual, s, 'disconnect')
Esempio n. 2
0
def test_sm_connect_existing_db():
    """
    Tries to connect to a db that already exists
    """
    s = SqlManager(db_name)
    s.connect()
    actual = s.con is None
    s.disconnect()
    n_ok(not actual, s, 'connect')
Esempio n. 3
0
def test_tr_exists():
    """
    Test it can remove a table that exists
    """
    s = SqlManager(db_name)
    if not table_name in s.tables:
        raise Exception('Bad Setup')
    del s
    TableRemover(db_name, table_name)
    s = SqlManager(db_name)
    actual = table_name in s.tables
    n_ok(not actual, message='table should be gone')
Esempio n. 4
0
def setup_module():
    """
    Makes a database for testing in.
    """
    sql = SqlManager(db_name)
    command = 'CREATE TABLE %s (col_one text);' % existing_table_name
    sql.connect()
    sql._no_fetch_command(command)
    sql.disconnect()
Esempio n. 5
0
def test_sm_pull_tables():
    """
    Checks that pull tables is retrieving all the tables
    """
    s = SqlManager(db_name)
    actual = s.tables[0]
    expected = table_name
    n_eq(expected, actual, s, '_pull_tables')
Esempio n. 6
0
def test_tm_good_quick_push():
    """
    @precondition: test_tm_with_enter passed
    @precondition: test_tm_with_exit passed
    @precondition: test_tm_with_exit_error passed
    Checks that data is being written with a good push
    """
    expected = ['abc', 1]
    with TableManager(db_name, table_name) as t:
        t.quick_push(expected)
    s = SqlManager(db_name)
    s.connect()
    values = s._fetch_command('SELECT * FROM ' + table_name + ';')
    s.disconnect()
    values = values[0]
    actual = []
    expected = ['abc', 1]
    for val in values:
        if type(val) == int:
            val = int(val)
        else:
            val = str(val)
        actual += [val]
    message = 'Expected: ' + str(expected) + '\n' + 'Actual' + str(actual)
    n_eq(expected, actual, message=message)
Esempio n. 7
0
def setup_module():
    """
    Makes a database for testing in.
    """
    sql = SqlManager(db_name)
    command = 'CREATE TABLE %s (col_one text);' % existing_table_name
    sql.connect()
    sql._no_fetch_command(command)
    sql.disconnect()
Esempio n. 8
0
def test_sm_connect_new_db():
    """
    Tries to connect to a db that does not exists
    """
    db = 'test_2.db'
    s = SqlManager(db)
    actual = os.path.isfile(db)
    if actual:
        os.remove(db)
    del s
    n_ok(actual, message='test_2.db was not created')
Esempio n. 9
0
def test_tm_good_quick_push():
    """
    @precondition: test_tm_with_enter passed
    @precondition: test_tm_with_exit passed
    @precondition: test_tm_with_exit_error passed
    Checks that data is being written with a good push
    """
    expected = ['abc', 1]
    with TableManager(db_name, table_name) as t:
        t.quick_push(expected)
    s = SqlManager(db_name)
    s.connect()
    values = s._fetch_command('SELECT * FROM ' + table_name + ';')
    s.disconnect()
    values = values[0]
    actual = []
    expected = ['abc', 1]
    for val in values:
        if type(val) == int:
            val = int(val)
        else:
            val = str(val)
        actual += [val]
    message = 'Expected: ' + str(expected) + '\n' + 'Actual' + str(actual)
    n_eq(expected, actual, message=message)
Esempio n. 10
0
def test_ta_commit():
    """
    Checks that the table is added to the database
    @precondition: SqlManager all test - Pass
    """
    table_name = 'def'
    t = TableAdder(db_name, table_name)
    t.add_column('text_column')
    t.add_column('int_column', 'integer')
    t.commit()
    s = SqlManager(db_name)
    actual = table_name in s.tables
    n_ok(actual, t, 'commit', message='finally table added')
Esempio n. 11
0
def test_sm_fetch_command():
    """
    Checks that the db can run a fetch command
    """
    command = 'SELECT * FROM %s;' % table_name
    s = SqlManager(db_name)
    s.connect()
    data = s._fetch_command(command)[0]
    s.disconnect()
    actual = [str(col) for col in data]
    expected = ['one', 'two', 'three']
    n_eq(expected, actual, s, '_fetch_command')
Esempio n. 12
0
def test_sm_disconnect():
    """
    Checks that the db is disconnecting properly
    """
    s = SqlManager(db_name)
    s.connect()
    s.disconnect()
    actual = s.con is None
    n_ok(actual, s, 'disconnect')
Esempio n. 13
0
def test_sm_connect_existing_db():
    """
    Tries to connect to a db that already exists
    """
    s = SqlManager(db_name)
    s.connect()
    actual = s.con is None
    s.disconnect()
    n_ok(not actual, s, 'connect')
Esempio n. 14
0
def test_sm_fetch_command():
    """
    Checks that the db can run a fetch command
    """
    command = 'SELECT * FROM %s;' % table_name
    s = SqlManager(db_name)
    s.connect()
    data = s._fetch_command(command)[0]
    s.disconnect()
    actual = [str(col) for col in data]
    expected = ['one', 'two', 'three']
    n_eq(expected, actual, s, '_fetch_command')
Esempio n. 15
0
def test_tm_clear_table():
    """
    @precondition: test_tm_with_enter passed
    @precondition: test_tm_with_exit passed
    @precondition: test_tm_with_exit_error passed
    Tries to clear the table of all data
    """
    with TableManager(db_name, table_name) as t:
        t.clear_table()
    s = SqlManager(db_name)
    command = 'SELECT * FROM ' + table_name + ';'
    s.connect()
    data = s._fetch_command(command)
    s.disconnect()
    actual = False
    if len(data) == 0:
        actual = True
    n_ok(actual, message=actual)
Esempio n. 16
0
def test_sm_no_fetch_command():
    """
    Checks that the table can run a no fetch command
    """
    expected = ['a', 'b', 'c']
    command = 'INSERT INTO %s VALUES(%s);' % (table_name, str(expected)[1:-1])
    s = SqlManager(db_name)
    s.connect()
    s._no_fetch_command(command)
    s.disconnect()
    con = lite.connect(db_name)
    cur = con.cursor()
    command = 'SELECT * FROM %s;' % table_name
    cur.execute(command)
    fetched = cur.fetchall()
    fetched = fetched[1]
    actual = [str(col) for col in fetched]
    n_eq(expected, actual, s, '_no_fetch_command', message='Good chance that I did not setup test right')
Esempio n. 17
0
def test_sm_no_fetch_command():
    """
    Checks that the table can run a no fetch command
    """
    expected = ['a', 'b', 'c']
    command = 'INSERT INTO %s VALUES(%s);' % (table_name, str(expected)[1:-1])
    s = SqlManager(db_name)
    s.connect()
    s._no_fetch_command(command)
    s.disconnect()
    con = lite.connect(db_name)
    cur = con.cursor()
    command = 'SELECT * FROM %s;' % table_name
    cur.execute(command)
    fetched = cur.fetchall()
    fetched = fetched[1]
    actual = [str(col) for col in fetched]
    n_eq(expected,
         actual,
         s,
         '_no_fetch_command',
         message='Good chance that I did not setup test right')
Esempio n. 18
0
def test_tm_sorted_good_push():
    """
    @precondition: test_tm_with_enter passed
    @precondition: test_tm_with_exit passed
    @precondition: test_tm_with_exit_error passed
    Tries to push a list where the columns are already in order with good info
    """
    push = [('text_col', 'one'), ('int_col', 1)]
    with TableManager(db_name, table_name) as t:
        t.push(push)
    s = SqlManager(db_name)
    command = 'SELECT * FROM ' + table_name + ';'
    s.connect()
    data = s._fetch_command(command)
    s.disconnect()
    data = data[0]
    expected = [str(val[1]) for val in push]
    actual = [str(val) for val in data]
    n_eq(expected, actual)
Esempio n. 19
0
def test_tm_unsorted_good_push():
    """
    @precondition: test_tm_with_enter passed
    @precondition: test_tm_with_exit passed
    @precondition: test_tm_with_exit_error passed
    Tries to sort the list of good info and then push it.
    Also does type conversion
    """
    push = [('int_col', '1'), ('text_col', 'one')]
    with TableManager(db_name, table_name) as t:
        t.push(push)
    s = SqlManager(db_name)
    command = 'SELECT * FROM ' + table_name + ';'
    s.connect()
    data = s._fetch_command(command)
    s.disconnect()
    data = data[1]
    expected = [str(val[1]) for val in push][::-1]
    actual = [str(val) for val in data]
    n_eq(expected, actual)
Esempio n. 20
0
def test_tm_clear_table():
    """
    @precondition: test_tm_with_enter passed
    @precondition: test_tm_with_exit passed
    @precondition: test_tm_with_exit_error passed
    Tries to clear the table of all data
    """
    with TableManager(db_name, table_name) as t:
        t.clear_table()
    s = SqlManager(db_name)
    command = 'SELECT * FROM ' + table_name + ';'
    s.connect()
    data = s._fetch_command(command)
    s.disconnect()
    actual = False
    if len(data) == 0:
        actual = True
    n_ok(actual, message=actual)
Esempio n. 21
0
def test_tm_sorted_good_push():
    """
    @precondition: test_tm_with_enter passed
    @precondition: test_tm_with_exit passed
    @precondition: test_tm_with_exit_error passed
    Tries to push a list where the columns are already in order with good info
    """
    push = [('text_col', 'one'), ('int_col', 1)]
    with TableManager(db_name, table_name) as t:
        t.push(push)
    s = SqlManager(db_name)
    command = 'SELECT * FROM ' + table_name + ';'
    s.connect()
    data = s._fetch_command(command)
    s.disconnect()
    data = data[0]
    expected = [str(val[1]) for val in push]
    actual = [str(val) for val in data]
    n_eq(expected, actual)
Esempio n. 22
0
def test_tm_unsorted_good_push():
    """
    @precondition: test_tm_with_enter passed
    @precondition: test_tm_with_exit passed
    @precondition: test_tm_with_exit_error passed
    Tries to sort the list of good info and then push it.
    Also does type conversion
    """
    push = [('int_col', '1'), ('text_col', 'one')]
    with TableManager(db_name, table_name) as t:
        t.push(push)
    s = SqlManager(db_name)
    command = 'SELECT * FROM ' + table_name + ';'
    s.connect()
    data = s._fetch_command(command)
    s.disconnect()
    data = data[1]
    expected = [str(val[1]) for val in push][::-1]
    actual = [str(val) for val in data]
    n_eq(expected, actual)