Exemple #1
0
 def test_sqlite_connection_from_file(self):
     connfile = os.path.join(TESTDATA_DIR, 'sqlite.conn')
     db = database_connection(conn=connfile)
     dbh = DatabaseHandler('sqlite', db)
     elements = dbh.resolve_table('elements')
     self.assertTrue(dbh.check_table_exists(elements))
     self.assertFalse(dbh.check_table_exists('does_not_exist'))
Exemple #2
0
def detect_database_table_from_file(table,
                                    constraints_path,
                                    conn=None,
                                    dbtype=None,
                                    db=None,
                                    host=None,
                                    port=None,
                                    user=None,
                                    password=None,
                                    **kwargs):
    """
    detect using the given database table, against constraints in the .tdda
    file specified.

    Not implemented
    """
    (table, dbtype) = parse_table_name(table, dbtype)
    db = database_connection(table=table,
                             conn=conn,
                             dbtype=dbtype,
                             db=db,
                             host=host,
                             port=port,
                             user=user,
                             password=password)
    print(detect_db_table(dbtype, db, table, constraints_path, **kwargs))
Exemple #3
0
def verify_database_table_from_file(table,
                                    constraints_path,
                                    conn=None,
                                    dbtype=None,
                                    db=None,
                                    host=None,
                                    port=None,
                                    user=None,
                                    password=None,
                                    **kwargs):
    """
    Verify the given database table, against constraints in the .tdda
    file specified.

    Prints results to stdout.
    """
    (table, dbtype) = parse_table_name(table, dbtype)
    db = database_connection(table=table,
                             conn=conn,
                             dbtype=dbtype,
                             db=db,
                             host=host,
                             port=port,
                             user=user,
                             password=password)
    print(verify_db_table(dbtype, db, table, constraints_path, **kwargs))
Exemple #4
0
 def test_sqlite_connection_from_file(self):
     connfile = os.path.join(TESTDATA_DIR, 'sqlite.conn')
     db = database_connection(conn=connfile)
     dbh = DatabaseHandler('sqlite', db)
     elements = dbh.resolve_table('elements')
     self.assertTrue(dbh.check_table_exists(elements))
     self.assertFalse(dbh.check_table_exists('does_not_exist'))
Exemple #5
0
def discover_constraints_from_database(table, constraints_path=None,
                                       conn=None, dbtype=None, db=None,
                                       host=None, port=None, user=None,
                                       password=None, **kwargs):
    """
    Discover constraints in the given database table.

    Writes constraints as JSON to the specified file (or to stdout).
    """
    (table, dbtype) = parse_table_name(table, dbtype)
    db = database_connection(table=table, conn=conn, dbtype=dbtype, db=db,
                             host=host, port=port,
                             user=user, password=password)
    constraints = discover_db_table(dbtype, db, table, **kwargs)
    if constraints is None:
        # should never happen
        return

    output = constraints.to_json(tddafile=constraints_path)

    if constraints_path:
        with open(constraints_path, 'w') as f:
            f.write(output);
    else:
        print(output)
    return output
Exemple #6
0
def discover_constraints_from_database(table,
                                       constraints_path=None,
                                       conn=None,
                                       dbtype=None,
                                       db=None,
                                       host=None,
                                       port=None,
                                       user=None,
                                       password=None,
                                       **kwargs):
    """
    Discover constraints in the given database table.

    Writes constraints as JSON to the specified file (or to stdout).
    """
    (table, dbtype) = parse_table_name(table, dbtype)
    db = database_connection(table=table,
                             conn=conn,
                             dbtype=dbtype,
                             db=db,
                             host=host,
                             port=port,
                             user=user,
                             password=password)
    constraints = discover_db_table(dbtype, db, table, **kwargs)
    if constraints_path:
        with open(constraints_path, 'w') as f:
            f.write(constraints.to_json())
    else:
        print(constraints.to_json())
Exemple #7
0
def detect_database_table_from_file(table, constraints_path,
                                    conn=None, dbtype=None, db=None,
                                    host=None, port=None, user=None,
                                    password=None, **kwargs):
    """
    detect using the given database table, against constraints in the .tdda
    file specified.

    Not implemented
    """
    (table, dbtype) = parse_table_name(table, dbtype)
    db = database_connection(table=table, conn=conn, dbtype=dbtype, db=db,
                             host=host, port=port,
                             user=user, password=password)
    print(detect_db_table(dbtype, db, table, constraints_path, **kwargs))
 def setUpClass(cls):
     dbfile = os.path.join(TESTDATA_DIR, 'example.db')
     cls.db = database_connection(dbtype='sqlite', db=dbfile)
Exemple #9
0
 def setUpClass(cls):
     cls.db = database_connection(dbtype='mysql')
     cls.dbh = DatabaseHandler('mysql', cls.db)
Exemple #10
0
 def setUpClass(cls):
     cls.db = database_connection(dbtype='postgres')
     cls.dbh = DatabaseHandler('postgres', cls.db)
Exemple #11
0
 def setUpClass(cls):
     cls.db = database_connection(dbtype='mongodb')
     cls.dbh = DatabaseHandler('mongodb', cls.db)
Exemple #12
0
 def setUpClass(cls):
     cls.db = database_connection(dbtype='postgres')
     cls.dbh = DatabaseHandler('postgres', cls.db)
Exemple #13
0
 def setUpClass(cls):
     dbfile = os.path.join(TESTDATA_DIR, 'example.db')
     cls.db = database_connection(dbtype='sqlite', db=dbfile)
     cls.dbh = DatabaseHandler('sqlite', cls.db)
Exemple #14
0
 def setUpClass(cls):
     db = database_connection(dbtype='mysql')
     cls.dbh = DatabaseHandler('mysql', db)
Exemple #15
0
 def setUpClass(cls):
     db = database_connection(dbtype='mongodb')
     cls.dbh = DatabaseHandler('mongodb', db)