Skip to content

Commit

Permalink
updated tests fo .on_null and .on_not_null
Browse files Browse the repository at this point in the history
  • Loading branch information
circulon committed Oct 25, 2024
1 parent e033bfd commit afb140b
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/masoniteorm/testing/BaseTestCaseSelectGrammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,22 @@ def test_can_compile_join_clause_with_null(self):
clause = (
JoinClause("report_groups as rg")
.on_null("bgt.acct")
.or_on_null("bgt.dept")
.on_value("rg.abc", 10)
)
to_sql = self.builder.join(clause).to_sql()

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

def test_can_compile_join_clause_with_not_null(self):
clause = (
JoinClause("report_groups as rg")
.on_not_null("bgt.acct")
.or_on_not_null("bgt.dept")
.on_value("rg.abc", 10)
)
to_sql = self.builder.join(clause).to_sql()

Expand Down
16 changes: 15 additions & 1 deletion tests/mssql/grammar/test_mssql_select_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,25 @@ def can_compile_join_clause_with_null(self):
clause = (
JoinClause("report_groups as rg")
.on_null("bgt.acct")
.or_on_null("bgt.dept")
.on_value("rg.abc", 10)
)
builder.join(clause).to_sql()
"""
return "SELECT * FROM [users] INNER JOIN [report_groups] AS [rg] ON [acct] IS NULL OR [dept] IS NULL AND [rg].[abc] = '10'"

def can_compile_join_clause_with_not_null(self):
"""
builder = self.get_builder()
clause = (
JoinClause("report_groups as rg")
.on_not_null("bgt.acct")
.or_on_not_null("bgt.dept")
.on_value("rg.abc", 10)
)
builder.join(clause).to_sql()
"""
return "SELECT * FROM [users] INNER JOIN [report_groups] AS [rg] ON [acct] IS NULL OR [dept] IS NOT NULL"
return "SELECT * FROM [users] INNER JOIN [report_groups] AS [rg] ON [acct] IS NOT NULL OR [dept] IS NOT NULL AND [rg].[abc] = '10'"

def can_compile_join_clause_with_lambda(self):
"""
Expand Down
16 changes: 15 additions & 1 deletion tests/mysql/grammar/test_mysql_select_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,25 @@ def can_compile_join_clause_with_null(self):
clause = (
JoinClause("report_groups as rg")
.on_null("bgt.acct")
.or_on_null("bgt.dept")
.on_value("rg.abc", 10)
)
builder.join(clause).to_sql()
"""
return "SELECT * FROM `users` INNER JOIN `report_groups` AS `rg` ON `acct` IS NULL OR `dept` IS NULL AND `rg`.`abc` = '10'"

def can_compile_join_clause_with_not_null(self):
"""
builder = self.get_builder()
clause = (
JoinClause("report_groups as rg")
.on_not_null("bgt.acct")
.or_on_not_null("bgt.dept")
.on_value("rg.abc", 10)
)
builder.join(clause).to_sql()
"""
return "SELECT * FROM `users` INNER JOIN `report_groups` AS `rg` ON `acct` IS NULL OR `dept` IS NOT NULL"
return "SELECT * FROM `users` INNER JOIN `report_groups` AS `rg` ON `acct` IS NOT NULL OR `dept` IS NOT NULL AND `rg`.`abc` = '10'"

def can_compile_join_clause_with_lambda(self):
"""
Expand Down
16 changes: 15 additions & 1 deletion tests/postgres/grammar/test_select_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,25 @@ def can_compile_join_clause_with_null(self):
clause = (
JoinClause("report_groups as rg")
.on_null("bgt.acct")
.or_on_null("bgt.dept")
.on_value("rg.abc", 10)
)
builder.join(clause).to_sql()
"""
return """SELECT * FROM "users" INNER JOIN "report_groups" AS "rg" ON "acct" IS NULL OR "dept" IS NULL AND "rg"."abc" = '10'"""

def can_compile_join_clause_with_not_null(self):
"""
builder = self.get_builder()
clause = (
JoinClause("report_groups as rg")
.on_not_null("bgt.acct")
.or_on_not_null("bgt.dept")
.on_value("rg.abc", 10)
)
builder.join(clause).to_sql()
"""
return """SELECT * FROM "users" INNER JOIN "report_groups" AS "rg" ON "acct" IS NULL OR "dept" IS NOT NULL"""
return """SELECT * FROM "users" INNER JOIN "report_groups" AS "rg" ON "acct" IS NOT NULL OR "dept" IS NOT NULL AND "rg"."abc" = '10'"""

def can_compile_join_clause_with_lambda(self):
"""
Expand Down
16 changes: 15 additions & 1 deletion tests/sqlite/grammar/test_sqlite_select_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,25 @@ def can_compile_join_clause_with_null(self):
clause = (
JoinClause("report_groups as rg")
.on_null("bgt.acct")
.or_on_null("bgt.dept")
.on_value("rg.abc", 10)
)
builder.join(clause).to_sql()
"""
return """SELECT * FROM "users" INNER JOIN "report_groups" AS "rg" ON "acct" IS NULL OR "dept" IS NULL AND "rg"."abc" = '10'"""

def can_compile_join_clause_with_not_null(self):
"""
builder = self.get_builder()
clause = (
JoinClause("report_groups as rg")
.on_not_null("bgt.acct")
.or_on_not_null("bgt.dept")
.on_value("rg.abc", 10)
)
builder.join(clause).to_sql()
"""
return """SELECT * FROM "users" INNER JOIN "report_groups" AS "rg" ON "acct" IS NULL OR "dept" IS NOT NULL"""
return """SELECT * FROM "users" INNER JOIN "report_groups" AS "rg" ON "acct" IS NOT NULL OR "dept" IS NOT NULL AND "rg"."abc" = '10'"""

def can_compile_join_clause_with_lambda(self):
"""
Expand Down

0 comments on commit afb140b

Please sign in to comment.