예제 #1
0
 def test_create_race_view(self):
     tally = create_tally()
     tally.users.add(self.user)
     view = views.CreateRaceView.as_view()
     file_size = settings.MAX_FILE_UPLOAD_SIZE
     image_file_name = "image.jpg"
     image_file = SimpleUploadedFile(image_file_name,
                                     bytes(file_size),
                                     content_type="image/jpeg")
     data = {
         'number': 2,
         'race_type': 0,
         'tally_id': tally.pk,
         'available_for_release': True,
         'document': image_file,
     }
     request = self.factory.post('/', data)
     request.user = self.user
     request.session = data
     configure_messages(request)
     response = view(request, tally_id=tally.pk)
     self.assertEqual(response.status_code, 302)
     ballot = Ballot.objects.get(document__isnull=False)
     self.assertIn(image_file_name, ballot.document.path)
     shutil.rmtree(os.path.dirname(ballot.document.path))
예제 #2
0
 def test_create_race_invalid_document_extension_error(self):
     tally = create_tally()
     tally.users.add(self.user)
     view = views.CreateRaceView.as_view()
     file_size = settings.MAX_FILE_UPLOAD_SIZE
     video = SimpleUploadedFile("file.mp4",
                                bytes(file_size),
                                content_type="video/mp4")
     data = {
         'number': 1,
         'race_type': 0,
         'tally_id': tally.pk,
         'available_for_release': True,
         'document': video,
     }
     request = self.factory.post('/', data)
     request.user = self.user
     request.session = data
     configure_messages(request)
     response = view(request, tally_id=tally.pk)
     self.assertFalse(response.context_data['form'].is_valid())
     self.assertEqual(
         response.context_data['form'].errors['document'][0],
         str('File extention (.mp4) is not supported.'
             ' Allowed extensions are: .png, .jpg, .doc, .pdf.'))
예제 #3
0
 def test_create_race_invalid_document_size_error(self):
     tally = create_tally()
     tally.users.add(self.user)
     view = views.CreateRaceView.as_view()
     file_size = settings.MAX_FILE_UPLOAD_SIZE * 2
     image = SimpleUploadedFile("image.jpg",
                                bytes(file_size),
                                content_type="image/jpeg")
     data = {
         'number': 1,
         'race_type': 0,
         'tally_id': tally.pk,
         'available_for_release': True,
         'document': image,
     }
     request = self.factory.post('/', data)
     request.user = self.user
     request.session = data
     configure_messages(request)
     response = view(request, tally_id=tally.pk)
     self.assertFalse(response.context_data['form'].is_valid())
     self.assertEqual(
         response.context_data['form'].errors['document'][0],
         str('File size must be under 10.0\xa0MB.'
             ' Current file size is 20.0\xa0MB.'))
예제 #4
0
 def test_create_station(self):
     tally = create_tally()
     tally.users.add(self.user)
     view = views.CreateStationView.as_view()
     data = {
         'tally_id': tally.pk,
     }
     request = self.factory.post('/', data)
     request.user = self.user
     configure_messages(request)
     response = view(request, tally_id=tally.pk)
     self.assertEqual(response.status_code, 200)
예제 #5
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)
예제 #6
0
 def test_edit_station_post(self):
     tally = create_tally()
     tally.users.add(self.user)
     center = create_center(tally=tally)
     station = create_station(center)
     view = views.EditStationView.as_view()
     data = {
         'center_code': center.code,
         'station_number': station.station_number,
         'tally_id': tally.pk,
         'gender': station.gender.value,
     }
     request = self.factory.post('/', data)
     request.user = self.user
     configure_messages(request)
     response = view(request, station_id=station.pk, tally_id=tally.pk)
     self.assertEqual(response.status_code, 302)
예제 #7
0
 def test_disable_race_view_post(self):
     tally = create_tally()
     tally.users.add(self.user)
     ballot = create_ballot(tally=tally)
     comment_text = 'example comment text'
     view = views.DisableRaceView.as_view()
     data = {
         'race_id_input': ballot.pk,
         'comment_input': comment_text,
         'tally_id': tally.pk,
         'disable_reason': '2',
     }
     request = self.factory.post('/', data)
     request.user = self.user
     configure_messages(request)
     response = view(request, tally_id=tally.pk)
     self.assertEqual(response.status_code, 302)
     self.assertIn('/data/races-list/%s/' % tally.pk, response['Location'])
     ballot.reload()
     self.assertEqual(ballot.disable_reason.value, 2)
     self.assertEqual(ballot.comments.all()[0].text, comment_text)
예제 #8
0
    def test_edit_race_view_post(self):
        tally = create_tally()
        tally.users.add(self.user)
        file_size = settings.MAX_FILE_UPLOAD_SIZE
        pdf_file_name = "file.pdf"
        image_file_name = "image.jpg"
        pdf_file = SimpleUploadedFile(pdf_file_name,
                                      bytes(file_size),
                                      content_type="application/pdf")
        image_file = SimpleUploadedFile(image_file_name,
                                        bytes(file_size),
                                        content_type="image/jpeg")
        ballot = create_ballot(tally, document=pdf_file)
        comment_text = 'jndfjs fsgfd'
        view = views.EditRaceView.as_view()
        data = {
            'comment_input': comment_text,
            'number': ballot.number,
            'race_type': ballot.race_type.value,
            'available_for_release': True,
            'race_id': ballot.pk,
            'tally_id': tally.pk,
            'document': image_file,
        }
        request = self.factory.post('/', data)
        request.user = self.user
        configure_messages(request)
        response = view(request, id=ballot.pk, tally_id=tally.pk)
        self.assertEqual(response.status_code, 302)
        ballot.reload()
        ballot.refresh_from_db()

        # testing auto_delete_document signal was called
        self.assertNotIn(pdf_file_name, ballot.document.path)
        self.assertIn(image_file_name, ballot.document.path)
        self.assertEqual(ballot.available_for_release, True)
        self.assertEqual(ballot.comments.first().text, comment_text)
        shutil.rmtree(os.path.dirname(ballot.document.path))
예제 #9
0
    def test_set_user_timeout_valid_post(self):
        tally = create_tally()
        tally.users.add(self.user)
        view = views.SetUserTimeOutView.as_view()
        user_idle_timeout = 60
        data = {'user_idle_timeout': user_idle_timeout}
        request = self.factory.post('/', data=data)
        request.user = self.user
        configure_messages(request)

        site_id = getattr(settings, "SITE_ID", None)
        try:
            Site.objects.get(pk=site_id)
        except Site.DoesNotExist:
            site = Site.objects.create(name="HENC RMS")
            site_id = site.id
        response = view(request, site_id=site_id)

        success_url = 'tally-manager'
        siteinfo = SiteInfo.objects.get(site__pk=site_id)

        self.assertEqual(siteinfo.user_idle_timeout, user_idle_timeout)
        self.assertEqual(response.status_code, 302)
        self.assertIn(success_url, response.url)
예제 #10
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)