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)
 def test_callback_called_on_remove_with_watch(self):
     new_instance = ArticleFactory(tags=self.tags)
     self.watcher.watch()
     new_instance.tags.remove(self.tags[0])
     self.assertFalse(self.tags in new_instance.tags.all())
     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)
Beispiel #3
0
 def test_callback_called_on_remove_with_watch(self):
     new_instance = ArticleFactory(tags=self.tags)
     self.watcher.watch()
     new_instance.tags.remove(self.tags[0])
     self.assertFalse(self.tags in new_instance.tags.all())
     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)
Beispiel #4
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)
Beispiel #5
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',
     ]))
 def test_callback_called_on_modification_with_watch(self):
     new_instance = ArticleFactory(revision=None)
     new_revision = RevisionFactory()
     self.watcher.watch()
     # reverse assignment does not work (it is django's definition)
     new_instance.revision = new_revision
     new_instance.save()
     self.assertRaises(
         ObjectDoesNotExist,
         lambda: Article.objects.get(pk=new_instance.pk).revision)
     # thus assign directly to new_revision
     new_revision.article = new_instance
     new_revision.save()
     # callback should be called with instance modification
     self.callback.assert_called_once_with(
         obj=new_instance, attr=self.attr, sender=self.watcher)
Beispiel #7
0
 def test_callback_called_on_modification_with_watch(self):
     new_instance = ArticleFactory(revision=None)
     new_revision = RevisionFactory()
     self.watcher.watch()
     # reverse assignment does not work (it is django's definition)
     new_instance.revision = new_revision
     new_instance.save()
     self.assertRaises(
         ObjectDoesNotExist,
         lambda: Article.objects.get(pk=new_instance.pk).revision)
     # thus assign directly to new_revision
     new_revision.article = new_instance
     new_revision.save()
     # callback should be called with instance modification
     self.callback.assert_called_once_with(obj=new_instance,
                                           attr=self.attr,
                                           sender=self.watcher)
 def test_callback_not_called_on_modification_with_non_interest_attr(self):
     new_instance = ArticleFactory()
     new_instance.content = 'modified'
     new_instance.save()
     # content is not watched thus callback should not be called
     self.assertFalse(self.callback.called)
 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)