|
8 | 8 | from django.urls import reverse |
9 | 9 | from django.utils import timezone |
10 | 10 |
|
| 11 | +from core.elections_eligibility import CandidateValidationResult, EligibleVoter |
11 | 12 | from core.freeipa.exceptions import FreeIPAMisconfiguredError |
12 | 13 | from core.freeipa.group import FreeIPAGroup |
13 | 14 | from core.freeipa.user import FreeIPAUser |
@@ -700,7 +701,75 @@ def _get_group(*, cn: str, require_fresh: bool = False) -> FreeIPAGroup: |
700 | 701 | self.assertEqual(resp.status_code, 200) |
701 | 702 | election.refresh_from_db() |
702 | 703 | self.assertEqual(election.status, Election.Status.draft) |
703 | | - self.assertContains(resp, "No eligible voters") |
| 704 | + |
| 705 | + def test_start_election_uses_membership_electorate_even_when_committee_filter_is_empty(self) -> None: |
| 706 | + now = timezone.now() |
| 707 | + election = Election.objects.create( |
| 708 | + name="Draft election", |
| 709 | + description="", |
| 710 | + url="", |
| 711 | + start_datetime=now + datetime.timedelta(days=1), |
| 712 | + end_datetime=now + datetime.timedelta(days=2), |
| 713 | + number_of_seats=1, |
| 714 | + status=Election.Status.draft, |
| 715 | + ) |
| 716 | + Candidate.objects.create(election=election, freeipa_username="alice", nominated_by="nominator") |
| 717 | + |
| 718 | + self._login_as_freeipa_user("admin") |
| 719 | + self._grant_manage_elections("admin") |
| 720 | + |
| 721 | + clean_validation = CandidateValidationResult( |
| 722 | + eligible_candidates={"alice"}, |
| 723 | + eligible_nominators={"nominator"}, |
| 724 | + disqualified_candidates=set(), |
| 725 | + disqualified_nominators=set(), |
| 726 | + ineligible_candidates=set(), |
| 727 | + ineligible_nominators=set(), |
| 728 | + ) |
| 729 | + |
| 730 | + start_str = (now + datetime.timedelta(days=1)).strftime("%Y-%m-%dT%H:%M") |
| 731 | + end_str = (now + datetime.timedelta(days=2)).strftime("%Y-%m-%dT%H:%M") |
| 732 | + |
| 733 | + with ( |
| 734 | + patch( |
| 735 | + "core.views_elections.edit.elections_eligibility.eligible_voters_from_memberships", |
| 736 | + return_value=[EligibleVoter(username="committee-member", weight=1)], |
| 737 | + ), |
| 738 | + patch( |
| 739 | + "core.views_elections.edit.elections_eligibility.start_eligible_voters", |
| 740 | + return_value=[], |
| 741 | + ), |
| 742 | + patch( |
| 743 | + "core.views_elections.edit.elections_eligibility.validate_candidates_for_election", |
| 744 | + return_value=clean_validation, |
| 745 | + ), |
| 746 | + patch( |
| 747 | + "core.views_elections.edit.issue_credentials_at_start_transition", |
| 748 | + return_value=[], |
| 749 | + ), |
| 750 | + ): |
| 751 | + resp = self.client.post( |
| 752 | + reverse("election-edit", args=[election.id]), |
| 753 | + data={ |
| 754 | + "action": "start_election", |
| 755 | + "name": election.name, |
| 756 | + "description": election.description, |
| 757 | + "url": election.url, |
| 758 | + "start_datetime": start_str, |
| 759 | + "end_datetime": end_str, |
| 760 | + "number_of_seats": str(election.number_of_seats), |
| 761 | + "quorum": str(election.quorum), |
| 762 | + "email_template_id": "", |
| 763 | + "subject": "", |
| 764 | + "html_content": "", |
| 765 | + "text_content": "", |
| 766 | + }, |
| 767 | + follow=False, |
| 768 | + ) |
| 769 | + |
| 770 | + self.assertEqual(resp.status_code, 302) |
| 771 | + election.refresh_from_db() |
| 772 | + self.assertEqual(election.status, Election.Status.open) |
704 | 773 |
|
705 | 774 | def test_start_election_blocks_ineligible_candidates(self) -> None: |
706 | 775 | now = timezone.now() |
|
0 commit comments