Ejemplo n.º 1
0
class BaseDeleteGrammarTest:
    def setUp(self):
        self.builder = QueryBuilder(GrammarFactory.make("sqlite"),
                                    table="users")

    def test_can_compile_delete(self):
        to_sql = self.builder.delete("id", 1, query=True).to_sql()

        sql = getattr(
            self,
            inspect.currentframe().f_code.co_name.replace("test_", ""))()
        self.assertEqual(to_sql, sql)

    def test_can_compile_delete_in(self):
        to_sql = self.builder.delete("id", [1, 2, 3], query=True).to_sql()

        sql = getattr(
            self,
            inspect.currentframe().f_code.co_name.replace("test_", ""))()
        self.assertEqual(to_sql, sql)

    def test_can_compile_delete_with_where(self):
        to_sql = (self.builder.where("age",
                                     20).where("profile",
                                               1).delete(query=True).to_sql())

        sql = getattr(
            self,
            inspect.currentframe().f_code.co_name.replace("test_", ""))()
        self.assertEqual(to_sql, sql)
Ejemplo n.º 2
0
class TestMySQLDeleteGrammar(unittest.TestCase):
    def setUp(self):
        self.builder = QueryBuilder(GrammarFactory.make("mssql"),
                                    table="users")

    def test_can_compile_delete(self):
        to_sql = self.builder.delete("id", 1, query=True).to_sql()

        sql = "DELETE FROM [users] WHERE [users].[id] = '1'"
        self.assertEqual(to_sql, sql)

    def test_can_compile_delete_with_where(self):
        to_sql = (self.builder.where("age", 20).where(
            "profile", 1).set_action("delete").delete(query=True).to_sql())

        sql = (
            "DELETE FROM [users] WHERE [users].[age] = '20' AND [users].[profile] = '1'"
        )
        self.assertEqual(to_sql, sql)