test: for qb Match and GroupConcat
This commit is contained in:
parent
ce10e36725
commit
681d0ab995
2 changed files with 36 additions and 2 deletions
|
|
@ -11,7 +11,6 @@ class db_type(Enum):
|
|||
MARIADB = "mariadb"
|
||||
POSTGRES = "postgres"
|
||||
|
||||
|
||||
class ImportMapper:
|
||||
def __init__(self, func_map: Dict[db_type, Callable]) -> None:
|
||||
self.func_map = func_map
|
||||
|
|
@ -32,7 +31,7 @@ def get_query_builder(type_of_db: Optional[str]) -> Query:
|
|||
Returns:
|
||||
Query: [Query object]
|
||||
"""
|
||||
db = db_type["MARIADB"]
|
||||
db = db_type.MARIADB
|
||||
if type_of_db:
|
||||
db = db_type(type_of_db)
|
||||
selecter = {db_type.MARIADB: MariaDB, db_type.POSTGRES: Postgres}
|
||||
|
|
|
|||
35
frappe/tests/test_query_builder.py
Normal file
35
frappe/tests/test_query_builder.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import unittest
|
||||
from typing import Callable
|
||||
|
||||
import frappe
|
||||
from frappe.query_builder.functions import GroupConcat, Match
|
||||
from frappe.query_builder.utils import db_type
|
||||
|
||||
|
||||
def CheckDB(dbtype: db_type) -> Callable:
|
||||
return unittest.skipIf(
|
||||
db_type(frappe.conf.db_type) != dbtype, f"Only runs for{db_type}"
|
||||
)
|
||||
|
||||
@CheckDB(dbtype=db_type.MARIADB)
|
||||
class TestCustomFunctionsMariaDB(unittest.TestCase):
|
||||
def test_concat(self):
|
||||
self.assertEqual("GROUP_CONCAT('Notes')", GroupConcat("Notes").get_sql())
|
||||
|
||||
def test_match(self):
|
||||
query = Match("Notes").Against("text")
|
||||
self.assertEqual(
|
||||
" MATCH('Notes') AGAINST ('+text*' IN BOOLEAN MODE)", query.get_sql()
|
||||
)
|
||||
|
||||
|
||||
@CheckDB(dbtype=db_type.POSTGRES)
|
||||
class TestCustomFunctionsPostgres(unittest.TestCase):
|
||||
def test_concat(self):
|
||||
self.assertEqual("STRING_AGG('Notes',',')", GroupConcat("Notes").get_sql())
|
||||
|
||||
def test_match(self):
|
||||
query = Match("Notes").Against("text")
|
||||
self.assertEqual(
|
||||
"TO_TSVECTOR('Notes') @@ PLAINTO_TSQUERY('text')", query.get_sql()
|
||||
)
|
||||
Loading…
Add table
Reference in a new issue