@@ -2600,6 +2600,121 @@ def test_qb_backlinks_error_01(self):
26002600 with self .assertRaisesRegex (ValueError , "unsupported query type" ):
26012601 self .client .query (query )
26022602
2603+ def test_qb_backlinks_error_02 (self ):
2604+ # Unions don't have backlinks
2605+ from models .orm_qb import default , std
2606+
2607+ with self .assertRaisesRegex (
2608+ AttributeError , "has no attribute '__backlinks__'"
2609+ ):
2610+ std .union (default .Inh_ABC , default .Inh_AB_AC ).__backlinks__
2611+
2612+ def test_qb_std_coalesce_scalar_01 (self ):
2613+ from models .orm_qb import std
2614+
2615+ query = std .coalesce (1 , 2 )
2616+ result = self .client .query (query )
2617+
2618+ self .assertEqual (result , [1 ])
2619+
2620+ def test_qb_std_coalesce_scalar_02 (self ):
2621+ from models .orm_qb import std
2622+
2623+ query = std .coalesce (None , 2 )
2624+ result = self .client .query (query )
2625+
2626+ self .assertEqual (result , [2 ])
2627+
2628+ def test_qb_std_coalesce_object_01 (self ):
2629+ from models .orm_qb import default , std
2630+
2631+ inh_a_objs = {
2632+ obj .a : obj
2633+ for obj in self .client .query (default .Inh_A .select (a = True ))
2634+ }
2635+
2636+ query = std .coalesce (default .Inh_AB_AC , default .Inh_ABC )
2637+ result = self .client .query (query )
2638+ self ._assertListEqualUnordered ([inh_a_objs [17 ]], result )
2639+
2640+ def test_qb_std_coalesce_object_02 (self ):
2641+ from models .orm_qb import default , std
2642+
2643+ inh_a_objs = {
2644+ obj .a : obj
2645+ for obj in self .client .query (default .Inh_A .select (a = True ))
2646+ }
2647+
2648+ query = std .coalesce (None , default .Inh_ABC )
2649+ result = self .client .query (query )
2650+
2651+ self ._assertListEqualUnordered ([inh_a_objs [13 ]], result )
2652+
2653+ def test_qb_std_coalesce_object_03 (self ):
2654+ from models .orm_qb import default , std
2655+
2656+ inh_a_objs = {
2657+ obj .a : obj
2658+ for obj in self .client .query (default .Inh_A .select (a = True ))
2659+ }
2660+
2661+ query = std .coalesce (
2662+ default .Inh_AB .is_ (default .Inh_AC ), default .Inh_ABC
2663+ )
2664+ result = self .client .query (query )
2665+ self ._assertListEqualUnordered ([inh_a_objs [17 ]], result )
2666+
2667+ def test_qb_std_union_scalar_01 (self ):
2668+ from models .orm_qb import std
2669+
2670+ query = std .union (1 , 2 )
2671+ result = self .client .query (query )
2672+ self ._assertListEqualUnordered (result , [1 , 2 ])
2673+
2674+ def test_qb_std_union_scalar_02 (self ):
2675+ from models .orm_qb import std
2676+
2677+ query = std .union (1 , [2 , 3 ])
2678+ result = self .client .query (query )
2679+ self ._assertListEqualUnordered (result , [1 , 2 , 3 ])
2680+
2681+ def test_qb_std_union_scalar_03 (self ):
2682+ from models .orm_qb import std
2683+
2684+ query = std .union ([1 , 2 ], [2 , 3 ])
2685+ result = self .client .query (query )
2686+ self ._assertListEqualUnordered (result , [1 , 2 , 2 , 3 ])
2687+
2688+ def test_qb_std_union_object_01 (self ):
2689+ from models .orm_qb import default , std
2690+
2691+ inh_a_objs = {
2692+ obj .a : obj
2693+ for obj in self .client .query (default .Inh_A .select (a = True ))
2694+ }
2695+
2696+ query = std .union (default .Inh_ABC , default .Inh_AB_AC ).select ('*' )
2697+ result = self .client .query (query )
2698+ self ._assertListEqualUnordered (
2699+ [inh_a_objs [13 ], inh_a_objs [17 ]], result
2700+ )
2701+
2702+ def test_qb_std_union_object_02 (self ):
2703+ from models .orm_qb import default , std
2704+
2705+ inh_a_objs = {
2706+ obj .a : obj
2707+ for obj in self .client .query (default .Inh_A .select (a = True ))
2708+ }
2709+
2710+ query = std .union (
2711+ default .Inh_ABC , default .Inh_AB .is_ (default .Inh_AC )
2712+ ).select ('*' )
2713+ result = self .client .query (query )
2714+ self ._assertListEqualUnordered (
2715+ [inh_a_objs [13 ], inh_a_objs [17 ]], result
2716+ )
2717+
26032718
26042719class TestQueryBuilderModify (tb .ModelTestCase ):
26052720 """This test suite is for data manipulation using QB."""
0 commit comments