Ejemplo n.º 1
0
    def test_distribution_by_election(self):
        tz = timezone(settings.TIME_ZONE)
        elections = Election.objects.all()

        # for each election, grab the report and initialize a counter for CenterOpen objects
        for election in elections:
            election.report = retrieve_report(
                election_key(ELECTION_DAY_REPORT_KEY, election))
            election.center_opens_found = 0

        # for each CenterOpen in the db, bump the counter for the particular election
        for center_open in CenterOpen.objects.all():
            open_date_str = astz(center_open.creation_date,
                                 tz).strftime('%Y-%m-%d')
            for election in elections:
                if open_date_str in election.report['dates']:
                    election.center_opens_found += 1

        for election in elections:
            center_opens_expected = 0
            for d in election.report['dates']:
                for office_data in election.report['by_office'].values():
                    if d in office_data and 'opened' in office_data[d]:
                        center_opens_expected += office_data[d]['opened']
            self.assertEqual(center_opens_expected,
                             election.center_opens_found)
Ejemplo n.º 2
0
 def test_db_versus_redis(self):
     for election in Election.objects.all():
         report_from_db, hq_reports_from_db, messages_from_db = \
             get_election_data_from_db(election)
         self.assertIsNotNone(report_from_db)
         self.assertIsNotNone(hq_reports_from_db)
         self.assertIsNotNone(messages_from_db)
         report_from_redis = retrieve_report(election_key(ELECTION_DAY_REPORT_KEY, election))
         hq_reports_from_redis = \
             retrieve_report(election_key(ELECTION_DAY_HQ_REPORTS_KEY, election))
         messages_from_redis = retrieve_report(election_key(ELECTION_DAY_LOG_KEY, election))
         self.assertIsNotNone(report_from_redis)
         self.assertIsNotNone(hq_reports_from_redis)
         self.assertIsNotNone(messages_from_redis)
         self.assertDictEqual(report_from_db, report_from_redis)
         self.assertDictEqual(hq_reports_from_db, hq_reports_from_redis)
         self.assertDictEqual(messages_from_db, messages_from_redis)
Ejemplo n.º 3
0
 def test_db_versus_redis(self):
     for election in Election.objects.all():
         report_from_db, hq_reports_from_db, messages_from_db = \
             get_election_data_from_db(election)
         self.assertIsNotNone(report_from_db)
         self.assertIsNotNone(hq_reports_from_db)
         self.assertIsNotNone(messages_from_db)
         report_from_redis = retrieve_report(
             election_key(ELECTION_DAY_REPORT_KEY, election))
         hq_reports_from_redis = \
             retrieve_report(election_key(ELECTION_DAY_HQ_REPORTS_KEY, election))
         messages_from_redis = retrieve_report(
             election_key(ELECTION_DAY_LOG_KEY, election))
         self.assertIsNotNone(report_from_redis)
         self.assertIsNotNone(hq_reports_from_redis)
         self.assertIsNotNone(messages_from_redis)
         self.assertDictEqual(report_from_db, report_from_redis)
         self.assertDictEqual(hq_reports_from_db, hq_reports_from_redis)
         self.assertDictEqual(messages_from_db, messages_from_redis)
Ejemplo n.º 4
0
    def test_lists_of_reports(self):
        r1, r2 = reports.retrieve_report([reports.REGISTRATIONS_METADATA_KEY, reports.REGISTRATIONS_STATS_KEY])
        self.assertTrue(bool(r1))
        self.assertTrue(bool(r2))

        class BadElection(object):
            def __init__(self):
                self.id = -1234

        election_with_bogus_id = BadElection()
        r1, r2 = reports.retrieve_report(
            [
                reports.REGISTRATIONS_METADATA_KEY,
                reports.election_key(reports.ELECTION_DAY_METADATA_KEY, election_with_bogus_id),
            ]
        )
        # although _METADATA_ exists, 1st result is None to indicate that something failed
        self.assertFalse(bool(r1))
        # 2nd result is None because there's no such election
        self.assertFalse(bool(r2))
Ejemplo n.º 5
0
    def test_lists_of_reports(self):
        r1, r2 = reports.retrieve_report([
            reports.REGISTRATIONS_METADATA_KEY, reports.REGISTRATIONS_STATS_KEY
        ])
        self.assertTrue(bool(r1))
        self.assertTrue(bool(r2))

        class BadElection(object):
            def __init__(self):
                self.id = -1234

        election_with_bogus_id = BadElection()
        r1, r2 = reports.retrieve_report([
            reports.REGISTRATIONS_METADATA_KEY,
            reports.election_key(reports.ELECTION_DAY_METADATA_KEY,
                                 election_with_bogus_id)
        ])
        # although _METADATA_ exists, 1st result is None to indicate that something failed
        self.assertFalse(bool(r1))
        # 2nd result is None because there's no such election
        self.assertFalse(bool(r2))
Ejemplo n.º 6
0
    def test_distribution_by_election(self):
        tz = timezone(settings.TIME_ZONE)
        elections = Election.objects.all()

        # for each election, grab the report and initialize a counter for CenterOpen objects
        for election in elections:
            election.report = retrieve_report(election_key(ELECTION_DAY_REPORT_KEY, election))
            election.center_opens_found = 0

        # for each CenterOpen in the db, bump the counter for the particular election
        for center_open in CenterOpen.objects.all():
            open_date_str = astz(center_open.creation_date, tz).strftime('%Y-%m-%d')
            for election in elections:
                if open_date_str in election.report['dates']:
                    election.center_opens_found += 1

        for election in elections:
            center_opens_expected = 0
            for d in election.report['dates']:
                for office_data in election.report['by_office'].values():
                    if d in office_data and 'opened' in office_data[d]:
                        center_opens_expected += office_data[d]['opened']
            self.assertEqual(center_opens_expected, election.center_opens_found)