def test_model_listener_turn_off(self): """ Simple model listener construction. Tests that the signals will not be fired when auto_on = False """ ml = ModelListener() ml.name = "test_listener" ml.app = "example_app" ml.model = "Dummy" ml.active = True ml.post_save_handler = "example.example_app.tests.fake_functions.fake" ml.post_delete_handler = "example.example_app.tests.fake_functions.fake" ml.auto_on = True ml.save() self.assertTrue(ml._is_method_valid(ml.post_save_handler)) self.assertTrue(ml._is_method_valid(ml.post_delete_handler)) dummy = mommy.make_one(Dummy) dummy.save() self.assertTrue(ModelListenerTestCase.fired) ml._stop_listening() ModelListenerTestCase.fired = False dummy2 = mommy.make_one(Dummy) self.assertFalse(ModelListenerTestCase.fired) ml._stop_listening()
def test_model_listener_stop(self): """ Tests that stopping the signal will not fire the events """ ml = ModelListener() ml.name = "test_listener" ml.app = "example_app" ml.model = "Dummy" ml.active = True ml.post_save_handler = "example.example_app.tests.fake_functions.fake" ml.post_delete_handler = "example.example_app.tests.fake_functions.fake" ml.auto_on = True ml.save() ModelListenerTestCase.fired = False self.assertTrue(ml._is_method_valid(ml.post_save_handler)) self.assertTrue(ml._is_method_valid(ml.post_delete_handler)) ml._stop_listening() dummy = mommy.make_one(Dummy) dummy.save() self.assertFalse(ModelListenerTestCase.fired) ml._start_listening() ModelListenerTestCase.fired = False dummy2 = mommy.make_one(Dummy) self.assertTrue(ModelListenerTestCase.fired) ml._stop_listening()