Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
django-taggit
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e04918d6
authored
Jun 03, 2010
by
Alex Gaynor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
A little bit of reformatting.
parent
e07091a4
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
55 deletions
+65
-55
docs/forms.txt
+9
-9
taggit/tests/tests.py
+55
-45
taggit/utils.py
+1
-1
No files found.
docs/forms.txt
View file @
e04918d6
...
@@ -22,14 +22,14 @@ as follows:
...
@@ -22,14 +22,14 @@ as follows:
Examples:
Examples:
====================== =================================
======
================================================
====================== ================================= ================================================
Tag input string Resulting tags Notes
Tag input string Resulting tags Notes
====================== =================================
======
================================================
====================== ================================= ================================================
apple ball cat
[``apple``], [``ball``], [``cat``]
No commas, so space delimited
apple ball cat
``["apple", "ball", "cat"]``
No commas, so space delimited
apple, ball cat
[``apple``], [``ball cat``]
Comma present, so comma delimited
apple, ball cat
``["apple", "ball cat"]``
Comma present, so comma delimited
"apple, ball" cat dog
[``apple, ball``], [``cat``], [``dog``]
All commas are quoted, so space delimited
"apple, ball" cat dog
``["apple, ball", "cat", "dog"]``
All commas are quoted, so space delimited
"apple, ball", cat dog
[``apple, ball``], [``cat dog``]
Contains an unquoted comma, so comma delimited
"apple, ball", cat dog
``["apple, ball", "cat dog"]``
Contains an unquoted comma, so comma delimited
apple "ball cat" dog
[``apple``], [``ball cat``], [``dog``]
No commas, so space delimited
apple "ball cat" dog
``["apple", "ball cat", "dog"]``
No commas, so space delimited
"apple" "ball dog
[``apple``], [``ball``], [``dog``]
Unclosed double quote is ignored
"apple" "ball dog
``["apple", "ball", "dog"]``
Unclosed double quote is ignored
====================== =================================
======
================================================
====================== ================================= ================================================
taggit/tests/tests.py
View file @
e04918d6
...
@@ -3,11 +3,11 @@ from unittest import TestCase as UnitTestCase
...
@@ -3,11 +3,11 @@ from unittest import TestCase as UnitTestCase
from
django.test
import
TestCase
,
TransactionTestCase
from
django.test
import
TestCase
,
TransactionTestCase
from
taggit.models
import
Tag
,
TaggedItem
from
taggit.models
import
Tag
,
TaggedItem
from
taggit.utils
import
parse_tags
,
edit_string_for_tags
from
taggit.tests.forms
import
FoodForm
,
DirectFoodForm
,
CustomPKFoodForm
from
taggit.tests.forms
import
FoodForm
,
DirectFoodForm
,
CustomPKFoodForm
from
taggit.tests.models
import
(
Food
,
Pet
,
HousePet
,
DirectFood
,
DirectPet
,
from
taggit.tests.models
import
(
Food
,
Pet
,
HousePet
,
DirectFood
,
DirectPet
,
DirectHousePet
,
TaggedPet
,
CustomPKFood
,
CustomPKPet
,
CustomPKHousePet
,
DirectHousePet
,
TaggedPet
,
CustomPKFood
,
CustomPKPet
,
CustomPKHousePet
,
TaggedCustomPKPet
)
TaggedCustomPKPet
)
from
taggit.utils
import
parse_tags
,
edit_string_for_tags
class
BaseTaggingTest
(
object
):
class
BaseTaggingTest
(
object
):
...
@@ -231,73 +231,83 @@ class TagStringParseTestCase(UnitTestCase):
...
@@ -231,73 +231,83 @@ class TagStringParseTestCase(UnitTestCase):
"""
"""
Ported from Jonathan Buchanan's `django-tagging
Ported from Jonathan Buchanan's `django-tagging
<http://django-tagging.googlecode.com/>`_
<http://django-tagging.googlecode.com/>`_
"""
"""
def
test_with_simple_space_delimited_tags
(
self
):
""" Test with simple space-delimited tags. """
self
.
assertEquals
(
parse_tags
(
'one'
),
[
u'one'
])
def
test_with_simple_space_delimited_tags
(
self
):
self
.
assertEquals
(
parse_tags
(
'one two'
),
[
u'one'
,
u'two'
])
"""
self
.
assertEquals
(
parse_tags
(
'one two three'
),
[
u'one'
,
u'three'
,
u'two'
])
Test with simple space-delimited tags.
self
.
assertEquals
(
parse_tags
(
'one one two two'
),
[
u'one'
,
u'two'
])
"""
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'
])
def
test_with_comma_delimited_multiple_words
(
self
):
def
test_with_comma_delimited_multiple_words
(
self
):
""" Test with comma-delimited multiple words.
"""
An unquoted comma in the input will trigger this. """
Test with comma-delimited multiple words.
An unquoted comma in the input will trigger this.
self
.
assertEquals
(
parse_tags
(
',one'
),
[
u'one'
])
"""
self
.
assertEquals
(
parse_tags
(
',one two'
),
[
u'one two'
])
self
.
assertEqual
(
parse_tags
(
',one'
),
[
u'one'
])
self
.
assertEquals
(
parse_tags
(
',one two three'
),
[
u'one two three'
])
self
.
assertEqual
(
parse_tags
(
',one two'
),
[
u'one two'
])
self
.
assertEquals
(
parse_tags
(
'a-one, a-two and a-three'
),
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'
])
[
u'a-one'
,
u'a-two and a-three'
])
def
test_with_double_quoted_multiple_words
(
self
):
def
test_with_double_quoted_multiple_words
(
self
):
""" Test with double-quoted multiple words.
"""
A completed quote will trigger this. Unclosed quotes are ignored. """
Test with double-quoted multiple words.
A completed quote will trigger this. Unclosed quotes are ignored.
self
.
assertEquals
(
parse_tags
(
'"one'
),
[
u'one'
])
"""
self
.
assertEquals
(
parse_tags
(
'"one two'
),
[
u'one'
,
u'two'
])
self
.
assertEqual
(
parse_tags
(
'"one'
),
[
u'one'
])
self
.
assertEquals
(
parse_tags
(
'"one two three'
),
[
u'one'
,
u'three'
,
u'two'
])
self
.
assertEqual
(
parse_tags
(
'"one two'
),
[
u'one'
,
u'two'
])
self
.
assertEquals
(
parse_tags
(
'"one two"'
),
[
u'one two'
])
self
.
assertEqual
(
parse_tags
(
'"one two three'
),
[
u'one'
,
u'three'
,
u'two'
])
self
.
assertEquals
(
parse_tags
(
'a-one "a-two and a-three"'
),
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'
])
[
u'a-one'
,
u'a-two and a-three'
])
def
test_with_no_loose_commas
(
self
):
def
test_with_no_loose_commas
(
self
):
""" Test with no loose commas -- split on spaces. """
"""
self
.
assertEquals
(
parse_tags
(
'one two "thr,ee"'
),
[
u'one'
,
u'thr,ee'
,
u'two'
])
Test with no loose commas -- split on spaces.
"""
self
.
assertEqual
(
parse_tags
(
'one two "thr,ee"'
),
[
u'one'
,
u'thr,ee'
,
u'two'
])
def
test_with_loose_commas
(
self
):
def
test_with_loose_commas
(
self
):
""" Loose commas - split on commas """
"""
self
.
assertEquals
(
parse_tags
(
'"one", two three'
),
[
u'one'
,
u'two three'
])
Loose commas - split on commas
"""
self
.
assertEqual
(
parse_tags
(
'"one", two three'
),
[
u'one'
,
u'two three'
])
def
test_tags_with_double_quotes_can_contain_commas
(
self
):
def
test_tags_with_double_quotes_can_contain_commas
(
self
):
""" Double quotes can contain commas """
"""
self
.
assertEquals
(
parse_tags
(
'a-one "a-two, and a-three"'
),
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'
])
[
u'a-one'
,
u'a-two, and a-three'
])
self
.
assertEqual
s
(
parse_tags
(
'"two", one, one, two, "one"'
),
self
.
assertEqual
(
parse_tags
(
'"two", one, one, two, "one"'
),
[
u'one'
,
u'two'
])
[
u'one'
,
u'two'
])
def
test_with_naughty_input
(
self
):
def
test_with_naughty_input
(
self
):
""" Test with naughty input. """
"""
Test with naughty input.
"""
# Bad users! Naughty users!
# Bad users! Naughty users!
self
.
assertEqual
s
(
parse_tags
(
None
),
[])
self
.
assertEqual
(
parse_tags
(
None
),
[])
self
.
assertEqual
s
(
parse_tags
(
''
),
[])
self
.
assertEqual
(
parse_tags
(
''
),
[])
self
.
assertEqual
s
(
parse_tags
(
'"'
),
[])
self
.
assertEqual
(
parse_tags
(
'"'
),
[])
self
.
assertEqual
s
(
parse_tags
(
'""'
),
[])
self
.
assertEqual
(
parse_tags
(
'""'
),
[])
self
.
assertEqual
s
(
parse_tags
(
'"'
*
7
),
[])
self
.
assertEqual
(
parse_tags
(
'"'
*
7
),
[])
self
.
assertEqual
s
(
parse_tags
(
',,,,,,'
),
[])
self
.
assertEqual
(
parse_tags
(
',,,,,,'
),
[])
self
.
assertEqual
s
(
parse_tags
(
'",",",",",",","'
),
[
u','
])
self
.
assertEqual
(
parse_tags
(
'",",",",",",","'
),
[
u','
])
self
.
assertEqual
s
(
parse_tags
(
'a-one "a-two" and "a-three'
),
self
.
assertEqual
(
parse_tags
(
'a-one "a-two" and "a-three'
),
[
u'a-one'
,
u'a-three'
,
u'a-two'
,
u'and'
])
[
u'a-one'
,
u'a-three'
,
u'a-two'
,
u'and'
])
def
test_recreation_of_tag_list_string_representations
(
self
):
def
test_recreation_of_tag_list_string_representations
(
self
):
plain
=
Tag
.
objects
.
create
(
name
=
'plain'
)
plain
=
Tag
.
objects
.
create
(
name
=
'plain'
)
spaces
=
Tag
.
objects
.
create
(
name
=
'spa ces'
)
spaces
=
Tag
.
objects
.
create
(
name
=
'spa ces'
)
comma
=
Tag
.
objects
.
create
(
name
=
'com,ma'
)
comma
=
Tag
.
objects
.
create
(
name
=
'com,ma'
)
self
.
assertEqual
s
(
edit_string_for_tags
([
plain
]),
u'plain'
)
self
.
assertEqual
(
edit_string_for_tags
([
plain
]),
u'plain'
)
self
.
assertEqual
s
(
edit_string_for_tags
([
plain
,
spaces
]),
u'plain, spa ces'
)
self
.
assertEqual
(
edit_string_for_tags
([
plain
,
spaces
]),
u'plain, spa ces'
)
self
.
assertEqual
s
(
edit_string_for_tags
([
plain
,
spaces
,
comma
]),
u'plain, spa ces, "com,ma"'
)
self
.
assertEqual
(
edit_string_for_tags
([
plain
,
spaces
,
comma
]),
u'plain, spa ces, "com,ma"'
)
self
.
assertEqual
s
(
edit_string_for_tags
([
plain
,
comma
]),
u'plain "com,ma"'
)
self
.
assertEqual
(
edit_string_for_tags
([
plain
,
comma
]),
u'plain "com,ma"'
)
self
.
assertEqual
s
(
edit_string_for_tags
([
comma
,
spaces
]),
u'"com,ma", spa ces'
)
self
.
assertEqual
(
edit_string_for_tags
([
comma
,
spaces
]),
u'"com,ma", spa ces'
)
taggit/utils.py
View file @
e04918d6
...
@@ -35,7 +35,7 @@ def parse_tags(tagstring):
...
@@ -35,7 +35,7 @@ def parse_tags(tagstring):
open_quote
=
False
open_quote
=
False
i
=
iter
(
tagstring
)
i
=
iter
(
tagstring
)
try
:
try
:
while
1
:
while
True
:
c
=
i
.
next
()
c
=
i
.
next
()
if
c
==
u'"'
:
if
c
==
u'"'
:
if
buffer
:
if
buffer
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment