def setUp(self): self.model = Tag self.attr = 'content_object' self.callback = MagicMock() self.watcher = GenericRelatedWatcher(self.model, self.attr, self.callback) self.addCleanup(self.watcher.unwatch)
def setUp(self): self.tags = ( TagFactory(), TagFactory(), TagFactory(), TagFactory(), TagFactory(), ) self.model = Article self.attr = 'tags' self.callback = MagicMock() self.watcher = GenericRelatedWatcher(self.model, self.attr, self.callback) self.addCleanup(self.watcher.unwatch)
class ObserverWatchersGenericRelatedWatcherTestCaseRev(TestCase): def setUp(self): self.model = Tag self.attr = 'content_object' self.callback = MagicMock() self.watcher = GenericRelatedWatcher(self.model, self.attr, self.callback) self.addCleanup(self.watcher.unwatch) def test_callback_not_called_on_create_without_watch(self): TagFactory() # have not watched, thus callback should not be called self.assertFalse(self.callback.called) def test_callback_called_on_create_with_watch(self): self.watcher.watch() new_instance = TagFactory() # callback should be called with newly created instance self.callback.assert_called_once_with( obj=new_instance, attr=self.attr, sender=self.watcher) def test_callback_not_called_on_create_without_call_on_created(self): self.watcher.watch(call_on_created=False) TagFactory() # have 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 = TagFactory() new_instance.content_object = ArticleFactory() new_instance.save() # have not watched, thus callback should not be called self.assertFalse(self.callback.called) @skip("TODO: Fix me") def test_callback_called_on_modification_with_watch(self): new_instance = TagFactory() self.watcher.watch() new_instance.content_object = ArticleFactory() 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_not_called_on_modification_with_non_interest_attr(self): new_instance = TagFactory() new_instance.label = '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_related_modification_without_watch(self): new_instance = TagFactory(content_object=UserFactory()) user = new_instance.content_object user.label = 'modified' user.save() # have not watched, thus callback should not be called self.assertFalse(self.callback.called) @skip("TODO: Fix me") def test_callback_called_on_related_modification_with_watch(self): new_instance = TagFactory(content_object=UserFactory()) user = new_instance.content_object 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)
class ObserverWatchersGenericRelatedWatcherTestCase(TestCase): def setUp(self): self.tags = ( TagFactory(), TagFactory(), TagFactory(), TagFactory(), TagFactory(), ) self.model = Article self.attr = 'tags' self.callback = MagicMock() self.watcher = GenericRelatedWatcher(self.model, self.attr, self.callback) self.addCleanup(self.watcher.unwatch) def test_callback_not_called_on_add_without_watch(self): new_instance = ArticleFactory(tags=self.tags) new_instance.tags.add(TagFactory()) # have not watched, thus callback should not be called self.assertFalse(self.callback.called) 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) 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) @skip("TODO: Fixme") 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) 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) 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) 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) @skip("TODO: Fixme") 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) def test_callback_not_called_on_create_without_watch(self): ArticleFactory() # have not watched, thus callback should not be called self.assertFalse(self.callback.called) 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) 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) 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(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) 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)
class ObserverWatchersGenericRelatedWatcherTestCaseRev(TestCase): def setUp(self): self.model = Tag self.attr = 'content_object' self.callback = MagicMock() self.watcher = GenericRelatedWatcher(self.model, self.attr, self.callback) self.addCleanup(self.watcher.unwatch) def test_callback_not_called_on_create_without_watch(self): TagFactory() # have not watched, thus callback should not be called self.assertFalse(self.callback.called) def test_callback_called_on_create_with_watch(self): self.watcher.watch() new_instance = TagFactory() # callback should be called with newly created instance self.callback.assert_called_once_with(obj=new_instance, attr=self.attr, sender=self.watcher) def test_callback_not_called_on_create_without_call_on_created(self): self.watcher.watch(call_on_created=False) TagFactory() # have 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 = TagFactory() new_instance.content_object = ArticleFactory() new_instance.save() # have not watched, thus callback should not be called self.assertFalse(self.callback.called) @skip("TODO: Fix me") def test_callback_called_on_modification_with_watch(self): new_instance = TagFactory() self.watcher.watch() new_instance.content_object = ArticleFactory() 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_not_called_on_modification_with_non_interest_attr(self): new_instance = TagFactory() new_instance.label = '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_related_modification_without_watch(self): new_instance = TagFactory(content_object=UserFactory()) user = new_instance.content_object user.label = 'modified' user.save() # have not watched, thus callback should not be called self.assertFalse(self.callback.called) @skip("TODO: Fix me") def test_callback_called_on_related_modification_with_watch(self): new_instance = TagFactory(content_object=UserFactory()) user = new_instance.content_object 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)
class ObserverWatchersGenericRelatedWatcherTestCase(TestCase): def setUp(self): self.tags = ( TagFactory(), TagFactory(), TagFactory(), TagFactory(), TagFactory(), ) self.model = Article self.attr = 'tags' self.callback = MagicMock() self.watcher = GenericRelatedWatcher(self.model, self.attr, self.callback) self.addCleanup(self.watcher.unwatch) def test_callback_not_called_on_add_without_watch(self): new_instance = ArticleFactory(tags=self.tags) new_instance.tags.add(TagFactory()) # have not watched, thus callback should not be called self.assertFalse(self.callback.called) 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) 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) @skip("TODO: Fixme") 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) 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) 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) 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) @skip("TODO: Fixme") 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) def test_callback_not_called_on_create_without_watch(self): ArticleFactory() # have not watched, thus callback should not be called self.assertFalse(self.callback.called) 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) 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) 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(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) 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)