summaryrefslogtreecommitdiff
path: root/tests/modeltests
diff options
context:
space:
mode:
authorJoseph Kocherhans <joseph@jkocherhans.com>2007-09-25 00:08:38 +0000
committerJoseph Kocherhans <joseph@jkocherhans.com>2007-09-25 00:08:38 +0000
commit609eaf130d2d9eac109aefa59bfced32b67b9eb1 (patch)
treeb8bf4fd18c0fe75a418525baefa485c5ce31ce2f /tests/modeltests
parentafb8f0a61969dff6450cd296be5eac2a5693ecd9 (diff)
newforms-admin: Merged to [6416]
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@6417 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/modeltests')
-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
7 files changed, 53 insertions, 4 deletions
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