@@ -6667,6 +6667,88 @@ def test_modelgen_sync_warning(self):
66676667 with self .assertNotWarns ():
66686668 self .client .sync (g , warn_on_large_sync = False )
66696669
6670+ @tb .xfail ('''
6671+ The save seems to fail for objects fetched via a computed link.
6672+ ''' )
6673+ def test_modelgen_computed_01 (self ):
6674+ from models .orm import default
6675+
6676+ # Fetch the user with linked computed groups. Then use one of the
6677+ # fetched groups to remove the user from it. Save. Check.
6678+
6679+ alice = self .client .get (
6680+ default .User .select (
6681+ "*" ,
6682+ groups = lambda u : u .groups .select (
6683+ "*" ,
6684+ users = True ,
6685+ )
6686+ ).filter (name = "Alice" )
6687+ )
6688+
6689+ for g in alice .groups :
6690+ if g .name == "red" :
6691+ g .users .remove (alice )
6692+ self .assertEqual (
6693+ [u .name for u in g .users ],
6694+ ['Billie' , 'Cameron' , 'Dana' ],
6695+ )
6696+ self .client .save (g )
6697+ break
6698+
6699+ refetch = self .client .get (
6700+ default .User .select (
6701+ "*" ,
6702+ groups = True ,
6703+ ).filter (name = "Alice" )
6704+ )
6705+ self .assertEqual (refetch .name , "Alice" )
6706+ self .assertEqual ([g .name for g in refetch .groups ], ["green" ])
6707+
6708+ @tb .xfail ('''
6709+ The sync seems to ignore objects fetched via a computed link
6710+ even though the objects are being explicitly added to the sync
6711+ arguments.
6712+ ''' )
6713+ def test_modelgen_computed_02 (self ):
6714+ from models .orm import default
6715+
6716+ # Fetch the user with linked computed groups. Then use one of the
6717+ # fetched groups to remove the user from it. Sync. Check.
6718+
6719+ alice = self .client .get (
6720+ default .User .select (
6721+ "*" ,
6722+ groups = lambda u : u .groups .select (
6723+ "*" ,
6724+ users = True ,
6725+ )
6726+ ).filter (name = "Alice" )
6727+ )
6728+
6729+ for g in alice .groups :
6730+ if g .name == "red" :
6731+ g .users .remove (alice )
6732+ self .assertEqual (
6733+ [u .name for u in g .users ],
6734+ ['Billie' , 'Cameron' , 'Dana' ],
6735+ )
6736+ break
6737+
6738+ self .client .sync (* alice .groups , alice )
6739+
6740+ self .assertEqual (alice .name , "Alice" )
6741+ self .assertEqual ([g .name for g in alice .groups ], ["green" ])
6742+
6743+ # double-check the group directly
6744+ red = self .client .get (
6745+ default .UserGroup .select (users = True ).filter (name = "red" )
6746+ )
6747+ self .assertEqual (
6748+ [u .name for u in red .users ],
6749+ ['Billie' , 'Cameron' , 'Dana' ],
6750+ )
6751+
66706752
66716753@tb .typecheck
66726754class TestEmptyModelGenerator (tb .ModelTestCase ):
0 commit comments