示例#1
0
    def setUp(self):
        self.registrations_per_center = 4
        self.oil_center_period_1_voters = 1
        self.oil_center_period_2_voters = 2
        self.offices = [OfficeFactory(region=Office.REGION_EAST),
                        OfficeFactory(region=Office.REGION_WEST)]
        # Note: An oil center doesn't normally allow registrations, but it does so for
        # this testcase.
        self.oil_center = RegistrationCenterFactory(office=self.offices[0],
                                                    center_type=RegistrationCenter.Types.OIL)

        # !reg_open won't affect election day counts but it will affect whether
        # or not any registrations are found
        self.inactive_for_reg_center = RegistrationCenterFactory(office=self.offices[1],
                                                                 reg_open=False)

        self.centers = [self.oil_center,
                        RegistrationCenterFactory(office=self.offices[0]),
                        RegistrationCenterFactory(office=self.offices[0]),
                        RegistrationCenterFactory(office=self.offices[1]),
                        self.inactive_for_reg_center,
                        ]

        copy_center = RegistrationCenterFactory(office=self.offices[1], copy_of=self.centers[3])
        self.centers.append(copy_center)

        self.election_decoy_before = ElectionFactory(
            name_english='decoy before',
            name_arabic='decoy before (ar)',
            polling_start_time=now() - timedelta(days=10),
            polling_end_time=now() - timedelta(days=9),
        )
        self.election = ElectionFactory(
            name_english='%s election' % type(self).__name__,
            name_arabic='not Arabic',
            polling_start_time=now() - timedelta(hours=2),
            polling_end_time=now() + timedelta(hours=2),
        )
        self.election_decoy_after = ElectionFactory(
            name_english='decoy after',
            name_arabic='decoy after (ar)',
            polling_start_time=now() + timedelta(days=9),
            polling_end_time=now() + timedelta(days=10),
        )

        self.center_opens = []
        for center in self.centers:
            if center != self.centers[1]:
                self.center_opens.append(CenterOpenFactory(election=self.election,
                                                           registration_center=center))

        # CenterOpen may refer to a deleted center. Make sure that we don't find those
        self.deleted_center = RegistrationCenterFactory(office=self.offices[0], deleted=True)
        self.center_open_referring_to_deleted_center = CenterOpenFactory(
            election=self.election,
            registration_center=self.deleted_center)

        # Performance enhancement: this dummy person and SMS allow me to avoid creation of two
        # spurious objects for each registration I create.
        self.citizen = CitizenFactory()
        self.sms = SMSFactory(citizen=self.citizen)

        # Create registrations, but be careful not to create any at the copy center
        # or at the center which doesn't support registrations.
        self.registrations = []
        for center in self.centers:
            if center.reg_open and not center.copy_of:
                self.registrations += \
                    RegistrationFactory.create_batch(self.registrations_per_center,
                                                     citizen=self.citizen,
                                                     sms=self.sms,
                                                     registration_center=center)

        # These reports include quirks such as multiple reports for a center (very common in real
        # life), a missing final period report, and multiple reports for the same center & period.
        self.reports = [
            PollingReportFactory(election=self.election,
                                 registration_center=self.oil_center,
                                 period_number=FIRST_PERIOD_NUMBER,
                                 num_voters=self.oil_center_period_1_voters),
            PollingReportFactory(election=self.election,
                                 registration_center=self.oil_center,
                                 period_number=FIRST_PERIOD_NUMBER + 1,
                                 num_voters=self.oil_center_period_2_voters),
            PollingReportFactory(election=self.election,
                                 registration_center=self.centers[2],
                                 period_number=FIRST_PERIOD_NUMBER,
                                 num_voters=1),
            # The next two reports are for the same center & period with different num_voters
            # to exercise the code that sorts by modification_date.
            PollingReportFactory(election=self.election,
                                 registration_center=self.centers[2],
                                 period_number=FIRST_PERIOD_NUMBER + 1,
                                 num_voters=4),
            PollingReportFactory(election=self.election,
                                 registration_center=self.centers[2],
                                 period_number=FIRST_PERIOD_NUMBER + 1,
                                 num_voters=6),
            PollingReportFactory(election=self.election,
                                 registration_center=self.centers[3],
                                 period_number=FIRST_PERIOD_NUMBER,
                                 num_voters=1),
            PollingReportFactory(election=self.election,
                                 registration_center=self.centers[3],
                                 period_number=FIRST_PERIOD_NUMBER + 1,
                                 num_voters=4),
            # This report for a deleted center should be ignored
            PollingReportFactory(election=self.election,
                                 registration_center=self.deleted_center,
                                 period_number=FIRST_PERIOD_NUMBER + 1,
                                 num_voters=50),
            PollingReportFactory(election=self.election,
                                 registration_center=self.inactive_for_reg_center,
                                 period_number=FIRST_PERIOD_NUMBER + 1,
                                 num_voters=50),
            # This report for a copy center should count towards the original/parent center
            PollingReportFactory(election=self.election,
                                 registration_center=copy_center,
                                 period_number=LAST_PERIOD_NUMBER,
                                 num_voters=1), ]

        self.result = generate_election_day_hq_reports(self.election)
        # Create an alternate result which reflects that the "oil center" is
        # marked inactive for this election.
        self.inactive_on_election = CenterClosedForElection(
            registration_center=self.oil_center, election=self.election
        )
        self.inactive_on_election.full_clean()
        self.inactive_on_election.save()
        self.result_with_inactive = generate_election_day_hq_reports(self.election)