summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-10-08 16:10:39 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-10-08 16:10:39 +0000
commit7ebf3068c16d29c0288a317dac45166a8bc4c23c (patch)
tree537b7f487e515d6870e6a61f41588b3d351256f2 /tests
parent94c320d8a982ce30f6dd4e7556f2696229b761c7 (diff)
queryset-refactor: Merged changed from trunk up to [6463].
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6466 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/basic/models.py2
-rw-r--r--tests/modeltests/field_defaults/models.py2
-rw-r--r--tests/modeltests/serializers/models.py14
-rw-r--r--tests/modeltests/signals/models.py4
-rw-r--r--tests/modeltests/user_commands/__init__.py0
-rw-r--r--tests/modeltests/user_commands/management/__init__.py0
-rw-r--r--tests/modeltests/user_commands/management/commands/__init__.py0
-rw-r--r--tests/modeltests/user_commands/management/commands/dance.py9
-rw-r--r--tests/modeltests/user_commands/models.py30
-rw-r--r--tests/regressiontests/httpwrappers/tests.py6
-rw-r--r--tests/regressiontests/i18n/models.py12
-rw-r--r--tests/regressiontests/i18n/tests.py8
-rw-r--r--tests/regressiontests/views/tests/generic/date_based.py10
13 files changed, 83 insertions, 14 deletions
diff --git a/tests/modeltests/basic/models.py b/tests/modeltests/basic/models.py
index 58770ef2ce..2f4b932fe0 100644
--- a/tests/modeltests/basic/models.py
+++ b/tests/modeltests/basic/models.py
@@ -152,7 +152,7 @@ TypeError: 'foo' is an invalid keyword argument for this function
>>> a6 = Article(pub_date=datetime(2005, 7, 31))
>>> a6.save()
>>> a6.headline
-'Default headline'
+u'Default headline'
# For DateTimeFields, Django saves as much precision (in seconds) as you
# give it.
diff --git a/tests/modeltests/field_defaults/models.py b/tests/modeltests/field_defaults/models.py
index 23c4733b8f..1132f1ca41 100644
--- a/tests/modeltests/field_defaults/models.py
+++ b/tests/modeltests/field_defaults/models.py
@@ -42,7 +42,7 @@ __test__ = {'API_TESTS':"""
# Access database columns via Python attributes.
>>> a.headline
-'Default headline'
+u'Default headline'
# make sure the two dates are sufficiently close
>>> d = now - a.pub_date
diff --git a/tests/modeltests/serializers/models.py b/tests/modeltests/serializers/models.py
index a0a68d4bcc..a2388223f0 100644
--- a/tests/modeltests/serializers/models.py
+++ b/tests/modeltests/serializers/models.py
@@ -63,6 +63,9 @@ class Movie(models.Model):
def __unicode__(self):
return self.title
+
+class Score(models.Model):
+ score = models.FloatField()
__test__ = {'API_TESTS':"""
# Create some data:
@@ -83,7 +86,7 @@ __test__ = {'API_TESTS':"""
>>> a2 = Article(
... author = joe,
... headline = "Time to reform copyright",
-... pub_date = datetime(2006, 6, 16, 13, 00))
+... pub_date = datetime(2006, 6, 16, 13, 00, 11, 345))
>>> a1.save(); a2.save()
>>> a1.categories = [sports, op_ed]
>>> a2.categories = [music, op_ed]
@@ -181,7 +184,7 @@ __test__ = {'API_TESTS':"""
# Serializer output can be restricted to a subset of fields
>>> print serializers.serialize("json", Article.objects.all(), fields=('headline','pub_date'))
-[{"pk": 1, "model": "serializers.article", "fields": {"headline": "Just kidding; I love TV poker", "pub_date": "2006-06-16 11:00:00"}}, {"pk": 2, "model": "serializers.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16 13:00:00"}}, {"pk": 3, "model": "serializers.article", "fields": {"headline": "Forward references pose no problem", "pub_date": "2006-06-16 15:00:00"}}]
+[{"pk": 1, "model": "serializers.article", "fields": {"headline": "Just kidding; I love TV poker", "pub_date": "2006-06-16 11:00:00"}}, {"pk": 2, "model": "serializers.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16 13:00:11"}}, {"pk": 3, "model": "serializers.article", "fields": {"headline": "Forward references pose no problem", "pub_date": "2006-06-16 15:00:00"}}]
# Every string is serialized as a unicode object, also primary key
# which is 'varchar'
@@ -207,4 +210,11 @@ u'G\u0119\u015bl\u0105 ja\u017a\u0144'
>>> print list(serializers.deserialize('json', serializers.serialize('json', [mv2])))[0].object.id
None
+# Serialization and deserialization of floats:
+>>> sc = Score(score=3.4)
+>>> print serializers.serialize("json", [sc])
+[{"pk": null, "model": "serializers.score", "fields": {"score": 3.4}}]
+>>> print list(serializers.deserialize('json', serializers.serialize('json', [sc])))[0].object.score
+3.4
+
"""}
diff --git a/tests/modeltests/signals/models.py b/tests/modeltests/signals/models.py
index d41142135e..1fb73828bb 100644
--- a/tests/modeltests/signals/models.py
+++ b/tests/modeltests/signals/models.py
@@ -54,7 +54,7 @@ Is updated
pre_delete signal, Tom Smith
instance.id is not None: True
post_delete signal, Tom Smith
-instance.id is None: True
+instance.id is None: False
>>> p2 = Person(first_name='James', last_name='Jones')
>>> p2.id = 99999
@@ -73,7 +73,7 @@ Is created
pre_delete signal, James Jones
instance.id is not None: True
post_delete signal, James Jones
-instance.id is None: True
+instance.id is None: False
>>> Person.objects.all()
[<Person: James Jones>]
diff --git a/tests/modeltests/user_commands/__init__.py b/tests/modeltests/user_commands/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/modeltests/user_commands/__init__.py
diff --git a/tests/modeltests/user_commands/management/__init__.py b/tests/modeltests/user_commands/management/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/modeltests/user_commands/management/__init__.py
diff --git a/tests/modeltests/user_commands/management/commands/__init__.py b/tests/modeltests/user_commands/management/commands/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/modeltests/user_commands/management/commands/__init__.py
diff --git a/tests/modeltests/user_commands/management/commands/dance.py b/tests/modeltests/user_commands/management/commands/dance.py
new file mode 100644
index 0000000000..5886cd1d8f
--- /dev/null
+++ b/tests/modeltests/user_commands/management/commands/dance.py
@@ -0,0 +1,9 @@
+from django.core.management.base import BaseCommand
+
+class Command(BaseCommand):
+ help = "Dance around like a madman."
+ args = ''
+ requires_model_validation = True
+
+ def handle(self, *args, **options):
+ print "I don't feel like dancing." \ No newline at end of file
diff --git a/tests/modeltests/user_commands/models.py b/tests/modeltests/user_commands/models.py
new file mode 100644
index 0000000000..5f96806dac
--- /dev/null
+++ b/tests/modeltests/user_commands/models.py
@@ -0,0 +1,30 @@
+"""
+37. User-registered management commands
+
+The manage.py utility provides a number of useful commands for managing a
+Django project. If you want to add a utility command of your own, you can.
+
+The user-defined command 'dance' is defined in the management/commands
+subdirectory of this test application. It is a simple command that responds
+with a printed message when invoked.
+
+For more details on how to define your own manage.py commands, look at the
+django.core.management.commands directory. This directory contains the
+definitions for the base Django manage.py commands.
+"""
+
+__test__ = {'API_TESTS': """
+>>> from django.core import management
+
+# Invoke a simple user-defined command
+>>> management.call_command('dance')
+I don't feel like dancing.
+
+# Invoke a command that doesn't exist
+>>> management.call_command('explode')
+Traceback (most recent call last):
+...
+CommandError: Unknown command: 'explode'
+
+
+"""} \ No newline at end of file
diff --git a/tests/regressiontests/httpwrappers/tests.py b/tests/regressiontests/httpwrappers/tests.py
index 9d5ca2006a..5cfae029bb 100644
--- a/tests/regressiontests/httpwrappers/tests.py
+++ b/tests/regressiontests/httpwrappers/tests.py
@@ -8,7 +8,7 @@
>>> q['foo']
Traceback (most recent call last):
...
-MultiValueDictKeyError: "Key 'foo' not found in <MultiValueDict: {}>"
+MultiValueDictKeyError: "Key 'foo' not found in <QueryDict: {}>"
>>> q['something'] = 'bar'
Traceback (most recent call last):
@@ -89,7 +89,7 @@ AttributeError: This QueryDict instance is immutable
>>> q['foo']
Traceback (most recent call last):
...
-MultiValueDictKeyError: "Key 'foo' not found in <MultiValueDict: {}>"
+MultiValueDictKeyError: "Key 'foo' not found in <QueryDict: {}>"
>>> q['name'] = 'john'
@@ -201,7 +201,7 @@ u'bar'
>>> q['bar']
Traceback (most recent call last):
...
-MultiValueDictKeyError: "Key 'bar' not found in <MultiValueDict: {u'foo': [u'bar']}>"
+MultiValueDictKeyError: "Key 'bar' not found in <QueryDict: {u'foo': [u'bar']}>"
>>> q['something'] = 'bar'
Traceback (most recent call last):
diff --git a/tests/regressiontests/i18n/models.py b/tests/regressiontests/i18n/models.py
index e69de29bb2..e1eefb8477 100644
--- a/tests/regressiontests/i18n/models.py
+++ b/tests/regressiontests/i18n/models.py
@@ -0,0 +1,12 @@
+from django.db import models
+from django.utils.translation import ugettext_lazy as _
+
+class TestModel(models.Model):
+ text = models.CharField(max_length=10, default=_('Anything'))
+
+__test__ = {'API_TESTS': '''
+>>> tm = TestModel()
+>>> tm.save()
+'''
+}
+
diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
index 8a7d2bee3e..99204451e4 100644
--- a/tests/regressiontests/i18n/tests.py
+++ b/tests/regressiontests/i18n/tests.py
@@ -30,4 +30,12 @@ True
>>> s4 = ugettext_lazy('Some other string')
>>> s == s4
False
+
+unicode(string_concat(...)) should not raise a TypeError - #4796
+
+>>> import django.utils.translation
+>>> reload(django.utils.translation)
+<module 'django.utils.translation' from ...>
+>>> unicode(django.utils.translation.string_concat("dja", "ngo"))
+u'django'
"""
diff --git a/tests/regressiontests/views/tests/generic/date_based.py b/tests/regressiontests/views/tests/generic/date_based.py
index aca93d4579..94ae99a20a 100644
--- a/tests/regressiontests/views/tests/generic/date_based.py
+++ b/tests/regressiontests/views/tests/generic/date_based.py
@@ -43,9 +43,9 @@ class MonthArchiveTest(TestCase):
author.save()
# 2004 was a leap year, so it should be weird enough to not cheat
- first_second_of_feb = datetime(2004, 2, 1, 0, 0, 0)
- first_second_of_mar = datetime(2004, 3, 1, 0, 0, 0)
- one_microsecond = timedelta(0, 0, 1)
+ first_second_of_feb = datetime(2004, 2, 1, 0, 0, 1)
+ first_second_of_mar = datetime(2004, 3, 1, 0, 0, 1)
+ two_seconds = timedelta(0, 2, 0)
article = Article(title="example", author=author)
article.date_created = first_second_of_feb
@@ -53,12 +53,12 @@ class MonthArchiveTest(TestCase):
response = self.client.get('/views/date_based/archive_month/2004/02/')
self.assertEqual(response.status_code, 200)
- article.date_created = first_second_of_feb-one_microsecond
+ article.date_created = first_second_of_feb-two_seconds
article.save()
response = self.client.get('/views/date_based/archive_month/2004/02/')
self.assertEqual(response.status_code, 404)
- article.date_created = first_second_of_mar-one_microsecond
+ article.date_created = first_second_of_mar-two_seconds
article.save()
response = self.client.get('/views/date_based/archive_month/2004/02/')
self.assertEqual(response.status_code, 200)