1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
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.
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.
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/>.
19 from mediagoblin
.tools
import template
20 from mediagoblin
.tests
.tools
import (fixture_add_user
, fixture_media_entry
,
21 fixture_add_comment
, fixture_add_comment_report
)
22 from mediagoblin
.db
.models
import (MediaReport
, CommentReport
, User
,
23 MediaComment
,ArchivedReport
)
26 class TestReportFiling
:
27 @pytest.fixture(autouse
=True)
28 def _setup(self
, test_app
):
29 self
.test_app
= test_app
31 fixture_add_user(u
'allie',
32 privileges
=[u
'reporter',u
'active'])
33 fixture_add_user(u
'natalie',
34 privileges
=[u
'active', u
'moderator'])
36 def login(self
, username
):
43 self
.test_app
.get('/auth/logout/')
45 def do_post(self
, data
, *context_keys
, **kwargs
):
46 url
= kwargs
.pop('url', '/submit/')
47 do_follow
= kwargs
.pop('do_follow', False)
48 template
.clear_test_template_context()
49 response
= self
.test_app
.post(url
, data
, **kwargs
)
52 context_data
= template
.TEMPLATE_TEST_CONTEXT
53 for key
in context_keys
:
54 context_data
= context_data
[key
]
55 return response
, context_data
57 def query_for_users(self
):
58 return (User
.query
.filter(User
.username
==u
'allie').first(),
59 User
.query
.filter(User
.username
==u
'natalie').first())
61 def testMediaReports(self
):
63 allie_user
, natalie_user
= self
.query_for_users()
64 allie_id
= allie_user
.id
66 media_entry
= fixture_media_entry(uploader
=natalie_user
.id,
70 media_uri_slug
= '/u/{0}/m/{1}/'.format(natalie_user
.username
,
73 response
= self
.test_app
.get(media_uri_slug
+ "report/")
74 assert response
.status
== "200 OK"
76 response
, context
= self
.do_post(
77 {'report_reason':u
'Testing Media Report',
78 'reporter_id':unicode(allie_id
)},url
= media_uri_slug
+ "report/")
80 assert response
.status
== "302 FOUND"
82 media_report
= MediaReport
.query
.first()
84 allie_user
, natalie_user
= self
.query_for_users()
85 assert media_report
is not None
86 assert media_report
.report_content
== u
'Testing Media Report'
87 assert media_report
.reporter_id
== allie_id
88 assert media_report
.reported_user_id
== natalie_user
.id
89 assert media_report
.created
is not None
90 assert media_report
.discriminator
== 'media_report'
92 def testCommentReports(self
):
94 allie_user
, natalie_user
= self
.query_for_users()
95 allie_id
= allie_user
.id
97 media_entry
= fixture_media_entry(uploader
=natalie_user
.id,
100 fixture_add_comment(media_entry
=mid
,
101 author
=natalie_user
.id)
102 comment
= MediaComment
.query
.first()
104 comment_uri_slug
= '/u/{0}/m/{1}/c/{2}/'.format(natalie_user
.username
,
108 response
= self
.test_app
.get(comment_uri_slug
+ "report/")
109 assert response
.status
== "200 OK"
111 response
, context
= self
.do_post({
112 'report_reason':u
'Testing Comment Report',
113 'reporter_id':unicode(allie_id
)},url
= comment_uri_slug
+ "report/")
115 assert response
.status
== "302 FOUND"
117 comment_report
= CommentReport
.query
.first()
119 allie_user
, natalie_user
= self
.query_for_users()
120 assert comment_report
is not None
121 assert comment_report
.report_content
== u
'Testing Comment Report'
122 assert comment_report
.reporter_id
== allie_id
123 assert comment_report
.reported_user_id
== natalie_user
.id
124 assert comment_report
.created
is not None
125 assert comment_report
.discriminator
== 'comment_report'
127 def testArchivingReports(self
):
128 self
.login(u
'natalie')
129 allie_user
, natalie_user
= self
.query_for_users()
130 allie_id
, natalie_id
= allie_user
.id, natalie_user
.id
132 fixture_add_comment(author
=allie_user
.id,
133 comment
=u
'Comment will be removed')
134 test_comment
= MediaComment
.query
.filter(
135 MediaComment
.author
==allie_user
.id).first()
136 fixture_add_comment_report(comment
=test_comment
,
137 reported_user
=allie_user
,
138 report_content
=u
'Testing Archived Reports #1',
139 reporter
=natalie_user
)
140 comment_report
= CommentReport
.query
.filter(
141 CommentReport
.reported_user
==allie_user
).first()
143 assert comment_report
.report_content
== u
'Testing Archived Reports #1'
144 response
, context
= self
.do_post(
145 {'action_to_resolve':[u
'userban', u
'delete'],
146 'targeted_user':allie_user
.id,
147 'resolution_content':u
'This is a test of archiving reports.'},
148 url
='/mod/reports/{0}/'.format(comment_report
.id))
150 assert response
.status
== "302 FOUND"
151 self
.query_for_users()
153 archived_report
= ArchivedReport
.query
.first()
155 assert CommentReport
.query
.count() == 0
156 assert archived_report
is not None
157 assert archived_report
.report_content
== u
'Testing Archived Reports #1'
158 assert archived_report
.reporter_id
== natalie_id
159 assert archived_report
.reported_user_id
== allie_id
160 assert archived_report
.created
is not None
161 assert archived_report
.resolved
is not None
162 assert archived_report
.result
== u
'This is a test of archiving reports\
163 .<br>natalie banned user allie indefinitely.<br>natalie deleted the comment.'
164 assert archived_report
.discriminator
== 'archived_report'