예제 #1
0
    def create_test_election(mock_stamp_create):
        mock_stamp = Stamp()
        mock_stamp.ip = "0.0.0.0"
        mock_stamp.createdBy = "TestAdmin"
        mock_stamp.createdAt = datetime.now()
        db.session.add(mock_stamp)
        db.session.flush()
        mock_stamp_create.return_value = mock_stamp

        from orm.entities.Election.election_helper import build_presidential_election
        election = Election.create(electionName="Test Election")

        basedir = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                               "..", "sample-data", "test")
        party_candidate_dataset_file = os.path.join(basedir,
                                                    "party-candidate.csv")
        polling_station_dataset_file = os.path.join(basedir, "data.csv")
        postal_counting_centers_dataset_file = os.path.join(
            basedir, "postal-data.csv")
        invalid_vote_categories_dataset_file = os.path.join(
            basedir, "invalid-vote-categories.csv")

        build_presidential_election(
            root_election=election,
            party_candidate_dataset_file=party_candidate_dataset_file,
            polling_station_dataset_file=polling_station_dataset_file,
            postal_counting_centers_dataset_file=
            postal_counting_centers_dataset_file,
            invalid_vote_categories_dataset_file=
            invalid_vote_categories_dataset_file)
        return election
def create(body):
    request_body = RequestBody(body)
    election_name = request_body.get("electionName")

    files = connexion.request.files
    polling_stations_dataset = files.get("pollingStationsDataset")
    postal_counting_centres_dataset = files.get("postalCountingCentresDataset")
    party_candidates_dataset = files.get("partyCandidatesDataset")
    invalid_vote_categories_dataset = files.get("invalidVoteCategoriesDataset")

    election = Election.create(electionName=election_name)
    election.set_polling_stations_dataset(fileSource=polling_stations_dataset)
    election.set_postal_counting_centres_dataset(fileSource=postal_counting_centres_dataset)
    election.set_party_candidates_dataset(fileSource=party_candidates_dataset)
    election.set_invalid_vote_categories_dataset(fileSource=invalid_vote_categories_dataset)

    build_presidential_election(root_election=election)

    db.session.commit()

    return Schema().dump(election).data