Esempio n. 1
0
    def test_general_get(self):
        barcode = '123456789'
        center = create_center()
        station = create_station(center=center)
        create_result_form(barcode,
                           center=center,
                           station_number=station.station_number,
                           form_state=FormState.QUALITY_CONTROL)
        result_form = ResultForm.objects.get(barcode=barcode)
        self._create_and_login_user()
        name = 'the candidate name'
        women_name = 'women candidate name'
        votes = 123

        create_candidates(result_form, self.user, name, votes, women_name)

        self._add_user_to_group(self.user,
                                groups.QUALITY_CONTROL_ARCHIVE_CLERK)
        view = views.QualityControlDashboardView.as_view()
        request = self.factory.get('/')
        request.user = self.user
        request.session = {'result_form': result_form.pk}
        response = view(request)
        response.render()
        self.assertEqual(response.status_code, 200)
        # gender has been removed
        # self.assertContains(response, str(result_form.gender_name))
        self.assertContains(response, 'General')
        self.assertContains(response, name)
        self.assertContains(response, women_name)
        self.assertContains(response, str(votes))
Esempio n. 2
0
    def setUp(self):
        self.factory = RequestFactory()
        self._create_permission_groups()
        self._create_and_login_user()
        self._add_user_to_group(self.user, groups.TALLY_MANAGER)
        self.tally = create_tally()
        self.tally.users.add(self.user)

        ballot = create_ballot(tally=self.tally)
        center = create_center('12345', tally=self.tally)
        station = create_station(center)
        result_form = create_result_form(tally=self.tally,
                                         ballot=ballot,
                                         center=center,
                                         station_number=station.station_number)
        votes = 12
        create_candidates(result_form,
                          votes=votes,
                          user=self.user,
                          num_results=1)
        for result in result_form.results.all():
            result.entry_version = EntryVersion.FINAL
            result.save()
            # create duplicate final results
            create_result(result_form, result.candidate, self.user, votes)
Esempio n. 3
0
    def test_archive_post_quarantine_pass_below_tolerance(self):
        center = create_center()
        create_station(center)
        create_quarantine_checks()
        self._create_and_login_user()
        barcode = '123456789'
        result_form = create_result_form(form_state=FormState.ARCHIVING,
                                         center=center,
                                         station_number=1)
        recon_form = create_reconciliation_form(result_form,
                                                self.user,
                                                number_ballots_inside_box=21,
                                                number_unstamped_ballots=0)
        create_candidates(result_form, self.user, votes=1, num_results=10)
        self._add_user_to_group(self.user,
                                groups.QUALITY_CONTROL_ARCHIVE_CLERK)
        view = views.ArchiveView.as_view()
        data = {'barcode': barcode, 'barcode_copy': barcode}
        request = self.factory.post('/', data=data)
        request.session = {}
        request.user = self.user
        response = view(request)
        result_form.reload()

        self.assertEqual(result_form.num_votes,
                         recon_form.number_ballots_expected)

        self.assertEqual(response.status_code, 302)
        self.assertTrue(result_form.form_state, FormState.AUDIT)
        self.assertTrue(result_form.audit)
        self.assertEqual(result_form.audit.quarantine_checks.count(), 1)
        self.assertEqual(result_form.audit.quarantine_checks.all()[0].name[:9],
                         'Trigger 1')
        self.assertEqual(result_form.audited_count, 1)
        self.assertIn('archive/print', response['location'])
Esempio n. 4
0
    def test_women_post_incorrect(self):
        self._create_and_login_user()
        barcode = "123456789"
        create_result_form(barcode, form_state=FormState.QUALITY_CONTROL)
        result_form = ResultForm.objects.get(barcode=barcode)
        create_quality_control(result_form, self.user)
        create_candidates(result_form, self.user)
        self._add_user_to_group(self.user, groups.QUALITY_CONTROL_CLERK)
        view = views.QualityControlDashboardView.as_view()
        data = {"result_form": result_form.pk, "incorrect": 1}
        request = self.factory.post("/", data=data)
        request.user = self.user
        request.session = {"result_form": result_form.pk}
        response = view(request)
        self.assertEqual(response.status_code, 302)
        self.assertIn("quality-control/reject", response["location"])
        self.assertEqual(result_form.rejected_count, 0)
        result_form = ResultForm.objects.get(pk=result_form.pk)
        quality_control = result_form.qualitycontrol_set.all()[0]

        results = result_form.results.all()
        self.assertTrue(len(results) > 0)

        for result in results:
            self.assertEqual(result.active, False)

        self.assertEqual(result_form.form_state, FormState.DATA_ENTRY_1)
        self.assertEqual(result_form.rejected_count, 1)
        self.assertEqual(quality_control.active, False)
        self.assertEqual(quality_control.passed_women, False)
Esempio n. 5
0
    def test_women_get(self):
        barcode = "123456789"
        center = create_center()
        station = create_station(center=center)
        create_result_form(
            barcode, center=center, station_number=station.station_number, form_state=FormState.QUALITY_CONTROL
        )
        result_form = ResultForm.objects.get(barcode=barcode)
        self._create_and_login_user()
        name = "general candidate name"
        women_name = "women candidate name"
        votes = 123

        create_candidates(result_form, self.user, name, votes, women_name)

        self._add_user_to_group(self.user, groups.QUALITY_CONTROL_CLERK)
        view = views.QualityControlDashboardView.as_view()
        request = self.factory.get("/")
        request.user = self.user
        request.session = {"result_form": result_form.pk}
        response = view(request)
        response.render()
        self.assertEqual(response.status_code, 200)
        # gender has been removed
        # self.assertContains(response, str(result_form.gender_name))
        self.assertContains(response, "Women")
        self.assertContains(response, women_name)
        self.assertContains(response, name)
        self.assertContains(response, str(votes))
Esempio n. 6
0
    def test_review_post_check_audit_state_when_no_action_prior(self):
        self._create_and_login_user(username='******')
        self._add_user_to_group(self.user, groups.AUDIT_SUPERVISOR)
        tally = create_tally()
        tally.users.add(self.user)
        result_form = create_result_form(form_state=FormState.AUDIT,
                                         tally=tally)
        create_reconciliation_form(result_form, self.user)
        create_candidates(result_form, self.user)

        view = views.ReviewView.as_view()
        data = {
            'result_form': result_form.pk,
            'resolution_recommendation': 1,
            'implement': 1,
            'tally_id': tally.pk,
        }
        request = self.factory.post('/', data=data)
        request.user = self.user
        request.session = data
        response = view(request, tally_id=tally.pk)

        self.assertEqual(response.status_code, 302)

        audit = Audit.objects.get(result_form=result_form)
        self.assertEqual(audit.reviewed_supervisor, True)
        self.assertNotEqual(audit.result_form.form_state, FormState.AUDIT)
        self.assertEqual(audit.result_form.form_state, FormState.DATA_ENTRY_1)
Esempio n. 7
0
    def test_archive_post_quarantine_pass_below_tolerance(self):
        center = create_center()
        create_station(center)
        create_quarantine_checks()
        self._create_and_login_user()
        barcode = '123456789'
        result_form = create_result_form(
            form_state=FormState.ARCHIVING,
            center=center, station_number=1)
        recon_form = create_reconciliation_form(
            result_form, self.user, number_ballots_inside_box=21,
            number_unstamped_ballots=0)
        create_candidates(result_form, self.user, votes=1, num_results=10)
        self._add_user_to_group(self.user, groups.ARCHIVE_CLERK)
        view = views.ArchiveView.as_view()
        data = {'barcode': barcode, 'barcode_copy': barcode}
        request = self.factory.post('/', data=data)
        request.session = {}
        request.user = self.user
        response = view(request)
        result_form.reload()

        self.assertEqual(result_form.num_votes,
                         recon_form.number_ballots_expected)

        self.assertEqual(response.status_code, 302)
        self.assertTrue(result_form.form_state, FormState.AUDIT)
        self.assertTrue(result_form.audit)
        self.assertEqual(result_form.audit.quarantine_checks.count(), 1)
        self.assertEqual(
            result_form.audit.quarantine_checks.all()[0].name[:9], 'Trigger 1')
        self.assertEqual(result_form.audited_count, 1)
        self.assertIn('archive/print', response['location'])
Esempio n. 8
0
    def test_dashboard_get(self):
        barcode = '123456789'
        self._create_and_login_user()
        center = create_center()
        station = create_station(center=center)
        create_result_form(barcode,
                           center=center,
                           station_number=station.station_number,
                           form_state=FormState.QUALITY_CONTROL)
        result_form = ResultForm.objects.get(barcode=barcode)
        create_candidates(result_form, self.user)
        create_quality_control(result_form, self.user)
        self._add_user_to_group(self.user, groups.QUALITY_CONTROL_ARCHIVE_CLERK)
        view = views.QualityControlDashboardView.as_view()
        request = self.factory.get('/')
        request.user = self.user
        request.session = {'result_form': result_form.pk}
        response = view(request)

        self.assertEqual(response.status_code, 200)
        # gender has been removed
        # self.assertContains(response, str(result_form.gender_name))
        self.assertContains(response, 'General Results Section')
        self.assertNotContains(response, 'Reconciliation')
        self.assertContains(response, 'Abort')
Esempio n. 9
0
    def test_dashboard_get_double_recon_raise(self):
        self._create_and_login_user()
        tally = create_tally()
        tally.users.add(self.user)
        barcode = '123456789'
        center = create_center(tally=tally)
        station = create_station(center=center)
        result_form = create_result_form(barcode,
                                         center=center,
                                         station_number=station.station_number,
                                         tally=tally,
                                         form_state=FormState.QUALITY_CONTROL)
        create_reconciliation_form(result_form, self.user)
        create_reconciliation_form(result_form,
                                   self.user,
                                   ballot_number_from=2)
        create_candidates(result_form, self.user)
        create_quality_control(result_form, self.user)

        self._add_user_to_group(self.user, groups.QUALITY_CONTROL_CLERK)
        view = views.QualityControlDashboardView.as_view()
        request = self.factory.get('/')
        request.user = self.user
        request.session = {'result_form': result_form.pk}

        with self.assertRaises(SuspiciousOperation):
            view(request, tally_id=tally.pk)
Esempio n. 10
0
 def test_women_post_incorrect_ballot_released(self):
     self._create_and_login_user()
     tally = create_tally()
     tally.users.add(self.user)
     barcode = '123456789'
     ballot = create_ballot(available_for_release=True)
     create_result_form(barcode,
                        tally=tally,
                        ballot=ballot,
                        form_state=FormState.QUALITY_CONTROL)
     result_form = ResultForm.objects.get(barcode=barcode)
     create_quality_control(result_form, self.user)
     create_candidates(result_form, self.user)
     self._add_user_to_group(self.user, groups.QUALITY_CONTROL_CLERK)
     view = views.QualityControlDashboardView.as_view()
     data = {
         'result_form': result_form.pk,
         'incorrect': 1,
         'tally_id': tally.pk,
     }
     request = self.factory.post('/', data=data)
     request.user = self.user
     request.session = {'result_form': result_form.pk}
     response = view(request, tally_id=tally.pk)
     self.assertEqual(response.status_code, 302)
     self.assertIn('quality-control/confirm-reject', response['location'])
     result_form = ResultForm.objects.get(pk=result_form.pk)
     quality_control = result_form.qualitycontrol_set.all()[0]
     self.assertTrue(quality_control.active)
     self.assertEqual(result_form.form_state, FormState.QUALITY_CONTROL)
     self.assertEqual(result_form.rejected_count, 0)
Esempio n. 11
0
    def test_women_get(self):
        self._create_and_login_user()
        tally = create_tally()
        tally.users.add(self.user)
        barcode = '123456789'
        center = create_center()
        station = create_station(center=center)
        create_result_form(barcode,
                           center=center,
                           station_number=station.station_number,
                           tally=tally,
                           form_state=FormState.QUALITY_CONTROL)
        result_form = ResultForm.objects.get(barcode=barcode)
        name = 'general candidate name'
        women_name = 'women candidate name'
        votes = 123

        create_candidates(result_form, self.user, name, votes, women_name)

        self._add_user_to_group(self.user, groups.QUALITY_CONTROL_CLERK)
        view = views.QualityControlDashboardView.as_view()
        request = self.factory.get('/')
        request.user = self.user
        request.session = {'result_form': result_form.pk}
        response = view(request, tally_id=tally.pk)
        response.render()
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'Women')
        self.assertContains(response, women_name)
        self.assertContains(response, name)
        self.assertContains(response, str(votes))
Esempio n. 12
0
    def test_women_get(self):
        self._create_and_login_user()
        tally = create_tally()
        tally.users.add(self.user)
        barcode = '123456789'
        center = create_center()
        station = create_station(center=center)
        create_result_form(barcode,
                           center=center,
                           station_number=station.station_number,
                           tally=tally,
                           form_state=FormState.QUALITY_CONTROL)
        result_form = ResultForm.objects.get(barcode=barcode)
        name = 'general candidate name'
        women_name = 'women candidate name'
        votes = 123

        create_candidates(result_form, self.user, name, votes, women_name)

        self._add_user_to_group(self.user, groups.QUALITY_CONTROL_CLERK)
        view = views.QualityControlDashboardView.as_view()
        request = self.factory.get('/')
        request.user = self.user
        request.session = {'result_form': result_form.pk}
        response = view(request, tally_id=tally.pk)
        response.render()
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'Women')
        self.assertContains(response, women_name)
        self.assertContains(response, name)
        self.assertContains(response, str(votes))
Esempio n. 13
0
 def test_women_post_incorrect_ballot_released(self):
     self._create_and_login_user()
     tally = create_tally()
     tally.users.add(self.user)
     barcode = '123456789'
     ballot = create_ballot(available_for_release=True)
     create_result_form(barcode,
                        tally=tally,
                        ballot=ballot,
                        form_state=FormState.QUALITY_CONTROL)
     result_form = ResultForm.objects.get(barcode=barcode)
     create_quality_control(result_form, self.user)
     create_candidates(result_form, self.user)
     self._add_user_to_group(self.user, groups.QUALITY_CONTROL_CLERK)
     view = views.QualityControlDashboardView.as_view()
     data = {
         'result_form': result_form.pk,
         'incorrect': 1,
         'tally_id': tally.pk,
     }
     request = self.factory.post('/', data=data)
     request.user = self.user
     request.session = {'result_form': result_form.pk}
     response = view(request, tally_id=tally.pk)
     self.assertEqual(response.status_code, 302)
     self.assertIn('quality-control/confirm-reject',
                   response['location'])
     result_form = ResultForm.objects.get(pk=result_form.pk)
     quality_control = result_form.qualitycontrol_set.all()[0]
     self.assertTrue(quality_control.active)
     self.assertEqual(result_form.form_state, FormState.QUALITY_CONTROL)
     self.assertEqual(result_form.rejected_count, 0)
Esempio n. 14
0
    def test_dashboard_get_double_recon(self):
        barcode = '123456789'
        self._create_and_login_user()
        center = create_center()
        station = create_station(center=center)
        result_form = create_result_form(barcode,
                                         center=center,
                                         station_number=station.station_number,
                                         form_state=FormState.QUALITY_CONTROL)
        create_reconciliation_form(result_form, self.user)
        create_reconciliation_form(result_form, self.user)
        create_candidates(result_form, self.user)
        create_quality_control(result_form, self.user)

        self._add_user_to_group(self.user,
                                groups.QUALITY_CONTROL_ARCHIVE_CLERK)
        view = views.QualityControlDashboardView.as_view()
        request = self.factory.get('/')
        request.user = self.user
        request.session = {'result_form': result_form.pk}
        response = view(request)

        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'General Results Section')
        self.assertContains(response, 'Abort')
Esempio n. 15
0
    def test_dashboard_get_double_recon_raise(self):
        self._create_and_login_user()
        tally = create_tally()
        tally.users.add(self.user)
        barcode = '123456789'
        center = create_center(tally=tally)
        station = create_station(center=center)
        result_form = create_result_form(barcode,
                                         center=center,
                                         station_number=station.station_number,
                                         tally=tally,
                                         form_state=FormState.QUALITY_CONTROL)
        create_reconciliation_form(result_form, self.user)
        create_reconciliation_form(result_form, self.user,
                                   ballot_number_from=2)
        create_candidates(result_form, self.user)
        create_quality_control(result_form, self.user)

        self._add_user_to_group(self.user, groups.QUALITY_CONTROL_CLERK)
        view = views.QualityControlDashboardView.as_view()
        request = self.factory.get('/')
        request.user = self.user
        request.session = {'result_form': result_form.pk}

        with self.assertRaises(SuspiciousOperation):
            view(request, tally_id=tally.pk)
Esempio n. 16
0
    def test_dashboard_get_double_recon(self):
        self._create_and_login_user()
        tally = create_tally()
        tally.users.add(self.user)
        barcode = '123456789'
        center = create_center(tally=tally)
        station = create_station(center=center)
        result_form = create_result_form(barcode,
                                         center=center,
                                         station_number=station.station_number,
                                         tally=tally,
                                         form_state=FormState.QUALITY_CONTROL)
        create_reconciliation_form(result_form, self.user)
        create_reconciliation_form(result_form, self.user)
        create_candidates(result_form, self.user)
        create_quality_control(result_form, self.user)

        self._add_user_to_group(self.user, groups.QUALITY_CONTROL_CLERK)
        view = views.QualityControlDashboardView.as_view()
        request = self.factory.get('/')
        request.user = self.user
        request.session = {'result_form': result_form.pk}
        response = view(request, tally_id=tally.pk)

        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'General Results Section')
        self.assertContains(response, 'Cancel')
Esempio n. 17
0
    def test_women_post_incorrect(self):
        self._create_and_login_user()
        barcode = '123456789'
        create_result_form(barcode, form_state=FormState.QUALITY_CONTROL)
        result_form = ResultForm.objects.get(barcode=barcode)
        create_quality_control(result_form, self.user)
        create_candidates(result_form, self.user)
        self._add_user_to_group(self.user,
                                groups.QUALITY_CONTROL_ARCHIVE_CLERK)
        view = views.QualityControlDashboardView.as_view()
        data = {'result_form': result_form.pk, 'incorrect': 1}
        request = self.factory.post('/', data=data)
        request.user = self.user
        request.session = {'result_form': result_form.pk}
        response = view(request)
        self.assertEqual(response.status_code, 302)
        self.assertIn('quality-control/reject', response['location'])
        self.assertEqual(result_form.rejected_count, 0)
        result_form = ResultForm.objects.get(pk=result_form.pk)
        quality_control = result_form.qualitycontrol_set.all()[0]

        results = result_form.results.all()
        self.assertTrue(len(results) > 0)

        for result in results:
            self.assertEqual(result.active, False)

        self.assertEqual(result_form.form_state, FormState.DATA_ENTRY_1)
        self.assertEqual(result_form.rejected_count, 1)
        self.assertEqual(quality_control.active, False)
        self.assertEqual(quality_control.passed_women, False)
Esempio n. 18
0
    def test_form_action_view_post_confirm_audit(self):
        result_form = create_result_form(form_state=FormState.AUDIT)
        create_reconciliation_form(result_form, self.user)
        create_reconciliation_form(result_form, self.user)
        create_candidates(result_form, self.user)
        audit = create_audit(result_form, self.user)

        request = self._get_request()
        view = views.FormActionView.as_view()
        data = {'result_form': result_form.pk, 'confirm': 1}
        request = self.factory.post('/', data=data)
        request.user = self.user
        request.session = {'result_form': result_form.pk}
        response = view(request)

        audit.reload()
        result_form.reload()
        self.assertFalse(audit.active)
        self.assertEqual(result_form.form_state, FormState.DATA_ENTRY_1)
        self.assertTrue(result_form.skip_quarantine_checks)

        self.assertEqual(len(result_form.results.all()), 20)
        self.assertEqual(len(result_form.reconciliationform_set.all()), 2)

        for result in result_form.results.all():
            self.assertFalse(result.active)

        for result in result_form.reconciliationform_set.all():
            self.assertFalse(result.active)

        self.assertEqual(response.status_code, 302)
        self.assertIn('/super-administrator/form-action-list',
                      response['Location'])
Esempio n. 19
0
    def test_form_action_view_post_confirm_audit(self):
        result_form = create_result_form(form_state=FormState.AUDIT)
        create_reconciliation_form(result_form, self.user)
        create_reconciliation_form(result_form, self.user)
        create_candidates(result_form, self.user)
        audit = create_audit(result_form, self.user)

        request = self._get_request()
        view = views.FormActionView.as_view()
        data = {'result_form': result_form.pk,
                'confirm': 1}
        request = self.factory.post('/', data=data)
        request.user = self.user
        request.session = {'result_form': result_form.pk}
        response = view(request)

        audit.reload()
        result_form.reload()
        self.assertFalse(audit.active)
        self.assertEqual(result_form.form_state, FormState.DATA_ENTRY_1)
        self.assertTrue(result_form.skip_quarantine_checks)

        self.assertEqual(len(result_form.results.all()), 20)
        self.assertEqual(len(result_form.reconciliationform_set.all()),
                         2)

        for result in result_form.results.all():
            self.assertFalse(result.active)

        for result in result_form.reconciliationform_set.all():
            self.assertFalse(result.active)

        self.assertEqual(response.status_code, 302)
        self.assertIn('/super-administrator/form-action-list',
                      response['Location'])
Esempio n. 20
0
    def test_dashboard_get(self):
        barcode = '123456789'
        self._create_and_login_user()
        tally = create_tally()
        tally.users.add(self.user)
        center = create_center(tally=tally)
        station = create_station(center=center)
        create_result_form(barcode,
                           center=center,
                           station_number=station.station_number,
                           tally=tally,
                           form_state=FormState.QUALITY_CONTROL)
        result_form = ResultForm.objects.get(barcode=barcode)
        create_candidates(result_form, self.user)
        create_quality_control(result_form, self.user)
        self._add_user_to_group(self.user, groups.QUALITY_CONTROL_CLERK)
        view = views.QualityControlDashboardView.as_view()
        request = self.factory.get('/')
        request.user = self.user
        request.session = {'result_form': result_form.pk}
        response = view(request, tally_id=tally.pk)

        self.assertEqual(response.status_code, 200)
        # gender has been removed
        # self.assertContains(response, str(result_form.gender_name))
        self.assertContains(response, 'General Results Section')
        self.assertNotContains(response, 'Reconciliation')
        self.assertContains(response, 'Cancel')
Esempio n. 21
0
    def test_create_audit_post(self):
        self._create_and_login_user()
        self._add_user_to_group(self.user, groups.AUDIT_CLERK)
        barcode = 123456789
        serial_number = 0
        auditable_states = [
            FormState.CORRECTION, FormState.ARCHIVING, FormState.DATA_ENTRY_1,
            FormState.DATA_ENTRY_2, FormState.QUALITY_CONTROL
        ]

        for form_state in auditable_states:
            result_form = create_result_form(form_state=form_state,
                                             barcode=barcode,
                                             serial_number=serial_number)
            create_recon_forms(result_form, self.user)
            create_candidates(result_form, self.user)
            view = views.CreateAuditView.as_view()
            data = {
                'barcode': result_form.barcode,
                'barcode_copy': result_form.barcode
            }
            request = self.factory.post('/', data=data)
            request.user = self.user
            request.session = data
            response = view(request)
            result_form.reload()

            self.assertEqual(response.status_code, 302)
            self.assertEqual(result_form.form_state, FormState.AUDIT)
            self.assertEqual(result_form.audited_count, 1)
            self.assertEqual(result_form.audit.user, self.user)

            for result in result_form.reconciliationform_set.all():
                self.assertFalse(result.active)

            for result in result_form.results.all():
                self.assertFalse(result.active)

            barcode = barcode + 1
            serial_number = serial_number + 1

        # not auditable state
        result_form = create_result_form(form_state=FormState.ARCHIVED,
                                         barcode=barcode,
                                         serial_number=serial_number)
        view = views.CreateAuditView.as_view()
        data = {
            'barcode': result_form.barcode,
            'barcode_copy': result_form.barcode
        }
        request = self.factory.post('/', data=data)
        request.user = self.user
        request.session = data
        response = view(request)
        result_form.reload()

        self.assertEqual(response.status_code, 200)
        self.assertEqual(result_form.form_state, FormState.ARCHIVED)
Esempio n. 22
0
    def test_create_clearance_post(self):
        self._create_and_login_user()
        self._add_user_to_group(self.user, groups.CLEARANCE_CLERK)
        barcode = 123456789
        serial_number = 0
        clearable_states = [FormState.CORRECTION,
                            FormState.DATA_ENTRY_1,
                            FormState.DATA_ENTRY_2,
                            FormState.INTAKE,
                            FormState.QUALITY_CONTROL,
                            FormState.ARCHIVING,
                            FormState.UNSUBMITTED]

        for form_state in clearable_states:
            result_form = create_result_form(form_state=form_state,
                                             barcode=barcode,
                                             serial_number=serial_number)
            create_recon_forms(result_form, self.user)
            create_candidates(result_form, self.user)
            view = views.CreateClearanceView.as_view()
            data = {'barcode': result_form.barcode,
                    'barcode_copy': result_form.barcode}
            request = self.factory.post('/', data=data)
            request.user = self.user
            request.session = data
            response = view(request)
            result_form.reload()

            self.assertEqual(response.status_code, 302)
            self.assertEqual(result_form.form_state, FormState.CLEARANCE)
            self.assertIsNotNone(result_form.clearance)
            self.assertEqual(result_form.clearance.user, self.user)

            for result in result_form.reconciliationform_set.all():
                self.assertFalse(result.active)

            for result in result_form.results.all():
                self.assertFalse(result.active)

            barcode = barcode + 1
            serial_number = serial_number + 1

        # unclearable
        result_form = create_result_form(form_state=FormState.ARCHIVED,
                                         barcode=barcode,
                                         serial_number=serial_number)
        view = views.CreateClearanceView.as_view()
        data = {'barcode': result_form.barcode,
                'barcode_copy': result_form.barcode}
        request = self.factory.post('/', data=data)
        request.user = self.user
        request.session = data
        response = view(request)
        result_form.reload()

        self.assertEqual(response.status_code, 200)
        self.assertEqual(result_form.form_state, FormState.ARCHIVED)
Esempio n. 23
0
 def test_pass_tampering_true_diff(self):
     center = create_center()
     create_station(center=center, registrants=1)
     result_form = create_result_form(center=center)
     create_candidates(result_form, self.user, num_results=1)
     create_reconciliation_form(result_form,
                                self.user,
                                number_ballots_inside_box=250,
                                number_unstamped_ballots=0)
     self.assertEqual(pass_tampering(result_form), True)
Esempio n. 24
0
    def test_create_audit_post(self):
        self._create_and_login_user()
        self._add_user_to_group(self.user, groups.AUDIT_CLERK)
        barcode = 123456789
        serial_number = 0
        auditable_states = [FormState.CORRECTION,
                            FormState.ARCHIVING,
                            FormState.DATA_ENTRY_1,
                            FormState.DATA_ENTRY_2,
                            FormState.QUALITY_CONTROL]

        for form_state in auditable_states:
            result_form = create_result_form(form_state=form_state,
                                             barcode=barcode,
                                             serial_number=serial_number)
            create_recon_forms(result_form, self.user)
            create_candidates(result_form, self.user)
            view = views.CreateAuditView.as_view()
            data = {'barcode': result_form.barcode,
                    'barcode_copy': result_form.barcode}
            request = self.factory.post('/', data=data)
            request.user = self.user
            request.session = data
            response = view(request)
            result_form.reload()

            self.assertEqual(response.status_code, 302)
            self.assertEqual(result_form.form_state, FormState.AUDIT)
            self.assertEqual(result_form.audited_count, 1)
            self.assertEqual(result_form.audit.user, self.user)

            for result in result_form.reconciliationform_set.all():
                self.assertFalse(result.active)

            for result in result_form.results.all():
                self.assertFalse(result.active)

            barcode = barcode + 1
            serial_number = serial_number + 1

        # not auditable state
        result_form = create_result_form(form_state=FormState.ARCHIVED,
                                         barcode=barcode,
                                         serial_number=serial_number)
        view = views.CreateAuditView.as_view()
        data = {'barcode': result_form.barcode,
                'barcode_copy': result_form.barcode}
        request = self.factory.post('/', data=data)
        request.user = self.user
        request.session = data
        response = view(request)
        result_form.reload()

        self.assertEqual(response.status_code, 200)
        self.assertEqual(result_form.form_state, FormState.ARCHIVED)
Esempio n. 25
0
    def test_review_post_supervisor_implement_de1(self):
        # save audit as clerk
        self._create_and_login_user()
        result_form = create_result_form(form_state=FormState.AUDIT)
        create_reconciliation_form(result_form, self.user)
        create_reconciliation_form(result_form, self.user)
        create_candidates(result_form, self.user)
        self._add_user_to_group(self.user, groups.AUDIT_CLERK)

        view = views.ReviewView.as_view()
        data = {
            'result_form': result_form.pk,
            'action_prior_to_recommendation': 1,
            'resolution_recommendation': 0,
            'forward': 1
        }
        request = self.factory.post('/', data=data)
        request.user = self.user
        request.session = data
        response = view(request)

        # save as supervisor
        self._create_and_login_user(username='******')
        self._add_user_to_group(self.user, groups.AUDIT_SUPERVISOR)

        view = views.ReviewView.as_view()
        data = {
            'result_form': result_form.pk,
            'action_prior_to_recommendation': 1,
            'resolution_recommendation': 1,
            'implement': 1
        }
        request = self.factory.post('/', data=data)
        request.user = self.user
        request.session = data
        response = view(request)

        audit = Audit.objects.get(result_form=result_form)
        self.assertEqual(audit.supervisor, self.user)
        self.assertTrue(audit.reviewed_supervisor)
        self.assertTrue(audit.reviewed_team)
        self.assertFalse(audit.active)
        self.assertEqual(audit.result_form.form_state, FormState.DATA_ENTRY_1)
        self.assertEqual(len(audit.result_form.results.all()), 20)
        self.assertEqual(len(audit.result_form.reconciliationform_set.all()),
                         2)

        for result in audit.result_form.results.all():
            self.assertFalse(result.active)

        for result in audit.result_form.reconciliationform_set.all():
            self.assertFalse(result.active)

        self.assertEqual(audit.action_prior_to_recommendation, 1)
        self.assertEqual(response.status_code, 302)
Esempio n. 26
0
 def test_pass_tampering_true_diff(self):
     center = create_center()
     create_station(center=center,
                    registrants=1)
     result_form = create_result_form(center=center)
     create_candidates(result_form, self.user, num_results=1)
     create_reconciliation_form(result_form,
                                self.user,
                                number_ballots_inside_box=250,
                                number_unstamped_ballots=0)
     self.assertEqual(pass_tampering(result_form), True)
Esempio n. 27
0
    def test_create_clearance_post_super(self):
        self._create_and_login_user()
        self._add_user_to_group(self.user, groups.SUPER_ADMINISTRATOR)
        tally = create_tally()
        tally.users.add(self.user)
        barcode = 123456789
        serial_number = 0
        clearable_states = [
            FormState.ARCHIVED, FormState.CORRECTION, FormState.DATA_ENTRY_1,
            FormState.DATA_ENTRY_2, FormState.INTAKE,
            FormState.QUALITY_CONTROL, FormState.UNSUBMITTED
        ]

        for form_state in clearable_states:
            result_form = create_result_form(form_state=form_state,
                                             barcode=barcode,
                                             tally=tally,
                                             serial_number=serial_number)
            create_recon_forms(result_form, self.user)
            create_candidates(result_form, self.user)
            view = views.AddClearanceFormView.as_view()
            data = {
                'accept_submit': 1,
                'result_form': result_form.pk,
                'tally_id': tally.pk,
            }
            request = self.factory.post('/', data=data)
            request.user = self.user
            data['encoded_result_form_clearance_start_time'] =\
                self.encoded_result_form_clearance_start_time
            request.session = data
            response = view(request, tally_id=tally.pk)
            result_form.reload()

            self.assertEqual(response.status_code, 302)
            self.assertEqual(result_form.form_state, FormState.CLEARANCE)
            self.assertIsNotNone(result_form.clearance)
            self.assertEqual(result_form.clearance.user, self.user)

            result_form_stat = ResultFormStats.objects.get(
                result_form=result_form)
            self.assertEqual(result_form_stat.approved_by_supervisor, False)
            self.assertEqual(result_form_stat.reviewed_by_supervisor, False)
            self.assertEqual(result_form_stat.user, self.user)
            self.assertEqual(result_form_stat.result_form, result_form)

            for result in result_form.reconciliationform_set.all():
                self.assertFalse(result.active)

            for result in result_form.results.all():
                self.assertFalse(result.active)

            barcode = barcode + 1
            serial_number = serial_number + 1
Esempio n. 28
0
    def test_review_post_supervisor_implement_de1(self):
        # save audit as clerk
        self._create_and_login_user()
        result_form = create_result_form(form_state=FormState.AUDIT)
        create_reconciliation_form(result_form, self.user)
        create_reconciliation_form(result_form, self.user)
        create_candidates(result_form, self.user)
        self._add_user_to_group(self.user, groups.AUDIT_CLERK)

        view = views.ReviewView.as_view()
        data = {'result_form': result_form.pk,
                'action_prior_to_recommendation': 1,
                'resolution_recommendation': 0,
                'forward': 1}
        request = self.factory.post('/', data=data)
        request.user = self.user
        request.session = data
        response = view(request)

        # save as supervisor
        self._create_and_login_user(username='******')
        self._add_user_to_group(self.user, groups.AUDIT_SUPERVISOR)

        view = views.ReviewView.as_view()
        data = {'result_form': result_form.pk,
                'action_prior_to_recommendation': 1,
                'resolution_recommendation': 1,
                'implement': 1}
        request = self.factory.post('/', data=data)
        request.user = self.user
        request.session = data
        response = view(request)

        audit = Audit.objects.get(result_form=result_form)
        self.assertEqual(audit.supervisor, self.user)
        self.assertTrue(audit.reviewed_supervisor)
        self.assertTrue(audit.reviewed_team)
        self.assertFalse(audit.active)
        self.assertEqual(audit.result_form.form_state,
                         FormState.AUDIT_PENDING_STATE)
        self.assertEqual(len(audit.result_form.results.all()), 20)
        self.assertEqual(len(audit.result_form.reconciliationform_set.all()),
                         2)

        for result in audit.result_form.results.all():
            self.assertFalse(result.active)

        for result in audit.result_form.reconciliationform_set.all():
            self.assertFalse(result.active)

        self.assertEqual(audit.action_prior_to_recommendation, 1)
        self.assertEqual(response.status_code, 302)
Esempio n. 29
0
    def test_duplicate_result_form_view_send_all_clearance_post(self):
        tally = create_tally()
        tally.users.add(self.user)
        ballot = create_ballot(tally=tally)
        barcode = '1234',
        center = create_center('12345', tally=tally)
        station = create_station(center)
        result_form_1 = create_result_form(
            tally=tally,
            ballot=ballot,
            center=center,
            station_number=station.station_number)
        result_form_2, _ = ResultForm.objects.get_or_create(
            id=2,
            ballot=ballot,
            barcode=barcode,
            serial_number=2,
            form_state=FormState.UNSUBMITTED,
            station_number=station.station_number,
            user=None,
            center=center,
            gender=Gender.MALE,
            is_replacement=False,
            tally=tally,
        )
        votes = 12
        create_candidates(result_form_1,
                          votes=votes,
                          user=self.user,
                          num_results=1)

        for result in result_form_1.results.all():
            result.entry_version = EntryVersion.FINAL
            result.save()
            # create duplicate final results
            create_result(result_form_2, result.candidate, self.user, votes)
        view = views.DuplicateResultFormView.as_view()
        data = {'send_all_clearance': 1}
        request = self.factory.post('/', data=data)
        request.user = self.user
        configure_messages(request)
        response = view(request, tally_id=tally.pk, ballot_id=ballot.pk)

        result_form_1.reload()
        result_form_2.reload()
        self.assertEqual(response.status_code, 302)
        self.assertIn("/super-administrator/duplicate-result-tracking",
                      response.url)
        self.assertEqual(result_form_1.form_state, FormState.CLEARANCE)
        self.assertTrue(result_form_1.duplicate_reviewed)
        self.assertEqual(result_form_2.form_state, FormState.CLEARANCE)
        self.assertTrue(result_form_2.duplicate_reviewed)
Esempio n. 30
0
 def test_sanity_check_results(self):
     votes = 12
     result_form = create_result_form()
     create_candidates(result_form, votes=votes, user=self.user,
                       num_results=1)
     for result in result_form.results.all():
         result.entry_version = EntryVersion.FINAL
         result.save()
         # create duplicate final results
         create_result(result_form, result.candidate, self.user, votes)
     self.assertEqual(result_form.results_final.filter().count(), 4)
     sanity_check_final_results(result_form)
     self.assertEqual(result_form.results_final.filter().count(), 2)
    def test_number_ballots_used_results(self):
        expected_votes = 0

        for num_results in xrange(1, 4):
            for votes in xrange(1, 4):
                result_form = create_result_form()
                create_candidates(result_form, self.user, votes=votes,
                                  num_results=num_results)
                re_form = create_reconciliation_form(result_form, self.user)

                expected_votes += num_results * votes * 2

                self.assertEqual(re_form.number_ballots_used,
                                 self.num_used + expected_votes)
Esempio n. 32
0
    def test_remove_center_post_result_exists(self):
        center = create_center('12345')
        result_form = create_result_form(center=center,
                                         form_state=FormState.AUDIT)
        create_reconciliation_form(result_form, self.user)
        create_reconciliation_form(result_form, self.user)
        create_candidates(result_form, self.user)
        self.assertTrue(Result.objects.filter().count() > 0)

        view = views.RemoveCenterView.as_view()
        data = {'center_number': center.code}
        request = self.factory.post('/', data)
        request.user = self.user
        response = view(request)
        self.assertContains(response, u"Results exist for barcodes")
        self.assertContains(response, result_form.barcode)
Esempio n. 33
0
    def test_number_ballots_used_results(self):
        expected_votes = 0

        for num_results in xrange(1, 4):
            for votes in xrange(1, 4):
                result_form = create_result_form()
                create_candidates(result_form,
                                  self.user,
                                  votes=votes,
                                  num_results=num_results)
                re_form = create_reconciliation_form(result_form, self.user)

                expected_votes += num_results * votes * 2

                self.assertEqual(re_form.number_ballots_used,
                                 self.num_used + expected_votes)
Esempio n. 34
0
    def test_remove_center_post_result_exists(self):
        center = create_center('12345')
        result_form = create_result_form(center=center,
                                         form_state=FormState.AUDIT)
        create_reconciliation_form(result_form, self.user)
        create_reconciliation_form(result_form, self.user)
        create_candidates(result_form, self.user)
        self.assertTrue(Result.objects.filter().count() > 0)

        view = views.RemoveCenterView.as_view()
        data = {'center_number': center.code}
        request = self.factory.post('/', data)
        request.user = self.user
        response = view(request)
        self.assertContains(response, u"Results exist for barcodes")
        self.assertContains(response, result_form.barcode)
Esempio n. 35
0
    def test_create_clearance_post_super(self):
        self._create_and_login_user()
        self._add_user_to_group(self.user, groups.SUPER_ADMINISTRATOR)
        tally = create_tally()
        tally.users.add(self.user)
        barcode = 123456789
        serial_number = 0
        clearable_states = [FormState.ARCHIVED,
                            FormState.CORRECTION,
                            FormState.DATA_ENTRY_1,
                            FormState.DATA_ENTRY_2,
                            FormState.INTAKE,
                            FormState.QUALITY_CONTROL,
                            FormState.UNSUBMITTED]

        for form_state in clearable_states:
            result_form = create_result_form(form_state=form_state,
                                             barcode=barcode,
                                             tally=tally,
                                             serial_number=serial_number)
            create_recon_forms(result_form, self.user)
            create_candidates(result_form, self.user)
            view = views.AddClearanceFormView.as_view()
            data = {
                'accept_submit': 1,
                'result_form': result_form.pk,
                'tally_id': tally.pk,
            }
            request = self.factory.post('/', data=data)
            request.user = self.user
            request.session = data
            response = view(request, tally_id=tally.pk)
            result_form.reload()

            self.assertEqual(response.status_code, 302)
            self.assertEqual(result_form.form_state, FormState.CLEARANCE)
            self.assertIsNotNone(result_form.clearance)
            self.assertEqual(result_form.clearance.user, self.user)

            for result in result_form.reconciliationform_set.all():
                self.assertFalse(result.active)

            for result in result_form.results.all():
                self.assertFalse(result.active)

            barcode = barcode + 1
            serial_number = serial_number + 1
Esempio n. 36
0
    def test_reconciliation_post_incorrect_ballot_not_released(self):
        self._create_and_login_user()
        tally = create_tally()
        tally.users.add(self.user)
        barcode = '123456789'
        create_result_form(barcode,
                           tally=tally,
                           form_state=FormState.QUALITY_CONTROL)
        result_form = ResultForm.objects.get(barcode=barcode)
        create_recon_forms(result_form, self.user)
        create_candidates(result_form, self.user)
        create_quality_control(result_form, self.user)
        self._add_user_to_group(self.user, groups.QUALITY_CONTROL_CLERK)
        view = views.QualityControlDashboardView.as_view()
        data = {
            'result_form': result_form.pk,
            'incorrect': 1,
            'tally_id': tally.pk,
        }
        request = self.factory.post('/', data=data)
        request.user = self.user
        request.session = {'result_form': result_form.pk}
        response = view(request, tally_id=tally.pk)
        self.assertEqual(response.status_code, 302)
        self.assertIn('quality-control/reject',
                      response['location'])
        self.assertEqual(result_form.rejected_count, 0)
        result_form = ResultForm.objects.get(pk=result_form.pk)
        quality_control = result_form.qualitycontrol_set.all()[0]

        results = result_form.results.all()
        self.assertTrue(len(results) > 0)

        for result in results:
            self.assertEqual(result.active, False)

        recon_forms = result_form.reconciliationform_set.all()
        self.assertTrue(len(recon_forms) > 0)

        for recon in recon_forms:
            self.assertEqual(recon.active, False)

        self.assertEqual(result_form.form_state, FormState.DATA_ENTRY_1)
        self.assertEqual(result_form.rejected_count, 1)
        self.assertEqual(quality_control.active, False)
        self.assertEqual(quality_control.passed_reconciliation, False)
Esempio n. 37
0
    def test_reviews_passed(self):
        result_form = create_result_form()
        create_candidates(result_form, self.user)
        quality_control = QualityControl.objects.create(
            result_form=result_form,
            user=self.user)

        self.assertFalse(quality_control.reviews_passed)

        quality_control.passed_general = True
        quality_control.save()
        self.assertFalse(quality_control.reviews_passed)

        quality_control.passed_reconciliation = True
        quality_control.save()
        self.assertFalse(quality_control.reviews_passed)

        quality_control.passed_women = True
        quality_control.save()
        self.assertTrue(quality_control.reviews_passed)
Esempio n. 38
0
    def test_quality_control_post_quarantine_pass_below_tolerance(self):
        center = create_center()
        create_station(center)
        create_quarantine_checks()
        self._create_and_login_user()
        tally = create_tally()
        tally.users.add(self.user)
        result_form = create_result_form(tally=tally,
                                         form_state=FormState.QUALITY_CONTROL,
                                         center=center,
                                         station_number=1)
        recon_form = create_reconciliation_form(result_form,
                                                self.user,
                                                number_ballots_inside_box=21,
                                                number_unstamped_ballots=0)
        create_quality_control(result_form, self.user)
        create_candidates(result_form, self.user, votes=1, num_results=10)
        self._add_user_to_group(self.user, groups.QUALITY_CONTROL_CLERK)
        view = views.QualityControlDashboardView.as_view()
        data = {
            'correct': 1,
            'result_form': result_form.pk,
            'tally_id': tally.pk,
        }
        request = self.factory.post('/', data=data)
        request.session = {'result_form': result_form.pk}
        request.user = self.user
        response = view(request, tally_id=tally.pk)
        result_form.reload()

        self.assertEqual(result_form.num_votes,
                         recon_form.number_ballots_expected)

        self.assertEqual(response.status_code, 302)
        self.assertTrue(result_form.form_state, FormState.AUDIT)
        self.assertTrue(result_form.audit)
        self.assertEqual(result_form.audit.quarantine_checks.count(), 1)
        self.assertEqual(result_form.audit.quarantine_checks.all()[0].name[:9],
                         'Trigger 1')
        self.assertEqual(result_form.audited_count, 1)
        self.assertIn('quality-control/print', response['location'])
Esempio n. 39
0
    def test_quality_control_post_quarantine_pass_below_tolerance(self):
        center = create_center()
        create_station(center)
        create_quarantine_checks()
        self._create_and_login_user()
        tally = create_tally()
        tally.users.add(self.user)
        result_form = create_result_form(
            tally=tally,
            form_state=FormState.QUALITY_CONTROL,
            center=center, station_number=1)
        recon_form = create_reconciliation_form(
            result_form, self.user, number_ballots_inside_box=21,
            number_unstamped_ballots=0)
        create_quality_control(result_form, self.user)
        create_candidates(result_form, self.user, votes=1, num_results=10)
        self._add_user_to_group(self.user, groups.QUALITY_CONTROL_CLERK)
        view = views.QualityControlDashboardView.as_view()
        data = {
            'correct': 1,
            'result_form': result_form.pk,
            'tally_id': tally.pk,
        }
        request = self.factory.post('/', data=data)
        request.session = {'result_form': result_form.pk}
        request.user = self.user
        response = view(request, tally_id=tally.pk)
        result_form.reload()

        self.assertEqual(result_form.num_votes,
                         recon_form.number_ballots_expected)

        self.assertEqual(response.status_code, 302)
        self.assertTrue(result_form.form_state, FormState.AUDIT)
        self.assertTrue(result_form.audit)
        self.assertEqual(result_form.audit.quarantine_checks.count(), 1)
        self.assertEqual(
            result_form.audit.quarantine_checks.all()[0].name[:9], 'Trigger 1')
        self.assertEqual(result_form.audited_count, 1)
        self.assertIn('quality-control/print', response['location'])
Esempio n. 40
0
    def setUp(self):
        self.factory = RequestFactory()
        self._create_permission_groups()
        self._create_and_login_user()
        self._add_user_to_group(self.user, groups.SUPER_ADMINISTRATOR)

        self.tally = create_tally()
        self.tally.users.add(self.user)

        ballot = create_ballot(tally=self.tally)
        self.center = create_center('12345', tally=self.tally)
        self.station = create_station(self.center)
        result_form = create_result_form(
            tally=self.tally,
            ballot=ballot,
            center=self.center,
            station_number=self.station.station_number)
        votes = 12
        create_candidates(result_form,
                          votes=votes,
                          user=self.user,
                          num_results=1)
Esempio n. 41
0
    def test_dashboard_get_double_recon(self):
        barcode = "123456789"
        self._create_and_login_user()
        center = create_center()
        station = create_station(center=center)
        result_form = create_result_form(
            barcode, center=center, station_number=station.station_number, form_state=FormState.QUALITY_CONTROL
        )
        create_reconciliation_form(result_form, self.user)
        create_reconciliation_form(result_form, self.user)
        create_candidates(result_form, self.user)
        create_quality_control(result_form, self.user)

        self._add_user_to_group(self.user, groups.QUALITY_CONTROL_CLERK)
        view = views.QualityControlDashboardView.as_view()
        request = self.factory.get("/")
        request.user = self.user
        request.session = {"result_form": result_form.pk}
        response = view(request)

        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "General Results Section")
        self.assertContains(response, "Abort")
Esempio n. 42
0
    def test_remove_station_post_result_exists(self):
        tally = create_tally()
        tally.users.add(self.user)
        center = create_center('12345', tally=tally)
        station = create_station(center)
        result_form = create_result_form(center=center,
                                         form_state=FormState.AUDIT,
                                         station_number=station.station_number)
        create_reconciliation_form(result_form, self.user)
        create_reconciliation_form(result_form, self.user)
        create_candidates(result_form, self.user)
        self.assertTrue(Result.objects.filter().count() > 0)

        view = views.RemoveStationView.as_view()
        data = {
            'center_number': center.code,
            'station_number': station.station_number,
            'tally_id': tally.pk,
        }
        request = self.factory.post('/', data)
        request.user = self.user
        response = view(request, tally_id=tally.pk)
        self.assertContains(response, u"Results exist for barcodes")
        self.assertContains(response, result_form.barcode)
Esempio n. 43
0
    def test_get_result_form_with_duplicate_results(self):
        tally = create_tally()
        tally.users.add(self.user)
        ballot_1 = create_ballot(tally=tally)
        barcode = '1234',
        center = create_center('12345', tally=tally)
        station = create_station(center)
        result_form_1 = create_result_form(
            tally=tally,
            ballot=ballot_1,
            center=center,
            station_number=station.station_number)
        result_form_2, _ = ResultForm.objects.get_or_create(
            id=2,
            ballot=ballot_1,
            barcode=barcode,
            serial_number=2,
            form_state=FormState.UNSUBMITTED,
            station_number=station.station_number,
            user=None,
            center=center,
            gender=Gender.MALE,
            is_replacement=False,
            tally=tally,
        )
        votes = 12
        create_candidates(result_form_1,
                          votes=votes,
                          user=self.user,
                          num_results=1)

        for result in result_form_1.results.all():
            result.entry_version = EntryVersion.FINAL
            result.save()
            # create duplicate final results
            create_result(result_form_2, result.candidate, self.user, votes)
        duplicate_results = views.get_result_form_with_duplicate_results(
            tally_id=tally.pk)
        self.assertIn(result_form_1, duplicate_results)
        self.assertIn(result_form_2, duplicate_results)

        # test filtering duplicate result forms by ballot
        ballot_2, _ = Ballot.objects.get_or_create(id=2,
                                                   active=True,
                                                   number=2,
                                                   tally=tally,
                                                   available_for_release=False,
                                                   race_type=RaceType.GENERAL,
                                                   document="")
        result_form_3, _ = ResultForm.objects.get_or_create(
            id=3,
            ballot=ballot_2,
            barcode="12345",
            serial_number=3,
            form_state=FormState.UNSUBMITTED,
            station_number=station.station_number,
            user=None,
            center=center,
            gender=Gender.MALE,
            is_replacement=False,
            tally=tally,
        )
        result_form_4, _ = ResultForm.objects.get_or_create(
            id=4,
            ballot=ballot_2,
            barcode="123456",
            serial_number=4,
            form_state=FormState.UNSUBMITTED,
            station_number=station.station_number,
            user=None,
            center=center,
            gender=Gender.MALE,
            is_replacement=False,
            tally=tally,
        )
        create_candidates(result_form_3,
                          votes=votes,
                          user=self.user,
                          num_results=1)

        for result in result_form_3.results.all():
            result.entry_version = EntryVersion.FINAL
            result.save()
            # create duplicate final results
            create_result(result_form_4, result.candidate, self.user, votes)
        ballot_1_duplicates = views.get_result_form_with_duplicate_results(
            ballot=ballot_1.pk, tally_id=tally.pk)
        ballot_2_duplicates = views.get_result_form_with_duplicate_results(
            ballot=ballot_2.pk, tally_id=tally.pk)
        all_duplicates = views.get_result_form_with_duplicate_results(
            tally_id=tally.pk)

        # check result_form_1 and result_form_2 are in ballot_1_duplicates
        self.assertIn(result_form_1, ballot_1_duplicates)
        self.assertIn(result_form_2, ballot_1_duplicates)

        # check result_form_3 and result_form_4 are not in ballot_1_duplicates
        self.assertNotIn(result_form_3, ballot_1_duplicates)
        self.assertNotIn(result_form_4, ballot_1_duplicates)

        # check result_form_3 and result_form_4 are in ballot_2_duplicates
        self.assertIn(result_form_3, ballot_2_duplicates)
        self.assertIn(result_form_4, ballot_2_duplicates)

        # check result_form_1 and result_form_2 are not in ballot_2_duplicates
        self.assertNotIn(result_form_1, ballot_2_duplicates)
        self.assertNotIn(result_form_2, ballot_2_duplicates)

        self.assertIn(result_form_1, all_duplicates)
        self.assertIn(result_form_2, all_duplicates)
        self.assertIn(result_form_3, all_duplicates)
        self.assertIn(result_form_4, all_duplicates)
Esempio n. 44
0
    def test_review_post_supervisor_implement_de1(self):
        # save audit as clerk
        self._create_and_login_user()
        self._add_user_to_group(self.user, groups.AUDIT_CLERK)
        tally = create_tally()
        tally.users.add(self.user)
        result_form = create_result_form(form_state=FormState.AUDIT,
                                         tally=tally)
        create_reconciliation_form(result_form, self.user)
        create_reconciliation_form(result_form, self.user)
        create_candidates(result_form, self.user)

        view = views.ReviewView.as_view()
        data = {
            'result_form': result_form.pk,
            'action_prior_to_recommendation': 1,
            'resolution_recommendation': 0,
            'forward': 1,
            'tally_id': tally.pk,
        }
        request = self.factory.post('/', data=data)
        request.user = self.user
        request.session = data
        response = view(request, tally_id=tally.pk)

        # save as supervisor
        self._create_and_login_user(username='******')
        self._add_user_to_group(self.user, groups.AUDIT_SUPERVISOR)
        tally.users.add(self.user)

        view = views.ReviewView.as_view()
        data = {
            'result_form': result_form.pk,
            'action_prior_to_recommendation': 1,
            'resolution_recommendation': 1,
            'implement': 1,
            'tally_id': tally.pk,
        }
        request = self.factory.post('/', data=data)
        request.user = self.user
        data['encoded_result_form_audit_start_time'] =\
            self.encoded_result_form_audit_start_time
        request.session = data
        response = view(request, tally_id=tally.pk)

        self.assertEqual(response.status_code, 302)

        audit = Audit.objects.get(result_form=result_form)
        self.assertEqual(audit.supervisor, self.user)
        self.assertTrue(audit.reviewed_supervisor)
        self.assertTrue(audit.reviewed_team)
        self.assertFalse(audit.active)
        self.assertEqual(audit.result_form.form_state, FormState.AUDIT)
        self.assertEqual(len(audit.result_form.results.all()), 20)
        self.assertEqual(len(audit.result_form.reconciliationform_set.all()),
                         2)

        result_form_stat = ResultFormStats.objects.get(result_form=result_form)
        approved_by_supervisor =\
            audit.for_superadmin and audit.active
        self.assertEqual(result_form_stat.approved_by_supervisor,
                         approved_by_supervisor)
        self.assertEqual(result_form_stat.reviewed_by_supervisor,
                         audit.reviewed_supervisor)
        self.assertEqual(result_form_stat.user, self.user)
        self.assertEqual(result_form_stat.result_form, result_form)

        for result in audit.result_form.results.all():
            self.assertFalse(result.active)

        for result in audit.result_form.reconciliationform_set.all():
            self.assertFalse(result.active)

        self.assertEqual(audit.action_prior_to_recommendation,
                         ActionsPrior.REQUEST_AUDIT_ACTION_FROM_FIELD)
Esempio n. 45
0
    def test_duplicate_result_form_view_send_clearance_post(self):
        tally = create_tally()
        tally.users.add(self.user)
        ballot = create_ballot(tally=tally)
        barcode = '1234',
        center = create_center('12345', tally=tally)
        station = create_station(center)
        result_form = create_result_form(tally=tally,
                                         ballot=ballot,
                                         barcode=barcode,
                                         center=center,
                                         station_number=station.station_number)
        votes = 12
        create_candidates(result_form,
                          votes=votes,
                          user=self.user,
                          num_results=1)
        view = views.DuplicateResultFormView.as_view()
        data = {'result_form': result_form.pk, 'send_clearance': 1}
        request = self.factory.post('/', data=data)
        request.user = self.user
        configure_messages(request)
        request.session = {'result_form': result_form.pk}
        response = view(request, tally_id=tally.pk, ballot_id=ballot.pk)

        result_form.reload()
        self.assertEqual(response.status_code, 302)
        self.assertIn("/super-administrator/duplicate-result-tracking",
                      response.url)
        self.assertEqual(result_form.form_state, FormState.CLEARANCE)
        self.assertTrue(result_form.duplicate_reviewed)

        # check archived form is not sent to clearance
        result_form_2, _ = ResultForm.objects.get_or_create(
            id=2,
            ballot=ballot,
            barcode="1234",
            serial_number=2,
            form_state=FormState.ARCHIVED,
            station_number=station.station_number,
            user=None,
            center=center,
            gender=Gender.MALE,
            is_replacement=False,
            tally=tally,
        )
        create_candidates(result_form_2,
                          votes=votes,
                          user=self.user,
                          num_results=1)
        data = {'result_form': result_form_2.pk, 'send_clearance': 1}
        request = self.factory.post('/', data=data)
        request.user = self.user
        configure_messages(request)
        request.session = {'result_form': result_form_2.pk}
        response = view(request, tally_id=tally.pk, ballot_id=ballot.pk)

        result_form_2.reload()
        self.assertNotEqual(result_form_2.form_state, FormState.CLEARANCE)
        self.assertEqual(result_form_2.form_state, FormState.ARCHIVED)
        self.assertEqual(response.status_code, 302)
        self.assertEqual("/", response.url)