When media is deleted, delete associated comments too.
authorBrett Smith <brettcsmith@brettcsmith.org>
Sat, 17 Mar 2012 21:53:00 +0000 (17:53 -0400)
committerBrett Smith <brettcsmith@brettcsmith.org>
Sat, 17 Mar 2012 21:53:00 +0000 (17:53 -0400)
The actual code is just a simple for loop; there might be a better
implementation but this is a fine start.  I also extended test_delete to
check this too.

mediagoblin/tests/test_submission.py
mediagoblin/user_pages/views.py

index 2f11bdfbd726351d9d0f2ff06e3bf24381243ac5..1f56779e4cae0c202d24a65756691d0202a9ab54 100644 (file)
@@ -180,6 +180,18 @@ class TestSubmission:
         # Does media entry exist?
         assert_true(media)
 
+        # Add a comment, so we can test for its deletion later.
+        get_comments = lambda: list(
+            request.db.MediaComment.find({'media_entry': media._id}))
+        assert_false(get_comments())
+        response = self.test_app.post(
+            request.urlgen('mediagoblin.user_pages.media_post_comment',
+                           user=self.test_user.username,
+                           media=media._id),
+            {'comment_content': 'i love this test'})
+        response.follow()
+        assert_true(get_comments())
+
         # Do not confirm deletion
         # ---------------------------------------------------
         response = self.test_app.post(
@@ -219,6 +231,9 @@ class TestSubmission:
             request.db.MediaEntry.find(
                 {'_id': media._id}).count())
 
+        # How about the comment?
+        assert_false(get_comments())
+
     def test_malicious_uploads(self):
         # Test non-suppoerted file with non-supported extension
         # -----------------------------------------------------
index 530dea6470feac6e9e22954ea70f64f21ba18930..6eff684c170940c10ae639ee13300d766906699b 100644 (file)
@@ -173,6 +173,10 @@ def media_confirm_delete(request, media):
         if form.confirm.data is True:
             username = media.get_uploader.username
 
+            # Delete all the associated comments
+            for comment in media.get_comments():
+                comment.delete()
+
             # Delete all files on the public storage
             delete_media_files(media)