def test_keywords_form_field_clean_repeated_semicolons(tag_string, tag_list): kwf = KeywordsField() # Repeated a semicolon first, semicolon, remainder = tag_string.partition(';') modified = first + semicolon + semicolon + remainder # Add a trailing semicolon, not repeated modified += semicolon data = kwf.clean(modified) assert data == tag_list
def test_keywords_form_field_clean_none(): kwf = KeywordsField(required=False) data = kwf.clean(None) assert data == []
def test_keywords_form_field_clean_required(): kwf = KeywordsField() with pytest.raises(ValidationError): kwf.clean('')
def test_keywords_form_field_clean_unsorted(tag_list): unsorted_string = '; '.join(reversed(tag_list)) kwf = KeywordsField() data = kwf.clean(unsorted_string) assert data == tag_list
def test_keywords_form_field_clean_good_data(tag_string, tag_list): kwf = KeywordsField() data = kwf.clean(tag_string) assert data == tag_list
def test_keywords_form_field_uses_correct_widget(): kwf = KeywordsField() assert isinstance(kwf.widget, KeywordsWidget)
def test_keywords_form_field_clean_bad_chars(): kwf = KeywordsField() for c in KeywordsField._NOT_ALLOWED: with pytest.raises(ValidationError): kwf.clean(c)
def test_keywords_form_field_clean_empty_string(): kwf = KeywordsField(required=False) data = kwf.clean('') assert data == []