Esempio n. 1
0
def test_del_column(tmpdir):
    dbm = DbManager(tmpdir)
    dbm.create_db('test_db')
    dbm.use_db('test_db')

    test_schema = {'name': 'str', 'age': 'int', 'employed': 'bool'}
    dbm.create_table("test_table", test_schema)
    path_db = os.path.join(tmpdir, "test_db")
    path_table = os.path.join(path_db, "test_table")

    #insert two rows in the current table
    test_row1 = {'name': 'EchipaRacheta', 'age': '24', 'employed': "False"}
    dbm.insert_row("test_table", test_row1)
    test_row2 = {'name': 'EchipaRacheta2', 'age': '25', 'employed': "False"}
    dbm.insert_row("test_table", test_row2)

    #remove a column for this test
    dbm.del_column("test_table", "age")
    updated_schema = dbm.get_table_schema("test_table")

    #check if new sschema has been updated accordingly
    assert not 'age' in updated_schema.keys()
    del test_schema['age']
    assert test_schema == updated_schema

    #get list of rows
    rows = dbm.scan_rows('test_table')

    for row in rows:
        path_column = os.path.join(path_table, str(row['_rowid']))
        check_path = os.path.join(path_column, 'age:bool')
        assert not os.path.exists(check_path)
        assert not "age" in row.keys()

    dbm.delete_table('test_table')
Esempio n. 2
0
def test_delete_table(tmpdir):
    dbm = DbManager(tmpdir)
    dbm.create_db('test_db')
    dbm.use_db('test_db')

    db_path = os.path.join(tmpdir, "test_db")
    table_path = os.path.join(db_path, "test_table")
    test_schema = {'name': 'str', 'age': 'int', 'employed': 'bool'}

    dbm.create_table("test_table", test_schema)
    dbm.delete_table("test_table")

    assert not os.path.exists(table_path)
Esempio n. 3
0
def test_create_table(tmpdir):
    dbm = DbManager(tmpdir)
    dbm.create_db('test_db')
    dbm.use_db('test_db')

    db_path = os.path.join(tmpdir, "test_db")
    table_path = os.path.join(db_path, "test_table")
    schema_path = os.path.join(table_path, ".schema")

    test_schema = {'name': 'str', 'age': 'int', 'employed': 'bool'}
    dbm.create_table("test_table", test_schema)
    schema_test = dbm.get_table_schema("test_table")

    assert os.path.exists(table_path)
    assert os.path.isdir(table_path)
    assert os.path.exists(schema_path)
    assert os.path.isfile(schema_path)
    assert schema_test == test_schema

    dbm.delete_table('test_table')
Esempio n. 4
0
def test_add_column(tmpdir):
    dbm = DbManager(tmpdir)
    dbm.create_db('test_db')
    dbm.use_db('test_db')

    test_schema = {'name': 'str', 'age': 'int', 'employed': 'bool'}
    dbm.create_table("test_table", test_schema)
    path_db = os.path.join(tmpdir, "test_db")
    path_table = os.path.join(path_db, "test_table")

    # #insert two dummy rows in the current table
    test_row1 = {'name': 'EchipaRacheta', 'age': '24', 'employed': "False"}
    dbm.insert_row("test_table", test_row1)
    test_row2 = {'name': 'EchipaRacheta2', 'age': '25', 'employed': "False"}
    dbm.insert_row("test_table", test_row2)

    # add column test
    dbm.add_column("test_table", "test_column", "bool")
    updated_schema = dbm.get_table_schema('test_table')

    #check if schema is updated
    assert "test_column" in updated_schema.keys()
    assert updated_schema['test_column'] == 'bool'
    del updated_schema['test_column']
    assert updated_schema == test_schema

    #check if a new file is created for the new column recently added
    rows = dbm.scan_rows('test_table')
    for row in rows:
        path_column = os.path.join(path_table, str(row['_rowid']))
        check_path = os.path.join(path_column, 'test_column.bool')
        assert os.path.exists(check_path)
        assert os.path.isfile(check_path)
        assert "test_column" in row.keys()
        assert row["test_column"] == ''

    dbm.delete_table('test_table')