Exemplo n.º 1
0
def ballot_styles(draw: _DrawType, party_ids: List[Party],
                  geo_units: List[GeopoliticalUnit]):
    """
    Generates a `BallotStyle` object, which rolls up a list of parties and
    geopolitical units (passed as arguments), with some additional information
    added on as well.
    :param draw: Hidden argument, used by Hypothesis.
    :param party_ids: a list of `Party` objects to be used in this ballot style
    :param geo_units: a list of `GeopoliticalUnit` objects to be used in this ballot style
    """
    assert len(party_ids) > 0
    assert len(geo_units) > 0

    gp_unit_ids = [x.object_id for x in geo_units]
    if len(gp_unit_ids) == 0:
        gp_unit_ids = None

    party_ids = [x.get_party_id() for x in party_ids]
    if len(party_ids) == 0:
        party_ids = None

    image_uri = draw(urls())
    return BallotStyle(str(draw(uuids())), gp_unit_ids, party_ids, image_uri)
Exemplo n.º 2
0
    def _ballot_style_from_id(
        self,
        dominion_ballot_style_id: str,
        party_map: Dict[str, Party],
        cd_map: Dict[str, ContestDescription],
    ) -> BallotStyle:

        contest_titles = self.metadata.style_map[dominion_ballot_style_id]

        bs_id = self.metadata.ballot_types[dominion_ballot_style_id]

        party_ids = [
            party_map[p].object_id
            for p in self._all_parties_for_contests(contest_titles)
        ]

        gp_ids = [cd_map[t].electoral_district_id for t in contest_titles]

        return BallotStyle(
            object_id=bs_id,
            geopolitical_unit_ids=gp_ids,
            party_ids=party_ids if party_ids else None,
        )
    def get_fake_election(self) -> ElectionDescription:
        """
        Get a single Fake Election object that is manually constructed with default values
        """

        fake_ballot_style = BallotStyle("some-ballot-style-id")
        fake_ballot_style.geopolitical_unit_ids = ["some-geopoltical-unit-id"]

        fake_referendum_ballot_selections = [
            # Referendum selections are simply a special case of `candidate` in the object model
            SelectionDescription("some-object-id-affirmative",
                                 "some-candidate-id-1", 0),
            SelectionDescription("some-object-id-negative",
                                 "some-candidate-id-2", 1),
        ]

        sequence_order = 0
        number_elected = 1
        votes_allowed = 1
        fake_referendum_contest = ReferendumContestDescription(
            "some-referendum-contest-object-id",
            "some-geopoltical-unit-id",
            sequence_order,
            VoteVariationType.one_of_m,
            number_elected,
            votes_allowed,
            "some-referendum-contest-name",
            fake_referendum_ballot_selections,
        )

        fake_candidate_ballot_selections = [
            SelectionDescription("some-object-id-candidate-1",
                                 "some-candidate-id-1", 0),
            SelectionDescription("some-object-id-candidate-2",
                                 "some-candidate-id-2", 1),
            SelectionDescription("some-object-id-candidate-3",
                                 "some-candidate-id-3", 2),
        ]

        sequence_order_2 = 1
        number_elected_2 = 2
        votes_allowed_2 = 2
        fake_candidate_contest = CandidateContestDescription(
            "some-candidate-contest-object-id",
            "some-geopoltical-unit-id",
            sequence_order_2,
            VoteVariationType.one_of_m,
            number_elected_2,
            votes_allowed_2,
            "some-candidate-contest-name",
            fake_candidate_ballot_selections,
        )

        fake_election = ElectionDescription(
            election_scope_id="some-scope-id",
            type=ElectionType.unknown,
            start_date=datetime.now(),
            end_date=datetime.now(),
            geopolitical_units=[
                GeopoliticalUnit(
                    "some-geopoltical-unit-id",
                    "some-gp-unit-name",
                    ReportingUnitType.unknown,
                )
            ],
            parties=[Party("some-party-id-1"),
                     Party("some-party-id-2")],
            candidates=[
                Candidate("some-candidate-id-1"),
                Candidate("some-candidate-id-2"),
                Candidate("some-candidate-id-3"),
            ],
            contests=[fake_referendum_contest, fake_candidate_contest],
            ballot_styles=[fake_ballot_style],
        )

        return fake_election