def test_valid_titles(self): """validate_title is ok with valid titles""" VALID_TITLES = ( 'Lorem ipsum dolor met', '123 456 789 112' 'Ugabugagagagagaga', ) for title in VALID_TITLES: validate_title(title)
def clean(self): data = super(MergeThreadsForm, self).clean() merged_thread_title = data.get('merged_thread_title') if merged_thread_title: validate_title(merged_thread_title) else: message = _("You have to enter merged thread title.") raise forms.ValidationError(message) return data
def test_valid_titles(self): """validate_title is ok with valid titles""" VALID_TITLES = [ 'Lorem ipsum dolor met', '123 456 789 112' 'Ugabugagagagagaga', ] for title in VALID_TITLES: validate_title(title)
def patch_title(request, thread, value): try: value_cleaned = six.text_type(value).strip() except (TypeError, ValueError): raise ValidationError(_("Invalid thread title.")) validate_title(value_cleaned) allow_edit_thread(request.user, thread) moderation.change_thread_title(request, thread, value_cleaned) return {'title': thread.title}
def patch_title(request, thread, value): try: value_cleaned = six.text_type(value).strip() except (TypeError, ValueError): raise PermissionDenied(_("Invalid thread title.")) try: validate_title(value_cleaned) except ValidationError as e: raise PermissionDenied(e.args[0]) allow_edit_thread(request.user, thread) moderation.change_thread_title(request, thread, value_cleaned) return {'title': thread.title}
def patch_title(request, thread, value): try: value_cleaned = str(value).strip() except (TypeError, ValueError): raise PermissionDenied(_('Not a valid string.')) try: validate_title(value_cleaned) except ValidationError as e: raise PermissionDenied(e.args[0]) allow_edit_thread(request.user, thread) moderation.change_thread_title(request, thread, value_cleaned) return {'title': thread.title}
def validate_data(self, data): errors = [] if not data.get('title') and not data.get('post'): raise forms.ValidationError(_("Enter thread title and message.")) try: validate_title(data.get('title', '')) except forms.ValidationError as e: errors.append(e) try: self.validate_post(data.get('post', '')) except forms.ValidationError as e: errors.append(e) if errors: raise forms.ValidationError(errors)
def clean(self): data = super(SplitThreadForm, self).clean() forum = data.get('forum') if forum: if forum.is_category: message = _("You can't start threads in category.") raise forms.ValidationError(message) if forum.is_redirect: message = _("You can't start threads in redirect.") raise forms.ValidationError(message) else: raise forms.ValidationError(_("You have to select forum.")) thread_title = data.get('thread_title') if thread_title: validate_title(thread_title) else: message = _("You have to enter new thread title.") raise forms.ValidationError(message) return data
def test_too_short_title(self): """too short title is unblocked""" with self.assertRaises(ValidationError): title = 'a' * settings.thread_title_length_min validate_title(title[1:])
def validate_title(self, title): return validate_title(title)
def test_unsluggable_title(self): """unsluggable title is blocked""" with self.assertRaises(ValidationError): title = '--' * settings.thread_title_length_min validate_title(title)
def test_too_long_title(self): """too long title is unblocked""" with self.assertRaises(ValidationError): title = 'a' * settings.thread_title_length_max validate_title(title * 2)
def test_unsluggable_title(self): """unsluggable title is rejected""" with self.assertRaises(ValidationError): title = '--' * settings.thread_title_length_min validate_title(title)
def test_too_long_title(self): """too long title is rejected""" with self.assertRaises(ValidationError): title = 'a' * settings.thread_title_length_max validate_title(title * 2)
def test_too_short_title(self): """too short title is rejected""" with self.assertRaises(ValidationError): title = 'a' * settings.thread_title_length_min validate_title(title[1:])
def test_empty_title(self): """empty title is rejected""" with self.assertRaises(ValidationError): validate_title("")