Ejemplo n.º 1
0
def prepare_table_definiton() -> TableDefinition:
    table_def = TableDefinition()
    table_def.name = 'sample_table'
    table_def.namespace = 'pjs_pytest_testing'
    table_def.connection = get_connection()

    return table_def
Ejemplo n.º 2
0
 def drop_db():
     db = get_connection()
     cursor = db.cursor()
     cursor.execute("DROP SCHEMA IF EXISTS pjs_pytest_testing CASCADE;")
     cursor.execute("DROP ROLE IF EXISTS pjs_pytest_role;")
     db.commit()
     return
Ejemplo n.º 3
0
    def test_table_exists(self):
        object = TableDefinition()
        object.name = 'not_real'
        object.namespace = 'not_real'
        object.connection = get_connection()
        assert object.check_table_exists() is False,\
            "The table should not exist"

        object = prepare_table_definiton()
        assert object.check_table_exists() is True,\
            "The table should exist"
Ejemplo n.º 4
0
def setup_db(request):
    def drop_db():
        db = get_connection()
        cursor = db.cursor()
        cursor.execute("DROP SCHEMA IF EXISTS pjs_pytest_testing CASCADE;")
        cursor.execute("DROP ROLE IF EXISTS pjs_pytest_role;")
        db.commit()
        return

    db = get_connection()
    cursor = db.cursor()
    # Create a schema to use
    cursor.execute("CREATE SCHEMA pjs_pytest_testing;")
    # Create a sample table that can have additional types to test
    cursor.execute("""CREATE TABLE pjs_pytest_testing.sample_table (
        id bigint not null,
        int_col int,
        int_nn_col int not null,
        text_col text,
        text_nn_col text not null,
        ts_col timestamp,
        ts_tz_col timestamp with time zone,
        ts_tz_default_col timestamp with time zone default now(),
        CONSTRAINT sample_table_pkey PRIMARY KEY (id)
    );""")
    # Create an index
    cursor.execute("CREATE UNIQUE INDEX pjs_index_name "
                   "ON pjs_pytest_testing.sample_table "
                   "USING btree(int_nn_col,text_nn_col);")
    # Create a role to test permissions
    cursor.execute("CREATE ROLE pjs_pytest_role;")
    cursor.execute("""GRANT ALL
        ON pjs_pytest_testing.sample_table
        TO pjs_pytest_role;""")
    db.commit()

    request.addfinalizer(drop_db)
Ejemplo n.º 5
0
def test_initialise_non_existing_table():
    with pytest.raises(NameError):
        TableDefinition('public', 'not_real', get_connection())
Ejemplo n.º 6
0
 def test_describe_to_json(self):
     expected = load_sample_json('pjs_pytest_test_sample_table.json')
     definition = TableDefinition('pjs_pytest_testing', 'sample_table',
                                  get_connection())
     assert definition.to_json() == expected