@@ -1104,7 +1104,6 @@ def test_model_sync_computed_single_prop_from_exclusive_backlink_06(self):
11041104
11051105 self .assertEqual (original .val , 10 )
11061106
1107- @tb .xfail # Syncing to None doesn't work
11081107 def test_model_sync_computed_single_prop_from_exclusive_backlink_07 (self ):
11091108 # Update with val set, initially has source
11101109 # source changes
@@ -1215,7 +1214,6 @@ def test_model_sync_computed_single_prop_from_single_backlink_06(self):
12151214
12161215 self .assertEqual (original .val , 25 )
12171216
1218- @tb .xfail # Syncing to None doesn't work
12191217 def test_model_sync_computed_single_prop_from_single_backlink_07 (self ):
12201218 # Update with val set, initially has sources
12211219 # sources change
@@ -2325,7 +2323,6 @@ def test_model_sync_computed_multi_prop_from_exclusive_backlink_06(self):
23252323
23262324 self .assertEqual (original .val , (9 ,) * 10 )
23272325
2328- @tb .xfail # Syncing to None doesn't work
23292326 def test_model_sync_computed_multi_prop_from_exclusive_backlink_07 (self ):
23302327 # Update with val set, initially has source
23312328 # source changes
@@ -2436,7 +2433,6 @@ def test_model_sync_computed_multi_prop_from_single_backlink_06(self):
24362433
24372434 self .assertEqual (original .val , (9 ,) * 25 )
24382435
2439- @tb .xfail # Syncing to None doesn't work
24402436 def test_model_sync_computed_multi_prop_from_single_backlink_07 (self ):
24412437 # Update with val set, initially has sources
24422438 # sources change
@@ -2625,6 +2621,45 @@ def test_model_sync_single_link_01a(self):
26252621 with_none = default .SourceWithProp (target = None )
26262622 self .client .sync (with_none )
26272623
2624+ def _testcase_02 (
2625+ self ,
2626+ model_type : typing .Type [GelModel ],
2627+ initial_target : typing .Any ,
2628+ changed_target : typing .Any ,
2629+ ) -> None :
2630+ original = model_type (target = initial_target )
2631+ self .client .save (original )
2632+
2633+ mirror_1 = self .client .query_required_single (
2634+ model_type .select (target = True ).limit (1 )
2635+ )
2636+ mirror_2 = self .client .query_required_single (
2637+ model_type .select (target = True ).limit (1 )
2638+ )
2639+ mirror_3 = self .client .query_required_single (
2640+ model_type .select (target = False ).limit (1 )
2641+ )
2642+
2643+ self ._check_links_equal (original .target , initial_target )
2644+ self ._check_links_equal (mirror_1 .target , initial_target )
2645+ self ._check_links_equal (mirror_2 .target , initial_target )
2646+ self .assertFalse (hasattr (mirror_3 , "val" ))
2647+
2648+ # change a value
2649+ original .target = changed_target
2650+
2651+ # sync some of the objects
2652+ self .client .sync (original , mirror_1 , mirror_3 )
2653+
2654+ # only synced objects with value set get update
2655+ self ._check_links_equal (original .target , changed_target )
2656+ self ._check_links_equal (mirror_1 .target , changed_target )
2657+ self ._check_links_equal (mirror_2 .target , initial_target )
2658+ self .assertFalse (hasattr (mirror_3 , 'val' ))
2659+
2660+ # cleanup
2661+ self .client .query (model_type .delete ())
2662+
26282663 def test_model_sync_single_link_02 (self ):
26292664 # Updating existing objects with single link
26302665
@@ -2634,177 +2669,117 @@ def test_model_sync_single_link_02(self):
26342669 target_b = default .Target ()
26352670 self .client .save (target_a , target_b )
26362671
2637- def _testcase (
2638- model_type : typing .Type [GelModel ],
2639- initial_target : typing .Any ,
2640- changed_target : typing .Any ,
2641- ) -> None :
2642- original = model_type (target = initial_target )
2643- self .client .save (original )
2672+ # Change to/from None
2673+ self ._testcase_02 (default .Source , None , target_b )
2674+ self ._testcase_02 (default .Source , target_a , None )
2675+ self ._testcase_02 (default .Source , target_a , target_b )
26442676
2645- mirror_1 = self .client .query_required_single (
2646- model_type .select (target = True ).limit (1 )
2647- )
2648- mirror_2 = self .client .query_required_single (
2649- model_type .select (target = True ).limit (1 )
2650- )
2651- mirror_3 = self .client .query_required_single (
2652- model_type .select (target = False ).limit (1 )
2653- )
2654-
2655- self ._check_links_equal (original .target , initial_target )
2656- self ._check_links_equal (mirror_1 .target , initial_target )
2657- self ._check_links_equal (mirror_2 .target , initial_target )
2658- self .assertFalse (hasattr (mirror_3 , "val" ))
2659-
2660- # change a value
2661- original .target = changed_target
2662-
2663- # sync some of the objects
2664- self .client .sync (original , mirror_1 , mirror_3 )
2665-
2666- # only synced objects with value set get update
2667- self ._check_links_equal (original .target , changed_target )
2668- self ._check_links_equal (mirror_1 .target , changed_target )
2669- self ._check_links_equal (mirror_2 .target , initial_target )
2670- self .assertFalse (hasattr (mirror_3 , 'val' ))
2671-
2672- # cleanup
2673- self .client .query (model_type .delete ())
2677+ # Moved to test_model_sync_single_link_02c
2678+ # self._testcase_02(
2679+ # default.SourceWithProp,
2680+ # None,
2681+ # default.SourceWithProp.target.link(target_b),
2682+ # )
2683+ # self._testcase_02(
2684+ # default.SourceWithProp,
2685+ # None,
2686+ # default.SourceWithProp.target.link(target_b, lprop=1),
2687+ # )
2688+ # self._testcase_02(
2689+ # default.SourceWithProp,
2690+ # default.SourceWithProp.target.link(target_a),
2691+ # None,
2692+ # )
2693+ # self._testcase_02(
2694+ # default.SourceWithProp,
2695+ # default.SourceWithProp.target.link(target_a, lprop=1),
2696+ # None,
2697+ # )
26742698
26752699 # Change to a new value
2676- _testcase (default .Source , target_a , target_b )
2677- _testcase (
2700+ self ._testcase_02 (
26782701 default .SourceWithProp ,
26792702 default .SourceWithProp .target .link (target_a ),
26802703 default .SourceWithProp .target .link (target_b ),
26812704 )
2682- _testcase (
2705+ self . _testcase_02 (
26832706 default .SourceWithProp ,
26842707 default .SourceWithProp .target .link (target_a , lprop = 1 ),
26852708 default .SourceWithProp .target .link (target_b ),
26862709 )
2687- _testcase (
2710+ self . _testcase_02 (
26882711 default .SourceWithProp ,
26892712 default .SourceWithProp .target .link (target_a ),
26902713 default .SourceWithProp .target .link (target_b , lprop = 1 ),
26912714 )
2692- _testcase (
2715+ self . _testcase_02 (
26932716 default .SourceWithProp ,
26942717 default .SourceWithProp .target .link (target_a , lprop = 1 ),
26952718 default .SourceWithProp .target .link (target_b , lprop = 1 ),
26962719 )
26972720
26982721 # only changing lprop
2699- _testcase (
2722+ self . _testcase_02 (
27002723 default .SourceWithProp ,
27012724 default .SourceWithProp .target .link (target_a ),
27022725 default .SourceWithProp .target .link (target_a , lprop = 2 ),
27032726 )
2704- _testcase (
2727+ self . _testcase_02 (
27052728 default .SourceWithProp ,
27062729 default .SourceWithProp .target .link (target_a , lprop = 1 ),
27072730 default .SourceWithProp .target .link (target_a ),
27082731 )
2709- _testcase (
2732+ self . _testcase_02 (
27102733 default .SourceWithProp ,
27112734 default .SourceWithProp .target .link (target_a , lprop = 1 ),
27122735 default .SourceWithProp .target .link (target_a , lprop = 2 ),
27132736 )
27142737
27152738 # Change to the same value
2716- _testcase (default .Source , target_a , target_a )
2717- _testcase (
2739+ self ._testcase_02 (default .Source , None , None )
2740+ self ._testcase_02 (default .Source , target_a , target_a )
2741+ self ._testcase_02 (
27182742 default .SourceWithProp ,
27192743 default .SourceWithProp .target .link (target_a ),
27202744 default .SourceWithProp .target .link (target_a ),
27212745 )
2722- _testcase (
2746+ self . _testcase_02 (
27232747 default .SourceWithProp ,
27242748 default .SourceWithProp .target .link (target_a , lprop = 1 ),
27252749 default .SourceWithProp .target .link (target_a , lprop = 1 ),
27262750 )
27272751
2728- @tb .xfail
2729- def test_model_sync_single_link_02a (self ):
2752+ @tb .xfail # Changing links with props to/from None fails assertion
2753+ def test_model_sync_single_link_02c (self ):
27302754 # Updating existing objects with single link
2731- # Change from None to value
27322755
27332756 from models .TestModelSyncSingleLink import default
27342757
2735- changed_target = default .Target ()
2736- self .client .save (changed_target )
2737-
2738- original = default .Source ()
2739- self .client .save (original )
2758+ target_a = default .Target ()
2759+ target_b = default .Target ()
2760+ self .client .save (target_a , target_b )
27402761
2741- mirror_1 = self .client .query_required_single (
2742- default .Source .select (target = True ).limit (1 )
2743- )
2744- mirror_2 = self .client .query_required_single (
2745- default .Source .select (target = True ).limit (1 )
2746- )
2747- mirror_3 = self .client .query_required_single (
2748- default .Source .select (target = False ).limit (1 )
2762+ self ._testcase_02 (
2763+ default .SourceWithProp ,
2764+ None ,
2765+ default .SourceWithProp .target .link (target_b ),
27492766 )
2750-
2751- self .assertIsNone (original .target , None )
2752- self .assertIsNone (mirror_1 .target , None )
2753- self .assertIsNone (mirror_2 .target , None )
2754- self .assertFalse (hasattr (mirror_3 , "val" ))
2755-
2756- # change a value
2757- original .target = changed_target
2758-
2759- # sync some of the objects
2760- self .client .sync (original , mirror_1 , mirror_3 ) # Error here
2761-
2762- # only synced objects with value set get update
2763- self ._check_links_equal (original .target , changed_target )
2764- self ._check_links_equal (mirror_1 .target , changed_target )
2765- self .assertIsNone (mirror_2 .target )
2766- self .assertFalse (hasattr (mirror_3 , 'val' ))
2767-
2768- @tb .xfail
2769- def test_model_sync_single_link_02b (self ):
2770- # Updating existing objects with single link
2771- # Change from value to None
2772-
2773- from models .TestModelSyncSingleLink import default
2774-
2775- initial_target = default .Target ()
2776- self .client .save (initial_target )
2777-
2778- original = default .Source (target = initial_target )
2779- self .client .save (original )
2780-
2781- mirror_1 = self .client .query_required_single (
2782- default .Source .select (target = True ).limit (1 )
2767+ self ._testcase_02 (
2768+ default .SourceWithProp ,
2769+ None ,
2770+ default .SourceWithProp .target .link (target_b , lprop = 1 ),
27832771 )
2784- mirror_2 = self .client .query_required_single (
2785- default .Source .select (target = True ).limit (1 )
2772+ self ._testcase_02 (
2773+ default .SourceWithProp ,
2774+ default .SourceWithProp .target .link (target_a ),
2775+ None ,
27862776 )
2787- mirror_3 = self .client .query_required_single (
2788- default .Source .select (target = False ).limit (1 )
2777+ self ._testcase_02 (
2778+ default .SourceWithProp ,
2779+ default .SourceWithProp .target .link (target_a , lprop = 1 ),
2780+ None ,
27892781 )
27902782
2791- self ._check_links_equal (original .target , initial_target )
2792- self ._check_links_equal (mirror_1 .target , initial_target )
2793- self ._check_links_equal (mirror_2 .target , initial_target )
2794- self .assertFalse (hasattr (mirror_3 , "val" ))
2795-
2796- # change a value
2797- original .target = None
2798-
2799- # sync some of the objects
2800- self .client .sync (original , mirror_1 , mirror_3 ) # Error here
2801-
2802- # only synced objects with value set get update
2803- self .assertIsNone (original .target )
2804- self .assertIsNone (mirror_1 .target )
2805- self ._check_links_equal (mirror_2 .target , initial_target )
2806- self .assertFalse (hasattr (mirror_3 , 'val' ))
2807-
28082783 def _testcase_03 (
28092784 self ,
28102785 model_type : typing .Type [GelModel ],
@@ -5002,7 +4977,7 @@ def _testcase(
50024977 _testcase (1 , None , 2 )
50034978 _testcase (1 , 0 , 2 )
50044979
5005- @tb .xfail # updated link is not refetched
4980+ @tb .xfail # rewritten link is not refetched
50064981 def test_model_sync_rewrite_insert_02 (self ):
50074982 # Insert, link with rewrite
50084983
@@ -5026,8 +5001,8 @@ def _testcase(
50265001 target_zero = default .Target (n = 0 )
50275002 self .client .save (target_zero )
50285003
5029- # _testcase(None, None, None) # Syncing to None doesn't work
5030- # _testcase(1, None, 2) # Syncing to None doesn't work
5004+ _testcase (None , None , None )
5005+ _testcase (1 , None , 2 )
50315006 _testcase (1 , target_zero , 2 )
50325007
50335008 def test_model_sync_rewrite_update_01 (self ):
@@ -5088,7 +5063,7 @@ def _testcase(
50885063 _testcase (1 , 1 , 3 )
50895064 _testcase (1 , 9 , 11 )
50905065
5091- @tb .xfail # Fails because of bugs syncing links
5066+ @tb .xfail # rewritten link is not refetched
50925067 def test_model_sync_rewrite_update_03 (self ):
50935068 # Update, link with rewrite
50945069 # Only update the rewrite field
@@ -5125,10 +5100,10 @@ def _testcase(
51255100 target_one = default .Target (n = 1 )
51265101 self .client .save (target_one )
51275102
5128- _testcase (1 , None , 3 ) # Syncing to None doesn't work
5129- _testcase (1 , target_one , 3 ) # Sync doesn't fetch linked new object
5103+ _testcase (1 , None , 3 )
5104+ _testcase (1 , target_one , 3 )
51305105
5131- @tb .xfail # Fails because of bugs syncing links
5106+ @tb .xfail # rewritten link is not refetched
51325107 def test_model_sync_rewrite_update_04 (self ):
51335108 # Update, link with rewrite
51345109 # Only update other field
@@ -5161,10 +5136,10 @@ def _testcase(
51615136 # cleanup
51625137 self .client .query (default .SingleLink .delete ())
51635138
5164- _testcase (None , None , None ) # Syncing to None doesn't work
5165- _testcase (1 , None , None ) # Syncing to None doesn't work
5166- _testcase (1 , 1 , 3 ) # Sync doesn't fetch linked new object
5167- _testcase (1 , 9 , 11 ) # Sync doesn't fetch linked new object
5139+ _testcase (None , None , None )
5140+ _testcase (1 , None , None )
5141+ _testcase (1 , 1 , 3 )
5142+ _testcase (1 , 9 , 11 )
51685143
51695144
51705145class TestModelSyncTrigger (tb .ModelTestCase ):
0 commit comments