Ejemplo n.º 1
0
class ForumDocumentSignalsTests(Elastic7TestCase):
    def setUp(self):
        self.post = PostFactory()
        self.post_id = self.post.id

    def get_doc(self):
        return ForumDocument.get(self.post_id)

    def test_post_save(self):
        self.post.content = "foobar"
        self.post.save()

        self.assertEqual(self.get_doc().content, "foobar")

    def test_thread_save(self):
        thread = self.post.thread
        thread.title = "foobar"
        thread.save()

        self.assertEqual(self.get_doc().thread_title, "foobar")

    def test_post_delete(self):
        self.post.delete()

        with self.assertRaises(NotFoundError):
            self.get_doc()

    def test_thread_delete(self):
        self.post.thread.delete()

        with self.assertRaises(NotFoundError):
            self.get_doc()
Ejemplo n.º 2
0
 def test_update_forum_does_not_update_thread(self):
     # Updating/saving an old post in a forum should _not_ update
     # the last_post key in that forum.
     t = ThreadFactory()
     old = PostFactory(thread=t)
     last = PostFactory(thread=t)
     old.content = 'updated content'
     old.save()
     eq_(last.id, t.forum.last_post_id)
Ejemplo n.º 3
0
 def test_update_post_does_not_update_thread(self):
     # Updating/saving an old post in a thread should _not_ update
     # the last_post key in that thread.
     t = ThreadFactory()
     old = PostFactory(thread=t)
     last = PostFactory(thread=t)
     old.content = "updated content"
     old.save()
     eq_(last.id, old.thread.last_post_id)
Ejemplo n.º 4
0
 def test_update_forum_does_not_update_thread(self):
     # Updating/saving an old post in a forum should _not_ update
     # the last_post key in that forum.
     t = ThreadFactory()
     old = PostFactory(thread=t)
     last = PostFactory(thread=t)
     old.content = 'updated content'
     old.save()
     eq_(last.id, t.forum.last_post_id)
Ejemplo n.º 5
0
    def test_save_old_post_no_timestamps(self):
        """Saving an existing post should update the updated date."""
        created = datetime(2010, 5, 4, 14, 4, 22)
        updated = datetime(2010, 5, 4, 14, 4, 31)
        p = PostFactory(thread=self.thread, created=created, updated=updated)

        eq_(updated, p.updated)

        p.content = 'baz'
        p.updated_by = self.user
        p.save()
        now = datetime.now()

        self.assertDateTimeAlmostEqual(now, p.updated, self.delta)
        eq_(created, p.created)
Ejemplo n.º 6
0
    def test_save_old_post_no_timestamps(self):
        """Saving an existing post should update the updated date."""
        created = datetime(2010, 5, 4, 14, 4, 22)
        updated = datetime(2010, 5, 4, 14, 4, 31)
        p = PostFactory(thread=self.thread, created=created, updated=updated)

        eq_(updated, p.updated)

        p.content = 'baz'
        p.updated_by = self.user
        p.save()
        now = datetime.now()

        self.assertDateTimeAlmostEqual(now, p.updated, self.delta)
        eq_(created, p.created)