|
|
@@ -1,5 +1,6 @@ |
|
|
|
import unittest |
|
|
|
from collections.abc import Callable |
|
|
|
from datetime import time |
|
|
|
|
|
|
|
import frappe |
|
|
|
from frappe.query_builder import Case |
|
|
@@ -74,6 +75,26 @@ class TestCustomFunctionsMariaDB(FrappeTestCase): |
|
|
|
str(select_query).lower(), |
|
|
|
) |
|
|
|
|
|
|
|
def test_time(self): |
|
|
|
note = frappe.qb.DocType("Note") |
|
|
|
self.assertEqual( |
|
|
|
"TIMESTAMP('2021-01-01','00:00:21')", CombineDatetime("2021-01-01", time(0, 0, 21)).get_sql() |
|
|
|
) |
|
|
|
|
|
|
|
select_query = frappe.qb.from_(note).select( |
|
|
|
CombineDatetime(note.posting_date, note.posting_time) |
|
|
|
) |
|
|
|
self.assertIn("select timestamp(`posting_date`,`posting_time`)", str(select_query).lower()) |
|
|
|
|
|
|
|
select_query = select_query.where( |
|
|
|
CombineDatetime(note.posting_date, note.posting_time) |
|
|
|
>= CombineDatetime("2021-01-01", time(0, 0, 1)) |
|
|
|
) |
|
|
|
self.assertIn( |
|
|
|
"timestamp(`posting_date`,`posting_time`)>=timestamp('2021-01-01','00:00:01')", |
|
|
|
str(select_query).lower(), |
|
|
|
) |
|
|
|
|
|
|
|
def test_cast(self): |
|
|
|
note = frappe.qb.DocType("Note") |
|
|
|
self.assertEqual("CONCAT(name,'')", Cast_(note.name, "varchar").get_sql()) |
|
|
@@ -141,6 +162,28 @@ class TestCustomFunctionsPostgres(FrappeTestCase): |
|
|
|
'"tabnote"."posting_date"+"tabnote"."posting_time" "timestamp"', str(select_query).lower() |
|
|
|
) |
|
|
|
|
|
|
|
def test_time(self): |
|
|
|
note = frappe.qb.DocType("Note") |
|
|
|
|
|
|
|
self.assertEqual( |
|
|
|
"CAST('2021-01-01' AS DATE)+CAST('00:00:21' AS TIME)", |
|
|
|
CombineDatetime("2021-01-01", time(0, 0, 21)).get_sql(), |
|
|
|
) |
|
|
|
|
|
|
|
select_query = frappe.qb.from_(note).select( |
|
|
|
CombineDatetime(note.posting_date, note.posting_time) |
|
|
|
) |
|
|
|
self.assertIn('select "posting_date"+"posting_time"', str(select_query).lower()) |
|
|
|
|
|
|
|
select_query = select_query.where( |
|
|
|
CombineDatetime(note.posting_date, note.posting_time) |
|
|
|
>= CombineDatetime("2021-01-01", time(0, 0, 1)) |
|
|
|
) |
|
|
|
self.assertIn( |
|
|
|
"""where "posting_date"+"posting_time">=cast('2021-01-01' as date)+cast('00:00:01' as time)""", |
|
|
|
str(select_query).lower(), |
|
|
|
) |
|
|
|
|
|
|
|
def test_cast(self): |
|
|
|
note = frappe.qb.DocType("Note") |
|
|
|
self.assertEqual("CAST(name AS VARCHAR)", Cast_(note.name, "varchar").get_sql()) |
|
|
|