Commit | Line | Data |
---|---|---|
968dd9e7 | 1 | # GNU MediaGoblin -- federated, autonomous media hosting |
cf29e8a8 | 2 | # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. |
968dd9e7 E |
3 | # |
4 | # This program is free software: you can redistribute it and/or modify | |
5 | # it under the terms of the GNU Affero General Public License as published by | |
6 | # the Free Software Foundation, either version 3 of the License, or | |
7 | # (at your option) any later version. | |
8 | # | |
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU Affero General Public License for more details. | |
13 | # | |
14 | # You should have received a copy of the GNU Affero General Public License | |
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | ||
3f931680 | 17 | from mediagoblin.db.base import Session |
e9b4e500 | 18 | from mediagoblin.db.models import User, MediaEntry, MediaComment |
5c2ece74 | 19 | from mediagoblin.tests.tools import fixture_add_user, fixture_media_entry |
e9b4e500 | 20 | |
968dd9e7 | 21 | |
5c2ece74 | 22 | def test_404_for_non_existent(test_app): |
b97144dc | 23 | res = test_app.get('/does-not-exist/', expect_errors=True) |
7d503a89 | 24 | assert res.status_int == 404 |
e9b4e500 E |
25 | |
26 | ||
5c2ece74 | 27 | def test_user_deletes_other_comments(test_app): |
e9b4e500 E |
28 | user_a = fixture_add_user(u"chris_a") |
29 | user_b = fixture_add_user(u"chris_b") | |
30 | ||
2d7b6bde | 31 | media_a = fixture_media_entry(uploader=user_a.id, save=False, |
56d13467 | 32 | expunge=False, fake_upload=False) |
2d7b6bde | 33 | media_b = fixture_media_entry(uploader=user_b.id, save=False, |
56d13467 | 34 | expunge=False, fake_upload=False) |
3f931680 E |
35 | Session.add(media_a) |
36 | Session.add(media_b) | |
37 | Session.flush() | |
e9b4e500 E |
38 | |
39 | # Create all 4 possible comments: | |
40 | for u_id in (user_a.id, user_b.id): | |
41 | for m_id in (media_a.id, media_b.id): | |
42 | cmt = MediaComment() | |
43 | cmt.media_entry = m_id | |
44 | cmt.author = u_id | |
45 | cmt.content = u"Some Comment" | |
3f931680 E |
46 | Session.add(cmt) |
47 | ||
48 | Session.flush() | |
e9b4e500 E |
49 | |
50 | usr_cnt1 = User.query.count() | |
51 | med_cnt1 = MediaEntry.query.count() | |
52 | cmt_cnt1 = MediaComment.query.count() | |
53 | ||
3f931680 | 54 | User.query.get(user_a.id).delete(commit=False) |
e9b4e500 E |
55 | |
56 | usr_cnt2 = User.query.count() | |
57 | med_cnt2 = MediaEntry.query.count() | |
58 | cmt_cnt2 = MediaComment.query.count() | |
59 | ||
60 | # One user deleted | |
7d503a89 | 61 | assert usr_cnt2 == usr_cnt1 - 1 |
e9b4e500 | 62 | # One media gone |
7d503a89 | 63 | assert med_cnt2 == med_cnt1 - 1 |
e9b4e500 | 64 | # Three of four comments gone. |
7d503a89 | 65 | assert cmt_cnt2 == cmt_cnt1 - 3 |
e9b4e500 E |
66 | |
67 | User.query.get(user_b.id).delete() | |
68 | ||
69 | usr_cnt2 = User.query.count() | |
70 | med_cnt2 = MediaEntry.query.count() | |
71 | cmt_cnt2 = MediaComment.query.count() | |
72 | ||
73 | # All users gone | |
7d503a89 | 74 | assert usr_cnt2 == usr_cnt1 - 2 |
e9b4e500 | 75 | # All media gone |
7d503a89 | 76 | assert med_cnt2 == med_cnt1 - 2 |
e9b4e500 | 77 | # All comments gone |
7d503a89 | 78 | assert cmt_cnt2 == cmt_cnt1 - 4 |
df5b142a E |
79 | |
80 | ||
5c2ece74 | 81 | def test_media_deletes_broken_attachment(test_app): |
df5b142a E |
82 | user_a = fixture_add_user(u"chris_a") |
83 | ||
2d7b6bde | 84 | media = fixture_media_entry(uploader=user_a.id, save=False, expunge=False) |
df5b142a E |
85 | media.attachment_files.append(dict( |
86 | name=u"some name", | |
87 | filepath=[u"does", u"not", u"exist"], | |
88 | )) | |
89 | Session.add(media) | |
90 | Session.flush() | |
91 | ||
92 | MediaEntry.query.get(media.id).delete() | |
93 | User.query.get(user_a.id).delete() |