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/>.
20 from mediagoblin
.tools
import template
21 from mediagoblin
.tests
.tools
import (fixture_add_user
, fixture_media_entry
,
22 fixture_add_comment
, fixture_add_comment_report
)
23 from mediagoblin
.db
.models
import (MediaReport
, CommentReport
, User
,
27 class TestReportFiling
:
28 @pytest.fixture(autouse
=True)
29 def _setup(self
, test_app
):
30 self
.test_app
= test_app
32 fixture_add_user(u
'allie',
33 privileges
=[u
'reporter',u
'active'])
34 fixture_add_user(u
'natalie',
35 privileges
=[u
'active', u
'moderator'])
37 def login(self
, username
):
44 self
.test_app
.get('/auth/logout/')
46 def do_post(self
, data
, *context_keys
, **kwargs
):
47 url
= kwargs
.pop('url', '/submit/')
48 do_follow
= kwargs
.pop('do_follow', False)
49 template
.clear_test_template_context()
50 response
= self
.test_app
.post(url
, data
, **kwargs
)
53 context_data
= template
.TEMPLATE_TEST_CONTEXT
54 for key
in context_keys
:
55 context_data
= context_data
[key
]
56 return response
, context_data
58 def query_for_users(self
):
59 return (User
.query
.filter(User
.username
==u
'allie').first(),
60 User
.query
.filter(User
.username
==u
'natalie').first())
62 def testMediaReports(self
):
64 allie_user
, natalie_user
= self
.query_for_users()
65 allie_id
= allie_user
.id
67 media_entry
= fixture_media_entry(uploader
=natalie_user
.id,
71 media_uri_slug
= '/u/{0}/m/{1}/'.format(natalie_user
.username
,
74 response
= self
.test_app
.get(media_uri_slug
+ "report/")
75 assert response
.status
== "200 OK"
77 response
, context
= self
.do_post(
78 {'report_reason':u
'Testing Media Report',
79 'reporter_id':six
.text_type(allie_id
)},url
= media_uri_slug
+ "report/")
81 assert response
.status
== "302 FOUND"
83 media_report
= MediaReport
.query
.first()
85 allie_user
, natalie_user
= self
.query_for_users()
86 assert media_report
is not None
87 assert media_report
.report_content
== u
'Testing Media Report'
88 assert media_report
.reporter_id
== allie_id
89 assert media_report
.reported_user_id
== natalie_user
.id
90 assert media_report
.created
is not None
91 assert media_report
.discriminator
== 'media_report'
93 def testCommentReports(self
):
95 allie_user
, natalie_user
= self
.query_for_users()
96 allie_id
= allie_user
.id
98 media_entry
= fixture_media_entry(uploader
=natalie_user
.id,
101 fixture_add_comment(media_entry
=mid
,
102 author
=natalie_user
.id)
103 comment
= MediaComment
.query
.first()
105 comment_uri_slug
= '/u/{0}/m/{1}/c/{2}/'.format(natalie_user
.username
,
109 response
= self
.test_app
.get(comment_uri_slug
+ "report/")
110 assert response
.status
== "200 OK"
112 response
, context
= self
.do_post({
113 'report_reason':u
'Testing Comment Report',
114 'reporter_id':six
.text_type(allie_id
)},url
= comment_uri_slug
+ "report/")
116 assert response
.status
== "302 FOUND"
118 comment_report
= CommentReport
.query
.first()
120 allie_user
, natalie_user
= self
.query_for_users()
121 assert comment_report
is not None
122 assert comment_report
.report_content
== u
'Testing Comment Report'
123 assert comment_report
.reporter_id
== allie_id
124 assert comment_report
.reported_user_id
== natalie_user
.id
125 assert comment_report
.created
is not None
126 assert comment_report
.discriminator
== 'comment_report'
128 def testArchivingReports(self
):
129 self
.login(u
'natalie')
130 allie_user
, natalie_user
= self
.query_for_users()
131 allie_id
, natalie_id
= allie_user
.id, natalie_user
.id
133 fixture_add_comment(author
=allie_user
.id,
134 comment
=u
'Comment will be removed')
135 test_comment
= MediaComment
.query
.filter(
136 MediaComment
.author
==allie_user
.id).first()
137 fixture_add_comment_report(comment
=test_comment
,
138 reported_user
=allie_user
,
139 report_content
=u
'Testing Archived Reports #1',
140 reporter
=natalie_user
)
141 comment_report
= CommentReport
.query
.filter(
142 CommentReport
.reported_user
==allie_user
).first()
144 assert comment_report
.report_content
== u
'Testing Archived Reports #1'
145 response
, context
= self
.do_post(
146 {'action_to_resolve':[u
'userban', u
'delete'],
147 'targeted_user':allie_user
.id,
148 'resolution_content':u
'This is a test of archiving reports.'},
149 url
='/mod/reports/{0}/'.format(comment_report
.id))
151 assert response
.status
== "302 FOUND"
152 allie_user
, natalie_user
= self
.query_for_users()
154 archived_report
= CommentReport
.query
.filter(
155 CommentReport
.reported_user
==allie_user
).first()
157 assert CommentReport
.query
.count() != 0
158 assert archived_report
is not None
159 assert archived_report
.report_content
== u
'Testing Archived Reports #1'
160 assert archived_report
.reporter_id
== natalie_id
161 assert archived_report
.reported_user_id
== allie_id
162 assert archived_report
.created
is not None
163 assert archived_report
.resolved
is not None
164 assert archived_report
.result
== u
'''This is a test of archiving reports.
165 natalie banned user allie indefinitely.
166 natalie deleted the comment.'''
167 assert archived_report
.discriminator
== 'comment_report'