def test_correct_url_with_redirect(self): mtv = ModelToValidate( number=10, name='Some Name', url_verify='http://qa-dev.w3.org/link-testsuite/http.php?code=301' ) #example.com is a redirect to iana.org now self.assertEqual(None, mtv.full_clean() ) # This will fail if there's no Internet connection
def test_correct_https_url_but_nonexisting(self): mtv = ModelToValidate(number=10, name='Some Name', url_verify='https://www.example.com/') self.assertFieldFailsValidationWithMessage( mtv.full_clean, 'url_verify', [u'This URL appears to be a broken link.'])
def test_correct_ftps_url_but_nonexisting(self): mtv = ModelToValidate( number=10, name='Some Name', url='ftps://ftp.google.com/we-love-microsoft.html') self.assertFieldFailsValidationWithMessage( mtv.full_clean, 'url', [u'This URL appears to be a broken link.'])
def test_correct_url_but_nonexisting_gives_404(self): mtv = ModelToValidate( number=10, name='Some Name', url_verify='http://qa-dev.w3.org/link-testsuite/http.php?code=404') self.assertFieldFailsValidationWithMessage( mtv.full_clean, 'url_verify', [u'This URL appears to be a broken link.'])
def test_correct_url_value_passes(self): mtv = ModelToValidate(number=10, name='Some Name', url='http://www.example.com/') self.assertEqual(None, mtv.full_clean() ) # This will fail if there's no Internet connection
def test_wrong_url_value_raises_error(self): mtv = ModelToValidate(number=10, name='Some Name', url='not a url') self.assertFieldFailsValidationWithMessage(mtv.full_clean, 'url', [u'Enter a valid value.'])
def test_correct_email_value_passes(self): mtv = ModelToValidate(number=10, name='Some Name', email='*****@*****.**') self.assertEqual(None, mtv.full_clean())
def test_wrong_email_value_raises_error(self): mtv = ModelToValidate(number=10, name='Some Name', email='not-an-email') self.assertFailsValidation(mtv.full_clean, ['email'])
def test_correct_email_value_passes(self): mtv = ModelToValidate(number=10, name="Some Name", email="*****@*****.**") self.assertEqual(None, mtv.full_clean())
def test_with_correct_value_model_validates(self): mtv = ModelToValidate(number=10, name="Some Name") self.assertEqual(None, mtv.full_clean())
def test_custom_validate_method(self): mtv = ModelToValidate(number=11) self.assertFailsValidation(mtv.full_clean, [NON_FIELD_ERRORS, 'name'])
def test_with_correct_value_model_validates(self): mtv = ModelToValidate(number=10, name='Some Name') self.assertEqual(None, mtv.full_clean())
def test_missing_required_field_raises_error(self): mtv = ModelToValidate(f_with_custom_validator=42) self.assertFailsValidation(mtv.full_clean, ['name', 'number'])
def test_correct_url_value_passes(self): mtv = ModelToValidate(number=10, name='Some Name', url='http://www.example.com/') self.assertEqual(None, mtv.full_clean()) # This will fail if there's no Internet connection
def test_correct_url_with_redirect(self): mtv = ModelToValidate(number=10, name='Some Name', url_verify='http://qa-dev.w3.org/link-testsuite/http.php?code=301') #example.com is a redirect to iana.org now self.assertEqual(None, mtv.full_clean()) # This will fail if there's no Internet connection
def test_text_greater_that_charfields_max_length_raises_erros(self): mtv = ModelToValidate(number=10, name='Some Name' * 100) self.assertFailsValidation(mtv.full_clean, [ 'name', ])
def test_wrong_FK_value_raises_error(self): mtv = ModelToValidate(number=10, name='Some Name', parent_id=3) self.assertFailsValidation(mtv.full_clean, ['parent'])
def test_correct_FK_value_validates(self): parent = ModelToValidate.objects.create(number=10, name="Some Name") mtv = ModelToValidate(number=10, name="Some Name", parent_id=parent.pk) self.assertEqual(None, mtv.full_clean())
def test_correct_FK_value_validates(self): parent = ModelToValidate.objects.create(number=10, name='Some Name') mtv = ModelToValidate(number=10, name='Some Name', parent_id=parent.pk) self.assertEqual(None, mtv.full_clean())
def test_correct_url_value_passes(self): mtv = ModelToValidate(number=10, name="Some Name", url="http://www.djangoproject.com/") self.assertEqual(None, mtv.full_clean()) # This will fail if there's no Internet connection
def test_limited_FK_raises_error(self): # The limit_choices_to on the parent field says that a parent object's # number attribute must be 10, so this should fail validation. parent = ModelToValidate.objects.create(number=11, name='Other Name') mtv = ModelToValidate(number=10, name='Some Name', parent_id=parent.pk) self.assertFailsValidation(mtv.full_clean, ['parent'])