@@ -110,15 +110,35 @@ def test_run_hooked_methods_for_when(self):
110110 MagicMock (
111111 __name__ = "method_that_does_fires" ,
112112 _hooked = [
113- HookConfig (hook = "after_create" , when = "first_name" , when_any = None , has_changed = None , is_now = "Bob" ,
114- is_not = NotSet , was = "*" , was_not = NotSet , changes_to = NotSet , priority = DEFAULT_PRIORITY )
113+ HookConfig (
114+ hook = "after_create" ,
115+ when = "first_name" ,
116+ when_any = None ,
117+ has_changed = None ,
118+ is_now = "Bob" ,
119+ is_not = NotSet ,
120+ was = "*" ,
121+ was_not = NotSet ,
122+ changes_to = NotSet ,
123+ priority = DEFAULT_PRIORITY ,
124+ )
115125 ],
116126 ),
117127 MagicMock (
118128 __name__ = "method_that_does_not_fire" ,
119129 _hooked = [
120- HookConfig (hook = "after_create" , when = "first_name" , when_any = None , has_changed = None , is_now = "Bill" ,
121- is_not = NotSet , was = "*" , was_not = NotSet , changes_to = NotSet , priority = DEFAULT_PRIORITY )
130+ HookConfig (
131+ hook = "after_create" ,
132+ when = "first_name" ,
133+ when_any = None ,
134+ has_changed = None ,
135+ is_now = "Bill" ,
136+ is_not = NotSet ,
137+ was = "*" ,
138+ was_not = NotSet ,
139+ changes_to = NotSet ,
140+ priority = DEFAULT_PRIORITY ,
141+ )
122142 ],
123143 ),
124144 ]
@@ -134,15 +154,35 @@ def test_run_hooked_methods_for_when_any(self):
134154 MagicMock (
135155 __name__ = "method_that_does_fires" ,
136156 _hooked = [
137- HookConfig (hook = "after_create" , when = None , when_any = ["first_name" , "last_name" , "password" ],
138- has_changed = None , is_now = "Bob" , is_not = NotSet , was = "*" , was_not = NotSet , changes_to = NotSet , priority = DEFAULT_PRIORITY )
157+ HookConfig (
158+ hook = "after_create" ,
159+ when = None ,
160+ when_any = ["first_name" , "last_name" , "password" ],
161+ has_changed = None ,
162+ is_now = "Bob" ,
163+ is_not = NotSet ,
164+ was = "*" ,
165+ was_not = NotSet ,
166+ changes_to = NotSet ,
167+ priority = DEFAULT_PRIORITY ,
168+ )
139169 ],
140170 ),
141171 MagicMock (
142172 __name__ = "method_that_does_not_fire" ,
143173 _hooked = [
144- HookConfig (hook = "after_create" , when = "first_name" , when_any = None , has_changed = None , is_now = "Bill" ,
145- is_not = NotSet , was = "*" , was_not = NotSet , changes_to = NotSet , priority = DEFAULT_PRIORITY )
174+ HookConfig (
175+ hook = "after_create" ,
176+ when = "first_name" ,
177+ when_any = None ,
178+ has_changed = None ,
179+ is_now = "Bill" ,
180+ is_not = NotSet ,
181+ was = "*" ,
182+ was_not = NotSet ,
183+ changes_to = NotSet ,
184+ priority = DEFAULT_PRIORITY ,
185+ )
146186 ],
147187 ),
148188 ]
@@ -350,57 +390,114 @@ def test_comparison_state_should_reset_after_save(self):
350390 self .assertTrue (account .has_changed ("first_name" ))
351391 with self .captureOnCommitCallbacks (execute = True ) as callbacks :
352392 account .save ()
353- self .assertEqual (len (callbacks ), 1 , msg = "Only the _reset_initial_state should be in the on_commit callbacks" )
393+ self .assertEqual (
394+ len (callbacks ),
395+ 1 ,
396+ msg = "Only the _reset_initial_state should be in the on_commit callbacks" ,
397+ )
354398 self .assertFalse (account .has_changed ("first_name" ))
355399
356400 def test_run_hooked_methods_for_on_commit (self ):
357401 instance = UserAccount (first_name = "Bob" )
358402
359403 instance ._potentially_hooked_methods = MagicMock (
360- return_value = [
404+ return_value = [
361405 MagicMock (
362406 __name__ = "method_that_fires_on_commit" ,
363407 _hooked = [
364- HookConfig (hook = "after_create" , when = None , when_any = None , has_changed = None , is_now = "*" , is_not = NotSet ,
365- was = "*" , was_not = NotSet , changes_to = NotSet , on_commit = True , priority = DEFAULT_PRIORITY )
408+ HookConfig (
409+ hook = "after_create" ,
410+ when = None ,
411+ when_any = None ,
412+ has_changed = None ,
413+ is_now = "*" ,
414+ is_not = NotSet ,
415+ was = "*" ,
416+ was_not = NotSet ,
417+ changes_to = NotSet ,
418+ on_commit = True ,
419+ priority = DEFAULT_PRIORITY ,
420+ )
366421 ],
367422 ),
368423 MagicMock (
369424 __name__ = "method_that_fires_in_transaction" ,
370425 _hooked = [
371- HookConfig (hook = "after_create" , when = None , when_any = None , has_changed = None , is_now = "*" , is_not = NotSet ,
372- was = "*" , was_not = NotSet , changes_to = NotSet , on_commit = False , priority = DEFAULT_PRIORITY )
426+ HookConfig (
427+ hook = "after_create" ,
428+ when = None ,
429+ when_any = None ,
430+ has_changed = None ,
431+ is_now = "*" ,
432+ is_not = NotSet ,
433+ was = "*" ,
434+ was_not = NotSet ,
435+ changes_to = NotSet ,
436+ on_commit = False ,
437+ priority = DEFAULT_PRIORITY ,
438+ )
373439 ],
374440 ),
375441 MagicMock (
376442 __name__ = "method_that_fires_in_default" ,
377443 _hooked = [
378- HookConfig (hook = "after_create" , when = None , when_any = None , has_changed = None , is_now = "*" , is_not = NotSet ,
379- was = "*" , was_not = NotSet , changes_to = NotSet , on_commit = None , priority = DEFAULT_PRIORITY )
444+ HookConfig (
445+ hook = "after_create" ,
446+ when = None ,
447+ when_any = None ,
448+ has_changed = None ,
449+ is_now = "*" ,
450+ is_not = NotSet ,
451+ was = "*" ,
452+ was_not = NotSet ,
453+ changes_to = NotSet ,
454+ on_commit = None ,
455+ priority = DEFAULT_PRIORITY ,
456+ )
380457 ],
381458 ),
382459 MagicMock (
383460 __name__ = "after_save_method_that_fires_on_commit" ,
384461 _hooked = [
385- HookConfig (hook = "after_save" , when = None , when_any = None , has_changed = None , is_now = "*" , is_not = NotSet ,
386- was = "*" , was_not = NotSet , changes_to = NotSet , on_commit = True , priority = DEFAULT_PRIORITY )
462+ HookConfig (
463+ hook = "after_save" ,
464+ when = None ,
465+ when_any = None ,
466+ has_changed = None ,
467+ is_now = "*" ,
468+ is_not = NotSet ,
469+ was = "*" ,
470+ was_not = NotSet ,
471+ changes_to = NotSet ,
472+ on_commit = True ,
473+ priority = DEFAULT_PRIORITY ,
474+ )
387475 ],
388476 ),
389477 MagicMock (
390478 __name__ = "after_save_method_that_fires_if_changed_on_commit" ,
391- _hooked = [HookConfig (hook = "after_save" , has_changed = True , on_commit = True )],
479+ _hooked = [
480+ HookConfig (hook = "after_save" , has_changed = True , on_commit = True )
481+ ],
392482 ),
393483 ]
394484 )
395485
396486 fired_methods = instance ._run_hooked_methods ("after_create" )
397- self .assertEqual (fired_methods , ["method_that_fires_on_commit_on_commit" , "method_that_fires_in_transaction" , "method_that_fires_in_default" ])
487+ self .assertEqual (
488+ fired_methods ,
489+ [
490+ "method_that_fires_on_commit_on_commit" ,
491+ "method_that_fires_in_transaction" ,
492+ "method_that_fires_in_default" ,
493+ ],
494+ )
398495
399496 fired_methods = instance ._run_hooked_methods ("after_save" )
400497 self .assertEqual (
401498 fired_methods ,
402499 [
403500 "after_save_method_that_fires_on_commit_on_commit" ,
404501 "after_save_method_that_fires_if_changed_on_commit_on_commit" ,
405- ]
502+ ],
406503 )
0 commit comments