|
| 1 | +from datetime import datetime |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from pgcommitfest.commitfest.models import ( |
| 6 | + Patch, |
| 7 | + PatchHistory, |
| 8 | + PatchOnCommitFest, |
| 9 | + PendingNotification, |
| 10 | + Tag, |
| 11 | +) |
| 12 | +from pgcommitfest.userprofile.models import UserProfile |
| 13 | + |
| 14 | +pytestmark = pytest.mark.django_db |
| 15 | + |
| 16 | + |
| 17 | +def test_remove_all_reviewers(client, open_cf, alice, bob, charlie): |
| 18 | + UserProfile.objects.create(user=bob, notify_all_reviewer=True) |
| 19 | + |
| 20 | + pgconfdev_tag = Tag.objects.create( |
| 21 | + name="PGConf.dev", color="#000000", description="PGConf.dev" |
| 22 | + ) |
| 23 | + patch = Patch.objects.create(name="Test patch") |
| 24 | + patch.authors.add(alice) |
| 25 | + patch.reviewers.add(bob, charlie) |
| 26 | + patch.tags.add(pgconfdev_tag) |
| 27 | + PatchOnCommitFest.objects.create( |
| 28 | + patch=patch, |
| 29 | + commitfest=open_cf, |
| 30 | + enterdate=datetime.now(), |
| 31 | + status=PatchOnCommitFest.STATUS_REVIEW, |
| 32 | + ) |
| 33 | + |
| 34 | + client.force_login(alice) |
| 35 | + response = client.get(f"/patch/{patch.id}/reviewer/remove_all/") |
| 36 | + assert response.status_code == 302 |
| 37 | + assert list(patch.reviewers.all()) == [] |
| 38 | + assert ( |
| 39 | + "Removed all reviewers" |
| 40 | + in PatchHistory.objects.filter(patch=patch).latest("date").what |
| 41 | + ) |
| 42 | + assert PendingNotification.objects.filter(user=bob).exists() |
| 43 | + |
| 44 | + |
| 45 | +def test_remove_all_reviewers_forbidden_without_tag(client, open_cf, alice, bob): |
| 46 | + patch = Patch.objects.create(name="Test patch") |
| 47 | + patch.authors.add(alice) |
| 48 | + patch.reviewers.add(bob) |
| 49 | + PatchOnCommitFest.objects.create( |
| 50 | + patch=patch, |
| 51 | + commitfest=open_cf, |
| 52 | + enterdate=datetime.now(), |
| 53 | + status=PatchOnCommitFest.STATUS_REVIEW, |
| 54 | + ) |
| 55 | + |
| 56 | + client.force_login(alice) |
| 57 | + response = client.get(f"/patch/{patch.id}/reviewer/remove_all/") |
| 58 | + assert response.status_code == 403 |
| 59 | + assert bob in patch.reviewers.all() |
0 commit comments