|
14 | 14 |
|
15 | 15 | from random import randint
|
16 | 16 |
|
| 17 | +import pretend |
17 | 18 | import pytest
|
18 | 19 |
|
19 | 20 | from pyramid.httpexceptions import HTTPBadRequest, HTTPNotFound
|
@@ -193,10 +194,55 @@ def test_found(self, db_request):
|
193 | 194 | lookup_id = verdicts[index].id
|
194 | 195 | db_request.matchdict["verdict_id"] = lookup_id
|
195 | 196 |
|
196 |
| - assert views.get_verdict(db_request) == {"verdict": verdicts[index]} |
| 197 | + assert views.get_verdict(db_request) == { |
| 198 | + "verdict": verdicts[index], |
| 199 | + "classifications": ["Benign", "Indeterminate", "Threat"], |
| 200 | + } |
197 | 201 |
|
198 | 202 | def test_not_found(self, db_request):
|
199 | 203 | db_request.matchdict["verdict_id"] = uuid.uuid4()
|
200 | 204 |
|
201 | 205 | with pytest.raises(HTTPNotFound):
|
202 | 206 | views.get_verdict(db_request)
|
| 207 | + |
| 208 | + |
| 209 | +class TestReviewVerdict: |
| 210 | + @pytest.mark.parametrize( |
| 211 | + "manually_reviewed, reviewer_verdict", |
| 212 | + [ |
| 213 | + (False, None), # unreviewed verdict |
| 214 | + (True, VerdictClassification.Threat), # previously reviewed |
| 215 | + ], |
| 216 | + ) |
| 217 | + def test_set_classification(self, db_request, manually_reviewed, reviewer_verdict): |
| 218 | + verdict = MalwareVerdictFactory.create( |
| 219 | + manually_reviewed=manually_reviewed, reviewer_verdict=reviewer_verdict, |
| 220 | + ) |
| 221 | + |
| 222 | + db_request.matchdict["verdict_id"] = verdict.id |
| 223 | + db_request.POST = {"classification": "Benign"} |
| 224 | + db_request.session = pretend.stub( |
| 225 | + flash=pretend.call_recorder(lambda *a, **kw: None) |
| 226 | + ) |
| 227 | + |
| 228 | + db_request.route_path = pretend.call_recorder( |
| 229 | + lambda *a, **kw: "/admin/verdicts/%s/review" % verdict.id |
| 230 | + ) |
| 231 | + |
| 232 | + views.review_verdict(db_request) |
| 233 | + |
| 234 | + assert db_request.session.flash.calls == [ |
| 235 | + pretend.call("Verdict %s marked as reviewed." % verdict.id, queue="success") |
| 236 | + ] |
| 237 | + |
| 238 | + assert verdict.manually_reviewed |
| 239 | + assert verdict.reviewer_verdict == VerdictClassification.Benign |
| 240 | + |
| 241 | + @pytest.mark.parametrize("post_params", [{}, {"classification": "Nope"}]) |
| 242 | + def test_errors(self, db_request, post_params): |
| 243 | + verdict = MalwareVerdictFactory.create() |
| 244 | + db_request.matchdict["verdict_id"] = verdict.id |
| 245 | + db_request.POST = post_params |
| 246 | + |
| 247 | + with pytest.raises(HTTPBadRequest): |
| 248 | + views.review_verdict(db_request) |
0 commit comments