Example #1
0
 def test_callback_called_on_modification_with_watch(self):
     new_instance = ArticleFactory()
     self.watcher.watch()
     new_instance.title = 'modified'
     new_instance.save()
     # callback should be called with instance modification
     self.callback.assert_called_once_with(
         obj=new_instance, attr=self.attr, sender=self.watcher)
Example #2
0
 def test_get_object_return_obj_from_database(self):
     """get_object should return obj from database"""
     unsaved_obj = ArticleFactory()
     unsaved_obj.title = 'unsaved value'
     r = self.investigator.get_object(unsaved_obj.pk)
     # title should not be different because unsaved_obj has not saved yet
     self.assertNotEqual(r.title, unsaved_obj.title)
     # save
     unsaved_obj.save()
     r = self.investigator.get_object(unsaved_obj.pk)
     self.assertEqual(r.title, unsaved_obj.title)
Example #3
0
 def test_investigate_yield_modified_attributes(self):
     """investigate should yields modified attribute names"""
     article = ArticleFactory()
     article.title = 'modified'
     article.content = 'modified'
     # call prepare before save
     self.investigator.prepare(article)
     # save the change
     article.save()
     # investigate
     iterator = self.investigator.investigate(article)
     self.assertEqual(set(list(iterator)), set([
         'title', 'content',
     ]))
Example #4
0
 def test_callback_not_called_on_modification_without_watch(self):
     new_instance = ArticleFactory()
     new_instance.title = 'modified'
     new_instance.save()
     # have not watched, thus callback should not be called
     self.assertFalse(self.callback.called)