Esempio n. 1
0
class DropTableTests(unittest.TestCase):
    database_xyz = Database("mydb")
    new_table, existing_table = Tables("abc", "efg")
    foo, bar = Columns(("a", "INT"), ("b", "VARCHAR(100)"))

    def test_drop_database(self):
        q1 = Query.drop_database(self.database_xyz)
        q2 = Query.drop_database(self.database_xyz).if_exists()

        self.assertEqual('DROP DATABASE "mydb"', str(q1))
        self.assertEqual('DROP DATABASE IF EXISTS "mydb"', str(q2))

    def test_drop_table(self):
        q1 = Query.drop_table(self.new_table)
        q2 = Query.drop_table(self.new_table).if_exists()

        self.assertEqual('DROP TABLE "abc"', str(q1))
        self.assertEqual('DROP TABLE IF EXISTS "abc"', str(q2))

    def test_drop_user(self):
        q1 = Query.drop_user("myuser")
        q2 = Query.drop_user("myuser").if_exists()

        self.assertEqual('DROP USER "myuser"', str(q1))
        self.assertEqual('DROP USER IF EXISTS "myuser"', str(q2))

    def test_drop_view(self):
        q1 = Query.drop_view("myview")
        q2 = Query.drop_view("myview").if_exists()

        self.assertEqual('DROP VIEW "myview"', str(q1))
        self.assertEqual('DROP VIEW IF EXISTS "myview"', str(q2))
Esempio n. 2
0
class ClickHouseDropQuery(TestCase):
    table_abc = Table("abc")
    database_xyz = Database("mydb")
    cluster_name = "mycluster"

    def test_drop_database(self):
        q1 = ClickHouseQuery.drop_database(self.database_xyz)
        q2 = ClickHouseQuery.drop_database(self.database_xyz).on_cluster(
            self.cluster_name)
        q3 = ClickHouseQuery.drop_database(
            self.database_xyz).if_exists().on_cluster(self.cluster_name)

        self.assertEqual('DROP DATABASE "mydb"', str(q1))
        self.assertEqual('DROP DATABASE "mydb" ON CLUSTER "mycluster"',
                         str(q2))
        self.assertEqual(
            'DROP DATABASE IF EXISTS "mydb" ON CLUSTER "mycluster"', str(q3))

    def test_drop_table(self):
        q1 = ClickHouseQuery.drop_table(self.table_abc)
        q2 = ClickHouseQuery.drop_table(self.table_abc).on_cluster(
            self.cluster_name)
        q3 = ClickHouseQuery.drop_table(self.table_abc).if_exists().on_cluster(
            self.cluster_name)

        self.assertEqual('DROP TABLE "abc"', str(q1))
        self.assertEqual('DROP TABLE "abc" ON CLUSTER "mycluster"', str(q2))
        self.assertEqual('DROP TABLE IF EXISTS "abc" ON CLUSTER "mycluster"',
                         str(q3))

    def test_drop_dictionary(self):
        q1 = ClickHouseQuery.drop_dictionary("dict")
        q2 = ClickHouseQuery.drop_dictionary("dict").on_cluster(
            self.cluster_name)
        q3 = ClickHouseQuery.drop_dictionary("dict").if_exists().on_cluster(
            self.cluster_name)

        self.assertEqual('DROP DICTIONARY "dict"', str(q1))
        self.assertEqual('DROP DICTIONARY "dict"', str(q2))  # NO CLUSTER
        self.assertEqual('DROP DICTIONARY IF EXISTS "dict"',
                         str(q3))  # NO CLUSTER

    def test_drop_other(self):
        q1 = ClickHouseQuery.drop_quota("myquota")
        q2 = ClickHouseQuery.drop_user("myuser")
        q3 = ClickHouseQuery.drop_view("myview")

        self.assertEqual('DROP QUOTA "myquota"', str(q1))
        self.assertEqual('DROP USER "myuser"', str(q2))
        self.assertEqual('DROP VIEW "myview"', str(q3))
Esempio n. 3
0
    def test_table_with_schema_and_schema_parent_arg(self):
        table = Table("test_table",
                      schema=Schema("x_schema", parent=Database("x_db")))

        self.assertEqual('"x_db"."x_schema"."test_table"', str(table))
Esempio n. 4
0
    def test_database_schema_table_attr(self):
        table = Database("x_db").x_schema.test_table

        self.assertEqual('"x_db"."x_schema"."test_table"', str(table))