Ejemplo n.º 1
0
def test_from_csv(tmpdir):
    dbm = DbManager(tmpdir)
    input_path = os.path.join(tmpdir, "test_db.csv")
    db_testPath = os.path.join(tmpdir, "test_db")
    table1_path = os.path.join(db_testPath, "test_table1")
    table2_path = os.path.join(db_testPath, "test_table2")
    record1 = {'name': 'EchipaRacheta', 'age': '24', 'employed': 'False'}
    record2 = {'name': 'EchipaRacheta2', 'age': '25', 'employed': 'False'}
    record3 = {'description': 'descrierea dummy ', 'isMember': 'True'}
    record4 = {'description': 'descrierea dummy 2', 'isMember': 'False'}
    record_list = [record1, record2, record3, record4]

    input_content = """test_table1,name:str,age:int,employed:bool
test_table1,0,age,24
test_table1,0,employed,False
test_table1,0,name,EchipaRacheta
test_table1,1,age,25
test_table1,1,employed,False
test_table1,1,name,EchipaRacheta2

test_table2,description:str,isMember:bool
test_table2,0,description,descrierea dummy 
test_table2,0,isMember,True
test_table2,1,description,descrierea dummy 2
test_table2,1,isMember,False

"""
    f = open(input_path, 'w')
    f.write(input_content)
    f.close()
    dbm.from_csv(input_path)

    assert os.path.exists(db_testPath)
    assert os.path.isdir(db_testPath)
    assert os.path.exists(table1_path)
    assert os.path.exists(table2_path)
    assert os.path.isdir(table1_path)
    assert os.path.isdir(table2_path)

    dbm = DbManager(tmpdir)
    dbm.use_db('test_db')
    schema1 = dbm.get_table_schema('test_table1')
    schema2 = dbm.get_table_schema('test_table2')
    #check schema
    assert schema1 == {'name': 'str', 'age': 'int', 'employed': 'bool'}
    assert schema2 == {'description': 'str', 'isMember': 'bool'}

    #check rows
    listOfTables = dbm.get_tables('test_db')
    for table in listOfTables:
        records_table1 = dbm.scan_rows(table)
        for record in records_table1:
            del record['_rowid']
            assert record in record_list
Ejemplo n.º 2
0
def test_get_tables(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)

    test_schema2 = {'name': 'str', 'description': 'str', 'isMale': 'bool'}
    dbm.create_table("test_table2", test_schema2)

    test_schema3 = {'name': 'str', 'age': 'int'}
    dbm.create_table("test_table3", test_schema3)

    existing_schemas = [test_schema, test_schema2, test_schema3]

    tables_list = dbm.get_tables("test_db")
    for table in tables_list:
        current_schema = dbm.get_table_schema(table)
        assert current_schema in existing_schemas
    dbm.delete_db('test_db')