summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2006-05-31 19:23:07 +0000
committerAdrian Holovaty <adrian@holovaty.com>2006-05-31 19:23:07 +0000
commit02fcfe621664488eab69d90158f65adef292e84a (patch)
tree7b300ad9768dfbb899f570cd8b6121c6846c3eb8
parenta846155118747d6cdebaa92326eac1b08118e8ff (diff)
Cleaned up numbering with model unit tests
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3031 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--tests/modeltests/field_defaults/models.py17
-rw-r--r--tests/modeltests/m2m_and_m2o/models.py10
-rw-r--r--tests/modeltests/m2m_recursive/models.py30
-rw-r--r--tests/modeltests/manipulators/models.py2
-rw-r--r--tests/modeltests/pagination/models.py2
-rw-r--r--tests/modeltests/validation/models.py2
6 files changed, 33 insertions, 30 deletions
diff --git a/tests/modeltests/field_defaults/models.py b/tests/modeltests/field_defaults/models.py
index e5b7fd8e6d..0d69ffd8be 100644
--- a/tests/modeltests/field_defaults/models.py
+++ b/tests/modeltests/field_defaults/models.py
@@ -1,7 +1,12 @@
"""
-XXX. Callable defaults
+31. Callable defaults
-???
+You can pass callable objects as the ``default`` parameter to a field. When
+the object is created without an explicit value passed in, Django will call
+the method to determine the default value.
+
+This example uses ``datetime.datetime.now`` as the default for the ``pub_date``
+field.
"""
from django.db import models
@@ -9,9 +14,9 @@ from datetime import datetime
class Article(models.Model):
headline = models.CharField(maxlength=100, default='Default headline')
- pub_date = models.DateTimeField(default = datetime.now)
-
- def __repr__(self):
+ pub_date = models.DateTimeField(default=datetime.now)
+
+ def __str__(self):
return self.headline
API_TESTS = """
@@ -43,6 +48,4 @@ API_TESTS = """
>>> d = now - a.pub_date
>>> d.seconds < 5
True
-
-
"""
diff --git a/tests/modeltests/m2m_and_m2o/models.py b/tests/modeltests/m2m_and_m2o/models.py
index 2c2c696fd6..d147644c3c 100644
--- a/tests/modeltests/m2m_and_m2o/models.py
+++ b/tests/modeltests/m2m_and_m2o/models.py
@@ -1,8 +1,7 @@
"""
-27. Many-to-many and many-to-one relationships to the same table
-
-This is a response to bug #1535
+28. Many-to-many and many-to-one relationships to the same table
+Make sure to set ``related_name`` if you use relationships to the same table.
"""
from django.db import models
@@ -14,8 +13,9 @@ class Issue(models.Model):
num = models.IntegerField()
cc = models.ManyToManyField(User, blank=True, related_name='test_issue_cc')
client = models.ForeignKey(User, related_name='test_issue_client')
- def __repr__(self):
- return "<Issue %d>" % (self.num,)
+
+ def __str__(self):
+ return str(self.num)
class Meta:
ordering = ('num',)
diff --git a/tests/modeltests/m2m_recursive/models.py b/tests/modeltests/m2m_recursive/models.py
index ff8a5a8f47..877a41fd14 100644
--- a/tests/modeltests/m2m_recursive/models.py
+++ b/tests/modeltests/m2m_recursive/models.py
@@ -1,15 +1,15 @@
"""
-26. Many-to-many relationships between the same two tables
+27. Many-to-many relationships between the same two tables
-In this example, A Person can have many friends, who are also people. Friendship is a
+In this example, A Person can have many friends, who are also people. Friendship is a
symmetrical relationshiup - if I am your friend, you are my friend.
A person can also have many idols - but while I may idolize you, you may not think
-the same of me. 'Idols' is an example of a non-symmetrical m2m field. Only recursive
+the same of me. 'Idols' is an example of a non-symmetrical m2m field. Only recursive
m2m fields may be non-symmetrical, and they are symmetrical by default.
This test validates that the m2m table will create a mangled name for the m2m table if
-there will be a clash, and tests that symmetry is preserved where appropriate.
+there will be a clash, and tests that symmetry is preserved where appropriate.
"""
from django.db import models
@@ -40,7 +40,7 @@ API_TESTS = """
>>> d.friends.add(a,c)
# Who is friends with Anne?
->>> a.friends.all()
+>>> a.friends.all()
[Bill, Chuck, David]
# Who is friends with Bill?
@@ -52,14 +52,14 @@ API_TESTS = """
[Anne, David]
# Who is friends with David?
->>> d.friends.all()
+>>> d.friends.all()
[Anne, Chuck]
# Bill is already friends with Anne - add Anne again, but in the reverse direction
>>> b.friends.add(a)
# Who is friends with Anne?
->>> a.friends.all()
+>>> a.friends.all()
[Bill, Chuck, David]
# Who is friends with Bill?
@@ -70,7 +70,7 @@ API_TESTS = """
>>> b.friends.remove(a)
# Who is friends with Anne?
->>> a.friends.all()
+>>> a.friends.all()
[Chuck, David]
# Who is friends with Bill?
@@ -81,7 +81,7 @@ API_TESTS = """
>>> a.friends.clear()
# Who is friends with Anne?
->>> a.friends.all()
+>>> a.friends.all()
[]
# Reverse relationships should also be gone
@@ -90,7 +90,7 @@ API_TESTS = """
[David]
# Who is friends with David?
->>> d.friends.all()
+>>> d.friends.all()
[Chuck]
@@ -105,7 +105,7 @@ API_TESTS = """
>>> d.stalkers.add(a,c)
# Who are Anne's idols?
->>> a.idols.all()
+>>> a.idols.all()
[Bill, Chuck, David]
# Who is stalking Anne?
@@ -140,7 +140,7 @@ API_TESTS = """
>>> b.stalkers.add(a)
# Who are Anne's idols?
->>> a.idols.all()
+>>> a.idols.all()
[Bill, Chuck, David]
# Who is stalking Anne?
@@ -158,7 +158,7 @@ API_TESTS = """
>>> b.stalkers.remove(a)
# Who are Anne's idols?
->>> a.idols.all()
+>>> a.idols.all()
[Chuck, David]
# Who is stalking Anne?
@@ -177,7 +177,7 @@ API_TESTS = """
>>> a.idols.clear()
# Who are Anne's idols
->>> a.idols.all()
+>>> a.idols.all()
[]
# Reverse relationships should also be gone
@@ -186,7 +186,7 @@ API_TESTS = """
[]
# Who is friends with David?
->>> d.stalkers.all()
+>>> d.stalkers.all()
[Chuck]
"""
diff --git a/tests/modeltests/manipulators/models.py b/tests/modeltests/manipulators/models.py
index abc21b112b..cf833cc468 100644
--- a/tests/modeltests/manipulators/models.py
+++ b/tests/modeltests/manipulators/models.py
@@ -1,5 +1,5 @@
"""
-25. Default manipulators
+26. Default manipulators
Each model gets an AddManipulator and ChangeManipulator by default.
"""
diff --git a/tests/modeltests/pagination/models.py b/tests/modeltests/pagination/models.py
index d0a91ad824..fa45616b52 100644
--- a/tests/modeltests/pagination/models.py
+++ b/tests/modeltests/pagination/models.py
@@ -1,5 +1,5 @@
"""
-28. Object pagination
+29. Object pagination
Django provides a framework for paginating a list of objects in a few lines
of code. This is often useful for dividing search results or long lists of
diff --git a/tests/modeltests/validation/models.py b/tests/modeltests/validation/models.py
index e5f85582b5..8904c42727 100644
--- a/tests/modeltests/validation/models.py
+++ b/tests/modeltests/validation/models.py
@@ -1,5 +1,5 @@
"""
-29. Validation
+30. Validation
This is an experimental feature!