Example #1
0
    def test_enter_results_success_data_entry_one(self):
        code = '12345'
        center = create_center(code)
        create_station(center)
        result_form = create_result_form(form_state=FormState.DATA_ENTRY_1,
                                         center=center)
        ballot = result_form.ballot
        candidate_name = 'candidate name'
        create_candidate(ballot, candidate_name)

        self._create_and_login_user()
        self._add_user_to_group(self.user, groups.DATA_ENTRY_1_CLERK)

        response = self._post_enter_results(result_form)

        self.assertEqual(response.status_code, 302)
        self.assertIn('data-entry',
                      response['location'])
        result_form.reload()
        self.assertEqual(result_form.form_state,
                         FormState.DATA_ENTRY_2)

        reconciliation_forms = result_form.reconciliationform_set.all()
        self.assertEqual(len(reconciliation_forms), 1)
        self.assertEqual(reconciliation_forms[0].entry_version,
                         EntryVersion.DATA_ENTRY_1)

        results = result_form.results.all()
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].entry_version, EntryVersion.DATA_ENTRY_1)

        for result in results:
            self.assertEqual(result.user, self.user)
Example #2
0
    def test_enter_results_success_data_entry_two(self):
        code = '12345'
        center = create_center(code)
        create_station(center)
        result_form = create_result_form(form_state=FormState.DATA_ENTRY_2,
                                         center=center)
        ballot = result_form.ballot
        candidate_name = 'candidate name'
        create_candidate(ballot, candidate_name)

        self._create_and_login_user()
        self._add_user_to_group(self.user, groups.DATA_ENTRY_2_CLERK)

        response = self._post_enter_results(result_form)

        self.assertEqual(response.status_code, 302)
        self.assertIn('data-entry',
                      response['location'])
        updated_result_form = ResultForm.objects.get(pk=result_form.pk)
        self.assertEqual(updated_result_form.form_state,
                         FormState.CORRECTION)

        reconciliation_forms = updated_result_form.reconciliationform_set.all()
        self.assertEqual(len(reconciliation_forms), 1)

        self.assertEqual(reconciliation_forms[0].entry_version,
                         EntryVersion.DATA_ENTRY_2)

        results = updated_result_form.results.all()
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].entry_version, EntryVersion.DATA_ENTRY_2)
        self.assertEqual(results[0].user, self.user)
Example #3
0
    def test_enter_results_success_data_entry_two(self):
        code = '12345'
        center = create_center(code)
        create_station(center)
        result_form = create_result_form(form_state=FormState.DATA_ENTRY_2,
                                         center=center)
        ballot = result_form.ballot
        candidate_name = 'candidate name'
        create_candidate(ballot, candidate_name)

        self._create_and_login_user()
        self._add_user_to_group(self.user, groups.DATA_ENTRY_2_CLERK)

        response = self._post_enter_results(result_form)

        self.assertEqual(response.status_code, 302)
        self.assertIn('data-entry', response['location'])
        updated_result_form = ResultForm.objects.get(pk=result_form.pk)
        self.assertEqual(updated_result_form.form_state, FormState.CORRECTION)

        reconciliation_forms = updated_result_form.reconciliationform_set.all()
        self.assertEqual(len(reconciliation_forms), 1)

        self.assertEqual(reconciliation_forms[0].entry_version,
                         EntryVersion.DATA_ENTRY_2)

        results = updated_result_form.results.all()
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].entry_version, EntryVersion.DATA_ENTRY_2)
        self.assertEqual(results[0].user, self.user)
Example #4
0
    def test_enter_results_success_data_entry_one(self):
        code = '12345'
        center = create_center(code)
        create_station(center)
        result_form = create_result_form(form_state=FormState.DATA_ENTRY_1,
                                         center=center)
        ballot = result_form.ballot
        candidate_name = 'candidate name'
        create_candidate(ballot, candidate_name)

        self._create_and_login_user()
        self._add_user_to_group(self.user, groups.DATA_ENTRY_1_CLERK)

        response = self._post_enter_results(result_form)

        self.assertEqual(response.status_code, 302)
        self.assertIn('data-entry', response['location'])
        result_form.reload()
        self.assertEqual(result_form.form_state, FormState.DATA_ENTRY_2)

        reconciliation_forms = result_form.reconciliationform_set.all()
        self.assertEqual(len(reconciliation_forms), 1)
        self.assertEqual(reconciliation_forms[0].entry_version,
                         EntryVersion.DATA_ENTRY_1)

        results = result_form.results.all()
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0].entry_version, EntryVersion.DATA_ENTRY_1)

        for result in results:
            self.assertEqual(result.user, self.user)
Example #5
0
    def test_enter_results_success_data_entry(self):
        self._create_and_login_user('data_entry_1')
        self._add_user_to_group(self.user, groups.DATA_ENTRY_1_CLERK)
        tally = create_tally()
        tally.users.add(self.user)
        code = '12345'
        center = create_center(code, tally=tally)
        create_station(center)
        result_form = create_result_form(form_state=FormState.DATA_ENTRY_1,
                                         tally=tally)
        ballot = result_form.ballot
        candidate_name = 'candidate name'
        create_candidate(ballot, candidate_name)

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

        data_entry_1 = self.user

        self._create_and_login_user('data_entry_2')
        self._add_user_to_group(self.user, groups.DATA_ENTRY_2_CLERK)
        tally.users.add(self.user)
        request.user = self.user
        response = view(request, tally_id=tally.pk)
        self.assertEqual(response.status_code, 302)
        self.assertIn('data-entry',
                      response['location'])
        updated_result_form = ResultForm.objects.get(pk=result_form.pk)
        self.assertEqual(updated_result_form.form_state,
                         FormState.CORRECTION)
        results = updated_result_form.results.filter(
            entry_version=EntryVersion.DATA_ENTRY_2)
        self.assertTrue(results.count() > 0)
        self.assertEqual(results.all()[0].user, self.user)
        results = updated_result_form.results.filter(
            entry_version=EntryVersion.DATA_ENTRY_2)
        self.assertTrue(results.count() > 0)

        for result in results:
            self.assertEqual(result.user, self.user)
            self.assertNotEqual(result.user, data_entry_1)
Example #6
0
    def test_enter_results_success_data_entry(self):
        self._create_and_login_user('data_entry_1')
        self._add_user_to_group(self.user, groups.DATA_ENTRY_1_CLERK)
        tally = create_tally()
        tally.users.add(self.user)
        code = '12345'
        center = create_center(code, tally=tally)
        create_station(center)
        result_form = create_result_form(form_state=FormState.DATA_ENTRY_1,
                                         tally=tally)
        ballot = result_form.ballot
        candidate_name = 'candidate name'
        create_candidate(ballot, candidate_name)

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

        data_entry_1 = self.user

        self._create_and_login_user('data_entry_2')
        self._add_user_to_group(self.user, groups.DATA_ENTRY_2_CLERK)
        tally.users.add(self.user)
        request.user = self.user
        response = view(request, tally_id=tally.pk)
        self.assertEqual(response.status_code, 302)
        self.assertIn('data-entry',
                      response['location'])
        updated_result_form = ResultForm.objects.get(pk=result_form.pk)
        self.assertEqual(updated_result_form.form_state,
                         FormState.CORRECTION)
        results = updated_result_form.results.filter(
            entry_version=EntryVersion.DATA_ENTRY_2)
        self.assertTrue(results.count() > 0)
        self.assertEqual(results.all()[0].user, self.user)
        results = updated_result_form.results.filter(
            entry_version=EntryVersion.DATA_ENTRY_2)
        self.assertTrue(results.count() > 0)

        for result in results:
            self.assertEqual(result.user, self.user)
            self.assertNotEqual(result.user, data_entry_1)
Example #7
0
    def test_enter_results_invalid(self):
        code = '12345'
        center = create_center(code)
        create_station(center)
        result_form = create_result_form(form_state=FormState.DATA_ENTRY_1)
        ballot = result_form.ballot
        candidate_name = 'candidate name'
        create_candidate(ballot, candidate_name)

        self._create_and_login_user()
        self._add_user_to_group(self.user, groups.DATA_ENTRY_1_CLERK)
        view = views.EnterResultsView.as_view()
        data = result_form_data_blank(result_form)
        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, 200)
        self.assertContains(response, 'Missing votes')
Example #8
0
    def test_enter_results_invalid(self):
        code = '12345'
        center = create_center(code)
        create_station(center)
        result_form = create_result_form(form_state=FormState.DATA_ENTRY_1)
        ballot = result_form.ballot
        candidate_name = 'candidate name'
        create_candidate(ballot, candidate_name)

        self._create_and_login_user()
        self._add_user_to_group(self.user, groups.DATA_ENTRY_1_CLERK)
        view = views.EnterResultsView.as_view()
        data = result_form_data_blank(result_form)
        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, 200)
        self.assertContains(response, 'Missing votes')
Example #9
0
    def test_enter_results_has_candidates(self):
        self._create_and_login_user()
        self._add_user_to_group(self.user, groups.DATA_ENTRY_1_CLERK)
        tally = create_tally()
        tally.users.add(self.user)
        code = '12345'
        center = create_center(code, tally=tally)
        create_station(center)
        result_form = create_result_form(form_state=FormState.DATA_ENTRY_1,
                                         tally=tally)
        ballot = result_form.ballot
        candidate_name = 'candidate name'
        create_candidate(ballot, candidate_name)

        view = views.EnterResultsView.as_view()
        data = center_data(code)
        request = self.factory.get('/', 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, 200)
        self.assertContains(response, candidate_name)
Example #10
0
    def test_enter_results_has_candidates(self):
        self._create_and_login_user()
        self._add_user_to_group(self.user, groups.DATA_ENTRY_1_CLERK)
        tally = create_tally()
        tally.users.add(self.user)
        code = '12345'
        center = create_center(code, tally=tally)
        create_station(center)
        result_form = create_result_form(form_state=FormState.DATA_ENTRY_1,
                                         tally=tally)
        ballot = result_form.ballot
        candidate_name = 'candidate name'
        create_candidate(ballot, candidate_name)

        view = views.EnterResultsView.as_view()
        data = center_data(code)
        request = self.factory.get('/', 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, 200)
        self.assertContains(response, candidate_name)
Example #11
0
    def test_get_office_candidates_ids(self):
        """
        Test that office candidate ids are returned
        """
        result_form = ResultForm.objects.all()[0]
        candidate =\
            create_candidate(result_form.ballot, 'the candidate name')
        candidate_ids =\
            progress.get_office_candidates_ids(
                self.office.id,
                self.tally.id)

        self.assertEqual(candidate_ids[0], candidate.id)
Example #12
0
def create_results(result_form, vote1=1, vote2=1, race_type=RaceType.GENERAL,
                   num=1):
    code = '12345'
    center = create_center(code)
    create_station(center)
    ballot = result_form.ballot
    candidate_name = 'candidate name'
    candidate = create_candidate(ballot, candidate_name, race_type)

    for i in xrange(num):
        Result.objects.create(
            candidate=candidate,
            result_form=result_form,
            entry_version=EntryVersion.DATA_ENTRY_1,
            votes=vote1)

        if vote2:
            Result.objects.create(
                candidate=candidate,
                result_form=result_form,
                entry_version=EntryVersion.DATA_ENTRY_2,
                votes=vote2)
Example #13
0
def create_results(result_form, vote1=1, vote2=1, race_type=RaceType.GENERAL,
                   num=1):
    code = '12345'
    center = create_center(code)
    create_station(center)
    ballot = result_form.ballot
    candidate_name = 'candidate name'
    candidate = create_candidate(ballot, candidate_name, race_type)

    for i in range(num):
        Result.objects.create(
            candidate=candidate,
            result_form=result_form,
            entry_version=EntryVersion.DATA_ENTRY_1,
            votes=vote1)

        if vote2:
            Result.objects.create(
                candidate=candidate,
                result_form=result_form,
                entry_version=EntryVersion.DATA_ENTRY_2,
                votes=vote2)