Exemple #1
0
 def test_tags_with_double_quotes_can_contain_commas(self):
     """
     Double quotes can contain commas
     """
     self.assertEqual(parse_tags('a-one "a-two, and a-three"'),
                      [u'a-one', u'a-two, and a-three'])
     self.assertEqual(parse_tags('"two", one, one, two, "one"'),
                      [u'one', u'two'])
Exemple #2
0
 def test_tags_with_double_quotes_can_contain_commas(self):
     """
     Double quotes can contain commas
     """
     self.assertEqual(parse_tags('a-one "a-two, and a-three"'),
                      [u'a-one', u'a-two, and a-three'])
     self.assertEqual(parse_tags('"two", one, one, two, "one"'),
                      [u'one', u'two'])
Exemple #3
0
 def test_with_simple_space_delimited_tags(self):
     """
     Test with simple space-delimited tags.
     """
     self.assertEqual(parse_tags('one'), [u'one'])
     self.assertEqual(parse_tags('one two'), [u'one', u'two'])
     self.assertEqual(parse_tags('one two three'),
                      [u'one', u'three', u'two'])
     self.assertEqual(parse_tags('one one two two'), [u'one', u'two'])
Exemple #4
0
 def test_with_simple_space_delimited_tags(self):
     """
     Test with simple space-delimited tags.
     """
     self.assertEqual(parse_tags('one'), [u'one'])
     self.assertEqual(parse_tags('one two'), [u'one', u'two'])
     self.assertEqual(
         parse_tags('one two three'), [u'one', u'three', u'two'])
     self.assertEqual(parse_tags('one one two two'), [u'one', u'two'])
Exemple #5
0
 def test_with_comma_delimited_multiple_words(self):
     """
     Test with comma-delimited multiple words.
     An unquoted comma in the input will trigger this.
     """
     self.assertEqual(parse_tags(',one'), [u'one'])
     self.assertEqual(parse_tags(',one two'), [u'one two'])
     self.assertEqual(parse_tags(',one two three'), [u'one two three'])
     self.assertEqual(parse_tags('a-one, a-two and a-three'),
                      [u'a-one', u'a-two and a-three'])
Exemple #6
0
 def test_with_comma_delimited_multiple_words(self):
     """
     Test with comma-delimited multiple words.
     An unquoted comma in the input will trigger this.
     """
     self.assertEqual(parse_tags(',one'), [u'one'])
     self.assertEqual(parse_tags(',one two'), [u'one two'])
     self.assertEqual(parse_tags(',one two three'), [u'one two three'])
     self.assertEqual(parse_tags('a-one, a-two and a-three'),
                      [u'a-one', u'a-two and a-three'])
Exemple #7
0
 def test_with_double_quoted_multiple_words(self):
     """
     Test with double-quoted multiple words.
     A completed quote will trigger this.  Unclosed quotes are ignored.
     """
     self.assertEqual(parse_tags('"one'), [u'one'])
     self.assertEqual(parse_tags('"one two'), [u'one', u'two'])
     self.assertEqual(parse_tags('"one two three'),
                      [u'one', u'three', u'two'])
     self.assertEqual(parse_tags('"one two"'), [u'one two'])
     self.assertEqual(parse_tags('a-one "a-two and a-three"'),
                      [u'a-one', u'a-two and a-three'])
Exemple #8
0
 def test_with_double_quoted_multiple_words(self):
     """
     Test with double-quoted multiple words.
     A completed quote will trigger this.  Unclosed quotes are ignored.
     """
     self.assertEqual(parse_tags('"one'), [u'one'])
     self.assertEqual(parse_tags('"one two'), [u'one', u'two'])
     self.assertEqual(
         parse_tags('"one two three'), [u'one', u'three', u'two'])
     self.assertEqual(parse_tags('"one two"'), [u'one two'])
     self.assertEqual(parse_tags('a-one "a-two and a-three"'),
                      [u'a-one', u'a-two and a-three'])
Exemple #9
0
 def clean(self, value):
     value = super(TagField, self).clean(value)
     try:
         return parse_tags(value)
     except ValueError:
         raise forms.ValidationError(
             _("Please provide a comma-separated list of tags."))
Exemple #10
0
 def clean(self, value):
     value = super(TagField, self).clean(value)
     try:
         return parse_tags(value)
     except ValueError:
         raise forms.ValidationError(
             _("Please provide a comma-separated list of tags."))
Exemple #11
0
 def test_with_naughty_input(self):
     """
     Test with naughty input.
     """
     # Bad users! Naughty users!
     self.assertEqual(parse_tags(None), [])
     self.assertEqual(parse_tags(''), [])
     self.assertEqual(parse_tags('"'), [])
     self.assertEqual(parse_tags('""'), [])
     self.assertEqual(parse_tags('"' * 7), [])
     self.assertEqual(parse_tags(',,,,,,'), [])
     self.assertEqual(parse_tags('",",",",",",","'), [u','])
     self.assertEqual(parse_tags('a-one "a-two" and "a-three'),
                      [u'a-one', u'a-three', u'a-two', u'and'])
Exemple #12
0
 def test_with_naughty_input(self):
     """
     Test with naughty input.
     """
     # Bad users! Naughty users!
     self.assertEqual(parse_tags(None), [])
     self.assertEqual(parse_tags(''), [])
     self.assertEqual(parse_tags('"'), [])
     self.assertEqual(parse_tags('""'), [])
     self.assertEqual(parse_tags('"' * 7), [])
     self.assertEqual(parse_tags(',,,,,,'), [])
     self.assertEqual(parse_tags('",",",",",",","'), [u','])
     self.assertEqual(parse_tags('a-one "a-two" and "a-three'),
                      [u'a-one', u'a-three', u'a-two', u'and'])
Exemple #13
0
 def test_with_loose_commas(self):
     """
     Loose commas - split on commas
     """
     self.assertEqual(parse_tags('"one", two three'),
                      [u'one', u'two three'])
Exemple #14
0
 def test_with_no_loose_commas(self):
     """
     Test with no loose commas -- split on spaces.
     """
     self.assertEqual(parse_tags('one two "thr,ee"'),
                      [u'one', u'thr,ee', u'two'])
Exemple #15
0
 def test_with_loose_commas(self):
     """
     Loose commas - split on commas
     """
     self.assertEqual(
         parse_tags('"one", two three'), [u'one', u'two three'])
Exemple #16
0
 def test_with_no_loose_commas(self):
     """
     Test with no loose commas -- split on spaces.
     """
     self.assertEqual(
         parse_tags('one two "thr,ee"'), [u'one', u'thr,ee', u'two'])