def test_clean_valid_url_with_protocol(self): """ If a valid url is passed into clean, with a protocol, return it. """ with patch('oneanddone.base.widgets.requests') as requests: requests.get.return_value = Mock(ok=True) eq_(MyURLField().clean('https://www.mozilla.org'), 'https://www.mozilla.org')
class SignUpForm(forms.ModelForm): pp_checkbox = forms.BooleanField(label=_( "You are creating a profile that will include a public username" " and work history." " You will begin to receive email communications from Mozilla" " once you have completed tasks." " You may configure email preferences when editing your profile."), required=True, initial=True) username = forms.RegexField( label=_("Username:"******"This value may contain only alphanumeric characters.") }) personal_url = MyURLField(label=_('Personal URL:')) bugzilla_email = forms.EmailField(label=_('Bugzilla email address:'), required=False) class Meta: model = UserProfile fields = ('name', 'username', 'pp_checkbox', 'personal_url', 'bugzilla_email') def save(self, *args, **kwargs): # We will only reach the save() method if the pp_checkbox was checked self.instance.privacy_policy_accepted = True return super(SignUpForm, self).save(*args, **kwargs)
def test_clean_invalid_url(self): """ If an invalid url is passed into clean, raise a ValidationError. """ with self.assertRaises(ValidationError): with patch('oneanddone.base.widgets.requests') as requests: requests.get.return_value = Mock(ok=False) MyURLField().clean('www.mozilla.org.bad.url')
def test_clean_valid_url_no_protocol(self): """ If a valid url is passed into clean, but without a protocol, add http:// to the url and return it. """ with patch('oneanddone.base.widgets.requests') as requests: requests.get.return_value = Mock(ok=True) eq_(MyURLField().clean('www.mozilla.org'), 'http://www.mozilla.org')
class UserProfileForm(forms.ModelForm): username = forms.RegexField( label=_("Username:"******"This value may contain only alphanumeric characters.") }) consent_to_email = forms.BooleanField(required=False) personal_url = MyURLField(label=_('Personal URL:')) class Meta: model = UserProfile fields = ('name', 'username', 'consent_to_email', 'personal_url')
def test_clean_no_value(self): """ If an empty string is passed into clean, then return None. """ eq_(MyURLField().clean(''), None)