aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/tests/test_misc.py
diff options
context:
space:
mode:
authorElrond <elrond+mediagoblin.org@samba-tng.org>2013-02-18 14:46:28 +0100
committerElrond <elrond+mediagoblin.org@samba-tng.org>2013-02-18 14:55:42 +0100
commitdf5b142ab9bfc590f17768079104f6cfa2cd7bba (patch)
treef9cc60f8cbc1aa0bf8103f33794d5261933f8fa6 /mediagoblin/tests/test_misc.py
parent61e39d90e58b8cea5c837d6da5731ab42127c642 (diff)
downloadmediagoblin-df5b142ab9bfc590f17768079104f6cfa2cd7bba.tar.lz
mediagoblin-df5b142ab9bfc590f17768079104f6cfa2cd7bba.tar.xz
mediagoblin-df5b142ab9bfc590f17768079104f6cfa2cd7bba.zip
Fix deleting media with attachments.
If one deletes a media with attachments, there have been various problems: 1) If the file in the storage did not exist any more (maybe because due to a previous deletion attempt?), the error propagation failed, because the wrong thing was gathered. 2) The attachment database entries were not deleted. Using cascade for this, for now. Also add a simple unit test, that tests both by having a broken attachment on a media.
Diffstat (limited to 'mediagoblin/tests/test_misc.py')
-rw-r--r--mediagoblin/tests/test_misc.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/mediagoblin/tests/test_misc.py b/mediagoblin/tests/test_misc.py
index b48b8762..776affc6 100644
--- a/mediagoblin/tests/test_misc.py
+++ b/mediagoblin/tests/test_misc.py
@@ -78,3 +78,18 @@ def test_user_deletes_other_comments():
assert_equal(med_cnt2, med_cnt1 - 2)
# All comments gone
assert_equal(cmt_cnt2, cmt_cnt1 - 4)
+
+
+def test_media_deletes_broken_attachment():
+ user_a = fixture_add_user(u"chris_a")
+
+ media = fixture_media_entry(uploader=user_a.id, save=False)
+ media.attachment_files.append(dict(
+ name=u"some name",
+ filepath=[u"does", u"not", u"exist"],
+ ))
+ Session.add(media)
+ Session.flush()
+
+ MediaEntry.query.get(media.id).delete()
+ User.query.get(user_a.id).delete()