def test_invalid_cert_list_rejected(self): """ Cert list rejected if not a spaceless comma delimited list of integers """ self.form_kwargs.update({'cert_list': 'US1,US2'}) form = CertificateRegisterForm(self.form_kwargs) self.assertFalse(form.is_valid())
def test_dupe_certificate_invalid(self): """ Validation fails when requested certificates already exist """ mommy.make(Certificate, number=1) form = CertificateRegisterForm(self.form_kwargs) self.assertFalse(form.is_valid())
def test_dupe_requested_certificate_invalid(self): """ Validation fails when requested certificates contain duplicates """ self.form_kwargs.update({'cert_list': '1,1'}) form = CertificateRegisterForm(self.form_kwargs) self.assertFalse(form.is_valid())
def test_validation_fails_if_licensee_inactive(self): """Fail validation if licensee not active""" self.licensee.is_active = False self.licensee.save() form = CertificateRegisterForm(self.form_kwargs) valid = form.is_valid() self.assertFalse(valid)
def test_id_ranges_must_be_valid(self): """cert_from is less than or equal to cert_to""" self._make_sequential(25, 10) form = CertificateRegisterForm(self.form_kwargs) valid = form.is_valid() self.assertIn("Certificate 'To' value must be greater than or equal to 'From' value.", [e.message for e in form.non_field_errors().data]) self.assertFalse(valid)
def test_id_list_required_if_method_is_list(self): """Reject w/ message if cert_list isn't populated but List method is selected""" self.form_kwargs.pop('cert_list') form = CertificateRegisterForm(self.form_kwargs) valid = form.is_valid() self.assertIn("Certificate List must be provided when List method is selected.", [e.message for e in form.non_field_errors().data]) self.assertFalse(valid)
def test_validation_fails_if_licensee_and_contact_dont_match(self): """Fail validation and provide msg if provided user is not associated with licensee""" self.user.profile.licensees.remove(self.licensee.id) form = CertificateRegisterForm(self.form_kwargs) valid = form.is_valid() self.assertIn('Contact is not associated with selected Licensee', [e.message for e in form.non_field_errors().data]) self.assertFalse(valid)
def test_id_range_required_if_method_is_sequential(self): """ Reject w/ message if cert_to & cert_from are not populated but sequential method is selected """ self.form_kwargs.pop('cert_list') self.form_kwargs['registration_method'] = 'sequential' form = CertificateRegisterForm(self.form_kwargs) valid = form.is_valid() self.assertIn("Certificate To and From must be provided when Sequential method is selected.", [e.message for e in form.non_field_errors().data]) self.assertFalse(valid)
def test_parse_list(self): """List of integers returned from incoming string""" form = CertificateRegisterForm(self.form_kwargs) form.is_valid() self.assertEqual(form.get_cert_list(), [1])
def test_parse_sequential(self): """List of sequential integers generated from provided start/end points""" self._make_sequential(1, 3) form = CertificateRegisterForm(self.form_kwargs) form.is_valid() self.assertEqual(form.get_cert_list(), [1, 2, 3])
def test_valid_form_no_errors_sequential(self): """Form validates w/ sequential data""" form = CertificateRegisterForm(self.form_kwargs) self._make_sequential(1, 2) valid = form.is_valid() self.assertTrue(valid)
def test_valid_form_no_errors_list(self): """Form validates w/ list data""" form = CertificateRegisterForm(self.form_kwargs) valid = form.is_valid() self.assertTrue(valid)
def test_valid_form_no_errors_sequential(self): """Form validates w/ sequential data""" self.form_kwargs['payment_amount'] = 40 form = CertificateRegisterForm(self.form_kwargs) self._make_sequential(1, 2) self.assertTrue(form.is_valid())
def test_payment_not_expected_amount(self): """Payment must be # of certs * Certificate.PRICE""" self.form_kwargs['payment_amount'] = 1 form = CertificateRegisterForm(self.form_kwargs) self.assertFalse(form.is_valid())