summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRobin Munn <robin.munn@gmail.com>2006-10-24 07:49:37 +0000
committerRobin Munn <robin.munn@gmail.com>2006-10-24 07:49:37 +0000
commit0b059aa4eadc1d95ceca3a32821b65a9fb2a53e8 (patch)
tree76f84c62e3ac5cd5172d43dd73a651bb8574e2d1 /tests
parent1bb4fa2cb66269b1eff3b7d73f8c7864c0622368 (diff)
sqlalchemy: Merged revisions 3832 to 3917 from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/sqlalchemy@3918 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/one_to_one/models.py14
-rw-r--r--tests/regressiontests/dateformat/tests.py42
-rw-r--r--tests/regressiontests/null_queries/__init__.py0
-rw-r--r--tests/regressiontests/null_queries/models.py54
-rw-r--r--tests/regressiontests/templates/tests.py3
5 files changed, 94 insertions, 19 deletions
diff --git a/tests/modeltests/one_to_one/models.py b/tests/modeltests/one_to_one/models.py
index 8afa74454d..7488204ff1 100644
--- a/tests/modeltests/one_to_one/models.py
+++ b/tests/modeltests/one_to_one/models.py
@@ -30,6 +30,14 @@ class Waiter(models.Model):
def __str__(self):
return "%s the waiter at %s" % (self.name, self.restaurant)
+class ManualPrimaryKey(models.Model):
+ primary_key = models.CharField(maxlength=10, primary_key=True)
+ name = models.CharField(maxlength = 50)
+
+class RelatedModel(models.Model):
+ link = models.OneToOneField(ManualPrimaryKey)
+ name = models.CharField(maxlength = 50)
+
__test__ = {'API_TESTS':"""
# Create a couple of Places.
>>> p1 = Place(name='Demon Dogs', address='944 W. Fullerton')
@@ -151,4 +159,10 @@ DoesNotExist: Restaurant matching query does not exist.
# Delete the restaurant; the waiter should also be removed
>>> r = Restaurant.objects.get(pk=1)
>>> r.delete()
+
+# One-to-one fields still work if you create your own primary key
+>>> o1 = ManualPrimaryKey(primary_key="abc123", name="primary")
+>>> o1.save()
+>>> o2 = RelatedModel(link=o1, name="secondary")
+>>> o2.save()
"""}
diff --git a/tests/regressiontests/dateformat/tests.py b/tests/regressiontests/dateformat/tests.py
index 0287587b4a..6e28759a92 100644
--- a/tests/regressiontests/dateformat/tests.py
+++ b/tests/regressiontests/dateformat/tests.py
@@ -21,22 +21,22 @@ r"""
'7'
>>> format(my_birthday, 'N')
'July'
->>> format(my_birthday, 'O')
-'+0100'
+>>> no_tz or format(my_birthday, 'O') == '+0100'
+True
>>> format(my_birthday, 'P')
'10 p.m.'
->>> format(my_birthday, 'r')
-'Sun, 8 Jul 1979 22:00:00 +0100'
+>>> no_tz or format(my_birthday, 'r') == 'Sun, 8 Jul 1979 22:00:00 +0100'
+True
>>> format(my_birthday, 's')
'00'
>>> format(my_birthday, 'S')
'th'
>>> format(my_birthday, 't')
'31'
->>> format(my_birthday, 'T')
-'CET'
->>> format(my_birthday, 'U')
-'300531600'
+>>> no_tz or format(my_birthday, 'T') == 'CET'
+True
+>>> no_tz or format(my_birthday, 'U') == '300531600'
+True
>>> format(my_birthday, 'w')
'0'
>>> format(my_birthday, 'W')
@@ -47,17 +47,17 @@ r"""
'1979'
>>> format(my_birthday, 'z')
'189'
->>> format(my_birthday, 'Z')
-'3600'
+>>> no_tz or format(my_birthday, 'Z') == '3600'
+True
->>> format(summertime, 'I')
-'1'
->>> format(summertime, 'O')
-'+0200'
->>> format(wintertime, 'I')
-'0'
->>> format(wintertime, 'O')
-'+0100'
+>>> no_tz or format(summertime, 'I') == '1'
+True
+>>> no_tz or format(summertime, 'O') == '+0200'
+True
+>>> no_tz or format(wintertime, 'I') == '0'
+True
+>>> no_tz or format(wintertime, 'O') == '+0100'
+True
>>> format(my_birthday, r'Y z \C\E\T')
'1979 189 CET'
@@ -73,7 +73,11 @@ format = dateformat.format
os.environ['TZ'] = 'Europe/Copenhagen'
translation.activate('en-us')
-time.tzset()
+try:
+ time.tzset()
+ no_tz = False
+except AttributeError:
+ no_tz = True
my_birthday = datetime.datetime(1979, 7, 8, 22, 00)
summertime = datetime.datetime(2005, 10, 30, 1, 00)
diff --git a/tests/regressiontests/null_queries/__init__.py b/tests/regressiontests/null_queries/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/regressiontests/null_queries/__init__.py
diff --git a/tests/regressiontests/null_queries/models.py b/tests/regressiontests/null_queries/models.py
new file mode 100644
index 0000000000..09024f18c2
--- /dev/null
+++ b/tests/regressiontests/null_queries/models.py
@@ -0,0 +1,54 @@
+from django.db import models
+
+class Poll(models.Model):
+ question = models.CharField(maxlength=200)
+
+ def __str__(self):
+ return "Q: %s " % self.question
+
+class Choice(models.Model):
+ poll = models.ForeignKey(Poll)
+ choice = models.CharField(maxlength=200)
+
+ def __str__(self):
+ return "Choice: %s in poll %s" % (self.choice, self.poll)
+
+__test__ = {'API_TESTS':"""
+# Regression test for the use of None as a query value. None is interpreted as
+# an SQL NULL, but only in __exact queries.
+# Set up some initial polls and choices
+>>> p1 = Poll(question='Why?')
+>>> p1.save()
+>>> c1 = Choice(poll=p1, choice='Because.')
+>>> c1.save()
+>>> c2 = Choice(poll=p1, choice='Why Not?')
+>>> c2.save()
+
+# Exact query with value None returns nothing (=NULL in sql)
+>>> Choice.objects.filter(id__exact=None)
+[]
+
+# Valid query, but fails because foo isn't a keyword
+>>> Choice.objects.filter(foo__exact=None)
+Traceback (most recent call last):
+...
+TypeError: Cannot resolve keyword 'foo' into field
+
+# Can't use None on anything other than __exact
+>>> Choice.objects.filter(id__gt=None)
+Traceback (most recent call last):
+...
+ValueError: Cannot use None as a query value
+
+# Can't use None on anything other than __exact
+>>> Choice.objects.filter(foo__gt=None)
+Traceback (most recent call last):
+...
+ValueError: Cannot use None as a query value
+
+# Related managers use __exact=None implicitly if the object hasn't been saved.
+>>> p2 = Poll(question="How?")
+>>> p2.choice_set.all()
+[]
+
+"""}
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index 368a46b8fb..e46b715490 100644
--- a/tests/regressiontests/templates/tests.py
+++ b/tests/regressiontests/templates/tests.py
@@ -170,6 +170,9 @@ class Templates(unittest.TestCase):
# Escaped backslash using known escape char
'basic-syntax35': (r'{{ var|default_if_none:"foo\now" }}', {"var": None}, r'foo\now'),
+ # Empty strings can be passed as arguments to filters
+ 'basic-syntax36': (r'{{ var|join:"" }}', {'var': ['a', 'b', 'c']}, 'abc'),
+
### COMMENT TAG ###########################################################
'comment-tag01': ("{% comment %}this is hidden{% endcomment %}hello", {}, "hello"),
'comment-tag02': ("{% comment %}this is hidden{% endcomment %}hello{% comment %}foo{% endcomment %}", {}, "hello"),