Fix errors in collection views
[mediagoblin.git] / mediagoblin / tests / test_misc.py
CommitLineData
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
17from nose.tools import assert_equal
18
3f931680 19from mediagoblin.db.base import Session
e9b4e500
E
20from mediagoblin.db.models import User, MediaEntry, MediaComment
21from mediagoblin.tests.tools import get_app, \
22 fixture_add_user, fixture_media_entry
23
968dd9e7 24
b97144dc 25def test_404_for_non_existent():
1be247b3 26 test_app = get_app(dump_old_app=False)
b97144dc
SS
27 res = test_app.get('/does-not-exist/', expect_errors=True)
28 assert_equal(res.status_int, 404)
e9b4e500
E
29
30
31def test_user_deletes_other_comments():
32 user_a = fixture_add_user(u"chris_a")
33 user_b = fixture_add_user(u"chris_b")
34
3f931680
E
35 media_a = fixture_media_entry(uploader=user_a.id, save=False)
36 media_b = fixture_media_entry(uploader=user_b.id, save=False)
37 Session.add(media_a)
38 Session.add(media_b)
39 Session.flush()
e9b4e500
E
40
41 # Create all 4 possible comments:
42 for u_id in (user_a.id, user_b.id):
43 for m_id in (media_a.id, media_b.id):
44 cmt = MediaComment()
45 cmt.media_entry = m_id
46 cmt.author = u_id
47 cmt.content = u"Some Comment"
3f931680
E
48 Session.add(cmt)
49
50 Session.flush()
e9b4e500
E
51
52 usr_cnt1 = User.query.count()
53 med_cnt1 = MediaEntry.query.count()
54 cmt_cnt1 = MediaComment.query.count()
55
3f931680 56 User.query.get(user_a.id).delete(commit=False)
e9b4e500
E
57
58 usr_cnt2 = User.query.count()
59 med_cnt2 = MediaEntry.query.count()
60 cmt_cnt2 = MediaComment.query.count()
61
62 # One user deleted
63 assert_equal(usr_cnt2, usr_cnt1 - 1)
64 # One media gone
65 assert_equal(med_cnt2, med_cnt1 - 1)
66 # Three of four comments gone.
67 assert_equal(cmt_cnt2, cmt_cnt1 - 3)
68
69 User.query.get(user_b.id).delete()
70
71 usr_cnt2 = User.query.count()
72 med_cnt2 = MediaEntry.query.count()
73 cmt_cnt2 = MediaComment.query.count()
74
75 # All users gone
76 assert_equal(usr_cnt2, usr_cnt1 - 2)
77 # All media gone
78 assert_equal(med_cnt2, med_cnt1 - 2)
79 # All comments gone
80 assert_equal(cmt_cnt2, cmt_cnt1 - 4)