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
f2b899f6
authored
Dec 16, 2010
by
Alex Gaynor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update the tests for trunk.
parent
8b991346
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
4 deletions
+25
-4
taggit/tests/tests.py
+25
-4
No files found.
taggit/tests/tests.py
View file @
f2b899f6
from
unittest
import
TestCase
as
UnitTestCase
import
django
from
django.conf
import
settings
from
django.core.exceptions
import
ValidationError
from
django.db
import
connection
...
...
@@ -37,6 +38,22 @@ class BaseTaggingTest(object):
finally
:
settings
.
DEBUG
=
original_DEBUG
def
_get_form_str
(
self
,
form_str
):
if
django
.
VERSION
>=
(
1
,
3
):
form_str
%=
{
"help_start"
:
'<span class="helptext">'
,
"help_stop"
:
"</span>"
}
else
:
form_str
%=
{
"help_start"
:
""
,
"help_stop"
:
""
}
return
form_str
def
assert_form_renders
(
self
,
form
,
html
):
self
.
assertEqual
(
str
(
form
),
self
.
_get_form_str
(
html
))
class
BaseTaggingTestCase
(
TestCase
,
BaseTaggingTest
):
pass
...
...
@@ -318,7 +335,8 @@ class TaggableFormTestCase(BaseTaggingTestCase):
self
.
assertEqual
(
self
.
form_class
.
base_fields
.
keys
(),
[
'name'
,
'tags'
])
f
=
self
.
form_class
({
'name'
:
'apple'
,
'tags'
:
'green, red, yummy'
})
self
.
assertEqual
(
str
(
f
),
"""<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" value="apple" maxlength="50" /></td></tr>
\n
<tr><th><label for="id_tags">Tags:</label></th><td><input type="text" name="tags" value="green, red, yummy" id="id_tags" /><br />A comma-separated list of tags.</td></tr>"""
)
self
.
assert_form_renders
(
f
,
"""<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" value="apple" maxlength="50" /></td></tr>
<tr><th><label for="id_tags">Tags:</label></th><td><input type="text" name="tags" value="green, red, yummy" id="id_tags" /><br />
%(help_start)
sA comma-separated list of tags.
%(help_stop)
s</td></tr>"""
)
f
.
save
()
apple
=
self
.
food_model
.
objects
.
get
(
name
=
'apple'
)
self
.
assert_tags_equal
(
apple
.
tags
.
all
(),
[
'green'
,
'red'
,
'yummy'
])
...
...
@@ -333,15 +351,18 @@ class TaggableFormTestCase(BaseTaggingTestCase):
self
.
assertFalse
(
f
.
is_valid
())
f
=
self
.
form_class
(
instance
=
apple
)
self
.
assertEqual
(
str
(
f
),
"""<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" value="apple" maxlength="50" /></td></tr>
\n
<tr><th><label for="id_tags">Tags:</label></th><td><input type="text" name="tags" value="delicious, green, red, yummy" id="id_tags" /><br />A comma-separated list of tags.</td></tr>"""
)
self
.
assert_form_renders
(
f
,
"""<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" value="apple" maxlength="50" /></td></tr>
<tr><th><label for="id_tags">Tags:</label></th><td><input type="text" name="tags" value="delicious, green, red, yummy" id="id_tags" /><br />
%(help_start)
sA comma-separated list of tags.
%(help_stop)
s</td></tr>"""
)
apple
.
tags
.
add
(
'has,comma'
)
f
=
self
.
form_class
(
instance
=
apple
)
self
.
assertEqual
(
str
(
f
),
"""<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" value="apple" maxlength="50" /></td></tr>
\n
<tr><th><label for="id_tags">Tags:</label></th><td><input type="text" name="tags" value=""has,comma", delicious, green, red, yummy" id="id_tags" /><br />A comma-separated list of tags.</td></tr>"""
)
self
.
assert_form_renders
(
f
,
"""<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" value="apple" maxlength="50" /></td></tr>
<tr><th><label for="id_tags">Tags:</label></th><td><input type="text" name="tags" value=""has,comma", delicious, green, red, yummy" id="id_tags" /><br />
%(help_start)
sA comma-separated list of tags.
%(help_stop)
s</td></tr>"""
)
apple
.
tags
.
add
(
'has space'
)
f
=
self
.
form_class
(
instance
=
apple
)
self
.
assertEqual
(
str
(
f
),
"""<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" value="apple" maxlength="50" /></td></tr>
\n
<tr><th><label for="id_tags">Tags:</label></th><td><input type="text" name="tags" value=""has space", "has,comma", delicious, green, red, yummy" id="id_tags" /><br />A comma-separated list of tags.</td></tr>"""
)
self
.
assert_form_renders
(
f
,
"""<tr><th><label for="id_name">Name:</label></th><td><input id="id_name" type="text" name="name" value="apple" maxlength="50" /></td></tr>
<tr><th><label for="id_tags">Tags:</label></th><td><input type="text" name="tags" value=""has space", "has,comma", delicious, green, red, yummy" id="id_tags" /><br />
%(help_start)
sA comma-separated list of tags.
%(help_stop)
s</td></tr>"""
)
def
test_formfield
(
self
):
tm
=
TaggableManager
(
verbose_name
=
'categories'
,
help_text
=
'Add some categories'
,
blank
=
True
)
...
...
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