def test_citizen_has_multiple_unconfirmed_registrations(self):
     # national id has multiple unconfirmed registration associated with it
     RegistrationFactory(citizen=self.citizen)  # unconfirmed registration
     RegistrationFactory(citizen=self.citizen)  # unconfirmed registration
     self.receive(self.good_nid, self.conn, fields=self.fields)
     self.assertEqual(self.get_last_response_code(),
                      constants.VOTER_QUERY_NOT_REGISTERED)
示例#2
0
 def test_phone_has_maximum_registrations(self):
     phone_number = '12345'
     reg = RegistrationFactory(sms__from_number=phone_number,
                               archive_time=None)
     self.assertFalse(reg.phone_has_maximum_registrations)
     RegistrationFactory(sms__from_number=phone_number, archive_time=None)
     self.assertTrue(reg.phone_has_maximum_registrations)
示例#3
0
 def test_citizen_has_mutiple_unconfirmed_registration(self):
     # A citizen with multiple unconfirmed registration is treated the same as
     # one with 1 unconfirmed registrations
     RegistrationFactory(citizen=self.citizen)
     RegistrationFactory(citizen=self.citizen)
     result = process_registration_lookup(self.good_nid, self.sms)
     self.assertEqual(result.message_code,
                      constants.VOTER_QUERY_NOT_REGISTERED)
示例#4
0
 def test_unique_registration(self):
     # Undeleted, confirmed registrations must be unique on citizen
     citizen = CitizenFactory()
     RegistrationFactory(citizen=citizen, deleted=False, archive_time=None)
     RegistrationFactory(citizen=citizen, deleted=True)
     RegistrationFactory(citizen=citizen, archive_time=now())
     with self.assertRaises(IntegrityError):
         RegistrationFactory(citizen=citizen,
                             deleted=False,
                             archive_time=None)
示例#5
0
 def test_citizen_is_registered(self):
     # Citizen correctly registered will be informed about the Election Center
     # where they are currently registered to vote.
     RegistrationFactory(citizen=self.citizen, archive_time=None)
     result = process_registration_lookup(self.good_nid, self.sms)
     self.assertEqual(result.message_code,
                      constants.VOTER_QUERY_REGISTERED_AT)
示例#6
0
 def test_citizen_has_no_confirmed_registrations(self):
     # A citizen with unconfirmed registration(s) should be informed that he
     # is not registered (VOTER_QUERY_NOT_REGISTERED)
     RegistrationFactory(citizen=self.citizen, archive_time=now())
     result = process_registration_lookup(self.good_nid, self.sms)
     self.assertEqual(result.message_code,
                      constants.VOTER_QUERY_NOT_REGISTERED)
示例#7
0
 def test_can_reregister_after_reg_capability_removed(self):
     registration = RegistrationFactory(archive_time=None)
     RegistrationFactory(archive_time=None, deleted=True)
     # Inactivate the center
     registration.registration_center.reg_open = False
     registration.registration_center.save()
     # Process a new registration
     result = process_registration_request(
         center_id=self.center.center_id,
         national_id=registration.citizen.national_id,
         sms=registration.sms)
     # We returned the 'successful center change' message
     self.assertEqual(result.message_code, constants.MESSAGE_1)
     # Only 1 registration present
     regs = models.Registration.objects.filter(citizen=registration.citizen)
     self.assertEqual(len(regs), 1)
示例#8
0
 def test_removing_reg_capability_doesnt_affect_registrations(self):
     registration = RegistrationFactory(archive_time=None)
     # Disallow registrations
     registration.registration_center.reg_open = False
     registration.registration_center.save()
     # Registration is still there
     regs = models.Registration.objects.filter(
         registration_center=registration.registration_center)
     self.assertEqual(len(regs), 1)
示例#9
0
    def test_copy_center_not_mistaken_for_no_registration_center(self):
        """ensure that a center that's a copy of a center with registrants is recognized as such"""
        RegistrationFactory(registration_center=self.center, archive_time=None)

        center_id = self.copy_center.center_id
        self.input_arguments['center_ids'] = [center_id]

        call_command(self.command_name, self.phase, center_ids=str(center_id),
                     output_root=self.output_path)
示例#10
0
    def test_no_office_center_can_be_forgiven(self):
        """ensure that a center that has no office is accepted when --forgive-no-office is True"""
        # Give it a registration so it doesn't raise an error.
        RegistrationFactory(registration_center=self.no_office_center, archive_time=None)
        center_id = self.no_office_center.center_id
        self.input_arguments['center_ids'] = [center_id]
        self.input_arguments['forgive_no_office'] = True

        call_command(self.command_name, self.phase, center_ids=str(center_id),
                     forgive_no_office=True, output_root=self.output_path)
示例#11
0
 def test_register_after_unconfirmed_registrations(self):
     # We might have unconfirmed registrations due to previous changes.
     # Create 2 registrations for this Citizen
     RegistrationFactory(citizen=self.citizen, archive_time=now())
     RegistrationFactory(citizen=self.citizen,
                         archive_time=now(),
                         deleted=True)
     RegistrationFactory(citizen=self.citizen,
                         archive_time=None,
                         deleted=True)
     RegistrationFactory(citizen=self.citizen, archive_time=None)
     # Process another registration update
     process_registration_request(sms=SMSFactory(),
                                  national_id=self.citizen.national_id,
                                  center_id=self.center.center_id)
     # There should be only one confirmed registration
     registrations = models.Registration.objects.filter(
         citizen=self.citizen)
     self.assertEqual(1, registrations.count())
示例#12
0
 def test_phone_reaches_only_one_more(self):
     number = '12345678'
     RegistrationFactory(sms__from_number=number, archive_time=None)
     new_sms = SMSFactory(from_number=number)
     result = process_registration_request(
         sms=new_sms,
         national_id=self.citizen.national_id,
         center_id=self.center.center_id)
     self.assertEqual(result.message_code,
                      constants.ONE_MORE_REGISTRATION_ON_PHONE)
     models.Registration.objects.get(citizen=self.citizen)
示例#13
0
 def test_phone_has_max_registrations(self):
     number = '12345678'
     RegistrationFactory(sms__from_number=number, archive_time=None)
     new_sms = SMSFactory(from_number=number)
     result = process_registration_request(
         sms=new_sms,
         national_id=self.citizen.national_id,
         center_id=self.center.center_id)
     self.assertEqual(result.message_code,
                      constants.TOO_MANY_REGISTRATIONS_ON_PHONE)
     with self.assertRaises(models.Registration.DoesNotExist):
         models.Registration.objects.get(citizen=self.citizen)
示例#14
0
 def test_registration_unlocked(self):
     reg = RegistrationFactory()
     case = Case()
     self.assertFalse(case.registration_unlocked())
     case.registration = reg
     self.assertFalse(case.registration_unlocked())
     reg.unlocked_until = now() + datetime.timedelta(hours=1)
     self.assertTrue(case.registration_unlocked())
     case.relock_registration()
     self.assertFalse(case.registration_unlocked())
     case.registration = None
     self.assertFalse(case.registration_unlocked())
示例#15
0
 def test_registration_archived(self):
     citizen = CitizenFactory(fbr_number=1234)
     registration = RegistrationFactory(citizen=citizen, archive_time=now())
     data = {
         'national_id': str(citizen.national_id),
         'fbr_number': citizen.fbr_number
     }
     data.update(self.captcha)
     rsp = self.client.post(self.url, data=data)
     self.assertEqual(200, rsp.status_code)
     content = rsp.content.decode('utf-8')
     self.assertIn("is not registered", content)
     self.assertNotIn("is registered at", content)
     self.assertNotIn(registration.registration_center.name, content)
示例#16
0
    def post(instance, create, extracted, **kwargs):
        instance.first_name = random.choice(person_names)
        instance.father_name = random.choice(person_names)
        instance.grandfather_name = random.choice(person_names)
        instance.family_name = random.choice(person_names)
        instance.mother_name = random.choice(person_names)

        if kwargs['center']:
            # Register this voter to this center
            reg_kwargs = dict(citizen=instance,
                              registration_center=kwargs['center'],
                              archive_time=None)
            if 'sms' in kwargs and kwargs['sms']:
                reg_kwargs['sms'] = kwargs['sms']
            RegistrationFactory(**reg_kwargs)
示例#17
0
 def test_fbr_number_mismatch(self):
     citizen = CitizenFactory(fbr_number=1234)
     RegistrationFactory(citizen=citizen, archive_time=None)
     data = {
         'national_id': str(citizen.national_id),
         'fbr_number': '2345678'
     }
     data.update(self.captcha)
     rsp = self.client.post(self.url, data=data)
     self.assertEqual(200, rsp.status_code)
     context = rsp.context
     self.assertIn('form', context)
     form = context['form']
     self.assertTrue(form.errors)
     content = rsp.content.decode('utf-8')
     self.assertIn(get_message(constants.FBRN_MISMATCH).msg, content)
示例#18
0
 def test_citizen_registered(self):
     # citizen has been registered
     RegistrationFactory(citizen=self.citizen,
                         registration_center=self.center,
                         archive_time=None)
     # let's query for the registration
     msg = u"{nid}".format(nid=self.good_nid)
     self.receive(msg, self.conn, fields=self.fields)
     self.assertEqual(self.get_last_response_code(),
                      constants.VOTER_QUERY_REGISTERED_AT)
     context = {
         "person": unicode(self.citizen),
         "centre": self.center.name,
         "code": self.center.center_id
     }
     expected = self.translate(constants.VOTER_QUERY_REGISTERED_AT,
                               context)  # Arabic
     self.assertEqual(self.get_last_response_message(), expected)
示例#19
0
 def test_attempt_update_wrong_from_number_same_center(
         self, registration_open):
     # create a valid registration
     sms = SMSFactory(from_number=self.number, citizen=self.citizen)
     RegistrationFactory(citizen=self.citizen,
                         registration_center=self.center,
                         archive_time=None,
                         sms=sms)
     # try to register at same center with a new number
     new_number = '919-888-8888'
     msg = "{nid}#{center}".format(nid=self.good_nid,
                                   center=self.center.center_id)
     new_conn = self.create_connection(data={'identity': new_number})
     self.receive(msg, new_conn, fields=self.fields)
     # message should have the existing number in it (not new_number)
     context = {'centre': self.center.name, 'number': self.number[-4:]}
     expected = self.translate(constants.MESSAGE_2,
                               context=context)  # arabic
     self.assertEqual(self.get_last_response_message(), expected)
 def test_citizen_is_registered(self):
     # national id belongs to a citizen in our db and has one confirmed registration
     RegistrationFactory(citizen=self.citizen, archive_time=None)
     self.receive(self.good_nid, self.conn, fields=self.fields)
     self.assertEqual(self.get_last_response_code(),
                      constants.VOTER_QUERY_REGISTERED_AT)
示例#21
0
 def setUp(self):
     # Start with a confirmed registration
     self.reg = RegistrationFactory(archive_time=None)
示例#22
0
 def test_block_citizen(self):
     citizen = CitizenFactory()
     RegistrationFactory(citizen=citizen, archive_time=None)
     self.assertIsNotNone(citizen.registration)
     citizen.block()
     self.assertIsNone(citizen.registration)