test: tests for Cast_ Function in qb (#16399)
* test: tests for Cast_ Function in qb * test: remove unneeded sync Co-authored-by: Mohammad Hasnain <hasnain2808@gmail.com>
This commit is contained in:
parent
fda544f424
commit
0d16c20f93
3 changed files with 13 additions and 4 deletions
|
|
@ -47,7 +47,7 @@ CombineDatetime = ImportMapper(
|
|||
class Cast_(Function):
|
||||
def __init__(self, value, as_type, alias=None):
|
||||
if db_type_is.MARIADB and (
|
||||
(hasattr(as_type, "get_sql") and as_type.get_sql() == "varchar") or str(as_type).lower() == "varchar"
|
||||
(hasattr(as_type, "get_sql") and as_type.get_sql().lower() == "varchar") or str(as_type).lower() == "varchar"
|
||||
):
|
||||
# mimics varchar cast in mariadb
|
||||
# as mariadb doesn't have varchar data cast
|
||||
|
|
@ -62,7 +62,7 @@ class Cast_(Function):
|
|||
|
||||
def get_special_params_sql(self, **kwargs):
|
||||
if self.name.lower() == "cast":
|
||||
type_sql = self.as_type.get_sql() if hasattr(self.as_type, "get_sql") else str(self.as_type).upper()
|
||||
type_sql = self.as_type.get_sql(**kwargs) if hasattr(self.as_type, "get_sql") else str(self.as_type).upper()
|
||||
return "AS {type}".format(type=type_sql)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -83,7 +83,6 @@ class TestGlobalSearch(unittest.TestCase):
|
|||
|
||||
def test_delete_doc(self):
|
||||
self.insert_test_events()
|
||||
global_search.sync_global_search()
|
||||
event_name = frappe.get_all('Event')[0].name
|
||||
event = frappe.get_doc('Event', event_name)
|
||||
test_subject = event.subject
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from typing import Callable
|
|||
|
||||
import frappe
|
||||
from frappe.query_builder.custom import ConstantColumn
|
||||
from frappe.query_builder.functions import Coalesce, GroupConcat, Match, CombineDatetime
|
||||
from frappe.query_builder.functions import Coalesce, GroupConcat, Match, CombineDatetime, Cast_
|
||||
from frappe.query_builder.utils import db_type_is
|
||||
from frappe.query_builder import Case
|
||||
|
||||
|
|
@ -53,6 +53,11 @@ class TestCustomFunctionsMariaDB(unittest.TestCase):
|
|||
select_query = select_query.select(CombineDatetime(note.posting_date, note.posting_time, alias="timestamp"))
|
||||
self.assertIn("timestamp(`tabnote`.`posting_date`,`tabnote`.`posting_time`) `timestamp`", str(select_query).lower())
|
||||
|
||||
def test_cast(self):
|
||||
note = frappe.qb.DocType("Note")
|
||||
self.assertEqual("CONCAT(`tabnote`.`name`, '')", Cast_(note.name, "varchar"))
|
||||
self.assertEqual("CAST(`tabnote`.`name` AS INTEGER)", Cast_(note.name, "integer"))
|
||||
|
||||
|
||||
@run_only_if(db_type_is.POSTGRES)
|
||||
class TestCustomFunctionsPostgres(unittest.TestCase):
|
||||
|
|
@ -97,6 +102,11 @@ class TestCustomFunctionsPostgres(unittest.TestCase):
|
|||
select_query = select_query.select(CombineDatetime(note.posting_date, note.posting_time, alias="timestamp"))
|
||||
self.assertIn('"tabnote"."posting_date"+"tabnote"."posting_time" "timestamp"', str(select_query).lower())
|
||||
|
||||
def test_cast(self):
|
||||
note = frappe.qb.DocType("Note")
|
||||
self.assertEqual("CAST(`tabnote`.`name` AS VARCHAR)", Cast_(note.name, "varchar"))
|
||||
self.assertEqual("CAST(`tabnote`.`name` AS INTEGER)", Cast_(note.name, "integer"))
|
||||
|
||||
|
||||
class TestBuilderBase(object):
|
||||
def test_adding_tabs(self):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue