Exemple #1
0
 def test_compare_get_schema_names_for_sql_and_odbc(self, engine_name):
     with self.engine_map[engine_name].begin() as c:
         dialect = EXADialect()
         schema_names_fallback = dialect.get_schema_names(
             connection=c, use_sql_fallback=True)
         schema_names_odbc = dialect.get_schema_names(connection=c)
         assert sorted(schema_names_fallback) == sorted(schema_names_odbc)
Exemple #2
0
 def test_get_view_names(self, use_sql_fallback, engine_name):
     with self.engine_map[engine_name].begin() as c:
         dialect = EXADialect()
         view_names = dialect.get_view_names(
             connection=c,
             schema=self.schema,
             use_sql_fallback=use_sql_fallback)
         assert "v" in view_names
Exemple #3
0
 def test_has_table_table_exists_not(self, use_sql_fallback, engine_name):
     with self.engine_map[engine_name].begin() as c:
         dialect = EXADialect()
         has_table = dialect.has_table(connection=c,
                                       schema=self.schema,
                                       table_name="not_exist",
                                       use_sql_fallback=use_sql_fallback)
         assert not has_table, "Table %s.not_exist was found, but should not exist" % self.schema
 def test_get_columns_table_name_none(self, use_sql_fallback, engine_name):
     with self.engine_map[engine_name].begin() as c:
         dialect = EXADialect()
         columns = dialect.get_columns(connection=c,
                                       schema=self.schema,
                                       table_name=None,
                                       use_sql_fallback=use_sql_fallback)
         assert columns == []
Exemple #5
0
 def test_get_view_definition(self, use_sql_fallback, engine_name):
     with self.engine_map[engine_name].begin() as c:
         dialect = EXADialect()
         view_definition = dialect.get_view_definition(
             connection=c,
             schema=self.schema,
             view_name="v",
             use_sql_fallback=use_sql_fallback)
         assert self.view_defintion == view_definition
Exemple #6
0
 def test_get_pk_constraint(self, use_sql_fallback, engine_name):
     with self.engine_map[engine_name].begin() as c:
         dialect = EXADialect()
         pk_constraint = dialect.get_pk_constraint(
             connection=c,
             schema=self.schema,
             table_name="t",
             use_sql_fallback=use_sql_fallback)
         assert pk_constraint["constrained_columns"] == ['pid1', 'pid2'] and \
                pk_constraint["name"].startswith("sys_")
 def test_get_pk_constraint_table_name_none(self, use_sql_fallback,
                                            engine_name):
     with self.engine_map[engine_name].begin() as c:
         dialect = EXADialect()
         pk_constraint = dialect.get_pk_constraint(
             connection=c,
             schema=self.schema,
             table_name=None,
             use_sql_fallback=use_sql_fallback)
         assert pk_constraint is None
Exemple #8
0
 def test_compare_get_view_names_for_sql_and_odbc(self, schema,
                                                  engine_name):
     with self.engine_map[engine_name].begin() as c:
         dialect = EXADialect()
         c.execute("OPEN SCHEMA %s" % self.schema)
         view_names_fallback = dialect.get_view_names(connection=c,
                                                      schema=schema,
                                                      use_sql_fallback=True)
         view_names_odbc = dialect.get_view_names(connection=c,
                                                  schema=schema)
         assert view_names_fallback == view_names_odbc
Exemple #9
0
 def test_compare_has_table_for_sql_and_odbc(self, schema, engine_name):
     with self.engine_map[engine_name].begin() as c:
         dialect = EXADialect()
         has_table_fallback = dialect.has_table(connection=c,
                                                schema=schema,
                                                use_sql_fallback=True,
                                                table_name="t")
         has_table_odbc = dialect.has_table(connection=c,
                                            schema=schema,
                                            table_name="t")
         assert has_table_fallback == has_table_odbc, "Expected table %s.t with odbc and fallback" % schema
Exemple #10
0
 def test_compare_get_foreign_keys_for_sql_and_odbc(self, schema, table,
                                                    engine_name):
     with self.engine_map[engine_name].begin() as c:
         if schema is None:
             c.execute("OPEN SCHEMA %s" % self.schema_2)
         dialect = EXADialect()
         foreign_keys_fallback = dialect.get_foreign_keys(
             connection=c,
             table_name=table,
             schema=schema,
             use_sql_fallback=True)
         foreign_keys_odbc = dialect.get_foreign_keys(connection=c,
                                                      table_name=table,
                                                      schema=schema)
         assert str(foreign_keys_fallback) == str(foreign_keys_odbc)
Exemple #11
0
 def test_compare_get_columns_for_sql_and_odbc(self, schema, table,
                                               engine_name):
     with self.engine_map[engine_name].begin() as c:
         if schema is None:
             c.execute("OPEN SCHEMA %s" % self.schema)
         dialect = EXADialect()
         columns_fallback = dialect.get_columns(connection=c,
                                                table_name=table,
                                                schema=schema,
                                                use_sql_fallback=True)
         columns_odbc = dialect.get_columns(connection=c,
                                            table_name=table,
                                            schema=schema)
         assert str(columns_fallback) == str(
             columns_odbc)  # object equality doesn't work for sqltypes
Exemple #12
0
 def test_compare_get_view_definition_for_sql_and_odbc(
         self, schema, engine_name):
     with self.engine_map[engine_name].begin() as c:
         if schema is None:
             c.execute("OPEN SCHEMA %s" % self.schema)
         view_name = "v"
         dialect = EXADialect()
         view_definition_fallback = dialect.get_view_definition(
             connection=c,
             view_name=view_name,
             schema=schema,
             use_sql_fallback=True)
         view_definition_odbc = dialect.get_view_definition(
             connection=c, view_name=view_name, schema=schema)
         assert view_definition_fallback == view_definition_odbc
Exemple #13
0
    def test_get_foreign_keys(self, use_sql_fallback, engine_name):
        with self.engine_map[engine_name].begin() as c:
            dialect = EXADialect()
            foreign_keys = dialect.get_foreign_keys(
                connection=c,
                schema=self.schema,
                table_name="s",
                use_sql_fallback=use_sql_fallback)
            expected = [{
                'name': 'fk_test',
                'constrained_columns': ['fid1', 'fid2'],
                'referred_schema': 'test_get_metadata_functions_schema',
                'referred_table': 't',
                'referred_columns': ['pid1', 'pid2']
            }]

            assert foreign_keys == expected
Exemple #14
0
    def test_get_columns(self, use_sql_fallback, engine_name):
        with self.engine_map[engine_name].begin() as c:
            dialect = EXADialect()
            columns = dialect.get_columns(connection=c,
                                          schema=self.schema,
                                          table_name="t",
                                          use_sql_fallback=use_sql_fallback)
            expected = [
                {
                    'default': None,
                    'is_distribution_key': False,
                    'name': 'pid1',
                    'nullable': False,
                    'type': INTEGER()
                },
                {
                    'default': None,
                    'is_distribution_key': False,
                    'name': 'pid2',
                    'nullable': False,
                    'type': INTEGER()
                },
                {
                    'default': None,
                    'is_distribution_key': False,
                    'name': 'name',
                    'nullable': True,
                    'type': VARCHAR(length=20)
                },
                {
                    'default': None,
                    'is_distribution_key': False,
                    'name': 'age',
                    'nullable': True,
                    'type': INTEGER()
                },
            ]

            assert self.make_columns_comparable(
                expected) == self.make_columns_comparable(columns)
Exemple #15
0
def test_view():
    q = LayerQueryView(EXADialect())

    expected = (
        "CREATE VIEW some_schema.test_view AS\n"
        "SELECT schema_one.simple_table.some_id, schema_one.simple_table.some_col\n"
        "FROM schema_one.simple_table\n"
        "WHERE schema_one.simple_table.some_id = '2'")

    actual = q.push_query(SimpleView)
    assert actual == expected

    expected = "DROP VIEW some_schema.test_view"
    assert q.pop_query(SimpleView) == expected
Exemple #16
0
def test_table():
    q = LayerQueryTable(EXADialect())

    expected = dedent("""
        CREATE TABLE schema_one.simple_table (
        \tsome_id VARCHAR(40) NOT NULL,
        \tsome_col VARCHAR(40),
        \tPRIMARY KEY (some_id)
        )\n
        """)
    actual = q.push_query(SimpleModel)
    assert actual == expected

    expected = "\nDROP TABLE schema_one.simple_table"
    assert q.pop_query(SimpleModel) == expected
 def without_fallback(session2, schema, table):
     dialect = EXADialect()
     dialect.get_foreign_keys(session2,
                              table_name=table,
                              schema=schema,
                              use_sql_fallback=False)
 def with_fallback(session2, schema, table):
     dialect = EXADialect()
     dialect.get_pk_constraint(session2,
                               table_name=table,
                               schema=schema,
                               use_sql_fallback=True)
 def with_fallback(session2, schema, table):
     dialect = EXADialect()
     dialect.get_columns(session2,
                         schema=schema,
                         table_name=table,
                         use_sql_fallback=True)
Exemple #20
0
 def test_get_view_names_for_sys(self, use_sql_fallback, engine_name):
     with self.engine_map[engine_name].begin() as c:
         dialect = EXADialect()
         view_names = dialect.get_view_names(
             connection=c, schema="sys", use_sql_fallback=use_sql_fallback)
         assert len(view_names) == 0
Exemple #21
0
 def test_get_schema_names(self, engine_name, use_sql_fallback):
     with self.engine_map[engine_name].begin() as c:
         dialect = EXADialect()
         schema_names = dialect.get_schema_names(
             connection=c, use_sql_fallback=use_sql_fallback)
         assert self.schema in schema_names and self.schema_2 in schema_names