mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
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
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
"""}
|
||||
|
||||
@@ -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>]
|
||||
|
||||
0
tests/modeltests/user_commands/__init__.py
Normal file
0
tests/modeltests/user_commands/__init__.py
Normal file
@@ -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."
|
||||
30
tests/modeltests/user_commands/models.py
Normal file
30
tests/modeltests/user_commands/models.py
Normal file
@@ -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'
|
||||
|
||||
|
||||
"""}
|
||||
@@ -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):
|
||||
|
||||
@@ -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()
|
||||
'''
|
||||
}
|
||||
|
||||
|
||||
@@ -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'
|
||||
"""
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user