예제 #1
0
class ObserverWatchersRelatedWatcherBaseTestCaseOneToManyRel(TestCase):
    def setUp(self):
        self.model = Article
        self.attr = 'author'
        self.callback = MagicMock()
        self.watcher = RelatedWatcherBase(self.model, self.attr, self.callback)
        self.addCleanup(self.watcher.unwatch)

    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)

    def test_callback_called_on_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)
예제 #2
0
class ObserverWatchersRelatedWatcherBaseTestCaseOneToManyRel(TestCase):
    def setUp(self):
        self.model = Article
        self.attr = 'author'
        self.callback = MagicMock()
        self.watcher = RelatedWatcherBase(self.model,
                                          self.attr,
                                          self.callback)
        self.addCleanup(self.watcher.unwatch)

    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)

    def test_callback_called_on_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)
예제 #3
0
class ObserverWatchersRelatedWatcherBaseTestCaseRevManyToManyRel(TestCase):
    def setUp(self):
        self.hyperlinks = (
            HyperlinkFactory(),
            HyperlinkFactory(),
            HyperlinkFactory(),
            HyperlinkFactory(),
            HyperlinkFactory(),
        )
        self.model = Article
        self.attr = 'hyperlinks'
        self.callback = MagicMock()
        self.watcher = RelatedWatcherBase(self.model,
                                          self.attr,
                                          self.callback)
        self.addCleanup(self.watcher.unwatch)

    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)

    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)
예제 #4
0
class ObserverWatchersRelatedWatcherBaseTestCaseRevManyToManyRel(TestCase):
    def setUp(self):
        self.hyperlinks = (
            HyperlinkFactory(),
            HyperlinkFactory(),
            HyperlinkFactory(),
            HyperlinkFactory(),
            HyperlinkFactory(),
        )
        self.model = Article
        self.attr = 'hyperlinks'
        self.callback = MagicMock()
        self.watcher = RelatedWatcherBase(self.model, self.attr, self.callback)
        self.addCleanup(self.watcher.unwatch)

    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)

    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)
예제 #5
0
 def setUp(self):
     self.hyperlinks = (
         HyperlinkFactory(),
         HyperlinkFactory(),
         HyperlinkFactory(),
         HyperlinkFactory(),
         HyperlinkFactory(),
     )
     self.model = Article
     self.attr = 'hyperlinks'
     self.callback = MagicMock()
     self.watcher = RelatedWatcherBase(self.model, self.attr, self.callback)
     self.addCleanup(self.watcher.unwatch)
예제 #6
0
 def setUp(self):
     self.users = (
         UserFactory(),
         UserFactory(),
         UserFactory(),
         UserFactory(),
         UserFactory(),
     )
     self.model = Article
     self.attr = 'collaborators'
     self.callback = MagicMock()
     self.watcher = RelatedWatcherBase(self.model, self.attr, self.callback)
     self.addCleanup(self.watcher.unwatch)
예제 #7
0
 def setUp(self):
     self.projects = (
         ProjectFactory(),
         ProjectFactory(),
         ProjectFactory(),
         ProjectFactory(),
         ProjectFactory(),
     )
     self.model = Article
     self.attr = 'projects'
     self.callback = MagicMock()
     self.watcher = RelatedWatcherBase(self.model, self.attr, self.callback)
     self.addCleanup(self.watcher.unwatch)
예제 #8
0
 def setUp(self):
     self.model = Article
     self.attr = 'author'
     self.callback = MagicMock()
     self.watcher = RelatedWatcherBase(self.model,
                                       self.attr,
                                       self.callback)
     self.addCleanup(self.watcher.unwatch)
예제 #9
0
 def setUp(self):
     self.hyperlinks = (
         HyperlinkFactory(),
         HyperlinkFactory(),
         HyperlinkFactory(),
         HyperlinkFactory(),
         HyperlinkFactory(),
     )
     self.model = Article
     self.attr = 'hyperlinks'
     self.callback = MagicMock()
     self.watcher = RelatedWatcherBase(self.model,
                                       self.attr,
                                       self.callback)
     self.addCleanup(self.watcher.unwatch)
예제 #10
0
 def setUp(self):
     self.users = (
         UserFactory(),
         UserFactory(),
         UserFactory(),
         UserFactory(),
         UserFactory(),
     )
     self.model = Article
     self.attr = 'collaborators'
     self.callback = MagicMock()
     self.watcher = RelatedWatcherBase(self.model,
                                       self.attr,
                                       self.callback)
     self.addCleanup(self.watcher.unwatch)
예제 #11
0
 def setUp(self):
     self.projects = (
         ProjectFactory(),
         ProjectFactory(),
         ProjectFactory(),
         ProjectFactory(),
         ProjectFactory(),
     )
     self.model = Article
     self.attr = 'projects'
     self.callback = MagicMock()
     self.watcher = RelatedWatcherBase(self.model,
                                       self.attr,
                                       self.callback)
     self.addCleanup(self.watcher.unwatch)
예제 #12
0
 def setUp(self):
     self.model = Article
     self.attr = 'author'
     self.callback = MagicMock()
     self.watcher = RelatedWatcherBase(self.model, self.attr, self.callback)
     self.addCleanup(self.watcher.unwatch)