From 07ee1bdc0c01492860c251032d528c1b03a4d164 Mon Sep 17 00:00:00 2001 From: saxenabhishek Date: Fri, 10 Dec 2021 12:30:19 +0530 Subject: [PATCH] test: ConstantColumn --- frappe/tests/test_query_builder.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/frappe/tests/test_query_builder.py b/frappe/tests/test_query_builder.py index 7a0935a63b..0b7382d4bd 100644 --- a/frappe/tests/test_query_builder.py +++ b/frappe/tests/test_query_builder.py @@ -2,6 +2,7 @@ import unittest from typing import Callable import frappe +from frappe.query_builder.custom import ConstantColumn from frappe.query_builder.functions import GroupConcat, Match from frappe.query_builder.utils import db_type_is @@ -23,7 +24,9 @@ class TestCustomFunctionsMariaDB(unittest.TestCase): " MATCH('Notes') AGAINST ('+text*' IN BOOLEAN MODE)", query.get_sql() ) - + def test_constant_column(self): + query = frappe.qb.from_("DocType").select("name", ConstantColumn("John").as_("User")) + self.assertEqual(query.get_sql(), "SELECT `name`,'John' `User` FROM `tabDocType`") @run_only_if(db_type_is.POSTGRES) class TestCustomFunctionsPostgres(unittest.TestCase): def test_concat(self): @@ -35,6 +38,9 @@ class TestCustomFunctionsPostgres(unittest.TestCase): "TO_TSVECTOR('Notes') @@ PLAINTO_TSQUERY('text')", query.get_sql() ) + def test_constant_column(self): + query = frappe.qb.from_("DocType").select("name", ConstantColumn("John").as_("User")) + self.assertEqual(query.get_sql(), 'SELECT "name",\'John\' "User" FROM "tabDocType"') class TestBuilderBase(object): def test_adding_tabs(self):