|
19 | 19 | import warehouse.malware.checks as checks
|
20 | 20 |
|
21 | 21 | from warehouse.malware.models import MalwareCheck, MalwareCheckState, MalwareVerdict
|
22 |
| -from warehouse.malware.tasks import run_check, sync_checks |
| 22 | +from warehouse.malware.tasks import remove_verdicts, run_check, sync_checks |
23 | 23 |
|
24 |
| -from ...common.db.malware import MalwareCheckFactory |
| 24 | +from ...common.db.malware import MalwareCheckFactory, MalwareVerdictFactory |
25 | 25 | from ...common.db.packaging import FileFactory, ProjectFactory, ReleaseFactory
|
26 | 26 |
|
27 | 27 |
|
@@ -255,3 +255,55 @@ def test_only_wiped_out(self, db_session):
|
255 | 255 | from codebase."
|
256 | 256 | ),
|
257 | 257 | ]
|
| 258 | + |
| 259 | + |
| 260 | +class TestRemoveVerdicts: |
| 261 | + def test_no_verdicts(self, db_session): |
| 262 | + check = MalwareCheckFactory.create() |
| 263 | + |
| 264 | + request = pretend.stub( |
| 265 | + db=db_session, |
| 266 | + log=pretend.stub(info=pretend.call_recorder(lambda *args, **kwargs: None),), |
| 267 | + ) |
| 268 | + task = pretend.stub() |
| 269 | + remove_verdicts(task, request, check.name) |
| 270 | + |
| 271 | + assert request.log.info.calls == [ |
| 272 | + pretend.call( |
| 273 | + "Removing 0 malware verdicts associated with %s version 1." % check.name |
| 274 | + ), |
| 275 | + ] |
| 276 | + |
| 277 | + @pytest.mark.parametrize(("check_with_verdicts"), [True, False]) |
| 278 | + def test_many_verdicts(self, db_session, check_with_verdicts): |
| 279 | + check0 = MalwareCheckFactory.create() |
| 280 | + check1 = MalwareCheckFactory.create() |
| 281 | + project = ProjectFactory.create(name="foo") |
| 282 | + release = ReleaseFactory.create(project=project) |
| 283 | + file0 = FileFactory.create(release=release, filename="foo.bar") |
| 284 | + num_verdicts = 10 |
| 285 | + |
| 286 | + for i in range(num_verdicts): |
| 287 | + MalwareVerdictFactory.create(check=check1, release_file=file0) |
| 288 | + |
| 289 | + request = pretend.stub( |
| 290 | + db=db_session, |
| 291 | + log=pretend.stub(info=pretend.call_recorder(lambda *args, **kwargs: None),), |
| 292 | + ) |
| 293 | + |
| 294 | + task = pretend.stub() |
| 295 | + |
| 296 | + if check_with_verdicts: |
| 297 | + wiped_out_check = check1 |
| 298 | + else: |
| 299 | + wiped_out_check = check0 |
| 300 | + num_verdicts = 0 |
| 301 | + |
| 302 | + remove_verdicts(task, request, wiped_out_check.name) |
| 303 | + |
| 304 | + assert request.log.info.calls == [ |
| 305 | + pretend.call( |
| 306 | + "Removing %d malware verdicts associated with %s version 1." |
| 307 | + % (num_verdicts, wiped_out_check.name) |
| 308 | + ), |
| 309 | + ] |
0 commit comments