Esempio n. 1
0
    def test_new_view_no_centers(self):
        """Pass criteria that generate no centers to the new job form and test output"""
        # This is the only validation that happens at the view level. All other validation happens
        # in the form.
        no_reg_center = RegistrationCenterFactory.build()
        no_reg_center.reg_open = False
        no_reg_center.save()
        with override_settings(ROLLGEN_OUTPUT_DIR=self.faux_output_dir):
            response = self.client.post(
                reverse('rollgen:new'), {
                    'name': 'kjghdhjdhjghfkjhgdf',
                    'center_selection_type': 'by_center_text_list',
                    'center_text_list': [str(no_reg_center.center_id)],
                    'phase': 'polling',
                    'forgive_no_voters': False,
                    'forgive_no_office': False,
                })

        self.assertResponseOK(response)
        self.assertTemplateUsed(response, 'rollgen/new.html')

        context = response.context

        expected_keys = ('form', )
        self.assertTrue(set(expected_keys) < set(context.keys()))
        self.assertIsInstance(context['form'], NewJobForm)
        self.assertFormError(
            response, 'form', None,
            "The criteria you specified didn't match any active centres.")
Esempio n. 2
0
    def test_new_view_no_centers(self):
        """Pass criteria that generate no centers to the new job form and test output"""
        # This is the only validation that happens at the view level. All other validation happens
        # in the form.
        no_reg_center = RegistrationCenterFactory.build()
        no_reg_center.reg_open = False
        no_reg_center.save()
        with override_settings(ROLLGEN_OUTPUT_DIR=self.faux_output_dir):
            response = self.client.post(reverse('rollgen:new'),
                                        {'name': 'kjghdhjdhjghfkjhgdf',
                                         'center_selection_type': 'by_center_text_list',
                                         'center_text_list': [str(no_reg_center.center_id)],
                                         'phase': 'polling',
                                         'forgive_no_voters': False,
                                         'forgive_no_office': False,
                                         }
                                        )

        self.assertResponseOK(response)
        self.assertTemplateUsed(response, 'rollgen/new.html')

        context = response.context

        expected_keys = ('form', )
        self.assertTrue(set(expected_keys) < set(context.keys()))
        self.assertIsInstance(context['form'], NewJobForm)
        self.assertFormError(response, 'form', None,
                             "The criteria you specified didn't match any active centres.")
Esempio n. 3
0
    def test_split_center_ok(self):
        """test that a split center can be created"""
        split_center_subcon, unused = \
            SubConstituency.objects.get_or_create(id=SPLIT_CENTER_SUBCONSTITUENCY_ID)

        center = RegistrationCenterFactory.build(center_type=RegistrationCenter.Types.SPLIT,
                                                 subconstituency=split_center_subcon)
        # This should not raise an error
        center.clean()
Esempio n. 4
0
    def test_copy_center_requires_copy_info(self):
        """test that a center with copy type requires copy_of info"""
        copy_center = RegistrationCenterFactory.build(center_type=RegistrationCenter.Types.COPY)
        copy_center.copy_of = None

        with self.assertRaises(ValidationError) as cm:
            copy_center.clean()
        self.assertEqual(cm.exception.message,
                         'Centre type "copy" requires copy centre information.')
Esempio n. 5
0
    def test_copy_center_requires_copy_type(self):
        """test that a copy center must have the correct type"""
        original_center = RegistrationCenterFactory()
        copy_center = RegistrationCenterFactory.build(copy_of=original_center)
        copy_center.center_type = RegistrationCenter.Types.GENERAL

        with self.assertRaises(ValidationError) as cm:
            copy_center.clean()
        self.assertEqual(cm.exception.message, 'Copy centre type must be "copy".')
Esempio n. 6
0
    def test_copy_of_copy_fails(self):
        """test that a copy center can't be a copy of another copy center"""
        original_center = RegistrationCenterFactory()
        copy_center = RegistrationCenterFactory(copy_of=original_center)
        copy_copy_center = RegistrationCenterFactory.build(copy_of=copy_center)

        with self.assertRaises(ValidationError) as cm:
            copy_copy_center.clean()
        self.assertEqual(cm.exception.message, 'A copy centre cannot copy another copy centre.')
Esempio n. 7
0
    def test_split_center_ok(self):
        """test that a split center can be created"""
        split_center_subcon, unused = \
            SubConstituency.objects.get_or_create(id=SPLIT_CENTER_SUBCONSTITUENCY_ID)

        center = RegistrationCenterFactory.build(
            center_type=RegistrationCenter.Types.SPLIT,
            subconstituency=split_center_subcon)
        # This should not raise an error
        center.clean()
Esempio n. 8
0
    def test_copy_center_requires_copy_type(self):
        """test that a copy center must have the correct type"""
        original_center = RegistrationCenterFactory()
        copy_center = RegistrationCenterFactory.build(copy_of=original_center)
        copy_center.center_type = RegistrationCenter.Types.GENERAL

        with self.assertRaises(ValidationError) as cm:
            copy_center.clean()
        self.assertEqual(cm.exception.message,
                         'Copy centre type must be "copy".')
Esempio n. 9
0
    def test_copy_of_copy_fails(self):
        """test that a copy center can't be a copy of another copy center"""
        original_center = RegistrationCenterFactory()
        copy_center = RegistrationCenterFactory(copy_of=original_center)
        copy_copy_center = RegistrationCenterFactory.build(copy_of=copy_center)

        with self.assertRaises(ValidationError) as cm:
            copy_copy_center.clean()
        self.assertEqual(cm.exception.message,
                         'A copy centre cannot copy another copy centre.')
Esempio n. 10
0
 def test_split_center_must_use_split_subcon(self):
     """test that a split center must be associated with the correct subcon"""
     some_random_subcon = SubConstituencyFactory()
     center = RegistrationCenterFactory.build(center_type=RegistrationCenter.Types.SPLIT,
                                              subconstituency=some_random_subcon)
     with self.assertRaises(ValidationError) as cm:
         center.clean()
     msg = "Split centers must be associated with subconstituency {}."
     msg = msg.format(SPLIT_CENTER_SUBCONSTITUENCY_ID)
     self.assertEqual(cm.exception.message, msg)
Esempio n. 11
0
 def test_split_center_must_use_split_subcon(self):
     """test that a split center must be associated with the correct subcon"""
     some_random_subcon = SubConstituencyFactory()
     center = RegistrationCenterFactory.build(
         center_type=RegistrationCenter.Types.SPLIT,
         subconstituency=some_random_subcon)
     with self.assertRaises(ValidationError) as cm:
         center.clean()
     msg = "Split centers must be associated with subconstituency {}."
     msg = msg.format(SPLIT_CENTER_SUBCONSTITUENCY_ID)
     self.assertEqual(cm.exception.message, msg)
Esempio n. 12
0
    def test_copy_center_requires_copy_info(self):
        """test that a center with copy type requires copy_of info"""
        copy_center = RegistrationCenterFactory.build(
            center_type=RegistrationCenter.Types.COPY)
        copy_center.copy_of = None

        with self.assertRaises(ValidationError) as cm:
            copy_center.clean()
        self.assertEqual(
            cm.exception.message,
            'Centre type "copy" requires copy centre information.')
Esempio n. 13
0
 def test_nonsplit_center_cannot_use_split_subcon(self):
     """test that a non-split center cannot be associated with the split-specific subcon"""
     split_center_subcon, unused = \
         SubConstituency.objects.get_or_create(id=SPLIT_CENTER_SUBCONSTITUENCY_ID)
     center = RegistrationCenterFactory.build(center_type=RegistrationCenter.Types.GENERAL,
                                              subconstituency=split_center_subcon)
     with self.assertRaises(ValidationError) as cm:
         center.clean()
     msg = "Only split centers may be associated with subconstituency {}."
     msg = msg.format(SPLIT_CENTER_SUBCONSTITUENCY_ID)
     self.assertEqual(cm.exception.message, msg)
Esempio n. 14
0
    def test_max_copies_per_center_limit(self):
        """test that register.models.N_MAX_COPY_CENTERS is respected"""
        original_center = RegistrationCenterFactory()
        create_batch(RegistrationCenterFactory, settings.N_MAX_COPY_CENTERS,
                     copy_of=original_center)

        copy_center = RegistrationCenterFactory.build(copy_of=original_center)
        with self.assertRaises(ValidationError) as cm:
            copy_center.clean()
        msg = 'Copy centre already has the maximum number of copies ({n_max}).'
        self.assertEqual(cm.exception.message, msg.format(n_max=settings.N_MAX_COPY_CENTERS))
Esempio n. 15
0
 def test_nonsplit_center_cannot_use_split_subcon(self):
     """test that a non-split center cannot be associated with the split-specific subcon"""
     split_center_subcon, unused = \
         SubConstituency.objects.get_or_create(id=SPLIT_CENTER_SUBCONSTITUENCY_ID)
     center = RegistrationCenterFactory.build(
         center_type=RegistrationCenter.Types.GENERAL,
         subconstituency=split_center_subcon)
     with self.assertRaises(ValidationError) as cm:
         center.clean()
     msg = "Only split centers may be associated with subconstituency {}."
     msg = msg.format(SPLIT_CENTER_SUBCONSTITUENCY_ID)
     self.assertEqual(cm.exception.message, msg)
Esempio n. 16
0
    def test_max_copies_per_center_limit(self):
        """test that register.models.N_MAX_COPY_CENTERS is respected"""
        original_center = RegistrationCenterFactory()
        create_batch(RegistrationCenterFactory,
                     settings.N_MAX_COPY_CENTERS,
                     copy_of=original_center)

        copy_center = RegistrationCenterFactory.build(copy_of=original_center)
        with self.assertRaises(ValidationError) as cm:
            copy_center.clean()
        msg = 'Copy centre already has the maximum number of copies ({n_max}).'
        self.assertEqual(cm.exception.message,
                         msg.format(n_max=settings.N_MAX_COPY_CENTERS))