예제 #1
0
 def test_numbers_unique(self):
     number1 = get_random_phone_number()
     number2 = str(1 + long(number1))
     reg = RegistrationCenterFactory()
     StaffPhone.objects.create(phone_number=number1, registration_center=reg)
     StaffPhone.objects.create(phone_number=number2, registration_center=reg)
     obj = StaffPhone(phone_number=number2, registration_center=reg)
     with self.assertRaises(ValidationError):
         obj.clean()
예제 #2
0
 def test_numbers_unique(self):
     number1 = get_random_phone_number()
     number2 = str(1 + long(number1))
     reg = RegistrationCenterFactory()
     StaffPhone.objects.create(phone_number=number1,
                               registration_center=reg)
     StaffPhone.objects.create(phone_number=number2,
                               registration_center=reg)
     obj = StaffPhone(phone_number=number2, registration_center=reg)
     with self.assertRaises(ValidationError):
         obj.clean()
예제 #3
0
def ensure_staff_phone_exists(staff_phone_number,
                              center,
                              staff_phones,
                              creation_date=None):
    """ Given a staff phone number and center, ensure that a corresponding StaffPhone
    exists.  White-list about half of them, and maintain a list of StaffPhones that
    have been created.
    """
    staff_phone = StaffPhone(phone_number=staff_phone_number,
                             registration_center=center)
    try:
        staff_phone.full_clean()
    except ValidationError:
        return  # assume staff phone exists
    if creation_date:
        staff_phone.creation_date = creation_date
    staff_phone.save()

    staff_phones.append(staff_phone)

    # white-list half of them
    if random.choice((1, 2)) == 1:
        w = Whitelist(phone_number=staff_phone.phone_number)
        w.full_clean()
        w.save()
예제 #4
0
def ensure_staff_phone_exists(staff_phone_number, center, staff_phones, creation_date=None):
    """ Given a staff phone number and center, ensure that a corresponding StaffPhone
    exists.  White-list about half of them, and maintain a list of StaffPhones that
    have been created.
    """
    staff_phone = StaffPhone(phone_number=staff_phone_number, registration_center=center)
    try:
        staff_phone.full_clean()
    except ValidationError:
        return  # assume staff phone exists
    if creation_date:
        staff_phone.creation_date = creation_date
    staff_phone.save()

    staff_phones.append(staff_phone)

    # white-list half of them
    if random.choice((1, 2)) == 1:
        w = Whitelist(phone_number=staff_phone.phone_number)
        w.full_clean()
        w.save()