Esempio n. 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)
Esempio n. 2
0
 def setUp(self):
     self.model = Article
     self.attr = 'foobar'
     self.callback = MagicMock()
     self.Investigator = MagicMock(wraps=Investigator)
     self.investigator = self.Investigator(self.model)
     self.investigator._object_cached[1] = ArticleFactory()
     self.investigator._object_cached[2] = ArticleFactory()
     self.investigator._object_cached[3] = ArticleFactory()
 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)
Esempio n. 4
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)
Esempio n. 5
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)
Esempio n. 6
0
 def test_callback_not_called_on_modification_without_watch(self):
     new_instance = ArticleFactory(collaborators=self.users)
     user = new_instance.collaborators.get(pk=1)
     user.label = 'modified'
     user.save()
     # have not watched, thus callback should not be called
     self.assertFalse(self.callback.called)
Esempio n. 7
0
 def test_callback_not_called_on_modification_without_watch(self):
     new_instance = ArticleFactory(projects=self.projects)
     project = new_instance.projects.get(pk=1)
     project.label = 'modified'
     project.save()
     # have not watched, thus callback should not be called
     self.assertFalse(self.callback.called)
Esempio n. 8
0
 def test_callback_called_on_create_with_watch(self):
     self.watcher.watch()
     new_instance = ArticleFactory()
     # callback should be called with newly created instance
     self.callback.assert_called_once_with(obj=new_instance,
                                           attr=self.attr,
                                           sender=self.watcher)
Esempio n. 9
0
 def test_callback_not_called_on_related_modification_without_watch(self):
     new_instance = ArticleFactory()
     revision = new_instance.revision
     revision.label = 'modified'
     revision.save()
     # have not watched, thus callback should not be called
     self.assertFalse(self.callback.called)
Esempio n. 10
0
 def test_callback_not_called_on_reverse_add_without_watch(self):
     new_instance = TagFactory()
     add_instance = ArticleFactory()
     new_instance.content_object = add_instance
     new_instance.save()
     # have not watched, thus callback should not be called
     self.assertFalse(self.callback.called)
Esempio n. 11
0
 def test_callback_not_called_on_modification_without_watch(self):
     new_instance = ArticleFactory(tags=self.tags)
     tag = new_instance.tags.get(pk=1)
     tag.label = 'modified'
     tag.save()
     # have not watched, thus callback should not be called
     self.assertFalse(self.callback.called)
Esempio n. 12
0
 def test_callback_not_called_on_modification_without_watch(self):
     new_instance = ArticleFactory()
     user = new_instance.author
     user.label = 'modified'
     user.save()
     # have not watched, thus callback should not be called
     self.assertFalse(self.callback.called)
Esempio n. 13
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)
Esempio n. 14
0
 def test_callback_not_called_on_modification_without_watch(self):
     new_instance = ArticleFactory(hyperlinks=self.hyperlinks)
     hyperlink = new_instance.hyperlinks.get(pk=1)
     hyperlink.label = 'modified'
     hyperlink.save()
     # have not watched, thus callback should not be called
     self.assertFalse(self.callback.called)
Esempio n. 15
0
 def test_callback_called_on_remove_with_watch(self):
     new_instance = ArticleFactory(collaborators=self.users)
     self.watcher.watch()
     new_instance.collaborators.remove(self.users[0])
     # callback should be called with instance modification
     self.callback.assert_called_once_with(obj=new_instance,
                                           attr=self.attr,
                                           sender=self.watcher)
Esempio n. 16
0
 def test_callback_called_on_add_with_watch(self):
     new_instance = ArticleFactory(tags=self.tags)
     self.watcher.watch()
     new_instance.tags.add(TagFactory())
     # callback should be called with instance modification
     self.callback.assert_called_once_with(obj=new_instance,
                                           attr=self.attr,
                                           sender=self.watcher)
Esempio n. 17
0
 def test_callback_called_on_reverse_remove_with_watch(self):
     add_instance = ArticleFactory(hyperlinks=self.hyperlinks)
     self.watcher.watch()
     self.hyperlinks[0].articles.remove(add_instance)
     # callback should be called with instance modification
     self.callback.assert_called_once_with(obj=add_instance,
                                           attr=self.attr,
                                           sender=self.watcher)
Esempio n. 18
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)
Esempio n. 19
0
 def test_callback_called_on_reverse_add_with_watch(self):
     new_instance = HyperlinkFactory()
     add_instance = ArticleFactory()
     self.watcher.watch()
     new_instance.articles.add(add_instance)
     # callback should be called with instance modification
     self.callback.assert_called_once_with(obj=add_instance,
                                           attr=self.attr,
                                           sender=self.watcher)
Esempio n. 20
0
 def test_callback_called_on_reverse_remove_with_watch(self):
     new_instance = ArticleFactory(tags=self.tags)
     self.watcher.watch()
     self.tags[0].article = None
     self.tags[0].save()
     # callback should be called with instance modification
     self.callback.assert_called_once_with(obj=new_instance,
                                           attr=self.attr,
                                           sender=self.watcher)
Esempio n. 21
0
 def test_callback_called_on_related_modification_with_watch(self):
     new_instance = ArticleFactory()
     self.watcher.watch()
     user = new_instance.author
     user.label = 'modified'
     user.save()
     # callback should be called with instance modification
     self.callback.assert_called_once_with(obj=new_instance,
                                           attr=self.attr,
                                           sender=self.watcher)
Esempio n. 22
0
 def test_callback_called_on_modification_with_watch(self):
     new_instance = ArticleFactory(collaborators=self.users)
     self.watcher.watch()
     user = new_instance.collaborators.get(pk=1)
     user.label = 'modified'
     user.save()
     # callback should be called with instance modification
     self.callback.assert_called_once_with(obj=new_instance,
                                           attr=self.attr,
                                           sender=self.watcher)
Esempio n. 23
0
 def test_callback_called_on_modification_with_watch(self):
     new_instance = ArticleFactory(hyperlinks=self.hyperlinks)
     self.watcher.watch()
     hyperlink = new_instance.hyperlinks.get(pk=1)
     hyperlink.label = 'modified'
     hyperlink.save()
     # callback should be called with instance modification
     self.callback.assert_called_once_with(obj=new_instance,
                                           attr=self.attr,
                                           sender=self.watcher)
Esempio n. 24
0
 def test_callback_called_on_modification_with_watch(self):
     new_instance = ArticleFactory(tags=self.tags)
     self.watcher.watch()
     tag = new_instance.tags.get(pk=1)
     tag.label = 'modified'
     tag.save()
     # callback should be called with instance modification
     self.callback.assert_called_once_with(obj=new_instance,
                                           attr=self.attr,
                                           sender=self.watcher)
Esempio n. 25
0
 def test_callback_called_on_reverse_add_with_watch(self):
     new_instance = TagFactory()
     add_instance = ArticleFactory()
     self.watcher.watch()
     new_instance.content_object = add_instance
     new_instance.save()
     # callback should be called with instance modification
     self.callback.assert_called_once_with(obj=add_instance,
                                           attr=self.attr,
                                           sender=self.watcher)
Esempio n. 26
0
 def test_investigate_not_yield_created(self):
     """investigate should not yields anythong on creation"""
     article = ArticleFactory.build()
     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())
Esempio n. 27
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',
     ]))
Esempio n. 28
0
 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)
Esempio n. 29
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)
Esempio n. 30
0
 def test_callback_not_called_on_create_without_call_on_created(self):
     self.watcher.watch(call_on_created=False)
     ArticleFactory()
     # have not watched, thus callback should not be called
     self.assertFalse(self.callback.called)
Esempio n. 31
0
 def test_callback_not_called_on_reverse_remove_without_watch(self):
     add_instance = ArticleFactory(hyperlinks=self.hyperlinks)
     self.hyperlinks[0].articles.remove(add_instance)
     # have not watched, thus callback should not be called
     self.assertFalse(self.callback.called)
Esempio n. 32
0
 def test_callback_not_called_on_remove_without_watch(self):
     new_instance = ArticleFactory(tags=self.tags)
     new_instance.tags.remove(self.tags[0])
     # have not watched, thus callback should not be called
     self.assertFalse(self.callback.called)
Esempio n. 33
0
 def test_callback_not_called_on_reverse_remove_without_watch(self):
     ArticleFactory(tags=self.tags)
     self.tags[0].article = None
     self.tags[0].save()
     # have not watched, thus callback should not be called
     self.assertFalse(self.callback.called)