Re: [Django] #10904: Fix incorrect term "Absolute URL" throughout documentation

2010-09-12 Thread Django
#10904: Fix incorrect term "Absolute URL" throughout documentation
+---
  Reporter:  sharan666  | Owner:  nobody
Status:  new| Milestone:
 Component:  Documentation  |   Version:  1.0   
Resolution: |  Keywords:
 Stage:  Accepted   | Has_patch:  0 
Needs_docs:  1  |   Needs_tests:  0 
Needs_better_patch:  0  |  
+---
Changes (by mtredinnick):

  * needs_docs:  0 => 1
  * stage:  Design decision needed => Accepted

Comment:

 We should definitely fix it and use the phrase "absolute path reference"
 (possibly abbreviated to "absolute path" after frequent use). That is the
 term used in RFC 2396, which is the URI spec. The current Django usage has
 always annoyed me and is almost certainly due to a misunderstanding when
 the docs were originally written. It's wrong currently; let's fix it.

 By the way, we can't use the 'i.e.' phrasing of the current docs after the
 terms "relative URL" since it's not an "i.e.", it's an "e.g." and that
 isn't correct in those contexts either.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13840 - django/branches/releases/1.2.X/tests/modeltests/proxy_models

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-13 00:48:18 -0500 (Mon, 13 Sep 2010)
New Revision: 13840

Added:
   django/branches/releases/1.2.X/tests/modeltests/proxy_models/tests.py
Modified:
   django/branches/releases/1.2.X/tests/modeltests/proxy_models/models.py
Log:
[1.2.X] Migrated proxy_models doctests. Thanks to Eric Florenzano.

Backport of r13831 from trunk.

Modified: django/branches/releases/1.2.X/tests/modeltests/proxy_models/models.py
===
--- django/branches/releases/1.2.X/tests/modeltests/proxy_models/models.py  
2010-09-13 05:48:06 UTC (rev 13839)
+++ django/branches/releases/1.2.X/tests/modeltests/proxy_models/models.py  
2010-09-13 05:48:18 UTC (rev 13840)
@@ -161,232 +161,4 @@
 
 class ProxyImprovement(Improvement):
 class Meta:
-proxy = True
-
-__test__ = {'API_TESTS' : """
-# The MyPerson model should be generating the same database queries as the
-# Person model (when the same manager is used in each case).
->>> from django.db import DEFAULT_DB_ALIAS
->>> MyPerson.other.all().query.get_compiler(DEFAULT_DB_ALIAS).as_sql() == 
Person.objects.order_by("name").query.get_compiler(DEFAULT_DB_ALIAS).as_sql()
-True
-
-# The StatusPerson models should have its own table (it's using ORM-level
-# inheritance).
->>> StatusPerson.objects.all().query.get_compiler(DEFAULT_DB_ALIAS).as_sql() 
== Person.objects.all().query.get_compiler(DEFAULT_DB_ALIAS).as_sql()
-False
-
-# Creating a Person makes them accessible through the MyPerson proxy.
->>> _ = Person.objects.create(name="Foo McBar")
->>> len(Person.objects.all())
-1
->>> len(MyPerson.objects.all())
-1
->>> MyPerson.objects.get(name="Foo McBar").id
-1
->>> MyPerson.objects.get(id=1).has_special_name()
-False
-
-# Person is not proxied by StatusPerson subclass, however.
->>> StatusPerson.objects.all()
-[]
-
-# A new MyPerson also shows up as a standard Person
->>> _ = MyPerson.objects.create(name="Bazza del Frob")
->>> len(MyPerson.objects.all())
-2
->>> len(Person.objects.all())
-2
-
->>> _ = LowerStatusPerson.objects.create(status="low", name="homer")
->>> LowerStatusPerson.objects.all()
-[]
-
-# Correct type when querying a proxy of proxy
-
->>> MyPersonProxy.objects.all()
-[, , ]
-
-# Proxy models are included in the ancestors for a model's DoesNotExist and 
MultipleObjectsReturned
->>> try:
-... MyPersonProxy.objects.get(name='Zathras')
-... except Person.DoesNotExist:
-... pass
->>> try:
-... MyPersonProxy.objects.get(id__lt=10)
-... except Person.MultipleObjectsReturned:
-... pass
->>> try:
-... StatusPerson.objects.get(name='Zathras')
-... except Person.DoesNotExist:
-... pass
->>> sp1 = StatusPerson.objects.create(name='Bazza Jr.')
->>> sp2 = StatusPerson.objects.create(name='Foo Jr.')
->>> try:
-... StatusPerson.objects.get(id__lt=10)
-... except Person.MultipleObjectsReturned:
-... pass
-
-# And now for some things that shouldn't work...
-#
-# All base classes must be non-abstract
->>> class NoAbstract(Abstract):
-... class Meta:
-... proxy = True
-Traceback (most recent call last):
-
-TypeError: Abstract base class containing model fields not permitted for proxy 
model 'NoAbstract'.
-
-# The proxy must actually have one concrete base class
->>> class TooManyBases(Person, Abstract):
-... class Meta:
-... proxy = True
-Traceback (most recent call last):
-
-TypeError: Abstract base class containing model fields not permitted for proxy 
model 'TooManyBases'.
-
->>> class NoBaseClasses(models.Model):
-... class Meta:
-... proxy = True
-Traceback (most recent call last):
-
-TypeError: Proxy model 'NoBaseClasses' has no non-abstract model base class.
-
-
-# A proxy cannot introduce any new fields
->>> class NoNewFields(Person):
-... newfield = models.BooleanField()
-... class Meta:
-... proxy = True
-Traceback (most recent call last):
-
-FieldError: Proxy model 'NoNewFields' contains model fields.
-
-# Manager tests.
-
->>> Person.objects.all().delete()
->>> _ = Person.objects.create(name="fred")
->>> _ = Person.objects.create(name="wilma")
->>> _ = Person.objects.create(name="barney")
-
->>> MyPerson.objects.all()
-[, ]
->>> MyPerson._default_manager.all()
-[, ]
-
->>> OtherPerson.objects.all()
-[, ]
->>> OtherPerson.excluder.all()
-[, ]
->>> OtherPerson._default_manager.all()
-[, ]
-
-# Test save signals for proxy models
->>> from django.db.models import signals
->>> def make_handler(model, event):
-... def _handler(*args, **kwargs):
-... print u"%s %s save" % (model, event)
-... return _handler
->>> h1 = make_handler('MyPerson', 'pre')
->>> h2 = make_handler('MyPerson', 'post')
->>> h3 = make_handler('Person', 'pre')
->>> h4 = make_handler('Person', 'post')
->>> signals.pre_save.connect(h1, sender=MyPerson)
->>> signals.post_save.connect(h2, sender=MyPerson)
->>> signals.pre_save.connect(h3, sender=Person)
->>> signals.post_save.connect(h4, 

[Changeset] r13839 - django/branches/releases/1.2.X/tests/modeltests/reserved_names

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-13 00:48:06 -0500 (Mon, 13 Sep 2010)
New Revision: 13839

Added:
   django/branches/releases/1.2.X/tests/modeltests/reserved_names/tests.py
Modified:
   django/branches/releases/1.2.X/tests/modeltests/reserved_names/models.py
Log:
[1.2.X] Migrated reserved_names doctests. Thanks to Eric Florenzano.

Backport of r13830 from trunk.

Modified: 
django/branches/releases/1.2.X/tests/modeltests/reserved_names/models.py
===
--- django/branches/releases/1.2.X/tests/modeltests/reserved_names/models.py
2010-09-13 05:47:52 UTC (rev 13838)
+++ django/branches/releases/1.2.X/tests/modeltests/reserved_names/models.py
2010-09-13 05:48:06 UTC (rev 13839)
@@ -22,33 +22,4 @@
db_table = 'select'
 
 def __unicode__(self):
-return self.when
-
-__test__ = {'API_TESTS':"""
->>> import datetime
->>> day1 = datetime.date(2005, 1, 1)
->>> day2 = datetime.date(2006, 2, 2)
->>> t = Thing(when='a', join='b', like='c', drop='d', alter='e', having='f', 
where=day1, has_hyphen='h')
->>> t.save()
->>> print t.when
-a
-
->>> u = Thing(when='h', join='i', like='j', drop='k', alter='l', having='m', 
where=day2)
->>> u.save()
->>> print u.when
-h
-
->>> Thing.objects.order_by('when')
-[, ]
->>> v = Thing.objects.get(pk='a')
->>> print v.join
-b
->>> print v.where
-2005-01-01
-
->>> Thing.objects.dates('where', 'year')
-[datetime.datetime(2005, 1, 1, 0, 0), datetime.datetime(2006, 1, 1, 0, 0)]
-
->>> Thing.objects.filter(where__month=1)
-[]
-"""}
+return self.when
\ No newline at end of file

Added: django/branches/releases/1.2.X/tests/modeltests/reserved_names/tests.py
===
--- django/branches/releases/1.2.X/tests/modeltests/reserved_names/tests.py 
(rev 0)
+++ django/branches/releases/1.2.X/tests/modeltests/reserved_names/tests.py 
2010-09-13 05:48:06 UTC (rev 13839)
@@ -0,0 +1,48 @@
+import datetime
+
+from django.test import TestCase
+
+from models import Thing
+
+class ReservedNameTests(TestCase):
+def generate(self):
+day1 = datetime.date(2005, 1, 1)
+t = Thing.objects.create(when='a', join='b', like='c', drop='d',
+alter='e', having='f', where=day1, has_hyphen='h')
+day2 = datetime.date(2006, 2, 2)
+u = Thing.objects.create(when='h', join='i', like='j', drop='k',
+alter='l', having='m', where=day2)
+
+def test_simple(self):
+day1 = datetime.date(2005, 1, 1)
+t = Thing.objects.create(when='a', join='b', like='c', drop='d',
+alter='e', having='f', where=day1, has_hyphen='h')
+self.assertEqual(t.when, 'a')
+
+day2 = datetime.date(2006, 2, 2)
+u = Thing.objects.create(when='h', join='i', like='j', drop='k',
+alter='l', having='m', where=day2)
+self.assertEqual(u.when, 'h')
+
+def test_order_by(self):
+self.generate()
+things = [t.when for t in Thing.objects.order_by('when')]
+self.assertEqual(things, ['a', 'h'])
+
+def test_fields(self):
+self.generate()
+v = Thing.objects.get(pk='a')
+self.assertEqual(v.join, 'b')
+self.assertEqual(v.where, datetime.date(year=2005, month=1, day=1))
+
+def test_dates(self):
+self.generate()
+resp = Thing.objects.dates('where', 'year')
+self.assertEqual(list(resp), [
+datetime.datetime(2005, 1, 1, 0, 0),
+datetime.datetime(2006, 1, 1, 0, 0),
+])
+
+def test_month_filter(self):
+self.generate()
+self.assertEqual(Thing.objects.filter(where__month=1)[0].when, 'a')

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13838 - django/branches/releases/1.2.X/tests/modeltests/reverse_lookup

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-13 00:47:52 -0500 (Mon, 13 Sep 2010)
New Revision: 13838

Added:
   django/branches/releases/1.2.X/tests/modeltests/reverse_lookup/tests.py
Modified:
   django/branches/releases/1.2.X/tests/modeltests/reverse_lookup/models.py
Log:
[1.2.X] Migrated reverse_lookup doctests. Thanks to Eric Florenzano

Backport of r13829 from trunk.

Modified: 
django/branches/releases/1.2.X/tests/modeltests/reverse_lookup/models.py
===
--- django/branches/releases/1.2.X/tests/modeltests/reverse_lookup/models.py
2010-09-13 05:47:39 UTC (rev 13837)
+++ django/branches/releases/1.2.X/tests/modeltests/reverse_lookup/models.py
2010-09-13 05:47:52 UTC (rev 13838)
@@ -26,34 +26,3 @@
 
 def __unicode__(self):
 return self.name
-
-__test__ = {'API_TESTS':"""
->>> john = User(name="John Doe")
->>> john.save()
->>> jim = User(name="Jim Bo")
->>> jim.save()
->>> first_poll = Poll(question="What's the first question?", creator=john)
->>> first_poll.save()
->>> second_poll = Poll(question="What's the second question?", creator=jim)
->>> second_poll.save()
->>> new_choice = Choice(poll=first_poll, related_poll=second_poll, name="This 
is the answer.")
->>> new_choice.save()
-
->>> # Reverse lookups by field name:
->>> User.objects.get(poll__question__exact="What's the first question?")
-
->>> User.objects.get(poll__question__exact="What's the second question?")
-
-
->>> # Reverse lookups by related_name:
->>> Poll.objects.get(poll_choice__name__exact="This is the answer.")
-
->>> Poll.objects.get(related_choice__name__exact="This is the answer.")
-
-
->>> # If a related_name is given you can't use the field name instead:
->>> Poll.objects.get(choice__name__exact="This is the answer")
-Traceback (most recent call last):
-...
-FieldError: Cannot resolve keyword 'choice' into field. Choices are: creator, 
id, poll_choice, question, related_choice
-"""}

Added: django/branches/releases/1.2.X/tests/modeltests/reverse_lookup/tests.py
===
--- django/branches/releases/1.2.X/tests/modeltests/reverse_lookup/tests.py 
(rev 0)
+++ django/branches/releases/1.2.X/tests/modeltests/reverse_lookup/tests.py 
2010-09-13 05:47:52 UTC (rev 13838)
@@ -0,0 +1,49 @@
+from django.test import TestCase
+from django.core.exceptions import FieldError
+
+from models import User, Poll, Choice
+
+class ReverseLookupTests(TestCase):
+
+def setUp(self):
+john = User.objects.create(name="John Doe")
+jim = User.objects.create(name="Jim Bo")
+first_poll = Poll.objects.create(
+question="What's the first question?",
+creator=john
+)
+second_poll = Poll.objects.create(
+question="What's the second question?",
+creator=jim
+)
+new_choice = Choice.objects.create(
+poll=first_poll,
+related_poll=second_poll,
+name="This is the answer."
+)
+
+def test_reverse_by_field(self):
+u1 = User.objects.get(
+poll__question__exact="What's the first question?"
+)
+self.assertEqual(u1.name, "John Doe")
+
+u2 = User.objects.get(
+poll__question__exact="What's the second question?"
+)
+self.assertEqual(u2.name, "Jim Bo")
+
+def test_reverse_by_related_name(self):
+p1 = Poll.objects.get(poll_choice__name__exact="This is the answer.")
+self.assertEqual(p1.question, "What's the first question?")
+
+p2 = Poll.objects.get(
+related_choice__name__exact="This is the answer.")
+self.assertEqual(p2.question, "What's the second question?")
+
+def test_reverse_field_name_disallowed(self):
+"""
+If a related_name is given you can't use the field name instead
+"""
+self.assertRaises(FieldError, Poll.objects.get,
+choice__name__exact="This is the answer")

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13837 - django/branches/releases/1.2.X/tests/modeltests/select_related

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-13 00:47:39 -0500 (Mon, 13 Sep 2010)
New Revision: 13837

Added:
   django/branches/releases/1.2.X/tests/modeltests/select_related/tests.py
Modified:
   django/branches/releases/1.2.X/tests/modeltests/select_related/models.py
Log:
[1.2.X] Migrated select_related doctests. Thanks to Eric Florenzano.

Backport of r13828 from trunk.

Modified: 
django/branches/releases/1.2.X/tests/modeltests/select_related/models.py
===
--- django/branches/releases/1.2.X/tests/modeltests/select_related/models.py
2010-09-13 05:47:26 UTC (rev 13836)
+++ django/branches/releases/1.2.X/tests/modeltests/select_related/models.py
2010-09-13 05:47:39 UTC (rev 13837)
@@ -56,134 +56,4 @@
 name = models.CharField(max_length=50)
 genus = models.ForeignKey(Genus)
 def __unicode__(self):
-return self.name
-
-def create_tree(stringtree):
-"""Helper to create a complete tree"""
-names = stringtree.split()
-models = [Domain, Kingdom, Phylum, Klass, Order, Family, Genus, Species]
-assert len(names) == len(models), (names, models)
-
-parent = None
-for name, model in zip(names, models):
-try:
-obj = model.objects.get(name=name)
-except model.DoesNotExist:
-obj = model(name=name)
-if parent:
-setattr(obj, parent.__class__.__name__.lower(), parent)
-obj.save()
-parent = obj
-
-__test__ = {'API_TESTS':"""
-
-# Set up.
-# The test runner sets settings.DEBUG to False, but we want to gather queries
-# so we'll set it to True here and reset it at the end of the test suite.
->>> from django.conf import settings
->>> settings.DEBUG = True
-
->>> create_tree("Eukaryota Animalia Anthropoda Insecta Diptera Drosophilidae 
Drosophila melanogaster")
->>> create_tree("Eukaryota Animalia Chordata Mammalia Primates Hominidae Homo 
sapiens")
->>> create_tree("Eukaryota Plantae Magnoliophyta Magnoliopsida Fabales 
Fabaceae Pisum sativum")
->>> create_tree("Eukaryota Fungi Basidiomycota Homobasidiomycatae Agaricales 
Amanitacae Amanita muscaria")
-
->>> from django import db
-
-# Normally, accessing FKs doesn't fill in related objects:
->>> db.reset_queries()
->>> fly = Species.objects.get(name="melanogaster")
->>> fly.genus.family.order.klass.phylum.kingdom.domain
-
->>> len(db.connection.queries)
-8
-
-# However, a select_related() call will fill in those related objects without 
any extra queries:
->>> db.reset_queries()
->>> person = Species.objects.select_related(depth=10).get(name="sapiens")
->>> person.genus.family.order.klass.phylum.kingdom.domain
-
->>> len(db.connection.queries)
-1
-
-# select_related() also of course applies to entire lists, not just items.
-# Without select_related()
->>> db.reset_queries()
->>> world = Species.objects.all()
->>> [o.genus.family for o in world]
-[, , , ]
->>> len(db.connection.queries)
-9
-
-# With select_related():
->>> db.reset_queries()
->>> world = Species.objects.all().select_related()
->>> [o.genus.family for o in world]
-[, , , ]
->>> len(db.connection.queries)
-1
-
-# The "depth" argument to select_related() will stop the descent at a 
particular level:
->>> db.reset_queries()
->>> pea = Species.objects.select_related(depth=1).get(name="sativum")
->>> pea.genus.family.order.klass.phylum.kingdom.domain
-
-
-# Notice: one fewer queries than above because of depth=1
->>> len(db.connection.queries)
-7
-
->>> db.reset_queries()
->>> pea = Species.objects.select_related(depth=5).get(name="sativum")
->>> pea.genus.family.order.klass.phylum.kingdom.domain
-
->>> len(db.connection.queries)
-3
-
->>> db.reset_queries()
->>> world = Species.objects.all().select_related(depth=2)
->>> [o.genus.family.order for o in world]
-[, , , ]
->>> len(db.connection.queries)
-5
-
->>> s = Species.objects.all().select_related(depth=1).extra(select={'a': 
'select_related_species.id + 10'})[0]
->>> s.id + 10 == s.a
-True
-
-# The optional fields passed to select_related() control which related models
-# we pull in. This allows for smaller queries and can act as an alternative
-# (or, in addition to) the depth parameter.
-
-# In the next two cases, we explicitly say to select the 'genus' and
-# 'genus.family' models, leading to the same number of queries as before.
->>> db.reset_queries()
->>> world = Species.objects.select_related('genus__family')
->>> [o.genus.family for o in world]
-[, , , ]
->>> len(db.connection.queries)
-1
-
->>> db.reset_queries()
->>> world = 
Species.objects.filter(genus__name='Amanita').select_related('genus__family')
->>> [o.genus.family.order for o in world]
-[]
->>> len(db.connection.queries)
-2
-
->>> db.reset_queries()
->>> 
Species.objects.all().select_related('genus__family__order').order_by('id')[0:1].get().genus.family.order.name
-u'Diptera'
->>> len(db.connection.queries)
-1
-
-# Specifying both "depth" and fields is an error.
->>> 

[Changeset] r13836 - django/branches/releases/1.2.X/tests/modeltests/str

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-13 00:47:26 -0500 (Mon, 13 Sep 2010)
New Revision: 13836

Added:
   django/branches/releases/1.2.X/tests/modeltests/str/tests.py
Modified:
   django/branches/releases/1.2.X/tests/modeltests/str/models.py
Log:
[1.2.X] Migrated str doctests. Thanks to Eric Florenzano.

Backport of r13827 from trunk.

Modified: django/branches/releases/1.2.X/tests/modeltests/str/models.py
===
--- django/branches/releases/1.2.X/tests/modeltests/str/models.py   
2010-09-13 05:47:13 UTC (rev 13835)
+++ django/branches/releases/1.2.X/tests/modeltests/str/models.py   
2010-09-13 05:47:26 UTC (rev 13836)
@@ -30,23 +30,4 @@
 pub_date = models.DateTimeField()
 
 def __unicode__(self):
-return self.headline
-
-__test__ = {'API_TESTS':ur"""
-# Create an Article.
->>> from datetime import datetime
->>> a = Article(headline='Area man programs in Python', 
pub_date=datetime(2005, 7, 28))
->>> a.save()
-
->>> str(a)
-'Area man programs in Python'
-
->>> a
-
-
->>> a1 = InternationalArticle(headline=u'Girl wins €12.500 in lottery', 
pub_date=datetime(2005, 7, 28))
-
-# The default str() output will be the UTF-8 encoded output of __unicode__().
->>> str(a1)
-'Girl wins \xe2\x82\xac12.500 in lottery'
-"""}
+return self.headline
\ No newline at end of file

Added: django/branches/releases/1.2.X/tests/modeltests/str/tests.py
===
--- django/branches/releases/1.2.X/tests/modeltests/str/tests.py
(rev 0)
+++ django/branches/releases/1.2.X/tests/modeltests/str/tests.py
2010-09-13 05:47:26 UTC (rev 13836)
@@ -0,0 +1,23 @@
+ # -*- coding: utf-8 -*-
+import datetime
+
+from django.test import TestCase
+
+from models import Article, InternationalArticle
+
+class SimpleTests(TestCase):
+def test_basic(self):
+a = Article.objects.create(
+headline='Area man programs in Python',
+pub_date=datetime.datetime(2005, 7, 28)
+)
+self.assertEqual(str(a), 'Area man programs in Python')
+self.assertEqual(repr(a), '')
+
+def test_international(self):
+a = InternationalArticle.objects.create(
+headline=u'Girl wins €12.500 in lottery',
+pub_date=datetime.datetime(2005, 7, 28)
+)
+# The default str() output will be the UTF-8 encoded output of 
__unicode__().
+self.assertEqual(str(a), 'Girl wins \xe2\x82\xac12.500 in lottery')
\ No newline at end of file

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13835 - django/branches/releases/1.2.X/tests/modeltests/transactions

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-13 00:47:13 -0500 (Mon, 13 Sep 2010)
New Revision: 13835

Added:
   django/branches/releases/1.2.X/tests/modeltests/transactions/tests.py
Modified:
   django/branches/releases/1.2.X/tests/modeltests/transactions/models.py
Log:
[1.2.X] Migrated transactions doctests. Thanks to Eric Florenzano.

Backport of r13826 from trunk.

Modified: django/branches/releases/1.2.X/tests/modeltests/transactions/models.py
===
--- django/branches/releases/1.2.X/tests/modeltests/transactions/models.py  
2010-09-13 05:46:59 UTC (rev 13834)
+++ django/branches/releases/1.2.X/tests/modeltests/transactions/models.py  
2010-09-13 05:47:13 UTC (rev 13835)
@@ -18,138 +18,4 @@
 ordering = ('first_name', 'last_name')
 
 def __unicode__(self):
-return u"%s %s" % (self.first_name, self.last_name)
-
-__test__ = {'API_TESTS':"""
->>> from django.db import connection, transaction
-"""}
-
-from django.conf import settings
-
-building_docs = getattr(settings, 'BUILDING_DOCS', False)
-
-if building_docs or settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'] != 
'django.db.backends.mysql':
-__test__['API_TESTS'] += """
-# the default behavior is to autocommit after each save() action
->>> def create_a_reporter_then_fail(first, last):
-... a = Reporter(first_name=first, last_name=last)
-... a.save()
-... raise Exception("I meant to do that")
-...
->>> create_a_reporter_then_fail("Alice", "Smith")
-Traceback (most recent call last):
-...
-Exception: I meant to do that
-
-# The object created before the exception still exists
->>> Reporter.objects.all()
-[]
-
-# the autocommit decorator works exactly the same as the default behavior
->>> autocomitted_create_then_fail = 
transaction.autocommit(create_a_reporter_then_fail)
->>> autocomitted_create_then_fail("Ben", "Jones")
-Traceback (most recent call last):
-...
-Exception: I meant to do that
-
-# Same behavior as before
->>> Reporter.objects.all()
-[, ]
-
-# the autocommit decorator also works with a using argument
->>> using_autocomitted_create_then_fail = 
transaction.autocommit(using='default')(create_a_reporter_then_fail)
->>> using_autocomitted_create_then_fail("Carol", "Doe")
-Traceback (most recent call last):
-...
-Exception: I meant to do that
-
-# Same behavior as before
->>> Reporter.objects.all()
-[, , ]
-
-# With the commit_on_success decorator, the transaction is only committed if 
the
-# function doesn't throw an exception
->>> committed_on_success = 
transaction.commit_on_success(create_a_reporter_then_fail)
->>> committed_on_success("Dirk", "Gently")
-Traceback (most recent call last):
-...
-Exception: I meant to do that
-
-# This time the object never got saved
->>> Reporter.objects.all()
-[, , ]
-
-# commit_on_success decorator also works with a using argument
->>> using_committed_on_success = 
transaction.commit_on_success(using='default')(create_a_reporter_then_fail)
->>> using_committed_on_success("Dirk", "Gently")
-Traceback (most recent call last):
-...
-Exception: I meant to do that
-
-# This time the object never got saved
->>> Reporter.objects.all()
-[, , ]
-
-# If there aren't any exceptions, the data will get saved
->>> def remove_a_reporter():
-... r = Reporter.objects.get(first_name="Alice")
-... r.delete()
-...
->>> remove_comitted_on_success = 
transaction.commit_on_success(remove_a_reporter)
->>> remove_comitted_on_success()
->>> Reporter.objects.all()
-[, ]
-
-# You can manually manage transactions if you really want to, but you
-# have to remember to commit/rollback
->>> def manually_managed():
-... r = Reporter(first_name="Dirk", last_name="Gently")
-... r.save()
-... transaction.commit()
->>> manually_managed = transaction.commit_manually(manually_managed)
->>> manually_managed()
->>> Reporter.objects.all()
-[, , ]
-
-# If you forget, you'll get bad errors
->>> def manually_managed_mistake():
-... r = Reporter(first_name="Edward", last_name="Woodward")
-... r.save()
-... # oops, I forgot to commit/rollback!
->>> manually_managed_mistake = 
transaction.commit_manually(manually_managed_mistake)
->>> manually_managed_mistake()
-Traceback (most recent call last):
-...
-TransactionManagementError: Transaction managed block ended with pending 
COMMIT/ROLLBACK
-
-# commit_manually also works with a using argument
->>> using_manually_managed_mistake = 
transaction.commit_manually(using='default')(manually_managed_mistake)
->>> using_manually_managed_mistake()
-Traceback (most recent call last):
-...
-TransactionManagementError: Transaction managed block ended with pending 
COMMIT/ROLLBACK
-
-"""
-
-# Regression for #11900: If a function wrapped by commit_on_success writes a
-# transaction that can't be committed, that transaction should be rolled back.
-# The bug is only visible using the psycopg2 backend, though
-# the fix is generally a good idea.
-pgsql_backends = 

[Changeset] r13834 - django/branches/releases/1.2.X/tests/modeltests/unmanaged_models

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-13 00:46:59 -0500 (Mon, 13 Sep 2010)
New Revision: 13834

Modified:
   django/branches/releases/1.2.X/tests/modeltests/unmanaged_models/models.py
   django/branches/releases/1.2.X/tests/modeltests/unmanaged_models/tests.py
Log:
[1.2.X] Migrated unmanaged_models doctests. Thanks to Eric Florenzano.

Backport of r13825 from trunk.

Modified: 
django/branches/releases/1.2.X/tests/modeltests/unmanaged_models/models.py
===
--- django/branches/releases/1.2.X/tests/modeltests/unmanaged_models/models.py  
2010-09-13 05:46:46 UTC (rev 13833)
+++ django/branches/releases/1.2.X/tests/modeltests/unmanaged_models/models.py  
2010-09-13 05:46:59 UTC (rev 13834)
@@ -123,30 +123,3 @@
 # table *will* be created (unless given a custom `through` as for C02 above).
 class Managed1(models.Model):
 mm = models.ManyToManyField(Unmanaged1)
-
-__test__ = {'API_TESTS':"""
-The main test here is that the all the models can be created without any
-database errors. We can also do some more simple insertion and lookup tests
-whilst we're here to show that the second of models do refer to the tables from
-the first set.
-
-# Insert some data into one set of models.
->>> a = A01.objects.create(f_a="foo", f_b=42)
->>> _ = B01.objects.create(fk_a=a, f_a="fred", f_b=1729)
->>> c = C01.objects.create(f_a="barney", f_b=1)
->>> c.mm_a = [a]
-
-# ... and pull it out via the other set.
->>> A02.objects.all()
-[]
->>> b = B02.objects.all()[0]
->>> b
-
->>> b.fk_a
-
->>> C02.objects.filter(f_a=None)
-[]
->>> C02.objects.filter(mm_a=a.id)
-[]
-
-"""}

Modified: 
django/branches/releases/1.2.X/tests/modeltests/unmanaged_models/tests.py
===
--- django/branches/releases/1.2.X/tests/modeltests/unmanaged_models/tests.py   
2010-09-13 05:46:46 UTC (rev 13833)
+++ django/branches/releases/1.2.X/tests/modeltests/unmanaged_models/tests.py   
2010-09-13 05:46:59 UTC (rev 13834)
@@ -1,9 +1,46 @@
 from django.test import TestCase
 from django.db import connection
 from models import Unmanaged1, Unmanaged2, Managed1
+from models import A01, A02, B01, B02, C01, C02
 
+class SimpleTests(TestCase):
+
+def test_simple(self):
+"""
+The main test here is that the all the models can be created without
+any database errors. We can also do some more simple insertion and
+lookup tests whilst we're here to show that the second of models do
+refer to the tables from the first set.
+"""
+# Insert some data into one set of models.
+a = A01.objects.create(f_a="foo", f_b=42)
+B01.objects.create(fk_a=a, f_a="fred", f_b=1729)
+c = C01.objects.create(f_a="barney", f_b=1)
+c.mm_a = [a]
+
+# ... and pull it out via the other set.
+a2 = A02.objects.all()[0]
+self.assertTrue(isinstance(a2, A02))
+self.assertEqual(a2.f_a, "foo")
+
+b2 = B02.objects.all()[0]
+self.assertTrue(isinstance(b2, B02))
+self.assertEqual(b2.f_a, "fred")
+
+self.assertTrue(isinstance(b2.fk_a, A02))
+self.assertEqual(b2.fk_a.f_a, "foo")
+
+self.assertEqual(list(C02.objects.filter(f_a=None)), [])
+
+resp = list(C02.objects.filter(mm_a=a.id))
+self.assertEqual(len(resp), 1)
+
+self.assertTrue(isinstance(resp[0], C02))
+self.assertEqual(resp[0].f_a, 'barney')
+
+
 class ManyToManyUnmanagedTests(TestCase):
-
+
 def test_many_to_many_between_unmanaged(self):
 """
 The intermediary table between two unmanaged models should not be 
created.
@@ -11,7 +48,7 @@
 table = Unmanaged2._meta.get_field('mm').m2m_db_table()
 tables = connection.introspection.table_names()
 self.assert_(table not in tables, "Table '%s' should not exist, but it 
does." % table)
-
+
 def test_many_to_many_between_unmanaged_and_managed(self):
 """
 An intermediary table between a managed and an unmanaged model should 
be created.
@@ -19,4 +56,3 @@
 table = Managed1._meta.get_field('mm').m2m_db_table()
 tables = connection.introspection.table_names()
 self.assert_(table in tables, "Table '%s' does not exist." % table)
-
\ No newline at end of file

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13833 - django/branches/releases/1.2.X/tests/modeltests/update

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-13 00:46:46 -0500 (Mon, 13 Sep 2010)
New Revision: 13833

Modified:
   django/branches/releases/1.2.X/tests/modeltests/update/models.py
   django/branches/releases/1.2.X/tests/modeltests/update/tests.py
Log:
[1.2.X] Migrated the update doctests. Thanks to Eric Florenzano.

Backport of r13824 from trunk.

Modified: django/branches/releases/1.2.X/tests/modeltests/update/models.py
===
--- django/branches/releases/1.2.X/tests/modeltests/update/models.py
2010-09-13 05:46:34 UTC (rev 13832)
+++ django/branches/releases/1.2.X/tests/modeltests/update/models.py
2010-09-13 05:46:46 UTC (rev 13833)
@@ -33,59 +33,3 @@
 
 class D(C):
 a = models.ForeignKey(A)
-
-__test__ = {'API_TESTS': """
->>> DataPoint(name="d0", value="apple").save()
->>> DataPoint(name="d2", value="banana").save()
->>> d3 = DataPoint.objects.create(name="d3", value="banana")
->>> RelatedPoint(name="r1", data=d3).save()
-
-Objects are updated by first filtering the candidates into a queryset and then
-calling the update() method. It executes immediately and returns nothing.
-
->>> DataPoint.objects.filter(value="apple").update(name="d1")
-1
->>> DataPoint.objects.filter(value="apple")
-[]
-
-We can update multiple objects at once.
-
->>> DataPoint.objects.filter(value="banana").update(value="pineapple")
-2
->>> DataPoint.objects.get(name="d2").value
-u'pineapple'
-
-Foreign key fields can also be updated, although you can only update the object
-referred to, not anything inside the related object.
-
->>> d = DataPoint.objects.get(name="d1")
->>> RelatedPoint.objects.filter(name="r1").update(data=d)
-1
->>> RelatedPoint.objects.filter(data__name="d1")
-[]
-
-Multiple fields can be updated at once
-
->>> DataPoint.objects.filter(value="pineapple").update(value="fruit", 
another_value="peaches")
-2
->>> d = DataPoint.objects.get(name="d2")
->>> d.value, d.another_value
-(u'fruit', u'peaches')
-
-In the rare case you want to update every instance of a model, update() is also
-a manager method.
-
->>> DataPoint.objects.update(value='thing')
-3
->>> DataPoint.objects.values('value').distinct()
-[{'value': u'thing'}]
-
-We do not support update on already sliced query sets.
-
->>> DataPoint.objects.all()[:2].update(another_value='another thing')
-Traceback (most recent call last):
-...
-AssertionError: Cannot update a query once a slice has been taken.
-
-"""
-}

Modified: django/branches/releases/1.2.X/tests/modeltests/update/tests.py
===
--- django/branches/releases/1.2.X/tests/modeltests/update/tests.py 
2010-09-13 05:46:34 UTC (rev 13832)
+++ django/branches/releases/1.2.X/tests/modeltests/update/tests.py 
2010-09-13 05:46:46 UTC (rev 13833)
@@ -1,6 +1,6 @@
 from django.test import TestCase
 
-from models import A, B, D
+from models import A, B, C, D, DataPoint, RelatedPoint
 
 class SimpleTest(TestCase):
 def setUp(self):
@@ -47,3 +47,69 @@
 self.failUnlessEqual(num_updated, 0)
 cnt = D.objects.filter(y=100).count()
 self.failUnlessEqual(cnt, 0)
+
+class AdvancedTests(TestCase):
+
+def setUp(self):
+self.d0 = DataPoint.objects.create(name="d0", value="apple")
+self.d2 = DataPoint.objects.create(name="d2", value="banana")
+self.d3 = DataPoint.objects.create(name="d3", value="banana")
+self.r1 = RelatedPoint.objects.create(name="r1", data=self.d3)
+
+def test_update(self):
+"""
+Objects are updated by first filtering the candidates into a queryset
+and then calling the update() method. It executes immediately and
+returns nothing.
+"""
+resp = DataPoint.objects.filter(value="apple").update(name="d1")
+self.assertEqual(resp, 1)
+resp = DataPoint.objects.filter(value="apple")
+self.assertEqual(list(resp), [self.d0])
+
+def test_update_multiple_objects(self):
+"""
+We can update multiple objects at once.
+"""
+resp = DataPoint.objects.filter(value="banana").update(
+value="pineapple")
+self.assertEqual(resp, 2)
+self.assertEqual(DataPoint.objects.get(name="d2").value, u'pineapple')
+
+def test_update_fk(self):
+"""
+Foreign key fields can also be updated, although you can only update
+the object referred to, not anything inside the related object.
+"""
+resp = RelatedPoint.objects.filter(name="r1").update(data=self.d0)
+self.assertEqual(resp, 1)
+resp = RelatedPoint.objects.filter(data__name="d0")
+self.assertEqual(list(resp), [self.r1])
+
+def test_update_multiple_fields(self):
+"""
+Multiple fields can be updated at once
+"""
+resp = DataPoint.objects.filter(value="apple").update(
+value="fruit", another_value="peach")
+self.assertEqual(resp, 1)
+ 

[Changeset] r13832 - in django/branches/releases/1.2.X/tests/modeltests/user_commands: . management/commands

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-13 00:46:34 -0500 (Mon, 13 Sep 2010)
New Revision: 13832

Added:
   django/branches/releases/1.2.X/tests/modeltests/user_commands/tests.py
Modified:
   
django/branches/releases/1.2.X/tests/modeltests/user_commands/management/commands/dance.py
   django/branches/releases/1.2.X/tests/modeltests/user_commands/models.py
Log:
[1.2.X] Migrated user_commands doctests. Thanks to Eric Florenzano.

Backport of r13823 from trunk.

Modified: 
django/branches/releases/1.2.X/tests/modeltests/user_commands/management/commands/dance.py
===
--- 
django/branches/releases/1.2.X/tests/modeltests/user_commands/management/commands/dance.py
  2010-09-13 05:29:21 UTC (rev 13831)
+++ 
django/branches/releases/1.2.X/tests/modeltests/user_commands/management/commands/dance.py
  2010-09-13 05:46:34 UTC (rev 13832)
@@ -11,4 +11,4 @@
 ]
 
 def handle(self, *args, **options):
-print "I don't feel like dancing %s." % options["style"]
+self.stdout.write("I don't feel like dancing %s." % options["style"])

Modified: 
django/branches/releases/1.2.X/tests/modeltests/user_commands/models.py
===
--- django/branches/releases/1.2.X/tests/modeltests/user_commands/models.py 
2010-09-13 05:29:21 UTC (rev 13831)
+++ django/branches/releases/1.2.X/tests/modeltests/user_commands/models.py 
2010-09-13 05:46:34 UTC (rev 13832)
@@ -12,22 +12,3 @@
 ``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', style="Jive")
-I don't feel like dancing Jive.
-
-# Invoke a command that doesn't exist
->>> management.call_command('explode')
-Traceback (most recent call last):
-...
-CommandError: Unknown command: 'explode'
-
-# Invoke a command with default option `style`
->>> management.call_command('dance')
-I don't feel like dancing Rock'n'Roll.
-
-"""}

Added: django/branches/releases/1.2.X/tests/modeltests/user_commands/tests.py
===
--- django/branches/releases/1.2.X/tests/modeltests/user_commands/tests.py  
(rev 0)
+++ django/branches/releases/1.2.X/tests/modeltests/user_commands/tests.py  
2010-09-13 05:46:34 UTC (rev 13832)
@@ -0,0 +1,21 @@
+from StringIO import StringIO
+
+from django.test import TestCase
+from django.core import management
+from django.core.management.base import CommandError
+
+class CommandTests(TestCase):
+def test_command(self):
+out = StringIO()
+management.call_command('dance', stdout=out)
+self.assertEquals(out.getvalue(),
+"I don't feel like dancing Rock'n'Roll.")
+
+def test_command_style(self):
+out = StringIO()
+management.call_command('dance', style='Jive', stdout=out)
+self.assertEquals(out.getvalue(),
+"I don't feel like dancing Jive.")
+
+def test_explode(self):
+self.assertRaises(CommandError, management.call_command, ('explode',))
\ No newline at end of file

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #7836: django.test.client._session should check for session middleware instead

2010-09-12 Thread Django
#7836: django.test.client._session should check for session middleware instead
+---
  Reporter:  trevor | Owner:  nobody
Status:  new| Milestone:
 Component:  Testing framework  |   Version:  SVN   
Resolution: |  Keywords:
 Stage:  Accepted   | Has_patch:  0 
Needs_docs:  0  |   Needs_tests:  0 
Needs_better_patch:  0  |  
+---
Changes (by mtredinnick):

  * stage:  Design decision needed => Accepted

Comment:

 This looks like a reasonable request.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #11023: replace distutils by setuptools

2010-09-12 Thread Django
#11023: replace distutils by setuptools
-+--
  Reporter:  benoitc | Owner:  nobody
Status:  closed  | Milestone:
 Component:  Uncategorized   |   Version:  1.0   
Resolution:  wontfix |  Keywords:
 Stage:  Design decision needed  | Has_patch:  0 
Needs_docs:  0   |   Needs_tests:  0 
Needs_better_patch:  0   |  
-+--
Changes (by mtredinnick):

  * status:  new => closed
  * resolution:  => wontfix

Comment:

 Distutils is shipped with Python. Setuptools requires downloads from the
 net to work (or frequent updates of the base file). This isn't worth the
 pain.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #12826: Use __slots__ for some simple objects.

2010-09-12 Thread Django
#12826: Use __slots__ for some simple objects.
--+-
  Reporter:  sebastian_noack  | Owner:  nobody
Status:  new  | Milestone:
 Component:  Uncategorized|   Version:
Resolution:   |  Keywords:
 Stage:  Accepted | Has_patch:  1 
Needs_docs:  0|   Needs_tests:  0 
Needs_better_patch:  0|  
--+-
Changes (by mtredinnick):

  * stage:  Design decision needed => Accepted

Comment:

 Slots aren't really a hack, so much as a targeted optimisation for certain
 cases. They definitely aren't to be used indiscriminately, but can show
 benefits in small objects that are frequently created and never monkey-
 patched. The general direction of this ticket is worthwhile. I haven't
 seriously reviewed the implementation yet.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13829 - django/trunk/tests/modeltests/reverse_lookup

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-13 00:28:59 -0500 (Mon, 13 Sep 2010)
New Revision: 13829

Added:
   django/trunk/tests/modeltests/reverse_lookup/tests.py
Modified:
   django/trunk/tests/modeltests/reverse_lookup/models.py
Log:
Migrated reverse_lookup doctests. Thanks to Eric Florenzano

Modified: django/trunk/tests/modeltests/reverse_lookup/models.py
===
--- django/trunk/tests/modeltests/reverse_lookup/models.py  2010-09-13 
05:28:47 UTC (rev 13828)
+++ django/trunk/tests/modeltests/reverse_lookup/models.py  2010-09-13 
05:28:59 UTC (rev 13829)
@@ -26,34 +26,3 @@
 
 def __unicode__(self):
 return self.name
-
-__test__ = {'API_TESTS':"""
->>> john = User(name="John Doe")
->>> john.save()
->>> jim = User(name="Jim Bo")
->>> jim.save()
->>> first_poll = Poll(question="What's the first question?", creator=john)
->>> first_poll.save()
->>> second_poll = Poll(question="What's the second question?", creator=jim)
->>> second_poll.save()
->>> new_choice = Choice(poll=first_poll, related_poll=second_poll, name="This 
is the answer.")
->>> new_choice.save()
-
->>> # Reverse lookups by field name:
->>> User.objects.get(poll__question__exact="What's the first question?")
-
->>> User.objects.get(poll__question__exact="What's the second question?")
-
-
->>> # Reverse lookups by related_name:
->>> Poll.objects.get(poll_choice__name__exact="This is the answer.")
-
->>> Poll.objects.get(related_choice__name__exact="This is the answer.")
-
-
->>> # If a related_name is given you can't use the field name instead:
->>> Poll.objects.get(choice__name__exact="This is the answer")
-Traceback (most recent call last):
-...
-FieldError: Cannot resolve keyword 'choice' into field. Choices are: creator, 
id, poll_choice, question, related_choice
-"""}

Added: django/trunk/tests/modeltests/reverse_lookup/tests.py
===
--- django/trunk/tests/modeltests/reverse_lookup/tests.py   
(rev 0)
+++ django/trunk/tests/modeltests/reverse_lookup/tests.py   2010-09-13 
05:28:59 UTC (rev 13829)
@@ -0,0 +1,49 @@
+from django.test import TestCase
+from django.core.exceptions import FieldError
+
+from models import User, Poll, Choice
+
+class ReverseLookupTests(TestCase):
+
+def setUp(self):
+john = User.objects.create(name="John Doe")
+jim = User.objects.create(name="Jim Bo")
+first_poll = Poll.objects.create(
+question="What's the first question?",
+creator=john
+)
+second_poll = Poll.objects.create(
+question="What's the second question?",
+creator=jim
+)
+new_choice = Choice.objects.create(
+poll=first_poll,
+related_poll=second_poll,
+name="This is the answer."
+)
+
+def test_reverse_by_field(self):
+u1 = User.objects.get(
+poll__question__exact="What's the first question?"
+)
+self.assertEqual(u1.name, "John Doe")
+
+u2 = User.objects.get(
+poll__question__exact="What's the second question?"
+)
+self.assertEqual(u2.name, "Jim Bo")
+
+def test_reverse_by_related_name(self):
+p1 = Poll.objects.get(poll_choice__name__exact="This is the answer.")
+self.assertEqual(p1.question, "What's the first question?")
+
+p2 = Poll.objects.get(
+related_choice__name__exact="This is the answer.")
+self.assertEqual(p2.question, "What's the second question?")
+
+def test_reverse_field_name_disallowed(self):
+"""
+If a related_name is given you can't use the field name instead
+"""
+self.assertRaises(FieldError, Poll.objects.get,
+choice__name__exact="This is the answer")

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13831 - django/trunk/tests/modeltests/proxy_models

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-13 00:29:21 -0500 (Mon, 13 Sep 2010)
New Revision: 13831

Added:
   django/trunk/tests/modeltests/proxy_models/tests.py
Modified:
   django/trunk/tests/modeltests/proxy_models/models.py
Log:
Migrated proxy_models doctests. Thanks to Eric Florenzano.

Modified: django/trunk/tests/modeltests/proxy_models/models.py
===
--- django/trunk/tests/modeltests/proxy_models/models.py2010-09-13 
05:29:09 UTC (rev 13830)
+++ django/trunk/tests/modeltests/proxy_models/models.py2010-09-13 
05:29:21 UTC (rev 13831)
@@ -161,232 +161,4 @@
 
 class ProxyImprovement(Improvement):
 class Meta:
-proxy = True
-
-__test__ = {'API_TESTS' : """
-# The MyPerson model should be generating the same database queries as the
-# Person model (when the same manager is used in each case).
->>> from django.db import DEFAULT_DB_ALIAS
->>> MyPerson.other.all().query.get_compiler(DEFAULT_DB_ALIAS).as_sql() == 
Person.objects.order_by("name").query.get_compiler(DEFAULT_DB_ALIAS).as_sql()
-True
-
-# The StatusPerson models should have its own table (it's using ORM-level
-# inheritance).
->>> StatusPerson.objects.all().query.get_compiler(DEFAULT_DB_ALIAS).as_sql() 
== Person.objects.all().query.get_compiler(DEFAULT_DB_ALIAS).as_sql()
-False
-
-# Creating a Person makes them accessible through the MyPerson proxy.
->>> _ = Person.objects.create(name="Foo McBar")
->>> len(Person.objects.all())
-1
->>> len(MyPerson.objects.all())
-1
->>> MyPerson.objects.get(name="Foo McBar").id
-1
->>> MyPerson.objects.get(id=1).has_special_name()
-False
-
-# Person is not proxied by StatusPerson subclass, however.
->>> StatusPerson.objects.all()
-[]
-
-# A new MyPerson also shows up as a standard Person
->>> _ = MyPerson.objects.create(name="Bazza del Frob")
->>> len(MyPerson.objects.all())
-2
->>> len(Person.objects.all())
-2
-
->>> _ = LowerStatusPerson.objects.create(status="low", name="homer")
->>> LowerStatusPerson.objects.all()
-[]
-
-# Correct type when querying a proxy of proxy
-
->>> MyPersonProxy.objects.all()
-[, , ]
-
-# Proxy models are included in the ancestors for a model's DoesNotExist and 
MultipleObjectsReturned
->>> try:
-... MyPersonProxy.objects.get(name='Zathras')
-... except Person.DoesNotExist:
-... pass
->>> try:
-... MyPersonProxy.objects.get(id__lt=10)
-... except Person.MultipleObjectsReturned:
-... pass
->>> try:
-... StatusPerson.objects.get(name='Zathras')
-... except Person.DoesNotExist:
-... pass
->>> sp1 = StatusPerson.objects.create(name='Bazza Jr.')
->>> sp2 = StatusPerson.objects.create(name='Foo Jr.')
->>> try:
-... StatusPerson.objects.get(id__lt=10)
-... except Person.MultipleObjectsReturned:
-... pass
-
-# And now for some things that shouldn't work...
-#
-# All base classes must be non-abstract
->>> class NoAbstract(Abstract):
-... class Meta:
-... proxy = True
-Traceback (most recent call last):
-
-TypeError: Abstract base class containing model fields not permitted for proxy 
model 'NoAbstract'.
-
-# The proxy must actually have one concrete base class
->>> class TooManyBases(Person, Abstract):
-... class Meta:
-... proxy = True
-Traceback (most recent call last):
-
-TypeError: Abstract base class containing model fields not permitted for proxy 
model 'TooManyBases'.
-
->>> class NoBaseClasses(models.Model):
-... class Meta:
-... proxy = True
-Traceback (most recent call last):
-
-TypeError: Proxy model 'NoBaseClasses' has no non-abstract model base class.
-
-
-# A proxy cannot introduce any new fields
->>> class NoNewFields(Person):
-... newfield = models.BooleanField()
-... class Meta:
-... proxy = True
-Traceback (most recent call last):
-
-FieldError: Proxy model 'NoNewFields' contains model fields.
-
-# Manager tests.
-
->>> Person.objects.all().delete()
->>> _ = Person.objects.create(name="fred")
->>> _ = Person.objects.create(name="wilma")
->>> _ = Person.objects.create(name="barney")
-
->>> MyPerson.objects.all()
-[, ]
->>> MyPerson._default_manager.all()
-[, ]
-
->>> OtherPerson.objects.all()
-[, ]
->>> OtherPerson.excluder.all()
-[, ]
->>> OtherPerson._default_manager.all()
-[, ]
-
-# Test save signals for proxy models
->>> from django.db.models import signals
->>> def make_handler(model, event):
-... def _handler(*args, **kwargs):
-... print u"%s %s save" % (model, event)
-... return _handler
->>> h1 = make_handler('MyPerson', 'pre')
->>> h2 = make_handler('MyPerson', 'post')
->>> h3 = make_handler('Person', 'pre')
->>> h4 = make_handler('Person', 'post')
->>> signals.pre_save.connect(h1, sender=MyPerson)
->>> signals.post_save.connect(h2, sender=MyPerson)
->>> signals.pre_save.connect(h3, sender=Person)
->>> signals.post_save.connect(h4, sender=Person)
->>> dino = MyPerson.objects.create(name=u"dino")
-MyPerson pre save
-MyPerson post save
-
-# Test save 

[Changeset] r13830 - django/trunk/tests/modeltests/reserved_names

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-13 00:29:09 -0500 (Mon, 13 Sep 2010)
New Revision: 13830

Added:
   django/trunk/tests/modeltests/reserved_names/tests.py
Modified:
   django/trunk/tests/modeltests/reserved_names/models.py
Log:
Migrated reserved_names doctests. Thanks to Eric Florenzano.

Modified: django/trunk/tests/modeltests/reserved_names/models.py
===
--- django/trunk/tests/modeltests/reserved_names/models.py  2010-09-13 
05:28:59 UTC (rev 13829)
+++ django/trunk/tests/modeltests/reserved_names/models.py  2010-09-13 
05:29:09 UTC (rev 13830)
@@ -22,33 +22,4 @@
db_table = 'select'
 
 def __unicode__(self):
-return self.when
-
-__test__ = {'API_TESTS':"""
->>> import datetime
->>> day1 = datetime.date(2005, 1, 1)
->>> day2 = datetime.date(2006, 2, 2)
->>> t = Thing(when='a', join='b', like='c', drop='d', alter='e', having='f', 
where=day1, has_hyphen='h')
->>> t.save()
->>> print t.when
-a
-
->>> u = Thing(when='h', join='i', like='j', drop='k', alter='l', having='m', 
where=day2)
->>> u.save()
->>> print u.when
-h
-
->>> Thing.objects.order_by('when')
-[, ]
->>> v = Thing.objects.get(pk='a')
->>> print v.join
-b
->>> print v.where
-2005-01-01
-
->>> Thing.objects.dates('where', 'year')
-[datetime.datetime(2005, 1, 1, 0, 0), datetime.datetime(2006, 1, 1, 0, 0)]
-
->>> Thing.objects.filter(where__month=1)
-[]
-"""}
+return self.when
\ No newline at end of file

Added: django/trunk/tests/modeltests/reserved_names/tests.py
===
--- django/trunk/tests/modeltests/reserved_names/tests.py   
(rev 0)
+++ django/trunk/tests/modeltests/reserved_names/tests.py   2010-09-13 
05:29:09 UTC (rev 13830)
@@ -0,0 +1,48 @@
+import datetime
+
+from django.test import TestCase
+
+from models import Thing
+
+class ReservedNameTests(TestCase):
+def generate(self):
+day1 = datetime.date(2005, 1, 1)
+t = Thing.objects.create(when='a', join='b', like='c', drop='d',
+alter='e', having='f', where=day1, has_hyphen='h')
+day2 = datetime.date(2006, 2, 2)
+u = Thing.objects.create(when='h', join='i', like='j', drop='k',
+alter='l', having='m', where=day2)
+
+def test_simple(self):
+day1 = datetime.date(2005, 1, 1)
+t = Thing.objects.create(when='a', join='b', like='c', drop='d',
+alter='e', having='f', where=day1, has_hyphen='h')
+self.assertEqual(t.when, 'a')
+
+day2 = datetime.date(2006, 2, 2)
+u = Thing.objects.create(when='h', join='i', like='j', drop='k',
+alter='l', having='m', where=day2)
+self.assertEqual(u.when, 'h')
+
+def test_order_by(self):
+self.generate()
+things = [t.when for t in Thing.objects.order_by('when')]
+self.assertEqual(things, ['a', 'h'])
+
+def test_fields(self):
+self.generate()
+v = Thing.objects.get(pk='a')
+self.assertEqual(v.join, 'b')
+self.assertEqual(v.where, datetime.date(year=2005, month=1, day=1))
+
+def test_dates(self):
+self.generate()
+resp = Thing.objects.dates('where', 'year')
+self.assertEqual(list(resp), [
+datetime.datetime(2005, 1, 1, 0, 0),
+datetime.datetime(2006, 1, 1, 0, 0),
+])
+
+def test_month_filter(self):
+self.generate()
+self.assertEqual(Thing.objects.filter(where__month=1)[0].when, 'a')

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13828 - django/trunk/tests/modeltests/select_related

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-13 00:28:47 -0500 (Mon, 13 Sep 2010)
New Revision: 13828

Added:
   django/trunk/tests/modeltests/select_related/tests.py
Modified:
   django/trunk/tests/modeltests/select_related/models.py
Log:
Migrated select_related doctests. Thanks to Eric Florenzano.

Modified: django/trunk/tests/modeltests/select_related/models.py
===
--- django/trunk/tests/modeltests/select_related/models.py  2010-09-13 
05:28:38 UTC (rev 13827)
+++ django/trunk/tests/modeltests/select_related/models.py  2010-09-13 
05:28:47 UTC (rev 13828)
@@ -56,134 +56,4 @@
 name = models.CharField(max_length=50)
 genus = models.ForeignKey(Genus)
 def __unicode__(self):
-return self.name
-
-def create_tree(stringtree):
-"""Helper to create a complete tree"""
-names = stringtree.split()
-models = [Domain, Kingdom, Phylum, Klass, Order, Family, Genus, Species]
-assert len(names) == len(models), (names, models)
-
-parent = None
-for name, model in zip(names, models):
-try:
-obj = model.objects.get(name=name)
-except model.DoesNotExist:
-obj = model(name=name)
-if parent:
-setattr(obj, parent.__class__.__name__.lower(), parent)
-obj.save()
-parent = obj
-
-__test__ = {'API_TESTS':"""
-
-# Set up.
-# The test runner sets settings.DEBUG to False, but we want to gather queries
-# so we'll set it to True here and reset it at the end of the test suite.
->>> from django.conf import settings
->>> settings.DEBUG = True
-
->>> create_tree("Eukaryota Animalia Anthropoda Insecta Diptera Drosophilidae 
Drosophila melanogaster")
->>> create_tree("Eukaryota Animalia Chordata Mammalia Primates Hominidae Homo 
sapiens")
->>> create_tree("Eukaryota Plantae Magnoliophyta Magnoliopsida Fabales 
Fabaceae Pisum sativum")
->>> create_tree("Eukaryota Fungi Basidiomycota Homobasidiomycatae Agaricales 
Amanitacae Amanita muscaria")
-
->>> from django import db
-
-# Normally, accessing FKs doesn't fill in related objects:
->>> db.reset_queries()
->>> fly = Species.objects.get(name="melanogaster")
->>> fly.genus.family.order.klass.phylum.kingdom.domain
-
->>> len(db.connection.queries)
-8
-
-# However, a select_related() call will fill in those related objects without 
any extra queries:
->>> db.reset_queries()
->>> person = Species.objects.select_related(depth=10).get(name="sapiens")
->>> person.genus.family.order.klass.phylum.kingdom.domain
-
->>> len(db.connection.queries)
-1
-
-# select_related() also of course applies to entire lists, not just items.
-# Without select_related()
->>> db.reset_queries()
->>> world = Species.objects.all()
->>> [o.genus.family for o in world]
-[, , , ]
->>> len(db.connection.queries)
-9
-
-# With select_related():
->>> db.reset_queries()
->>> world = Species.objects.all().select_related()
->>> [o.genus.family for o in world]
-[, , , ]
->>> len(db.connection.queries)
-1
-
-# The "depth" argument to select_related() will stop the descent at a 
particular level:
->>> db.reset_queries()
->>> pea = Species.objects.select_related(depth=1).get(name="sativum")
->>> pea.genus.family.order.klass.phylum.kingdom.domain
-
-
-# Notice: one fewer queries than above because of depth=1
->>> len(db.connection.queries)
-7
-
->>> db.reset_queries()
->>> pea = Species.objects.select_related(depth=5).get(name="sativum")
->>> pea.genus.family.order.klass.phylum.kingdom.domain
-
->>> len(db.connection.queries)
-3
-
->>> db.reset_queries()
->>> world = Species.objects.all().select_related(depth=2)
->>> [o.genus.family.order for o in world]
-[, , , ]
->>> len(db.connection.queries)
-5
-
->>> s = Species.objects.all().select_related(depth=1).extra(select={'a': 
'select_related_species.id + 10'})[0]
->>> s.id + 10 == s.a
-True
-
-# The optional fields passed to select_related() control which related models
-# we pull in. This allows for smaller queries and can act as an alternative
-# (or, in addition to) the depth parameter.
-
-# In the next two cases, we explicitly say to select the 'genus' and
-# 'genus.family' models, leading to the same number of queries as before.
->>> db.reset_queries()
->>> world = Species.objects.select_related('genus__family')
->>> [o.genus.family for o in world]
-[, , , ]
->>> len(db.connection.queries)
-1
-
->>> db.reset_queries()
->>> world = 
Species.objects.filter(genus__name='Amanita').select_related('genus__family')
->>> [o.genus.family.order for o in world]
-[]
->>> len(db.connection.queries)
-2
-
->>> db.reset_queries()
->>> 
Species.objects.all().select_related('genus__family__order').order_by('id')[0:1].get().genus.family.order.name
-u'Diptera'
->>> len(db.connection.queries)
-1
-
-# Specifying both "depth" and fields is an error.
->>> Species.objects.select_related('genus__family__order', depth=4)
-Traceback (most recent call last):
-...
-TypeError: Cannot pass both "depth" and fields to select_related()
-
-# 

[Changeset] r13827 - django/trunk/tests/modeltests/str

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-13 00:28:38 -0500 (Mon, 13 Sep 2010)
New Revision: 13827

Added:
   django/trunk/tests/modeltests/str/tests.py
Modified:
   django/trunk/tests/modeltests/str/models.py
Log:
Migrated str doctests. Thanks to Eric Florenzano.

Modified: django/trunk/tests/modeltests/str/models.py
===
--- django/trunk/tests/modeltests/str/models.py 2010-09-13 05:28:29 UTC (rev 
13826)
+++ django/trunk/tests/modeltests/str/models.py 2010-09-13 05:28:38 UTC (rev 
13827)
@@ -30,23 +30,4 @@
 pub_date = models.DateTimeField()
 
 def __unicode__(self):
-return self.headline
-
-__test__ = {'API_TESTS':ur"""
-# Create an Article.
->>> from datetime import datetime
->>> a = Article(headline='Area man programs in Python', 
pub_date=datetime(2005, 7, 28))
->>> a.save()
-
->>> str(a)
-'Area man programs in Python'
-
->>> a
-
-
->>> a1 = InternationalArticle(headline=u'Girl wins €12.500 in lottery', 
pub_date=datetime(2005, 7, 28))
-
-# The default str() output will be the UTF-8 encoded output of __unicode__().
->>> str(a1)
-'Girl wins \xe2\x82\xac12.500 in lottery'
-"""}
+return self.headline
\ No newline at end of file

Added: django/trunk/tests/modeltests/str/tests.py
===
--- django/trunk/tests/modeltests/str/tests.py  (rev 0)
+++ django/trunk/tests/modeltests/str/tests.py  2010-09-13 05:28:38 UTC (rev 
13827)
@@ -0,0 +1,23 @@
+ # -*- coding: utf-8 -*-
+import datetime
+
+from django.test import TestCase
+
+from models import Article, InternationalArticle
+
+class SimpleTests(TestCase):
+def test_basic(self):
+a = Article.objects.create(
+headline='Area man programs in Python',
+pub_date=datetime.datetime(2005, 7, 28)
+)
+self.assertEqual(str(a), 'Area man programs in Python')
+self.assertEqual(repr(a), '')
+
+def test_international(self):
+a = InternationalArticle.objects.create(
+headline=u'Girl wins €12.500 in lottery',
+pub_date=datetime.datetime(2005, 7, 28)
+)
+# The default str() output will be the UTF-8 encoded output of 
__unicode__().
+self.assertEqual(str(a), 'Girl wins \xe2\x82\xac12.500 in lottery')
\ No newline at end of file

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13826 - django/trunk/tests/modeltests/transactions

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-13 00:28:29 -0500 (Mon, 13 Sep 2010)
New Revision: 13826

Added:
   django/trunk/tests/modeltests/transactions/tests.py
Modified:
   django/trunk/tests/modeltests/transactions/models.py
Log:
Migrated transactions doctests. Thanks to Eric Florenzano.

Modified: django/trunk/tests/modeltests/transactions/models.py
===
--- django/trunk/tests/modeltests/transactions/models.py2010-09-13 
05:28:18 UTC (rev 13825)
+++ django/trunk/tests/modeltests/transactions/models.py2010-09-13 
05:28:29 UTC (rev 13826)
@@ -18,138 +18,4 @@
 ordering = ('first_name', 'last_name')
 
 def __unicode__(self):
-return u"%s %s" % (self.first_name, self.last_name)
-
-__test__ = {'API_TESTS':"""
->>> from django.db import connection, transaction
-"""}
-
-from django.conf import settings
-
-building_docs = getattr(settings, 'BUILDING_DOCS', False)
-
-if building_docs or settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'] != 
'django.db.backends.mysql':
-__test__['API_TESTS'] += """
-# the default behavior is to autocommit after each save() action
->>> def create_a_reporter_then_fail(first, last):
-... a = Reporter(first_name=first, last_name=last)
-... a.save()
-... raise Exception("I meant to do that")
-...
->>> create_a_reporter_then_fail("Alice", "Smith")
-Traceback (most recent call last):
-...
-Exception: I meant to do that
-
-# The object created before the exception still exists
->>> Reporter.objects.all()
-[]
-
-# the autocommit decorator works exactly the same as the default behavior
->>> autocomitted_create_then_fail = 
transaction.autocommit(create_a_reporter_then_fail)
->>> autocomitted_create_then_fail("Ben", "Jones")
-Traceback (most recent call last):
-...
-Exception: I meant to do that
-
-# Same behavior as before
->>> Reporter.objects.all()
-[, ]
-
-# the autocommit decorator also works with a using argument
->>> using_autocomitted_create_then_fail = 
transaction.autocommit(using='default')(create_a_reporter_then_fail)
->>> using_autocomitted_create_then_fail("Carol", "Doe")
-Traceback (most recent call last):
-...
-Exception: I meant to do that
-
-# Same behavior as before
->>> Reporter.objects.all()
-[, , ]
-
-# With the commit_on_success decorator, the transaction is only committed if 
the
-# function doesn't throw an exception
->>> committed_on_success = 
transaction.commit_on_success(create_a_reporter_then_fail)
->>> committed_on_success("Dirk", "Gently")
-Traceback (most recent call last):
-...
-Exception: I meant to do that
-
-# This time the object never got saved
->>> Reporter.objects.all()
-[, , ]
-
-# commit_on_success decorator also works with a using argument
->>> using_committed_on_success = 
transaction.commit_on_success(using='default')(create_a_reporter_then_fail)
->>> using_committed_on_success("Dirk", "Gently")
-Traceback (most recent call last):
-...
-Exception: I meant to do that
-
-# This time the object never got saved
->>> Reporter.objects.all()
-[, , ]
-
-# If there aren't any exceptions, the data will get saved
->>> def remove_a_reporter():
-... r = Reporter.objects.get(first_name="Alice")
-... r.delete()
-...
->>> remove_comitted_on_success = 
transaction.commit_on_success(remove_a_reporter)
->>> remove_comitted_on_success()
->>> Reporter.objects.all()
-[, ]
-
-# You can manually manage transactions if you really want to, but you
-# have to remember to commit/rollback
->>> def manually_managed():
-... r = Reporter(first_name="Dirk", last_name="Gently")
-... r.save()
-... transaction.commit()
->>> manually_managed = transaction.commit_manually(manually_managed)
->>> manually_managed()
->>> Reporter.objects.all()
-[, , ]
-
-# If you forget, you'll get bad errors
->>> def manually_managed_mistake():
-... r = Reporter(first_name="Edward", last_name="Woodward")
-... r.save()
-... # oops, I forgot to commit/rollback!
->>> manually_managed_mistake = 
transaction.commit_manually(manually_managed_mistake)
->>> manually_managed_mistake()
-Traceback (most recent call last):
-...
-TransactionManagementError: Transaction managed block ended with pending 
COMMIT/ROLLBACK
-
-# commit_manually also works with a using argument
->>> using_manually_managed_mistake = 
transaction.commit_manually(using='default')(manually_managed_mistake)
->>> using_manually_managed_mistake()
-Traceback (most recent call last):
-...
-TransactionManagementError: Transaction managed block ended with pending 
COMMIT/ROLLBACK
-
-"""
-
-# Regression for #11900: If a function wrapped by commit_on_success writes a
-# transaction that can't be committed, that transaction should be rolled back.
-# The bug is only visible using the psycopg2 backend, though
-# the fix is generally a good idea.
-pgsql_backends = ('django.db.backends.postgresql_psycopg2', 
'postgresql_psycopg2',)
-if building_docs or 

[Changeset] r13825 - django/trunk/tests/modeltests/unmanaged_models

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-13 00:28:18 -0500 (Mon, 13 Sep 2010)
New Revision: 13825

Modified:
   django/trunk/tests/modeltests/unmanaged_models/models.py
   django/trunk/tests/modeltests/unmanaged_models/tests.py
Log:
Migrated unmanaged_models doctests. Thanks to Eric Florenzano.

Modified: django/trunk/tests/modeltests/unmanaged_models/models.py
===
--- django/trunk/tests/modeltests/unmanaged_models/models.py2010-09-13 
05:28:10 UTC (rev 13824)
+++ django/trunk/tests/modeltests/unmanaged_models/models.py2010-09-13 
05:28:18 UTC (rev 13825)
@@ -123,30 +123,3 @@
 # table *will* be created (unless given a custom `through` as for C02 above).
 class Managed1(models.Model):
 mm = models.ManyToManyField(Unmanaged1)
-
-__test__ = {'API_TESTS':"""
-The main test here is that the all the models can be created without any
-database errors. We can also do some more simple insertion and lookup tests
-whilst we're here to show that the second of models do refer to the tables from
-the first set.
-
-# Insert some data into one set of models.
->>> a = A01.objects.create(f_a="foo", f_b=42)
->>> _ = B01.objects.create(fk_a=a, f_a="fred", f_b=1729)
->>> c = C01.objects.create(f_a="barney", f_b=1)
->>> c.mm_a = [a]
-
-# ... and pull it out via the other set.
->>> A02.objects.all()
-[]
->>> b = B02.objects.all()[0]
->>> b
-
->>> b.fk_a
-
->>> C02.objects.filter(f_a=None)
-[]
->>> C02.objects.filter(mm_a=a.id)
-[]
-
-"""}

Modified: django/trunk/tests/modeltests/unmanaged_models/tests.py
===
--- django/trunk/tests/modeltests/unmanaged_models/tests.py 2010-09-13 
05:28:10 UTC (rev 13824)
+++ django/trunk/tests/modeltests/unmanaged_models/tests.py 2010-09-13 
05:28:18 UTC (rev 13825)
@@ -1,9 +1,46 @@
 from django.test import TestCase
 from django.db import connection
 from models import Unmanaged1, Unmanaged2, Managed1
+from models import A01, A02, B01, B02, C01, C02
 
+class SimpleTests(TestCase):
+
+def test_simple(self):
+"""
+The main test here is that the all the models can be created without
+any database errors. We can also do some more simple insertion and
+lookup tests whilst we're here to show that the second of models do
+refer to the tables from the first set.
+"""
+# Insert some data into one set of models.
+a = A01.objects.create(f_a="foo", f_b=42)
+B01.objects.create(fk_a=a, f_a="fred", f_b=1729)
+c = C01.objects.create(f_a="barney", f_b=1)
+c.mm_a = [a]
+
+# ... and pull it out via the other set.
+a2 = A02.objects.all()[0]
+self.assertTrue(isinstance(a2, A02))
+self.assertEqual(a2.f_a, "foo")
+
+b2 = B02.objects.all()[0]
+self.assertTrue(isinstance(b2, B02))
+self.assertEqual(b2.f_a, "fred")
+
+self.assertTrue(isinstance(b2.fk_a, A02))
+self.assertEqual(b2.fk_a.f_a, "foo")
+
+self.assertEqual(list(C02.objects.filter(f_a=None)), [])
+
+resp = list(C02.objects.filter(mm_a=a.id))
+self.assertEqual(len(resp), 1)
+
+self.assertTrue(isinstance(resp[0], C02))
+self.assertEqual(resp[0].f_a, 'barney')
+
+
 class ManyToManyUnmanagedTests(TestCase):
-
+
 def test_many_to_many_between_unmanaged(self):
 """
 The intermediary table between two unmanaged models should not be 
created.
@@ -11,7 +48,7 @@
 table = Unmanaged2._meta.get_field('mm').m2m_db_table()
 tables = connection.introspection.table_names()
 self.assert_(table not in tables, "Table '%s' should not exist, but it 
does." % table)
-
+
 def test_many_to_many_between_unmanaged_and_managed(self):
 """
 An intermediary table between a managed and an unmanaged model should 
be created.
@@ -19,4 +56,3 @@
 table = Managed1._meta.get_field('mm').m2m_db_table()
 tables = connection.introspection.table_names()
 self.assert_(table in tables, "Table '%s' does not exist." % table)
-
\ No newline at end of file

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13824 - django/trunk/tests/modeltests/update

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-13 00:28:10 -0500 (Mon, 13 Sep 2010)
New Revision: 13824

Modified:
   django/trunk/tests/modeltests/update/models.py
   django/trunk/tests/modeltests/update/tests.py
Log:
Migrated the update doctests. Thanks to Eric Florenzano.

Modified: django/trunk/tests/modeltests/update/models.py
===
--- django/trunk/tests/modeltests/update/models.py  2010-09-13 05:28:01 UTC 
(rev 13823)
+++ django/trunk/tests/modeltests/update/models.py  2010-09-13 05:28:10 UTC 
(rev 13824)
@@ -33,59 +33,3 @@
 
 class D(C):
 a = models.ForeignKey(A)
-
-__test__ = {'API_TESTS': """
->>> DataPoint(name="d0", value="apple").save()
->>> DataPoint(name="d2", value="banana").save()
->>> d3 = DataPoint.objects.create(name="d3", value="banana")
->>> RelatedPoint(name="r1", data=d3).save()
-
-Objects are updated by first filtering the candidates into a queryset and then
-calling the update() method. It executes immediately and returns nothing.
-
->>> DataPoint.objects.filter(value="apple").update(name="d1")
-1
->>> DataPoint.objects.filter(value="apple")
-[]
-
-We can update multiple objects at once.
-
->>> DataPoint.objects.filter(value="banana").update(value="pineapple")
-2
->>> DataPoint.objects.get(name="d2").value
-u'pineapple'
-
-Foreign key fields can also be updated, although you can only update the object
-referred to, not anything inside the related object.
-
->>> d = DataPoint.objects.get(name="d1")
->>> RelatedPoint.objects.filter(name="r1").update(data=d)
-1
->>> RelatedPoint.objects.filter(data__name="d1")
-[]
-
-Multiple fields can be updated at once
-
->>> DataPoint.objects.filter(value="pineapple").update(value="fruit", 
another_value="peaches")
-2
->>> d = DataPoint.objects.get(name="d2")
->>> d.value, d.another_value
-(u'fruit', u'peaches')
-
-In the rare case you want to update every instance of a model, update() is also
-a manager method.
-
->>> DataPoint.objects.update(value='thing')
-3
->>> DataPoint.objects.values('value').distinct()
-[{'value': u'thing'}]
-
-We do not support update on already sliced query sets.
-
->>> DataPoint.objects.all()[:2].update(another_value='another thing')
-Traceback (most recent call last):
-...
-AssertionError: Cannot update a query once a slice has been taken.
-
-"""
-}

Modified: django/trunk/tests/modeltests/update/tests.py
===
--- django/trunk/tests/modeltests/update/tests.py   2010-09-13 05:28:01 UTC 
(rev 13823)
+++ django/trunk/tests/modeltests/update/tests.py   2010-09-13 05:28:10 UTC 
(rev 13824)
@@ -1,6 +1,6 @@
 from django.test import TestCase
 
-from models import A, B, D
+from models import A, B, C, D, DataPoint, RelatedPoint
 
 class SimpleTest(TestCase):
 def setUp(self):
@@ -47,3 +47,69 @@
 self.failUnlessEqual(num_updated, 0)
 cnt = D.objects.filter(y=100).count()
 self.failUnlessEqual(cnt, 0)
+
+class AdvancedTests(TestCase):
+
+def setUp(self):
+self.d0 = DataPoint.objects.create(name="d0", value="apple")
+self.d2 = DataPoint.objects.create(name="d2", value="banana")
+self.d3 = DataPoint.objects.create(name="d3", value="banana")
+self.r1 = RelatedPoint.objects.create(name="r1", data=self.d3)
+
+def test_update(self):
+"""
+Objects are updated by first filtering the candidates into a queryset
+and then calling the update() method. It executes immediately and
+returns nothing.
+"""
+resp = DataPoint.objects.filter(value="apple").update(name="d1")
+self.assertEqual(resp, 1)
+resp = DataPoint.objects.filter(value="apple")
+self.assertEqual(list(resp), [self.d0])
+
+def test_update_multiple_objects(self):
+"""
+We can update multiple objects at once.
+"""
+resp = DataPoint.objects.filter(value="banana").update(
+value="pineapple")
+self.assertEqual(resp, 2)
+self.assertEqual(DataPoint.objects.get(name="d2").value, u'pineapple')
+
+def test_update_fk(self):
+"""
+Foreign key fields can also be updated, although you can only update
+the object referred to, not anything inside the related object.
+"""
+resp = RelatedPoint.objects.filter(name="r1").update(data=self.d0)
+self.assertEqual(resp, 1)
+resp = RelatedPoint.objects.filter(data__name="d0")
+self.assertEqual(list(resp), [self.r1])
+
+def test_update_multiple_fields(self):
+"""
+Multiple fields can be updated at once
+"""
+resp = DataPoint.objects.filter(value="apple").update(
+value="fruit", another_value="peach")
+self.assertEqual(resp, 1)
+d = DataPoint.objects.get(name="d0")
+self.assertEqual(d.value, u'fruit')
+self.assertEqual(d.another_value, u'peach')
+
+def test_update_all(self):
+   

[Changeset] r13823 - in django/trunk/tests/modeltests/user_commands: . management/commands

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-13 00:28:01 -0500 (Mon, 13 Sep 2010)
New Revision: 13823

Added:
   django/trunk/tests/modeltests/user_commands/tests.py
Modified:
   django/trunk/tests/modeltests/user_commands/management/commands/dance.py
   django/trunk/tests/modeltests/user_commands/models.py
Log:
Migrated user_commands doctests. Thanks to Eric Florenzano.

Modified: 
django/trunk/tests/modeltests/user_commands/management/commands/dance.py
===
--- django/trunk/tests/modeltests/user_commands/management/commands/dance.py
2010-09-13 05:08:24 UTC (rev 13822)
+++ django/trunk/tests/modeltests/user_commands/management/commands/dance.py
2010-09-13 05:28:01 UTC (rev 13823)
@@ -11,4 +11,4 @@
 ]
 
 def handle(self, *args, **options):
-print "I don't feel like dancing %s." % options["style"]
+self.stdout.write("I don't feel like dancing %s." % options["style"])

Modified: django/trunk/tests/modeltests/user_commands/models.py
===
--- django/trunk/tests/modeltests/user_commands/models.py   2010-09-13 
05:08:24 UTC (rev 13822)
+++ django/trunk/tests/modeltests/user_commands/models.py   2010-09-13 
05:28:01 UTC (rev 13823)
@@ -12,22 +12,3 @@
 ``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', style="Jive")
-I don't feel like dancing Jive.
-
-# Invoke a command that doesn't exist
->>> management.call_command('explode')
-Traceback (most recent call last):
-...
-CommandError: Unknown command: 'explode'
-
-# Invoke a command with default option `style`
->>> management.call_command('dance')
-I don't feel like dancing Rock'n'Roll.
-
-"""}

Added: django/trunk/tests/modeltests/user_commands/tests.py
===
--- django/trunk/tests/modeltests/user_commands/tests.py
(rev 0)
+++ django/trunk/tests/modeltests/user_commands/tests.py2010-09-13 
05:28:01 UTC (rev 13823)
@@ -0,0 +1,21 @@
+from StringIO import StringIO
+
+from django.test import TestCase
+from django.core import management
+from django.core.management.base import CommandError
+
+class CommandTests(TestCase):
+def test_command(self):
+out = StringIO()
+management.call_command('dance', stdout=out)
+self.assertEquals(out.getvalue(),
+"I don't feel like dancing Rock'n'Roll.")
+
+def test_command_style(self):
+out = StringIO()
+management.call_command('dance', style='Jive', stdout=out)
+self.assertEquals(out.getvalue(),
+"I don't feel like dancing Jive.")
+
+def test_explode(self):
+self.assertRaises(CommandError, management.call_command, ('explode',))
\ No newline at end of file

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #8794: Profanity filter suffers from the Scunthorpe problem

2010-09-12 Thread Django
#8794: Profanity filter suffers from the Scunthorpe problem
+---
  Reporter:  Daniel Pope   | Owner:  
nobody
Status:  new| Milestone:  
2.0   
 Component:  django.contrib.comments|   Version:  
SVN   
Resolution: |  Keywords:

 Stage:  Accepted   | Has_patch:  0 

Needs_docs:  0  |   Needs_tests:  0 

Needs_better_patch:  0  |  
+---
Changes (by thejaswi_puthraya):

  * milestone:  => 2.0

Comment:

 Check #6290. This ticket has to be pushed for the next major revision ie
 2.0.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13822 - django/trunk/docs/topics

2010-09-12 Thread noreply
Author: mtredinnick
Date: 2010-09-13 00:08:24 -0500 (Mon, 13 Sep 2010)
New Revision: 13822

Modified:
   django/trunk/docs/topics/templates.txt
Log:
Documented the permitted syntax for template variable names.

Modified: django/trunk/docs/topics/templates.txt
===
--- django/trunk/docs/topics/templates.txt  2010-09-13 05:08:21 UTC (rev 
13821)
+++ django/trunk/docs/topics/templates.txt  2010-09-13 05:08:24 UTC (rev 
13822)
@@ -79,7 +79,11 @@
 
 Variables look like this: ``{{ variable }}``. When the template engine
 encounters a variable, it evaluates that variable and replaces it with the
-result.
+result. Variable names consist of any combination of alphanumeric characters
+and the underscore (``"_"``). The dot (``"."``) also appears in variable
+sections, although that has a special meaning, as indicated below.
+Importantly, *you cannot have spaces or punctuation characters in variable
+names.*
 
 Use a dot (``.``) to access attributes of a variable.
 

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13821 - in django/trunk/tests: modeltests/validation regressiontests/multiple_database

2010-09-12 Thread noreply
Author: mtredinnick
Date: 2010-09-13 00:08:21 -0500 (Mon, 13 Sep 2010)
New Revision: 13821

Modified:
   django/trunk/tests/modeltests/validation/tests.py
   django/trunk/tests/regressiontests/multiple_database/tests.py
Log:
Fix a couple of typos in test names and descriptions.

Modified: django/trunk/tests/modeltests/validation/tests.py
===
--- django/trunk/tests/modeltests/validation/tests.py   2010-09-13 05:08:17 UTC 
(rev 13820)
+++ django/trunk/tests/modeltests/validation/tests.py   2010-09-13 05:08:21 UTC 
(rev 13821)
@@ -33,7 +33,7 @@
 mtv = ModelToValidate(number=10, name='Some Name', parent_id=parent.pk)
 self.assertEqual(None, mtv.full_clean())
 
-def test_limitted_FK_raises_error(self):
+def test_limited_FK_raises_error(self):
 # The limit_choices_to on the parent field says that a parent object's
 # number attribute must be 10, so this should fail validation.
 parent = ModelToValidate.objects.create(number=11, name='Other Name')
@@ -60,7 +60,7 @@
 mtv = ModelToValidate(number=10, name='Some Name', 
url='http://www.djangoproject.com/')
 self.assertEqual(None, mtv.full_clean()) # This will fail if there's 
no Internet connection
 
-def test_text_greater_that_charfields_max_length_eaises_erros(self):
+def test_text_greater_that_charfields_max_length_raises_erros(self):
 mtv = ModelToValidate(number=10, name='Some Name'*100)
 self.assertFailsValidation(mtv.full_clean, ['name',])
 

Modified: django/trunk/tests/regressiontests/multiple_database/tests.py
===
--- django/trunk/tests/regressiontests/multiple_database/tests.py   
2010-09-13 05:08:17 UTC (rev 13820)
+++ django/trunk/tests/regressiontests/multiple_database/tests.py   
2010-09-13 05:08:21 UTC (rev 13821)
@@ -24,7 +24,7 @@
 multi_db = True
 
 def test_db_selection(self):
-"Check that querysets will use the default databse by default"
+"Check that querysets will use the default database by default"
 self.assertEquals(Book.objects.db, DEFAULT_DB_ALIAS)
 self.assertEquals(Book.objects.all().db, DEFAULT_DB_ALIAS)
 
@@ -1221,7 +1221,7 @@
 
 mark = Person.objects.using('default').create(pk=2, name="Mark 
Pilgrim")
 
-# Now save back onto the usual databse.
+# Now save back onto the usual database.
 # This simulates master/slave - the objects exist on both database,
 # but the _state.db is as it is for all other tests.
 pro.save(using='default')

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13820 - django/trunk/docs/topics/db

2010-09-12 Thread noreply
Author: mtredinnick
Date: 2010-09-13 00:08:17 -0500 (Mon, 13 Sep 2010)
New Revision: 13820

Modified:
   django/trunk/docs/topics/db/optimization.txt
Log:
The optimization docs were a little too enthusiastic in recommending
defer() and only() usage. Disk access patterns affect when this is a
good idea, so this patch adds a note about the trade-offs.

Modified: django/trunk/docs/topics/db/optimization.txt
===
--- django/trunk/docs/topics/db/optimization.txt2010-09-13 05:08:10 UTC 
(rev 13819)
+++ django/trunk/docs/topics/db/optimization.txt2010-09-13 05:08:17 UTC 
(rev 13820)
@@ -171,6 +171,8 @@
 them. Note that if you *do* use them, the ORM will have to go and get them in a
 separate query, making this a pessimization if you use it inappropriately.
 
+Also, be aware that there is some (small extra) overhead incurred inside 
Django when constructing a model with deferred fields. Don't be too aggressive 
in deferring fields without profiling as the database has to read most of the 
non-text, non-VARCHAR data from the disk for a single row in the results, even 
if it ends up only using a few columns. The `defer()` and `only()` methods are 
most useful when you can avoid loading a lot of text data or for fields that 
might take a lot of processing to convert back to Python. As always, profile 
first, then optimize.
+
 Use QuerySet.count()
 
 

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13819 - in django/trunk/django/db: backends models

2010-09-12 Thread noreply
Author: mtredinnick
Date: 2010-09-13 00:08:10 -0500 (Mon, 13 Sep 2010)
New Revision: 13819

Modified:
   django/trunk/django/db/backends/util.py
   django/trunk/django/db/models/query_utils.py
Log:
Changed the way we create class names for deferred field models to avoid
problems when people have hundreds of fields on model. Maximum class
name length is now 80 characters and uses a hash when necessary.

Modified: django/trunk/django/db/backends/util.py
===
--- django/trunk/django/db/backends/util.py 2010-09-13 00:04:27 UTC (rev 
13818)
+++ django/trunk/django/db/backends/util.py 2010-09-13 05:08:10 UTC (rev 
13819)
@@ -105,15 +105,15 @@
 return None
 return str(d)
 
-def truncate_name(name, length=None):
+def truncate_name(name, length=None, hash_len=4):
 """Shortens a string to a repeatable mangled version with the given length.
 """
 if length is None or len(name) <= length:
 return name
 
-hash = md5_constructor(name).hexdigest()[:4]
+hash = md5_constructor(name).hexdigest()[:hash_len]
 
-return '%s%s' % (name[:length-4], hash)
+return '%s%s' % (name[:length-hash_len], hash)
 
 def format_number(value, max_digits, decimal_places):
 """

Modified: django/trunk/django/db/models/query_utils.py
===
--- django/trunk/django/db/models/query_utils.py2010-09-13 00:04:27 UTC 
(rev 13818)
+++ django/trunk/django/db/models/query_utils.py2010-09-13 05:08:10 UTC 
(rev 13819)
@@ -9,6 +9,7 @@
 import weakref
 from django.utils.copycompat import deepcopy
 
+from django.db.backends import util
 from django.utils import tree
 from django.utils.datastructures import SortedDict
 
@@ -262,9 +263,10 @@
 
 # The app_cache wants a unique name for each model, otherwise the new class
 # won't be created (we get an old one back). Therefore, we generate the
-# name using the passed in attrs. It's OK to reuse an old case if the attrs
-# are identical.
+# name using the passed in attrs. It's OK to reuse an existing class
+# object if the attrs are identical.
 name = "%s_Deferred_%s" % (model.__name__, '_'.join(sorted(list(attrs
+name = util.truncate_name(name, 80, 32)
 
 overrides = dict([(attr, DeferredAttribute(attr, model))
 for attr in attrs])

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Django] #14282: Add Guatemala to Localflavors

2010-09-12 Thread Django
#14282: Add Guatemala to Localflavors
+---
 Reporter:  dmonroy |   Owner:  nobody
   Status:  new |   Milestone:  1.3   
Component:  django.contrib.localflavor  | Version:  1.2   
 Keywords:  Guatemalan  |   Stage:  Unreviewed
Has_patch:  1   |  
+---
 Hi, attached is the patch for guatemalan form helpers.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #14275: Russian file name file in upload

2010-09-12 Thread Django
#14275: Russian file name file in upload
+---
  Reporter:  Squidy | Owner:  nobody
Status:  closed | Milestone:
 Component:  Uncategorized  |   Version:  1.2   
Resolution:  invalid|  Keywords:  utf8 utf-8 russian
 Stage:  Unreviewed | Has_patch:  0 
Needs_docs:  0  |   Needs_tests:  0 
Needs_better_patch:  0  |  
+---
Changes (by kmtracey):

  * status:  new => closed
  * needs_better_patch:  => 0
  * resolution:  => invalid
  * needs_tests:  => 0
  * needs_docs:  => 0

Comment:

 The full traceback would help to diagnose, but this sounds like the server
 locale is not set correctly, see:
 http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#if-you-
 get-a-unicodeencodeerror (the problem is common to any server environment,
 not just Apache/mod_python, even though that is where this bit of doc
 happens to be).

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Django] #14281: Small documentation fixes after djangocon 2010 sprints commit-fest

2010-09-12 Thread Django
#14281: Small documentation fixes after djangocon 2010 sprints commit-fest
---+
 Reporter:  ramiro |   Owner:  nobody
   Status:  new|   Milestone:
Component:  Documentation  | Version:  SVN   
 Keywords: |   Stage:  Unreviewed
Has_patch:  1  |  
---+
 Patch attached.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #11161: Added plural rules for supported languages

2010-09-12 Thread Django
#11161: Added plural rules for supported languages
---+
  Reporter:  daniels   | Owner:  nobody
Status:  new   | Milestone:
 Component:  Internationalization  |   Version:  1.0   
Resolution:|  Keywords:  plural
 Stage:  Accepted  | Has_patch:  1 
Needs_docs:  0 |   Needs_tests:  1 
Needs_better_patch:  1 |  
---+
Changes (by ramiro):

  * component:  Translations => Internationalization

Comment:

 oops, this is why it has been flying under the radar for one year :(

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #14280: Duplicate deepcopy import in django/db/models/query.py

2010-09-12 Thread Django
#14280: Duplicate deepcopy import in django/db/models/query.py
---+
  Reporter:  carljm| Owner:  nobody 
  
Status:  new   | Milestone: 
  
 Component:  Database layer (models, ORM)  |   Version:  SVN
  
Resolution:|  Keywords:  
sprintSep2010
 Stage:  Ready for checkin | Has_patch:  1  
  
Needs_docs:  0 |   Needs_tests:  0  
  
Needs_better_patch:  0 |  
---+
Changes (by Alex):

  * needs_better_patch:  => 0
  * stage:  Unreviewed => Ready for checkin
  * needs_tests:  => 0
  * needs_docs:  => 0

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Django] #14280: Duplicate deepcopy import in django/db/models/query.py

2010-09-12 Thread Django
#14280: Duplicate deepcopy import in django/db/models/query.py
--+-
 Reporter:  carljm|   Owner:  nobody
   Status:  new   |   Milestone:
Component:  Database layer (models, ORM)  | Version:  SVN   
 Keywords:  sprintSep2010 |   Stage:  Unreviewed
Has_patch:  1 |  
--+-
 In django/db/models/query.py, deepcopy is imported once from copy, and
 later from django.utils.copycompat. The duplicate was introduced by the
 multi-db merge (r11952), after the switch had been made to
 django.utils.copycompat only a few days earlier (r11901).

 The copy.deepcopy import is higher in the file, so has no effect, but
 removing it could help avoid confusion in future.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #11789: Aggregates ignore none()

2010-09-12 Thread Django
#11789: Aggregates ignore none()
--+-
  Reporter:  alexr| Owner:  noah  
Status:  assigned | Milestone:  1.3   
 Component:  ORM aggregation  |   Version:  1.1   
Resolution:   |  Keywords:  aggregates
 Stage:  Accepted | Has_patch:  1 
Needs_docs:  0|   Needs_tests:  0 
Needs_better_patch:  1|  
--+-
Changes (by mtredinnick):

  * stage:  Design decision needed => Accepted

Comment:

 Russell is questioning the implementation, not the functionality. (I agree
 with no exception -- it's not an error). Moving back to "accepted"

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #11161: Added plural rules for supported languages

2010-09-12 Thread Django
#11161: Added plural rules for supported languages
---+
  Reporter:  daniels   | Owner:  nobody
Status:  new   | Milestone:
 Component:  Translations  |   Version:  1.0   
Resolution:|  Keywords:  plural
 Stage:  Accepted  | Has_patch:  1 
Needs_docs:  0 |   Needs_tests:  1 
Needs_better_patch:  1 |  
---+
Changes (by mtredinnick):

  * needs_better_patch:  0 => 1

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #11161: Added plural rules for supported languages

2010-09-12 Thread Django
#11161: Added plural rules for supported languages
---+
  Reporter:  daniels   | Owner:  nobody
Status:  new   | Milestone:
 Component:  Translations  |   Version:  1.0   
Resolution:|  Keywords:  plural
 Stage:  Accepted  | Has_patch:  1 
Needs_docs:  0 |   Needs_tests:  1 
Needs_better_patch:  0 |  
---+
Changes (by mtredinnick):

  * stage:  Design decision needed => Accepted

Comment:

 It should pull the rules from Django's own locale file. This doesn't go
 into global settings, since we already a copy.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #6989: Inability to define DNS_NAME in django.core.mail results in e-mail messages being rejected or marked as spam

2010-09-12 Thread Django
#6989: Inability to define DNS_NAME in django.core.mail results in e-mail 
messages
being rejected or marked as spam
---+
  Reporter:  Franklin  | Owner:  nobody 
 
Status:  new   | Milestone: 
 
 Component:  django.core.mail  |   Version:  SVN
 
Resolution:|  Keywords:  local_hostname, 
DNS_NAME, CachedDnsName, smtplib, SMTPConnection
 Stage:  Accepted  | Has_patch:  1  
 
Needs_docs:  1 |   Needs_tests:  0  
 
Needs_better_patch:  1 |  
---+
Changes (by mtredinnick):

  * stage:  Design decision needed => Accepted

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #6730: postgresql_psycopg2 introspection includes views in generated models

2010-09-12 Thread Django
#6730: postgresql_psycopg2 introspection includes views in generated models
-+--
  Reporter:  Michael van der Westhuizen   | 
Owner:  nobody
Status:  new | 
Milestone:
 Component:  django-admin.py inspectdb   |   
Version:  SVN   
Resolution:  |  
Keywords:
 Stage:  Accepted| 
Has_patch:  1 
Needs_docs:  0   |   
Needs_tests:  0 
Needs_better_patch:  1   |  
-+--
Changes (by mtredinnick):

  * needs_better_patch:  0 => 1
  * stage:  Design decision needed => Accepted

Comment:

 We should process views and make them managed models (Malcolm + Russ
 decision). Those backends that don't do it at the moment can be done
 piecemeal -- this isn't an all-or-nothing change before it goes in. But
 Meta.managed = True would be good here.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Django] #14279: typo in tests for private flatpage not showing sitemaps

2010-09-12 Thread Django
#14279: typo in tests for private flatpage not showing sitemaps
+---
 Reporter:  jamesodo|   Owner:  nobody
   Status:  new |   Milestone:
Component:  Contrib apps| Version:  SVN   
 Keywords:  flatpages sitemaps  |   Stage:  Unreviewed
Has_patch:  1   |  
+---
 In django/trunk/django/contrib/sitemaps/tests/basic.py, both the public
 and private Flatpage objects have their title set to "Public Page"

 The attached patch changes the title of the public Flatpage to "Private
 Page"

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #12761: Paraguayan local flavor

2010-09-12 Thread Django
#12761: Paraguayan local flavor
-+--
  Reporter:  dschulz | Owner:  nobody   

Status:  new | Milestone:   

 Component:  django.contrib.localflavor  |   Version:  SVN  

Resolution:  |  Keywords:  local flavor 
paraguay
 Stage:  Unreviewed  | Has_patch:  0

Needs_docs:  0   |   Needs_tests:  0

Needs_better_patch:  0   |  
-+--
Changes (by anonymous):

  * stage:  Accepted => Unreviewed

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13817 - in django/trunk: django/contrib/auth django/contrib/auth/tests docs/topics

2010-09-12 Thread noreply
Author: mtredinnick
Date: 2010-09-12 17:38:01 -0500 (Sun, 12 Sep 2010)
New Revision: 13817

Modified:
   django/trunk/django/contrib/auth/forms.py
   django/trunk/django/contrib/auth/tests/urls.py
   django/trunk/django/contrib/auth/tests/views.py
   django/trunk/django/contrib/auth/views.py
   django/trunk/docs/topics/auth.txt
Log:
Permit custom from-email address in auth forms email.

Patch from cassidy and Rob Hudson. Fixed #11300.

Modified: django/trunk/django/contrib/auth/forms.py
===
--- django/trunk/django/contrib/auth/forms.py   2010-09-12 22:27:59 UTC (rev 
13816)
+++ django/trunk/django/contrib/auth/forms.py   2010-09-12 22:38:01 UTC (rev 
13817)
@@ -117,7 +117,7 @@
 return email
 
 def save(self, domain_override=None, 
email_template_name='registration/password_reset_email.html',
- use_https=False, token_generator=default_token_generator):
+ use_https=False, token_generator=default_token_generator, 
from_email=None):
 """
 Generates a one-use only link for resetting password and sends to the 
user
 """
@@ -140,7 +140,7 @@
 'protocol': use_https and 'https' or 'http',
 }
 send_mail(_("Password reset on %s") % site_name,
-t.render(Context(c)), None, [user.email])
+t.render(Context(c)), from_email, [user.email])
 
 class SetPasswordForm(forms.Form):
 """

Modified: django/trunk/django/contrib/auth/tests/urls.py
===
--- django/trunk/django/contrib/auth/tests/urls.py  2010-09-12 22:27:59 UTC 
(rev 13816)
+++ django/trunk/django/contrib/auth/tests/urls.py  2010-09-12 22:38:01 UTC 
(rev 13817)
@@ -16,6 +16,7 @@
 (r'^logout/custom_query/$', 'django.contrib.auth.views.logout', 
dict(redirect_field_name='follow')),
 (r'^logout/next_page/$', 'django.contrib.auth.views.logout', 
dict(next_page='/somewhere/')),
 (r'^remote_user/$', remote_user_auth_view),
+(r'^password_reset_from_email/$', 
'django.contrib.auth.views.password_reset', 
dict(from_email='staffmem...@example.com')),
 (r'^login_required/$', login_required(password_reset)),
 (r'^login_required_login_url/$', login_required(password_reset, 
login_url='/somewhere/')),
 )

Modified: django/trunk/django/contrib/auth/tests/views.py
===
--- django/trunk/django/contrib/auth/tests/views.py 2010-09-12 22:27:59 UTC 
(rev 13816)
+++ django/trunk/django/contrib/auth/tests/views.py 2010-09-12 22:38:01 UTC 
(rev 13817)
@@ -62,7 +62,15 @@
 self.assertEquals(response.status_code, 302)
 self.assertEquals(len(mail.outbox), 1)
 self.assert_("http://; in mail.outbox[0].body)
+self.assertEquals(settings.DEFAULT_FROM_EMAIL, 
mail.outbox[0].from_email)
 
+def test_email_found_custom_from(self):
+"Email is sent if a valid email address is provided for password reset 
when a custom from_email is provided."
+response = self.client.post('/password_reset_from_email/', {'email': 
'staffmem...@example.com'})
+self.assertEquals(response.status_code, 302)
+self.assertEquals(len(mail.outbox), 1)
+self.assertEquals("staffmem...@example.com", mail.outbox[0].from_email)
+
 def _test_confirm_start(self):
 # Start by creating the email
 response = self.client.post('/password_reset/', {'email': 
'staffmem...@example.com'})

Modified: django/trunk/django/contrib/auth/views.py
===
--- django/trunk/django/contrib/auth/views.py   2010-09-12 22:27:59 UTC (rev 
13816)
+++ django/trunk/django/contrib/auth/views.py   2010-09-12 22:38:01 UTC (rev 
13817)
@@ -105,7 +105,7 @@
 def password_reset(request, is_admin_site=False, 
template_name='registration/password_reset_form.html',
 email_template_name='registration/password_reset_email.html',
 password_reset_form=PasswordResetForm, 
token_generator=default_token_generator,
-post_reset_redirect=None):
+post_reset_redirect=None, from_email=None):
 if post_reset_redirect is None:
 post_reset_redirect = 
reverse('django.contrib.auth.views.password_reset_done')
 if request.method == "POST":
@@ -114,6 +114,7 @@
 opts = {}
 opts['use_https'] = request.is_secure()
 opts['token_generator'] = token_generator
+opts['from_email'] = from_email
 if is_admin_site:
 opts['domain_override'] = request.META['HTTP_HOST']
 else:

Modified: django/trunk/docs/topics/auth.txt
===
--- django/trunk/docs/topics/auth.txt   2010-09-12 22:27:59 UTC (rev 13816)
+++ django/trunk/docs/topics/auth.txt   2010-09-12 22:38:01 UTC (rev 13817)
@@ -906,7 +906,7 @@

[Changeset] r13816 - django/trunk/tests/regressiontests/forms

2010-09-12 Thread noreply
Author: mtredinnick
Date: 2010-09-12 17:27:59 -0500 (Sun, 12 Sep 2010)
New Revision: 13816

Modified:
   django/trunk/tests/regressiontests/forms/forms.py
Log:
Added a test for hidden SplitDateTime fields. Thanks, seveas.

Fixed #11213

Modified: django/trunk/tests/regressiontests/forms/forms.py
===
--- django/trunk/tests/regressiontests/forms/forms.py   2010-09-12 22:16:36 UTC 
(rev 13815)
+++ django/trunk/tests/regressiontests/forms/forms.py   2010-09-12 22:27:59 UTC 
(rev 13816)
@@ -522,6 +522,18 @@
 
 
 
+DateTimeField rendered as_hidden() is special too
+
+>>> class MessageForm(Form):
+... when = SplitDateTimeField()
+>>> f = MessageForm({'when_0': '1992-01-01', 'when_1': '01:01'})
+>>> print f.is_valid()
+True
+>>> print f['when']
+
+>>> print f['when'].as_hidden()
+
+
 MultipleChoiceField can also be used with the CheckboxSelectMultiple widget.
 >>> class SongForm(Form):
 ... name = CharField()

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #14278: sqlite3 backend an d django 1.2.3, bug: «no such table»

2010-09-12 Thread Django
#14278: sqlite3 backend and django 1.2.3, bug: «no such table»
---+
  Reporter:  cld   | Owner:  nobody
Status:  new   | Milestone:
 Component:  Database layer (models, ORM)  |   Version:  1.2   
Resolution:|  Keywords:
 Stage:  Unreviewed| Has_patch:  0 
Needs_docs:  0 |   Needs_tests:  0 
Needs_better_patch:  0 |  
---+
Changes (by mtredinnick):

  * needs_better_patch:  => 0
  * needs_tests:  => 0
  * needs_docs:  => 0

Comment:

 Using exactly this example (thanks so much for a simple example, btw), I
 couldn't repeat the problem. I created an empty project, filled in
 testbug/, added it and admin to settings, added admin to urls.py and ran
 syncdb and viewed /admin/ in the browser. No problems when adding a
 TestBug entry.

 So what step are you doing differently? I'd be *very* surprised if this
 really was a general bug, since even in the two days since 1.2.3 was
 announced, we would have heard about it, but please verify which step
 above is different in your situation.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13815 - django/branches/releases/1.2.X/tests/modeltests/get_or_create

2010-09-12 Thread noreply
Author: mtredinnick
Date: 2010-09-12 17:16:36 -0500 (Sun, 12 Sep 2010)
New Revision: 13815

Modified:
   django/branches/releases/1.2.X/tests/modeltests/get_or_create/tests.py
Log:
[1.2.X] Fixed the get_or_create tests for postgreSQL, by using
TransactionTestCase.

Backport of r13814 from trunk.

Modified: django/branches/releases/1.2.X/tests/modeltests/get_or_create/tests.py
===
--- django/branches/releases/1.2.X/tests/modeltests/get_or_create/tests.py  
2010-09-12 22:03:44 UTC (rev 13814)
+++ django/branches/releases/1.2.X/tests/modeltests/get_or_create/tests.py  
2010-09-12 22:16:36 UTC (rev 13815)
@@ -1,12 +1,12 @@
 from datetime import date
 
 from django.db import IntegrityError
-from django.test import TestCase
+from django.test import TransactionTestCase
 
 from models import Person, ManualPrimaryKeyTest
 
 
-class GetOrCreateTests(TestCase):
+class GetOrCreateTests(TransactionTestCase):
 def test_get_or_create(self):
 p = Person.objects.create(
 first_name='John', last_name='Lennon', birthday=date(1940, 10, 9)

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13814 - django/trunk/tests/modeltests/get_or_create

2010-09-12 Thread noreply
Author: mtredinnick
Date: 2010-09-12 17:03:44 -0500 (Sun, 12 Sep 2010)
New Revision: 13814

Modified:
   django/trunk/tests/modeltests/get_or_create/tests.py
Log:
Fixed the get_or_create tests for postgreSQL, by using
TransactionTestCase.

Modified: django/trunk/tests/modeltests/get_or_create/tests.py
===
--- django/trunk/tests/modeltests/get_or_create/tests.py2010-09-12 
21:56:25 UTC (rev 13813)
+++ django/trunk/tests/modeltests/get_or_create/tests.py2010-09-12 
22:03:44 UTC (rev 13814)
@@ -1,12 +1,12 @@
 from datetime import date
 
 from django.db import IntegrityError
-from django.test import TestCase
+from django.test import TransactionTestCase
 
 from models import Person, ManualPrimaryKeyTest
 
 
-class GetOrCreateTests(TestCase):
+class GetOrCreateTests(TransactionTestCase):
 def test_get_or_create(self):
 p = Person.objects.create(
 first_name='John', last_name='Lennon', birthday=date(1940, 10, 9)

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Django] #14278: sqlite3 backend and dj ango 1.2.3, bug: «no such table»

2010-09-12 Thread Django
#14278: sqlite3 backend and django 1.2.3, bug: «no such table»
--+-
 Reporter:  cld   |   Owner:  nobody
   Status:  new   |   Milestone:
Component:  Database layer (models, ORM)  | Version:  1.2   
 Keywords:|   Stage:  Unreviewed
Has_patch:  0 |  
--+-
 I such start a new project, and like all new project I start I take a new
 django version...

 Write some models and for all of them in administration page I got a
 Exception Type: DatabaseError
 Exception Value:no such table: appsname_modelsname

 With the dbshell, it's ok, table exist and with python shell I can
 create/delete/update object without problem.

 Retest with completly clean and simple models:
 http://pastebin.com/z1wgBWYC
 (Well I don't know how to made simpler :))

 Same error.

 I had tested on Django 1.2.1, it's works. Not tested (yet) with other
 database backend.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13813 - django/branches/releases/1.2.X/tests/regressiontests/templates

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 16:56:25 -0500 (Sun, 12 Sep 2010)
New Revision: 13813

Modified:
   django/branches/releases/1.2.X/tests/regressiontests/templates/loaders.py
Log:
[1.2.X] Modified the egg template loader tests; firstly to ensure that we are 
testing the new, non-deprecated interface; secondly to ensure that the old 
deprecated interface is also tested, but deprecation warnings are silenced.

Backport of r13812 from trunk.

Modified: 
django/branches/releases/1.2.X/tests/regressiontests/templates/loaders.py
===
--- django/branches/releases/1.2.X/tests/regressiontests/templates/loaders.py   
2010-09-12 21:53:35 UTC (rev 13812)
+++ django/branches/releases/1.2.X/tests/regressiontests/templates/loaders.py   
2010-09-12 21:56:25 UTC (rev 13813)
@@ -15,9 +15,11 @@
 import imp
 import StringIO
 import os.path
+import warnings
 
 from django.template import TemplateDoesNotExist, Context
 from django.template.loaders.eggs import load_template_source as lts_egg
+from django.template.loaders.eggs import Loader as EggLoader
 from django.template import loader
 
 # Mock classes and objects for pkg_resources functions.
@@ -53,7 +55,8 @@
 egg._resources = resources
 sys.modules[name] = egg
 
-class EggLoader(unittest.TestCase):
+class DeprecatedEggLoaderTest(unittest.TestCase):
+"Test the deprecated load_template_source interface to the egg loader"
 def setUp(self):
 pkg_resources._provider_factories[MockLoader] = MockProvider
 
@@ -64,31 +67,60 @@
 })
 self._old_installed_apps = settings.INSTALLED_APPS
 settings.INSTALLED_APPS = []
+warnings.simplefilter("ignore", PendingDeprecationWarning)
 
 def tearDown(self):
 settings.INSTALLED_APPS = self._old_installed_apps
+warnings.resetwarnings()
 
+def test_existing(self):
+"A template can be loaded from an egg"
+settings.INSTALLED_APPS = ['egg_1']
+contents, template_name = lts_egg("y.html")
+self.assertEqual(contents, "y")
+self.assertEqual(template_name, "egg:egg_1:templates/y.html")
+
+
+class EggLoaderTest(unittest.TestCase):
+def setUp(self):
+pkg_resources._provider_factories[MockLoader] = MockProvider
+
+self.empty_egg = create_egg("egg_empty", {})
+self.egg_1 = create_egg("egg_1", {
+os.path.normcase('templates/y.html') : StringIO.StringIO("y"),
+os.path.normcase('templates/x.txt') : StringIO.StringIO("x"),
+})
+self._old_installed_apps = settings.INSTALLED_APPS
+settings.INSTALLED_APPS = []
+
+def tearDown(self):
+settings.INSTALLED_APPS = self._old_installed_apps
+
 def test_empty(self):
 "Loading any template on an empty egg should fail"
 settings.INSTALLED_APPS = ['egg_empty']
-self.assertRaises(TemplateDoesNotExist, lts_egg, "not-existing.html")
+egg_loader = EggLoader()
+self.assertRaises(TemplateDoesNotExist, 
egg_loader.load_template_source, "not-existing.html")
 
 def test_non_existing(self):
 "Template loading fails if the template is not in the egg"
 settings.INSTALLED_APPS = ['egg_1']
-self.assertRaises(TemplateDoesNotExist, lts_egg, "not-existing.html")
+egg_loader = EggLoader()
+self.assertRaises(TemplateDoesNotExist, 
egg_loader.load_template_source, "not-existing.html")
 
 def test_existing(self):
 "A template can be loaded from an egg"
 settings.INSTALLED_APPS = ['egg_1']
-contents, template_name = lts_egg("y.html")
+egg_loader = EggLoader()
+contents, template_name = egg_loader.load_template_source("y.html")
 self.assertEqual(contents, "y")
 self.assertEqual(template_name, "egg:egg_1:templates/y.html")
 
 def test_not_installed(self):
 "Loading an existent template from an egg not included in 
INSTALLED_APPS should fail"
 settings.INSTALLED_APPS = []
-self.assertRaises(TemplateDoesNotExist, lts_egg, "y.html")
+egg_loader = EggLoader()
+self.assertRaises(TemplateDoesNotExist, 
egg_loader.load_template_source, "y.html")
 
 class CachedLoader(unittest.TestCase):
 def setUp(self):

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13812 - django/trunk/tests/regressiontests/templates

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 16:53:35 -0500 (Sun, 12 Sep 2010)
New Revision: 13812

Modified:
   django/trunk/tests/regressiontests/templates/loaders.py
Log:
Modified the egg template loader tests; firstly to ensure that we are testing 
the new, non-deprecated interface; secondly to ensure that the old deprecated 
interface is also tested, but deprecation warnings are silenced.

Modified: django/trunk/tests/regressiontests/templates/loaders.py
===
--- django/trunk/tests/regressiontests/templates/loaders.py 2010-09-12 
21:52:56 UTC (rev 13811)
+++ django/trunk/tests/regressiontests/templates/loaders.py 2010-09-12 
21:53:35 UTC (rev 13812)
@@ -15,9 +15,11 @@
 import imp
 import StringIO
 import os.path
+import warnings
 
 from django.template import TemplateDoesNotExist, Context
 from django.template.loaders.eggs import load_template_source as lts_egg
+from django.template.loaders.eggs import Loader as EggLoader
 from django.template import loader
 
 # Mock classes and objects for pkg_resources functions.
@@ -53,7 +55,8 @@
 egg._resources = resources
 sys.modules[name] = egg
 
-class EggLoader(unittest.TestCase):
+class DeprecatedEggLoaderTest(unittest.TestCase):
+"Test the deprecated load_template_source interface to the egg loader"
 def setUp(self):
 pkg_resources._provider_factories[MockLoader] = MockProvider
 
@@ -64,31 +67,60 @@
 })
 self._old_installed_apps = settings.INSTALLED_APPS
 settings.INSTALLED_APPS = []
+warnings.simplefilter("ignore", PendingDeprecationWarning)
 
 def tearDown(self):
 settings.INSTALLED_APPS = self._old_installed_apps
+warnings.resetwarnings()
 
+def test_existing(self):
+"A template can be loaded from an egg"
+settings.INSTALLED_APPS = ['egg_1']
+contents, template_name = lts_egg("y.html")
+self.assertEqual(contents, "y")
+self.assertEqual(template_name, "egg:egg_1:templates/y.html")
+
+
+class EggLoaderTest(unittest.TestCase):
+def setUp(self):
+pkg_resources._provider_factories[MockLoader] = MockProvider
+
+self.empty_egg = create_egg("egg_empty", {})
+self.egg_1 = create_egg("egg_1", {
+os.path.normcase('templates/y.html') : StringIO.StringIO("y"),
+os.path.normcase('templates/x.txt') : StringIO.StringIO("x"),
+})
+self._old_installed_apps = settings.INSTALLED_APPS
+settings.INSTALLED_APPS = []
+
+def tearDown(self):
+settings.INSTALLED_APPS = self._old_installed_apps
+
 def test_empty(self):
 "Loading any template on an empty egg should fail"
 settings.INSTALLED_APPS = ['egg_empty']
-self.assertRaises(TemplateDoesNotExist, lts_egg, "not-existing.html")
+egg_loader = EggLoader()
+self.assertRaises(TemplateDoesNotExist, 
egg_loader.load_template_source, "not-existing.html")
 
 def test_non_existing(self):
 "Template loading fails if the template is not in the egg"
 settings.INSTALLED_APPS = ['egg_1']
-self.assertRaises(TemplateDoesNotExist, lts_egg, "not-existing.html")
+egg_loader = EggLoader()
+self.assertRaises(TemplateDoesNotExist, 
egg_loader.load_template_source, "not-existing.html")
 
 def test_existing(self):
 "A template can be loaded from an egg"
 settings.INSTALLED_APPS = ['egg_1']
-contents, template_name = lts_egg("y.html")
+egg_loader = EggLoader()
+contents, template_name = egg_loader.load_template_source("y.html")
 self.assertEqual(contents, "y")
 self.assertEqual(template_name, "egg:egg_1:templates/y.html")
 
 def test_not_installed(self):
 "Loading an existent template from an egg not included in 
INSTALLED_APPS should fail"
 settings.INSTALLED_APPS = []
-self.assertRaises(TemplateDoesNotExist, lts_egg, "y.html")
+egg_loader = EggLoader()
+self.assertRaises(TemplateDoesNotExist, 
egg_loader.load_template_source, "y.html")
 
 class CachedLoader(unittest.TestCase):
 def setUp(self):

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13811 - in django/branches/soc2010/app-loading: django/core tests/appcachetests

2010-09-12 Thread noreply
Author: arthurk
Date: 2010-09-12 16:52:56 -0500 (Sun, 12 Sep 2010)
New Revision: 13811

Modified:
   django/branches/soc2010/app-loading/django/core/apps.py
   django/branches/soc2010/app-loading/tests/appcachetests/runtests.py
Log:
[soc2010/app-loading] update get_app/get_apps tests

Modified: django/branches/soc2010/app-loading/django/core/apps.py
===
--- django/branches/soc2010/app-loading/django/core/apps.py 2010-09-12 
21:16:09 UTC (rev 13810)
+++ django/branches/soc2010/app-loading/django/core/apps.py 2010-09-12 
21:52:56 UTC (rev 13811)
@@ -189,7 +189,7 @@
 return self.loaded
 
 def get_apps(self):
-"Returns a list of all installed modules that contain models."
+"Returns a list of all models modules."
 self._populate()
 return [app.models_module for app in self.app_instances\
 if hasattr(app, 'models_module')]

Modified: django/branches/soc2010/app-loading/tests/appcachetests/runtests.py
===
--- django/branches/soc2010/app-loading/tests/appcachetests/runtests.py 
2010-09-12 21:16:09 UTC (rev 13810)
+++ django/branches/soc2010/app-loading/tests/appcachetests/runtests.py 
2010-09-12 21:52:56 UTC (rev 13811)
@@ -84,23 +84,31 @@
 class GetAppsTests(AppCacheTestCase):
 """Tests for the get_apps function"""
 
-def test_get_apps(self):
-"""Test that the correct models modules are returned"""
-settings.INSTALLED_APPS = ('django.contrib.sites',
-   'django.contrib.contenttypes',
-   'django.contrib.auth',
-   'django.contrib.flatpages',)
+def test_app_classes(self):
+"""
+Test that the correct models modules are returned for apps installed
+via the APP_CLASSES setting
+"""
+settings.APP_CLASSES = ('model_app.apps.MyApp',)
 apps = cache.get_apps()
-self.assertEqual(len(apps), 4)
-self.assertTrue(apps[0], 'django.contrib.auth.models')
-self.assertTrue(apps[1], 'django.contrib.flatpages.models')
-self.assertTrue(apps[2], 'django.contrib.sites.models')
-self.assertTrue(apps[3], 'django.contrib.contenttypes.models')
 self.assertTrue(cache.app_cache_ready())
+self.assertEquals(apps[0].__name__, 'model_app.othermodels')
 
+def test_installed_apps(self):
+"""
+Test that the correct models modules are returned for apps installed
+via the INSTALLED_APPS setting
+"""
+settings.INSTALLED_APPS = ('model_app',)
+apps = cache.get_apps()
+self.assertTrue(cache.app_cache_ready())
+self.assertEquals(apps[0].__name__, 'model_app.models')
+
 def test_empty_models(self):
-"""Test that modules that don't contain models are not returned"""
-settings.INSTALLED_APPS = ('django.contrib.csrf',)
+"""
+Test that modules that don't contain models are not returned
+"""
+settings.INSTALLED_APPS = ('nomodel_app',)
 self.assertEqual(cache.get_apps(), [])
 self.assertTrue(cache.app_cache_ready())
 
@@ -116,21 +124,31 @@
 class GetAppTests(AppCacheTestCase):
 """Tests for the get_app function"""
 
-def test_get_app(self):
-"""Test that the correct module is returned"""
-settings.INSTALLED_APPS = ('django.contrib.contenttypes',
-   'django.contrib.auth',)
-module = cache.get_app('auth')
-self.assertTrue(module, 'django.contrib.auth.models')
-self.assertTrue(cache.app_cache_ready())
+def test_app_classes(self):
+"""
+Test that the correct module is returned when the app was installed
+via the APP_CLASSES setting
+"""
+settings.APP_CLASSES = ('model_app.apps.MyApp',)
+rv = cache.get_app('model_app')
+self.assertEquals(rv.__name__, 'model_app.othermodels')
 
+def test_installed_apps(self):
+"""
+Test that the correct module is returned when the app was installed
+via the INSTALLED_APPS setting
+"""
+settings.INSTALLED_APPS = ('model_app',)
+rv = cache.get_app('model_app')
+self.assertEquals(rv.__name__, 'model_app.models')
+
 def test_not_found_exception(self):
 """
 Test that an ImproperlyConfigured exception is raised if an app
 could not be found
 """
 self.assertRaises(ImproperlyConfigured, cache.get_app,
-  'django.contrib.auth')
+  'notarealapp')
 self.assertTrue(cache.app_cache_ready())
 
 def test_emptyOK(self):
@@ -143,16 +161,6 @@
 self.failUnless(module is None)
 self.assertTrue(cache.app_cache_ready())
 
-def test_load_app_modules(self):
-"""
-Test 

Re: [Django] #14276: Typo in the docstring to one of the unittests

2010-09-12 Thread Django
#14276: Typo in the docstring to one of the unittests
+---
  Reporter:  andrewsk   | Owner:  nobody
Status:  new| Milestone:
 Component:  Testing framework  |   Version:  1.2   
Resolution: |  Keywords:
 Stage:  Unreviewed | Has_patch:  1 
Needs_docs:  0  |   Needs_tests:  0 
Needs_better_patch:  0  |  
+---
Changes (by andrewsk):

  * needs_better_patch:  => 0
  * summary:  Type in the docstring to one of the unittests => Typo in the
  docstring to one of the unittests
  * needs_tests:  => 0
  * needs_docs:  => 0

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Django] #14277: Error in documentation for mod_wsgi

2010-09-12 Thread Django
#14277: Error in documentation for mod_wsgi
---+
 Reporter:  nietpiet   |   Owner:  nobody
   Status:  new|   Milestone:
Component:  Documentation  | Version:  1.2   
 Keywords:  mod_wsgi   |   Stage:  Unreviewed
Has_patch:  1  |  
---+
 Hi,

 First, i'd like to say: Good work!
 Second, i found some small errors in the documentation that describes
 Django deployment with mod_wsgi:
 http://docs.djangoproject.com/en/1.2/howto/deployment/modwsgi/

 The documentation says to
  add "sys.path.append('/usr/local/django') just above the final import
 line to place your project on the path."

 This is not correct. It should not be "above", it should be "below", ie,
 after importing sys:  "just after the 'import sys' line to place your
 project on the path"
 It does not work if you append a path to sys before importing sys itself.
 (Shoule be obvious but better to have it correct)

 Further.. it is a little unclear that "/usr/local/django" is intended to
 be the same as "/path/to/mysite" which is used for the WSGIScriptAlias at
 the beginning of the document; while at the end of the document it
 suddenly changes again to: WSGIScriptAlias /
 /usr/local/wsgi/scripts/django.wsgi
 This is not very clear, I think it is better to be consistent for file
 paths.
 So, perhaps it is better to either use /path/to/mysite or alternatively,
 give a disclaimer that the local files are stored at /usr/local/django or
 at /usr/local/wsgi

 Keep up the good work!

 Kind regards,

 Jan

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Django] #14276: Type in the docstring to one of the unittests

2010-09-12 Thread Django
#14276: Type in the docstring to one of the unittests
---+
 Reporter:  andrewsk   |   Owner:  nobody
   Status:  new|   Milestone:
Component:  Testing framework  | Version:  1.2   
 Keywords: |   Stage:  Unreviewed
Has_patch:  1  |  
---+
 Docstring in the regressiontests/multiple_database/tests.py
 QueryTestCase.test_db_selection should say "database" instead of "databse"

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #11058: list_display_links doesn't allow callables not defined in the model

2010-09-12 Thread Django
#11058: list_display_links doesn't allow callables not defined in the model
---+
  Reporter:  dvine | Owner:
Status:  new   | Milestone:
 Component:  django.contrib.admin  |   Version:  SVN   
Resolution:|  Keywords:  list_display_links
 Stage:  Accepted  | Has_patch:  1 
Needs_docs:  0 |   Needs_tests:  0 
Needs_better_patch:  1 |  
---+
Changes (by mtredinnick):

  * needs_better_patch:  0 => 1
  * stage:  Ready for checkin => Accepted

Comment:

 Ok, I like the idea, but I can't make the tests pass (not the new tests,
 but it breaks existing tests). The modeladmin tests show why just removing
 that single line in admin/validate.py isn't a good idea -- it provides a
 misleading error message in another case (and possibly others that aren't
 even tested). So a more logical approach to validation is needed there,
 rather than just removing it.

 Also, as a second point for the next (single!) patch to this ticket:
 there's no need to create contrib/admin/tests/. We already have
 tests/regressiontests/admin_views, ../admin_widgets, etc for admin
 testing.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Django] #14275: Russian file name file in upload

2010-09-12 Thread Django
#14275: Russian file name file in upload
+---
 Reporter:  Squidy  |   Owner:  nobody
   Status:  new |   Milestone:
Component:  Uncategorized   | Version:  1.2   
 Keywords:  utf8 utf-8 russian  |   Stage:  Unreviewed
Has_patch:  0   |  
+---
 I have some model

 {{{

   ogrn  = StdImageField(upload_to=get_upload_to ,blank=True)

   file1 = models.FileField(upload_to=get_upload_to ,blank=True)
   file2 = models.FileField(upload_to=get_upload_to ,blank=True)
   file3 = models.FileField(upload_to=get_upload_to ,blank=True)
   file4 = models.FileField(upload_to=get_upload_to ,blank=True)
   file5 = models.FileField(upload_to=get_upload_to ,blank=True)
   file6 = models.FileField(upload_to=get_upload_to ,blank=True)
 }}}


 When I upload file with russian name i get some error


 {{{
 UnicodeEncodeError at /manager/write/basket/1/

 'ascii' codec can't encode characters in position 55-58: ordinal not in
 range(128)

 Request Method: POST
 Request URL:http://rudjins.squidy.ru/manager/write/basket/1/
 Django Version: 1.2.1
 Exception Type: UnicodeEncodeError
 Exception Value:

 'ascii' codec can't encode characters in position 55-58: ordinal not in
 range(128)

 Exception Location: /usr/local/lib/python2.6/genericpath.py in exists,
 line 18
 Python Executable:  /usr/local/bin/python
 Python Version: 2.6.5
 Python Path:['/usr/local/lib/python2.6/site-
 packages/setuptools-0.6c11-py2.6.egg', '/usr/local/lib/python2.6/site-
 packages/pytz-2010b-py2.6.egg', '/usr/local/lib/python2.6/site-
 packages/Pygments-1.2.2-py2.6.egg', '/usr/local/lib/python2.6/site-
 packages/Genshi-0.5.1-py2.6-freebsd-7.0-RELEASE-p10-amd64.egg',
 '/usr/local/lib/python2.6/site-
 packages/MySQL_python-1.2.3c1-py2.6-freebsd-7.0-RELEASE-p10-amd64.egg',
 '/usr/local/lib/python2.6/site-
 packages/Jinja2-2.1.1-py2.6-freebsd-7.0-RELEASE-p10-amd64.egg',
 '/usr/local/lib/python2.6/site-packages/Sphinx-0.6.4-py2.6.egg',
 '/usr/local/lib/python2.6/site-packages/flup-1.0.2-py2.6.egg',
 '/usr/local/lib/python2.6/site-packages/hg_git-0.2.2-py2.6.egg',
 '/usr/local/lib/python26.zip', '/usr/local/lib/python2.6',
 '/usr/local/lib/python2.6/plat-freebsd7', '/usr/local/lib/python2.6/lib-
 tk', '/usr/local/lib/python2.6/lib-old', '/usr/local/lib/python2.6/lib-
 dynload', '/usr/local/lib/python2.6/site-packages',
 '/usr/local/lib/python2.6/site-packages/PIL', '/usr/local/lib/python2.6
 /site-packages/django',
 '/pub/www/homepage/rudjins.squidy.ru/www/application']
 Server time:Пнд, 13 Сен 2010 01:10:05 +0400
 }}}

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13810 - in django/branches/soc2010/app-loading: django/core tests/appcachetests tests/appcachetests/model_app tests/appcachetests/nomodel_app tests/appcachetests/same_label/nomodel_app

2010-09-12 Thread noreply
Author: arthurk
Date: 2010-09-12 16:16:09 -0500 (Sun, 12 Sep 2010)
New Revision: 13810

Added:
   django/branches/soc2010/app-loading/tests/appcachetests/model_app/apps.py
   django/branches/soc2010/app-loading/tests/appcachetests/nomodel_app/apps.py
   
django/branches/soc2010/app-loading/tests/appcachetests/same_label/nomodel_app/apps.py
Modified:
   django/branches/soc2010/app-loading/django/core/apps.py
   django/branches/soc2010/app-loading/tests/appcachetests/model_app/__init__.py
   
django/branches/soc2010/app-loading/tests/appcachetests/nomodel_app/__init__.py
   django/branches/soc2010/app-loading/tests/appcachetests/runtests.py
   
django/branches/soc2010/app-loading/tests/appcachetests/same_label/nomodel_app/__init__.py
Log:
[soc2010/app-loading] update tests

Modified: django/branches/soc2010/app-loading/django/core/apps.py
===
--- django/branches/soc2010/app-loading/django/core/apps.py 2010-09-12 
20:52:49 UTC (rev 13809)
+++ django/branches/soc2010/app-loading/django/core/apps.py 2010-09-12 
21:16:09 UTC (rev 13810)
@@ -46,11 +46,6 @@
 # List of App instances
 app_instances = [],
 
-# Normalized list of INSTALLED_APPS
-# This stores the module name of settings.INSTALLED_APPS
-# e.g. 'django.contrib.auth' for 'django.contrib.auth.AuthApp'
-installed_apps = [],
-
 # Mapping of app_labels to a dictionary of model names to model code.
 unbound_models = {},
 
@@ -142,14 +137,11 @@
 app_instance.module = app_module
 app_instance.path = app_name
 self.app_instances.append(app_instance)
-self.installed_apps.append(app_name)
 
-# Check if the app instance specifies a path to models
+# Check if the app instance specifies a path to a models module
 # if not, we use the models.py file from the package dir
-try:
-models_path = app_instance.models_path
-except AttributeError:
-models_path = '%s.models' % app_name
+models_path = getattr(app_instance, 'models_path',
+'%s.models' % app_name)
 
 try:
 models = import_module(models_path)
@@ -178,9 +170,11 @@
 return models
 
 def find_app(self, name):
-"Returns the App instance that matches name"
-if '.' in name:
-name = name.rsplit('.', 1)[1]
+"""
+Returns the app instance that matches name
+"""
+#if '.' in name:
+#name = name.rsplit('.', 1)[1]
 for app in self.app_instances:
 if app.name == name:
 return app

Modified: 
django/branches/soc2010/app-loading/tests/appcachetests/model_app/__init__.py
===
--- 
django/branches/soc2010/app-loading/tests/appcachetests/model_app/__init__.py   
2010-09-12 20:52:49 UTC (rev 13809)
+++ 
django/branches/soc2010/app-loading/tests/appcachetests/model_app/__init__.py   
2010-09-12 21:16:09 UTC (rev 13810)
@@ -1,12 +0,0 @@
-from django.core.apps import App
-
-class MyApp(App):
-models_path = 'model_app.othermodels'
-
-def __repr__(self):
-return '' % self.name
-
-class MyOtherApp(MyApp):
-def __init__(self, name):
-super(MyOtherApp, self).__init__(name)
-self.db_prefix = 'nomodel_app'

Added: django/branches/soc2010/app-loading/tests/appcachetests/model_app/apps.py
===
--- django/branches/soc2010/app-loading/tests/appcachetests/model_app/apps.py   
(rev 0)
+++ django/branches/soc2010/app-loading/tests/appcachetests/model_app/apps.py   
2010-09-12 21:16:09 UTC (rev 13810)
@@ -0,0 +1,9 @@
+from django.core.apps import App
+
+class MyApp(App):
+models_path = 'model_app.othermodels'
+
+class MyOtherApp(MyApp):
+def __init__(self, name):
+super(MyOtherApp, self).__init__(name)
+self.db_prefix = 'nomodel_app'

Modified: 
django/branches/soc2010/app-loading/tests/appcachetests/nomodel_app/__init__.py
===
--- 
django/branches/soc2010/app-loading/tests/appcachetests/nomodel_app/__init__.py 
2010-09-12 20:52:49 UTC (rev 13809)
+++ 
django/branches/soc2010/app-loading/tests/appcachetests/nomodel_app/__init__.py 
2010-09-12 21:16:09 UTC (rev 13810)
@@ -1,6 +0,0 @@
-from django.core.apps import App
-
-class MyApp(App):
-
-def __repr__(self):
-return '' % self.name

Added: 
django/branches/soc2010/app-loading/tests/appcachetests/nomodel_app/apps.py
===
--- django/branches/soc2010/app-loading/tests/appcachetests/nomodel_app/apps.py 
(rev 0)
+++ django/branches/soc2010/app-loading/tests/appcachetests/nomodel_app/apps.py 
2010-09-12 21:16:09 UTC 

Re: [Django] #14223: Inconsistent exception raising on DB integrity errors

2010-09-12 Thread Django
#14223: Inconsistent exception raising on DB integrity errors
---+
  Reporter:  ramiro| Owner:  ramiro 

Status:  assigned  | Milestone: 

 Component:  Database layer (models, ORM)  |   Version:  SVN

Resolution:|  Keywords:  
integrityerror backends orm
 Stage:  Accepted  | Has_patch:  1  

Needs_docs:  0 |   Needs_tests:  0  

Needs_better_patch:  0 |  
---+
Changes (by ramiro):

  * owner:  nobody => ramiro
  * status:  new => assigned
  * has_patch:  0 => 1

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #14226: Bug in dumpdata dependency calculation involving ManyToManyFields

2010-09-12 Thread Django
#14226: Bug in dumpdata dependency calculation involving ManyToManyFields
+---
  Reporter:  aneil  | Owner:  outofculture 
Status:  assigned   | Milestone:   
 Component:  Serialization  |   Version:  1.2  
Resolution: |  Keywords:  easy-pickings
 Stage:  Accepted   | Has_patch:  1
Needs_docs:  0  |   Needs_tests:  0
Needs_better_patch:  1  |  
+---
Changes (by outofculture):

  * needs_tests:  1 => 0

Comment:

 active development of this at http://github.com/outofculture/django

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #11058: list_display_links doesn't allow callables not defined in the model

2010-09-12 Thread Django
#11058: list_display_links doesn't allow callables not defined in the model
---+
  Reporter:  dvine | Owner:
Status:  new   | Milestone:
 Component:  django.contrib.admin  |   Version:  SVN   
Resolution:|  Keywords:  list_display_links
 Stage:  Ready for checkin | Has_patch:  1 
Needs_docs:  0 |   Needs_tests:  0 
Needs_better_patch:  0 |  
---+
Comment (by mtredinnick):

 For next time: ready for checkin means there is a single patch that can be
 applied. Not three patches. (Also, generally a poor idea to "ready for
 checkin" your own work -- it's like editing your own writing: invariably
 hard because you're too close to it).

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13809 - in django/trunk: django/http docs/ref tests/regressiontests/requests

2010-09-12 Thread noreply
Author: mtredinnick
Date: 2010-09-12 15:52:49 -0500 (Sun, 12 Sep 2010)
New Revision: 13809

Modified:
   django/trunk/django/http/__init__.py
   django/trunk/docs/ref/request-response.txt
   django/trunk/tests/regressiontests/requests/tests.py
Log:
Allow setting HttpResponse cookie expiry times with datetime objects.

Patch from SmileyChris. Fixed #7770.

Modified: django/trunk/django/http/__init__.py
===
--- django/trunk/django/http/__init__.py2010-09-12 20:34:11 UTC (rev 
13808)
+++ django/trunk/django/http/__init__.py2010-09-12 20:52:49 UTC (rev 
13809)
@@ -1,5 +1,7 @@
+import datetime
 import os
 import re
+import time
 from Cookie import BaseCookie, SimpleCookie, CookieError
 from pprint import pformat
 from urllib import urlencode
@@ -12,6 +14,7 @@
 
 from django.utils.datastructures import MultiValueDict, ImmutableList
 from django.utils.encoding import smart_str, iri_to_uri, force_unicode
+from django.utils.http import cookie_date
 from django.http.multipartparser import MultiPartParser
 from django.conf import settings
 from django.core.files import uploadhandler
@@ -373,11 +376,32 @@
 
 def set_cookie(self, key, value='', max_age=None, expires=None, path='/',
domain=None, secure=False):
+"""
+Sets a cookie.
+
+``expires`` can be a string in the correct format or a 
+``datetime.datetime`` object in UTC. If ``expires`` is a datetime
+object then ``max_age`` will be calculated.
+"""
 self.cookies[key] = value
+if expires is not None:
+if isinstance(expires, datetime.datetime):
+delta = expires - expires.utcnow()
+# Add one second so the date matches exactly (a fraction of
+# time gets lost between converting to a timedelta and
+# then the date string).
+delta = delta + datetime.timedelta(seconds=1)
+# Just set max_age - the max_age logic will set expires.
+expires = None
+max_age = max(0, delta.days * 86400 + delta.seconds)
+else:
+self.cookies[key]['expires'] = expires
 if max_age is not None:
 self.cookies[key]['max-age'] = max_age
-if expires is not None:
-self.cookies[key]['expires'] = expires
+# IE requires expires, so set it if hasn't been already.
+if not expires:
+self.cookies[key]['expires'] = cookie_date(time.time() +
+   max_age) 
 if path is not None:
 self.cookies[key]['path'] = path
 if domain is not None:

Modified: django/trunk/docs/ref/request-response.txt
===
--- django/trunk/docs/ref/request-response.txt  2010-09-12 20:34:11 UTC (rev 
13808)
+++ django/trunk/docs/ref/request-response.txt  2010-09-12 20:52:49 UTC (rev 
13809)
@@ -529,8 +529,11 @@
 
 * ``max_age`` should be a number of seconds, or ``None`` (default) if
   the cookie should last only as long as the client's browser session.
-* ``expires`` should be a string in the format
-  ``"Wdy, DD-Mon-YY HH:MM:SS GMT"``.
+  If ``expires`` is not specified, it will be calculated.
+* ``expires`` should either be a string in the format
+  ``"Wdy, DD-Mon-YY HH:MM:SS GMT"`` or a ``datetime.datetime`` object
+  in UTC. If ``expires`` is a ``datetime`` object, the ``max_age``
+  will be calculated.
 * Use ``domain`` if you want to set a cross-domain cookie. For example,
   ``domain=".lawrence.com"`` will set a cookie that is readable by
   the domains www.lawrence.com, blogs.lawrence.com and

Modified: django/trunk/tests/regressiontests/requests/tests.py
===
--- django/trunk/tests/regressiontests/requests/tests.py2010-09-12 
20:34:11 UTC (rev 13808)
+++ django/trunk/tests/regressiontests/requests/tests.py2010-09-12 
20:52:49 UTC (rev 13809)
@@ -1,5 +1,5 @@
 """
->>> from django.http import HttpRequest
+>>> from django.http import HttpRequest, HttpResponse
 >>> print repr(HttpRequest())
 >> request.path = ''
 >>> print request.build_absolute_uri(location="/path/with:colons")
 http://www.example.com/path/with:colons
+
+
+# Test cookie datetime expiration logic
+>>> from datetime import datetime, timedelta
+>>> delta = timedelta(seconds=10)
+>>> response = HttpResponse()
+>>> response.set_cookie('datetime', expires=datetime.utcnow()+delta)
+>>> datetime_cookie = response.cookies['datetime']
+>>> datetime_cookie['max-age']
+10
+>>> response.set_cookie('datetime', expires=datetime(2028, 1, 1, 4, 5, 6))
+>>> response.cookies['datetime']['expires']
+'Sat, 01-Jan-2028 04:05:06 GMT'
+
+# Test automatically setting 

Re: [Django] #6218: Require trailing slash always on MEDIA_URL

2010-09-12 Thread Django
#6218: Require trailing slash always on MEDIA_URL
+---
  Reporter:  Michael Toomim   | 
Owner:  cmheisel 
Status:  assigned   | 
Milestone:   
 Component:  Core framework |   
Version:  SVN  
Resolution: |  
Keywords:  easy-pickings
 Stage:  Accepted   | 
Has_patch:  1
Needs_docs:  0  |   
Needs_tests:  0
Needs_better_patch:  0  |  
+---
Changes (by cmheisel):

  * needs_better_patch:  1 => 0

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13808 - in django/trunk/docs/topics: . db

2010-09-12 Thread noreply
Author: mtredinnick
Date: 2010-09-12 15:34:11 -0500 (Sun, 12 Sep 2010)
New Revision: 13808

Modified:
   django/trunk/docs/topics/db/queries.txt
   django/trunk/docs/topics/templates.txt
Log:
Add intro-user-level documentation about calling model methods from views.

Patch from timo and shacker. Fixed #10903.

Modified: django/trunk/docs/topics/db/queries.txt
===
--- django/trunk/docs/topics/db/queries.txt 2010-09-12 20:12:33 UTC (rev 
13807)
+++ django/trunk/docs/topics/db/queries.txt 2010-09-12 20:34:11 UTC (rev 
13808)
@@ -823,6 +823,8 @@
 # THIS WILL RAISE A FieldError
 >>> Entry.objects.update(headline=F('blog__name'))
 
+.. _topics-db-queries-related:
+
 Related objects
 ===
 

Modified: django/trunk/docs/topics/templates.txt
===
--- django/trunk/docs/topics/templates.txt  2010-09-12 20:12:33 UTC (rev 
13807)
+++ django/trunk/docs/topics/templates.txt  2010-09-12 20:34:11 UTC (rev 
13808)
@@ -569,6 +569,45 @@
 The variable's contents are still automatically escaped, if necessary, because
 they're beyond the control of the template author.
 
+.. _template-accessing-methods:
+
+Accessing method calls
+==
+
+Most method calls attached to objects are also available from within templates.
+This means that templates have access to much more than just class attributes
+(like field names) and variables passed in from views. For example, the Django
+ORM provides the :ref:`"entry_set"` syntax for
+finding a collection of objects related on a foreign key. Therefore, given
+a model called "comment" with a foreign key relationship to a model called
+"task" you can loop through all comments attached to a given task like this::
+
+{% for comment in task.comment_set.all %}
+{{ comment }}
+{% endfor %}
+
+Similarly, :doc:`QuerySets` provide a ``count()`` method
+to count the number of objects they contain. Therefore, you can obtain a count
+of all comments related to the current task with::
+
+{{ task.comment_set.all.count }}
+
+And of course you can easily access methods you've explicitly defined on your
+own models::
+
+# In model
+class Task(models.Model):
+def foo(self):
+return "bar"
+
+# In template
+{{ task.foo }}
+
+Because Django intentionally limits the amount of logic processing available
+in the template language, it is not possible to pass arguments to method calls
+accessed from within templates. Data should be calculated in views, then passed
+to templates for display.
+
 .. _template-built-in-reference:
 
 Using the built-in reference

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13807 - django/branches/releases/1.2.X/tests/modeltests/expressions

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:12:33 -0500 (Sun, 12 Sep 2010)
New Revision: 13807

Added:
   django/branches/releases/1.2.X/tests/modeltests/expressions/tests.py
Modified:
   django/branches/releases/1.2.X/tests/modeltests/expressions/models.py
Log:
[1.2.X] Migrated expressions doctests. Thanks to Alex Gaynor.

Backport of r13790 from trunk.

Modified: django/branches/releases/1.2.X/tests/modeltests/expressions/models.py
===
--- django/branches/releases/1.2.X/tests/modeltests/expressions/models.py   
2010-09-12 20:12:23 UTC (rev 13806)
+++ django/branches/releases/1.2.X/tests/modeltests/expressions/models.py   
2010-09-12 20:12:33 UTC (rev 13807)
@@ -25,108 +25,3 @@
 
 def __unicode__(self):
 return self.name
-
-
-__test__ = {'API_TESTS': """
->>> from django.db.models import F
-
->>> Company(name='Example Inc.', num_employees=2300, num_chairs=5,
-... ceo=Employee.objects.create(firstname='Joe', lastname='Smith')).save()
->>> Company(name='Foobar Ltd.', num_employees=3, num_chairs=3,
-... ceo=Employee.objects.create(firstname='Frank', 
lastname='Meyer')).save()
->>> Company(name='Test GmbH', num_employees=32, num_chairs=1,
-... ceo=Employee.objects.create(firstname='Max', 
lastname='Mustermann')).save()
-
->>> company_query = 
Company.objects.values('name','num_employees','num_chairs').order_by('name','num_employees','num_chairs')
-
-# We can filter for companies where the number of employees is greater than the
-# number of chairs.
->>> company_query.filter(num_employees__gt=F('num_chairs'))
-[{'num_chairs': 5, 'name': u'Example Inc.', 'num_employees': 2300}, 
{'num_chairs': 1, 'name': u'Test GmbH', 'num_employees': 32}]
-
-# We can set one field to have the value of another field
-# Make sure we have enough chairs
->>> _ = company_query.update(num_chairs=F('num_employees'))
->>> company_query
-[{'num_chairs': 2300, 'name': u'Example Inc.', 'num_employees': 2300}, 
{'num_chairs': 3, 'name': u'Foobar Ltd.', 'num_employees': 3}, {'num_chairs': 
32, 'name': u'Test GmbH', 'num_employees': 32}]
-
-# We can perform arithmetic operations in expressions
-# Make sure we have 2 spare chairs
->>> _ =company_query.update(num_chairs=F('num_employees')+2)
->>> company_query
-[{'num_chairs': 2302, 'name': u'Example Inc.', 'num_employees': 2300}, 
{'num_chairs': 5, 'name': u'Foobar Ltd.', 'num_employees': 3}, {'num_chairs': 
34, 'name': u'Test GmbH', 'num_employees': 32}]
-
-# Law of order of operations is followed
->>> _ =company_query.update(num_chairs=F('num_employees') + 2 * 
F('num_employees'))
->>> company_query
-[{'num_chairs': 6900, 'name': u'Example Inc.', 'num_employees': 2300}, 
{'num_chairs': 9, 'name': u'Foobar Ltd.', 'num_employees': 3}, {'num_chairs': 
96, 'name': u'Test GmbH', 'num_employees': 32}]
-
-# Law of order of operations can be overridden by parentheses
->>> _ =company_query.update(num_chairs=((F('num_employees') + 2) * 
F('num_employees')))
->>> company_query
-[{'num_chairs': 5294600, 'name': u'Example Inc.', 'num_employees': 2300}, 
{'num_chairs': 15, 'name': u'Foobar Ltd.', 'num_employees': 3}, {'num_chairs': 
1088, 'name': u'Test GmbH', 'num_employees': 32}]
-
-# The relation of a foreign key can become copied over to an other foreign key.
->>> Company.objects.update(point_of_contact=F('ceo'))
-3
-
->>> [c.point_of_contact for c in Company.objects.all()]
-[, , ]
-
->>> c = Company.objects.all()[0]
->>> c.point_of_contact = Employee.objects.create(firstname="Guido", 
lastname="van Rossum")
->>> c.save()
-
-# F Expressions can also span joins
->>> 
Company.objects.filter(ceo__firstname=F('point_of_contact__firstname')).distinct().order_by('name')
-[, ]
-
->>> _ = 
Company.objects.exclude(ceo__firstname=F('point_of_contact__firstname')).update(name='foo')
->>> 
Company.objects.exclude(ceo__firstname=F('point_of_contact__firstname')).get().name
-u'foo'
-
->>> _ = 
Company.objects.exclude(ceo__firstname=F('point_of_contact__firstname')).update(name=F('point_of_contact__lastname'))
-Traceback (most recent call last):
-...
-FieldError: Joined field references are not permitted in this query
-
-# F expressions can be used to update attributes on single objects
->>> test_gmbh = Company.objects.get(name='Test GmbH')
->>> test_gmbh.num_employees
-32
->>> test_gmbh.num_employees = F('num_employees') + 4
->>> test_gmbh.save()
->>> test_gmbh = Company.objects.get(pk=test_gmbh.pk)
->>> test_gmbh.num_employees
-36
-
-# F expressions cannot be used to update attributes which are foreign keys, or
-# attributes which involve joins.
->>> test_gmbh.point_of_contact = None
->>> test_gmbh.save()
->>> test_gmbh.point_of_contact is None
-True
->>> test_gmbh.point_of_contact = F('ceo')
-Traceback (most recent call last):
-...
-ValueError: Cannot assign "": 
"Company.point_of_contact" must be a "Employee" instance.
-
->>> test_gmbh.point_of_contact = test_gmbh.ceo
->>> test_gmbh.save()
->>> test_gmbh.name = 

[Changeset] r13806 - django/branches/releases/1.2.X/tests/modeltests/empty

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:12:23 -0500 (Sun, 12 Sep 2010)
New Revision: 13806

Added:
   django/branches/releases/1.2.X/tests/modeltests/empty/tests.py
Modified:
   django/branches/releases/1.2.X/tests/modeltests/empty/models.py
Log:
[1.2.X] Migrated empty doctests. Thanks to Alex Gaynor.

Backport of r13789 from trunk.

Modified: django/branches/releases/1.2.X/tests/modeltests/empty/models.py
===
--- django/branches/releases/1.2.X/tests/modeltests/empty/models.py 
2010-09-12 20:12:14 UTC (rev 13805)
+++ django/branches/releases/1.2.X/tests/modeltests/empty/models.py 
2010-09-12 20:12:23 UTC (rev 13806)
@@ -7,20 +7,6 @@
 
 from django.db import models
 
+
 class Empty(models.Model):
 pass
-
-__test__ = {'API_TESTS':"""
->>> m = Empty()
->>> m.id
->>> m.save()
->>> m2 = Empty()
->>> m2.save()
->>> len(Empty.objects.all())
-2
->>> m.id is not None
-True
->>> existing = Empty(m.id)
->>> existing.save()
-
-"""}

Added: django/branches/releases/1.2.X/tests/modeltests/empty/tests.py
===
--- django/branches/releases/1.2.X/tests/modeltests/empty/tests.py  
(rev 0)
+++ django/branches/releases/1.2.X/tests/modeltests/empty/tests.py  
2010-09-12 20:12:23 UTC (rev 13806)
@@ -0,0 +1,15 @@
+from django.test import TestCase
+
+from models import Empty
+
+
+class EmptyModelTests(TestCase):
+def test_empty(self):
+m = Empty()
+self.assertEqual(m.id, None)
+m.save()
+m2 = Empty.objects.create()
+self.assertEqual(len(Empty.objects.all()), 2)
+self.assertTrue(m.id is not None)
+existing = Empty(m.id)
+existing.save()

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13805 - django/branches/releases/1.2.X/tests/modeltests/m2m_multiple

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:12:14 -0500 (Sun, 12 Sep 2010)
New Revision: 13805

Added:
   django/branches/releases/1.2.X/tests/modeltests/m2m_multiple/tests.py
Modified:
   django/branches/releases/1.2.X/tests/modeltests/m2m_multiple/models.py
Log:
[1.2.X] Migrated m2m_multiple doctests. Thanks to Alex Gaynor.

Backport of r13789 from trunk.

Modified: django/branches/releases/1.2.X/tests/modeltests/m2m_multiple/models.py
===
--- django/branches/releases/1.2.X/tests/modeltests/m2m_multiple/models.py  
2010-09-12 20:12:02 UTC (rev 13804)
+++ django/branches/releases/1.2.X/tests/modeltests/m2m_multiple/models.py  
2010-09-12 20:12:14 UTC (rev 13805)
@@ -28,52 +28,3 @@
 def __unicode__(self):
 return self.headline
 
-__test__ = {'API_TESTS':"""
->>> from datetime import datetime
-
->>> c1 = Category(name='Sports')
->>> c1.save()
->>> c2 = Category(name='News')
->>> c2.save()
->>> c3 = Category(name='Crime')
->>> c3.save()
->>> c4 = Category(name='Life')
->>> c4.save()
-
->>> a1 = Article(headline='Area man steals', pub_date=datetime(2005, 11, 27))
->>> a1.save()
->>> a1.primary_categories.add(c2, c3)
->>> a1.secondary_categories.add(c4)
-
->>> a2 = Article(headline='Area man runs', pub_date=datetime(2005, 11, 28))
->>> a2.save()
->>> a2.primary_categories.add(c1, c2)
->>> a2.secondary_categories.add(c4)
-
->>> a1.primary_categories.all()
-[, ]
-
->>> a2.primary_categories.all()
-[, ]
-
->>> a1.secondary_categories.all()
-[]
-
-
->>> c1.primary_article_set.all()
-[]
->>> c1.secondary_article_set.all()
-[]
->>> c2.primary_article_set.all()
-[, ]
->>> c2.secondary_article_set.all()
-[]
->>> c3.primary_article_set.all()
-[]
->>> c3.secondary_article_set.all()
-[]
->>> c4.primary_article_set.all()
-[]
->>> c4.secondary_article_set.all()
-[, ]
-"""}

Added: django/branches/releases/1.2.X/tests/modeltests/m2m_multiple/tests.py
===
--- django/branches/releases/1.2.X/tests/modeltests/m2m_multiple/tests.py   
(rev 0)
+++ django/branches/releases/1.2.X/tests/modeltests/m2m_multiple/tests.py   
2010-09-12 20:12:14 UTC (rev 13805)
@@ -0,0 +1,84 @@
+from datetime import datetime
+
+from django.test import TestCase
+
+from models import Article, Category
+
+
+class M2MMultipleTests(TestCase):
+def test_multiple(self):
+c1, c2, c3, c4 = [
+Category.objects.create(name=name)
+for name in ["Sports", "News", "Crime", "Life"]
+]
+
+a1 = Article.objects.create(
+headline="Area man steals", pub_date=datetime(2005, 11, 27)
+)
+a1.primary_categories.add(c2, c3)
+a1.secondary_categories.add(c4)
+
+a2 = Article.objects.create(
+headline="Area man runs", pub_date=datetime(2005, 11, 28)
+)
+a2.primary_categories.add(c1, c2)
+a2.secondary_categories.add(c4)
+
+self.assertQuerysetEqual(
+a1.primary_categories.all(), [
+"Crime",
+"News",
+],
+lambda c: c.name
+)
+self.assertQuerysetEqual(
+a2.primary_categories.all(), [
+"News",
+"Sports",
+],
+lambda c: c.name
+)
+self.assertQuerysetEqual(
+a1.secondary_categories.all(), [
+"Life",
+],
+lambda c: c.name
+)
+self.assertQuerysetEqual(
+c1.primary_article_set.all(), [
+"Area man runs",
+],
+lambda a: a.headline
+)
+self.assertQuerysetEqual(
+c1.secondary_article_set.all(), []
+)
+self.assertQuerysetEqual(
+c2.primary_article_set.all(), [
+"Area man steals",
+"Area man runs",
+],
+lambda a: a.headline
+)
+self.assertQuerysetEqual(
+c2.secondary_article_set.all(), []
+)
+self.assertQuerysetEqual(
+c3.primary_article_set.all(), [
+"Area man steals",
+],
+lambda a: a.headline
+)
+self.assertQuerysetEqual(
+c3.secondary_article_set.all(), []
+)
+self.assertQuerysetEqual(
+c4.primary_article_set.all(), []
+)
+self.assertQuerysetEqual(
+c4.secondary_article_set.all(), [
+"Area man steals",
+"Area man runs",
+],
+lambda a: a.headline
+)

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 

[Changeset] r13804 - in django/branches/releases/1.2.X/tests/modeltests: m2m_and_m2o m2m_intermediary

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:12:02 -0500 (Sun, 12 Sep 2010)
New Revision: 13804

Added:
   django/branches/releases/1.2.X/tests/modeltests/m2m_intermediary/tests.py
Modified:
   django/branches/releases/1.2.X/tests/modeltests/m2m_and_m2o/tests.py
   django/branches/releases/1.2.X/tests/modeltests/m2m_intermediary/models.py
Log:
[1.2.X] Migrated m2m_intermediary doctests. Thanks to Alex Gaynor.

Backport of r13787 from trunk.

Modified: django/branches/releases/1.2.X/tests/modeltests/m2m_and_m2o/tests.py
===
--- django/branches/releases/1.2.X/tests/modeltests/m2m_and_m2o/tests.py
2010-09-12 20:11:52 UTC (rev 13803)
+++ django/branches/releases/1.2.X/tests/modeltests/m2m_and_m2o/tests.py
2010-09-12 20:12:02 UTC (rev 13804)
@@ -8,21 +8,21 @@
 def test_m2m_and_m2o(self):
 r = User.objects.create(username="russell")
 g = User.objects.create(username="gustav")
-
+
 i1 = Issue(num=1)
 i1.client = r
 i1.save()
-
+
 i2 = Issue(num=2)
 i2.client = r
 i2.save()
 i2.cc.add(r)
-
+
 i3 = Issue(num=3)
 i3.client = g
 i3.save()
 i3.cc.add(r)
-
+
 self.assertQuerysetEqual(
 Issue.objects.filter(client=r.id), [
 1,
@@ -46,7 +46,7 @@
 ],
 lambda i: i.num
 )
-
+
 # These queries combine results from the m2m and the m2o relationships.
 # They're three ways of saying the same thing.
 self.assertQuerysetEqual(

Modified: 
django/branches/releases/1.2.X/tests/modeltests/m2m_intermediary/models.py
===
--- django/branches/releases/1.2.X/tests/modeltests/m2m_intermediary/models.py  
2010-09-12 20:11:52 UTC (rev 13803)
+++ django/branches/releases/1.2.X/tests/modeltests/m2m_intermediary/models.py  
2010-09-12 20:12:02 UTC (rev 13804)
@@ -34,35 +34,3 @@
 def __unicode__(self):
 return u'%s (%s)' % (self.reporter, self.position)
 
-__test__ = {'API_TESTS':"""
-# Create a few Reporters.
->>> r1 = Reporter(first_name='John', last_name='Smith')
->>> r1.save()
->>> r2 = Reporter(first_name='Jane', last_name='Doe')
->>> r2.save()
-
-# Create an Article.
->>> from datetime import datetime
->>> a = Article(headline='This is a test', pub_date=datetime(2005, 7, 27))
->>> a.save()
-
-# Create a few Writers.
->>> w1 = Writer(reporter=r1, article=a, position='Main writer')
->>> w1.save()
->>> w2 = Writer(reporter=r2, article=a, position='Contributor')
->>> w2.save()
-
-# Play around with the API.
->>> a.writer_set.select_related().order_by('-position')
-[, ]
->>> w1.reporter
-
->>> w2.reporter
-
->>> w1.article
-
->>> w2.article
-
->>> r1.writer_set.all()
-[]
-"""}

Added: django/branches/releases/1.2.X/tests/modeltests/m2m_intermediary/tests.py
===
--- django/branches/releases/1.2.X/tests/modeltests/m2m_intermediary/tests.py   
(rev 0)
+++ django/branches/releases/1.2.X/tests/modeltests/m2m_intermediary/tests.py   
2010-09-12 20:12:02 UTC (rev 13804)
@@ -0,0 +1,38 @@
+from datetime import datetime
+
+from django.test import TestCase
+
+from models import Reporter, Article, Writer
+
+
+class M2MIntermediaryTests(TestCase):
+def test_intermeiary(self):
+r1 = Reporter.objects.create(first_name="John", last_name="Smith")
+r2 = Reporter.objects.create(first_name="Jane", last_name="Doe")
+
+a = Article.objects.create(
+headline="This is a test", pub_date=datetime(2005, 7, 27)
+)
+
+w1 = Writer.objects.create(reporter=r1, article=a, position="Main 
writer")
+w2 = Writer.objects.create(reporter=r2, article=a, 
position="Contributor")
+
+self.assertQuerysetEqual(
+a.writer_set.select_related().order_by("-position"), [
+("John Smith", "Main writer"),
+("Jane Doe", "Contributor"),
+],
+lambda w: (unicode(w.reporter), w.position)
+)
+self.assertEqual(w1.reporter, r1)
+self.assertEqual(w2.reporter, r2)
+
+self.assertEqual(w1.article, a)
+self.assertEqual(w2.article, a)
+
+self.assertQuerysetEqual(
+r1.writer_set.all(), [
+("John Smith", "Main writer")
+],
+lambda w: (unicode(w.reporter), w.position)
+)

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13803 - django/branches/releases/1.2.X/tests/modeltests/m2m_and_m2o

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:11:52 -0500 (Sun, 12 Sep 2010)
New Revision: 13803

Added:
   django/branches/releases/1.2.X/tests/modeltests/m2m_and_m2o/tests.py
Modified:
   django/branches/releases/1.2.X/tests/modeltests/m2m_and_m2o/models.py
Log:
[1.2.X] Migrate m2m_and_m2o doctests. Thanks to Alex Gaynor.

Backport of r13786 from trunk.

Modified: django/branches/releases/1.2.X/tests/modeltests/m2m_and_m2o/models.py
===
--- django/branches/releases/1.2.X/tests/modeltests/m2m_and_m2o/models.py   
2010-09-12 20:11:41 UTC (rev 13802)
+++ django/branches/releases/1.2.X/tests/modeltests/m2m_and_m2o/models.py   
2010-09-12 20:11:52 UTC (rev 13803)
@@ -19,47 +19,3 @@
 
 class Meta:
 ordering = ('num',)
-
-
-__test__ = {'API_TESTS':"""
->>> Issue.objects.all()
-[]
->>> r = User(username='russell')
->>> r.save()
->>> g = User(username='gustav')
->>> g.save()
-
->>> i = Issue(num=1)
->>> i.client = r
->>> i.save()
-
->>> i2 = Issue(num=2)
->>> i2.client = r
->>> i2.save()
->>> i2.cc.add(r)
-
->>> i3 = Issue(num=3)
->>> i3.client = g
->>> i3.save()
->>> i3.cc.add(r)
-
->>> from django.db.models.query import Q
-
->>> Issue.objects.filter(client=r.id)
-[, ]
->>> Issue.objects.filter(client=g.id)
-[]
->>> Issue.objects.filter(cc__id__exact=g.id)
-[]
->>> Issue.objects.filter(cc__id__exact=r.id)
-[, ]
-
-# These queries combine results from the m2m and the m2o relationships.
-# They're three ways of saying the same thing.
->>> Issue.objects.filter(Q(cc__id__exact=r.id) | Q(client=r.id))
-[, , ]
->>> Issue.objects.filter(cc__id__exact=r.id) | 
Issue.objects.filter(client=r.id)
-[, , ]
->>> Issue.objects.filter(Q(client=r.id) | Q(cc__id__exact=r.id))
-[, , ]
-"""}

Added: django/branches/releases/1.2.X/tests/modeltests/m2m_and_m2o/tests.py
===
--- django/branches/releases/1.2.X/tests/modeltests/m2m_and_m2o/tests.py
(rev 0)
+++ django/branches/releases/1.2.X/tests/modeltests/m2m_and_m2o/tests.py
2010-09-12 20:11:52 UTC (rev 13803)
@@ -0,0 +1,75 @@
+from django.db.models import Q
+from django.test import TestCase
+
+from models import Issue, User
+
+
+class RelatedObjectTests(TestCase):
+def test_m2m_and_m2o(self):
+r = User.objects.create(username="russell")
+g = User.objects.create(username="gustav")
+
+i1 = Issue(num=1)
+i1.client = r
+i1.save()
+
+i2 = Issue(num=2)
+i2.client = r
+i2.save()
+i2.cc.add(r)
+
+i3 = Issue(num=3)
+i3.client = g
+i3.save()
+i3.cc.add(r)
+
+self.assertQuerysetEqual(
+Issue.objects.filter(client=r.id), [
+1,
+2,
+],
+lambda i: i.num
+)
+self.assertQuerysetEqual(
+Issue.objects.filter(client=g.id), [
+3,
+],
+lambda i: i.num
+)
+self.assertQuerysetEqual(
+Issue.objects.filter(cc__id__exact=g.id), []
+)
+self.assertQuerysetEqual(
+Issue.objects.filter(cc__id__exact=r.id), [
+2,
+3,
+],
+lambda i: i.num
+)
+
+# These queries combine results from the m2m and the m2o relationships.
+# They're three ways of saying the same thing.
+self.assertQuerysetEqual(
+Issue.objects.filter(Q(cc__id__exact = r.id) | Q(client=r.id)), [
+1,
+2,
+3,
+],
+lambda i: i.num
+)
+self.assertQuerysetEqual(
+Issue.objects.filter(cc__id__exact=r.id) | 
Issue.objects.filter(client=r.id), [
+1,
+2,
+3,
+],
+lambda i: i.num
+)
+self.assertQuerysetEqual(
+Issue.objects.filter(Q(client=r.id) | Q(cc__id__exact=r.id)), [
+1,
+2,
+3,
+],
+lambda i: i.num
+)

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13802 - django/branches/releases/1.2.X/tests/modeltests/get_or_create

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:11:41 -0500 (Sun, 12 Sep 2010)
New Revision: 13802

Added:
   django/branches/releases/1.2.X/tests/modeltests/get_or_create/tests.py
Modified:
   django/branches/releases/1.2.X/tests/modeltests/get_or_create/models.py
Log:
[1.2.X] Migrate get_or_create doctests. Thanks to Alex Gaynor.

Backport of r13785 from trunk.

Modified: 
django/branches/releases/1.2.X/tests/modeltests/get_or_create/models.py
===
--- django/branches/releases/1.2.X/tests/modeltests/get_or_create/models.py 
2010-09-12 20:11:30 UTC (rev 13801)
+++ django/branches/releases/1.2.X/tests/modeltests/get_or_create/models.py 
2010-09-12 20:11:41 UTC (rev 13802)
@@ -19,65 +19,3 @@
 class ManualPrimaryKeyTest(models.Model):
 id = models.IntegerField(primary_key=True)
 data = models.CharField(max_length=100)
-
-__test__ = {'API_TESTS':"""
-# Acting as a divine being, create an Person.
->>> from datetime import date
->>> p = Person(first_name='John', last_name='Lennon', birthday=date(1940, 10, 
9))
->>> p.save()
-
-# Only one Person is in the database at this point.
->>> Person.objects.count()
-1
-
-# get_or_create() a person with similar first names.
->>> p, created = Person.objects.get_or_create(first_name='John', 
last_name='Lennon', defaults={'birthday': date(1940, 10, 9)})
-
-# get_or_create() didn't have to create an object.
->>> created
-False
-
-# There's still only one Person in the database.
->>> Person.objects.count()
-1
-
-# get_or_create() a Person with a different name.
->>> p, created = Person.objects.get_or_create(first_name='George', 
last_name='Harrison', defaults={'birthday': date(1943, 2, 25)})
->>> created
-True
->>> Person.objects.count()
-2
-
-# If we execute the exact same statement, it won't create a Person.
->>> p, created = Person.objects.get_or_create(first_name='George', 
last_name='Harrison', defaults={'birthday': date(1943, 2, 25)})
->>> created
-False
->>> Person.objects.count()
-2
-
-# If you don't specify a value or default value for all required fields, you
-# will get an error.
->>> try:
-... p, created = Person.objects.get_or_create(first_name='Tom', 
last_name='Smith')
-... except Exception, e:
-... if isinstance(e, IntegrityError):
-... print "Pass"
-... else:
-... print "Fail with %s" % type(e)
-Pass
-
-# If you specify an existing primary key, but different other fields, then you
-# will get an error and data will not be updated.
->>> m = ManualPrimaryKeyTest(id=1, data='Original')
->>> m.save()
->>> try:
-...m, created = ManualPrimaryKeyTest.objects.get_or_create(id=1, 
data='Different')
-... except Exception, e:
-...if isinstance(e, IntegrityError):
-...print "Pass"
-...else:
-...print "Fail with %s" % type(e)
-Pass
->>> ManualPrimaryKeyTest.objects.get(id=1).data == 'Original'
-True
-"""}

Added: django/branches/releases/1.2.X/tests/modeltests/get_or_create/tests.py
===
--- django/branches/releases/1.2.X/tests/modeltests/get_or_create/tests.py  
(rev 0)
+++ django/branches/releases/1.2.X/tests/modeltests/get_or_create/tests.py  
2010-09-12 20:11:41 UTC (rev 13802)
@@ -0,0 +1,52 @@
+from datetime import date
+
+from django.db import IntegrityError
+from django.test import TestCase
+
+from models import Person, ManualPrimaryKeyTest
+
+
+class GetOrCreateTests(TestCase):
+def test_get_or_create(self):
+p = Person.objects.create(
+first_name='John', last_name='Lennon', birthday=date(1940, 10, 9)
+)
+
+p, created = Person.objects.get_or_create(
+first_name="John", last_name="Lennon", defaults={
+"birthday": date(1940, 10, 9)
+}
+)
+self.assertFalse(created)
+self.assertEqual(Person.objects.count(), 1)
+
+p, created = Person.objects.get_or_create(
+first_name='George', last_name='Harrison', defaults={
+'birthday': date(1943, 2, 25)
+}
+)
+self.assertTrue(created)
+self.assertEqual(Person.objects.count(), 2)
+
+# If we execute the exact same statement, it won't create a Person.
+p, created = Person.objects.get_or_create(
+first_name='George', last_name='Harrison', defaults={
+'birthday': date(1943, 2, 25)
+}
+)
+self.assertFalse(created)
+self.assertEqual(Person.objects.count(), 2)
+
+# If you don't specify a value or default value for all required
+# fields, you will get an error.
+self.assertRaises(IntegrityError,
+Person.objects.get_or_create, first_name="Tom", last_name="Smith"
+)
+
+# If you specify an existing primary key, but different other fields,
+# then you will get an error and data will not be updated.
+m = 

[Changeset] r13801 - django/branches/releases/1.2.X/tests/modeltests/get_object_or_404

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:11:30 -0500 (Sun, 12 Sep 2010)
New Revision: 13801

Added:
   django/branches/releases/1.2.X/tests/modeltests/get_object_or_404/tests.py
Modified:
   django/branches/releases/1.2.X/tests/modeltests/get_object_or_404/models.py
Log:
[1.2.X] Migrated get_object_or_404 doctests. Thanks to Alex Gaynor.

Backport of r13784 from trunk.

Modified: 
django/branches/releases/1.2.X/tests/modeltests/get_object_or_404/models.py
===
--- django/branches/releases/1.2.X/tests/modeltests/get_object_or_404/models.py 
2010-09-12 20:11:17 UTC (rev 13800)
+++ django/branches/releases/1.2.X/tests/modeltests/get_object_or_404/models.py 
2010-09-12 20:11:30 UTC (rev 13801)
@@ -32,76 +32,3 @@
 
 def __unicode__(self):
 return self.title
-
-__test__ = {'API_TESTS':"""
-# Create some Authors.
->>> a = Author.objects.create(name="Brave Sir Robin")
->>> a.save()
->>> a2 = Author.objects.create(name="Patsy")
->>> a2.save()
-
-# No Articles yet, so we should get a Http404 error.
->>> get_object_or_404(Article, title="Foo")
-Traceback (most recent call last):
-...
-Http404: No Article matches the given query.
-
-# Create an Article.
->>> article = Article.objects.create(title="Run away!")
->>> article.authors = [a, a2]
->>> article.save()
-
-# get_object_or_404 can be passed a Model to query.
->>> get_object_or_404(Article, title__contains="Run")
-
-
-# We can also use the Article manager through an Author object.
->>> get_object_or_404(a.article_set, title__contains="Run")
-
-
-# No articles containing "Camelot".  This should raise a Http404 error.
->>> get_object_or_404(a.article_set, title__contains="Camelot")
-Traceback (most recent call last):
-...
-Http404: No Article matches the given query.
-
-# Custom managers can be used too.
->>> get_object_or_404(Article.by_a_sir, title="Run away!")
-
-
-# QuerySets can be used too.
->>> get_object_or_404(Article.objects.all(), title__contains="Run")
-
-
-# Just as when using a get() lookup, you will get an error if more than one
-# object is returned.
->>> get_object_or_404(Author.objects.all())
-Traceback (most recent call last):
-...
-MultipleObjectsReturned: get() returned more than one Author -- it returned 
...! Lookup parameters were {}
-
-# Using an EmptyQuerySet raises a Http404 error.
->>> get_object_or_404(Article.objects.none(), title__contains="Run")
-Traceback (most recent call last):
-...
-Http404: No Article matches the given query.
-
-# get_list_or_404 can be used to get lists of objects
->>> get_list_or_404(a.article_set, title__icontains='Run')
-[]
-
-# Http404 is returned if the list is empty.
->>> get_list_or_404(a.article_set, title__icontains='Shrubbery')
-Traceback (most recent call last):
-...
-Http404: No Article matches the given query.
-
-# Custom managers can be used too.
->>> get_list_or_404(Article.by_a_sir, title__icontains="Run")
-[]
-
-# QuerySets can be used too.
->>> get_list_or_404(Article.objects.all(), title__icontains="Run")
-[]
-
-"""}

Added: 
django/branches/releases/1.2.X/tests/modeltests/get_object_or_404/tests.py
===
--- django/branches/releases/1.2.X/tests/modeltests/get_object_or_404/tests.py  
(rev 0)
+++ django/branches/releases/1.2.X/tests/modeltests/get_object_or_404/tests.py  
2010-09-12 20:11:30 UTC (rev 13801)
@@ -0,0 +1,80 @@
+from django.http import Http404
+from django.shortcuts import get_object_or_404, get_list_or_404
+from django.test import TestCase
+
+from models import Author, Article
+
+
+class GetObjectOr404Tests(TestCase):
+def test_get_object_or_404(self):
+a1 = Author.objects.create(name="Brave Sir Robin")
+a2 = Author.objects.create(name="Patsy")
+
+# No Articles yet, so we should get a Http404 error.
+self.assertRaises(Http404, get_object_or_404, Article, title="Foo")
+
+article = Article.objects.create(title="Run away!")
+article.authors = [a1, a2]
+# get_object_or_404 can be passed a Model to query.
+self.assertEqual(
+get_object_or_404(Article, title__contains="Run"),
+article
+)
+
+# We can also use the Article manager through an Author object.
+self.assertEqual(
+get_object_or_404(a1.article_set, title__contains="Run"),
+article
+)
+
+# No articles containing "Camelot".  This should raise a Http404 error.
+self.assertRaises(Http404,
+get_object_or_404, a1.article_set, title__contains="Camelot"
+)
+
+# Custom managers can be used too.
+self.assertEqual(
+get_object_or_404(Article.by_a_sir, title="Run away!"),
+article
+)
+
+# QuerySets can be used too.
+self.assertEqual(
+get_object_or_404(Article.objects.all(), title__contains="Run"),
+article
+)

[Changeset] r13800 - django/branches/releases/1.2.X/tests/modeltests/get_latest

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:11:17 -0500 (Sun, 12 Sep 2010)
New Revision: 13800

Added:
   django/branches/releases/1.2.X/tests/modeltests/get_latest/tests.py
Modified:
   django/branches/releases/1.2.X/tests/modeltests/get_latest/models.py
Log:
[1.2.X] Migrate get_latest doctests. Thanks to Alex Gaynor.

Backport of r13783 from trunk.

Modified: django/branches/releases/1.2.X/tests/modeltests/get_latest/models.py
===
--- django/branches/releases/1.2.X/tests/modeltests/get_latest/models.py
2010-09-12 20:11:06 UTC (rev 13799)
+++ django/branches/releases/1.2.X/tests/modeltests/get_latest/models.py
2010-09-12 20:11:17 UTC (rev 13800)
@@ -28,52 +28,3 @@
 
 def __unicode__(self):
 return self.name
-
-__test__ = {'API_TESTS':"""
-# Because no Articles exist yet, latest() raises ArticleDoesNotExist.
->>> Article.objects.latest()
-Traceback (most recent call last):
-...
-DoesNotExist: Article matching query does not exist.
-
-# Create a couple of Articles.
->>> from datetime import datetime
->>> a1 = Article(headline='Article 1', pub_date=datetime(2005, 7, 26), 
expire_date=datetime(2005, 9, 1))
->>> a1.save()
->>> a2 = Article(headline='Article 2', pub_date=datetime(2005, 7, 27), 
expire_date=datetime(2005, 7, 28))
->>> a2.save()
->>> a3 = Article(headline='Article 3', pub_date=datetime(2005, 7, 27), 
expire_date=datetime(2005, 8, 27))
->>> a3.save()
->>> a4 = Article(headline='Article 4', pub_date=datetime(2005, 7, 28), 
expire_date=datetime(2005, 7, 30))
->>> a4.save()
-
-# Get the latest Article.
->>> Article.objects.latest()
-
-
-# Get the latest Article that matches certain filters.
->>> Article.objects.filter(pub_date__lt=datetime(2005, 7, 27)).latest()
-
-
-# Pass a custom field name to latest() to change the field that's used to
-# determine the latest object.
->>> Article.objects.latest('expire_date')
-
-
->>> Article.objects.filter(pub_date__gt=datetime(2005, 7, 
26)).latest('expire_date')
-
-
-# You can still use latest() with a model that doesn't have "get_latest_by"
-# set -- just pass in the field name manually.
->>> p1 = Person(name='Ralph', birthday=datetime(1950, 1, 1))
->>> p1.save()
->>> p2 = Person(name='Stephanie', birthday=datetime(1960, 2, 3))
->>> p2.save()
->>> Person.objects.latest()
-Traceback (most recent call last):
-...
-AssertionError: latest() requires either a field_name parameter or 
'get_latest_by' in the model
-
->>> Person.objects.latest('birthday')
-
-"""}

Added: django/branches/releases/1.2.X/tests/modeltests/get_latest/tests.py
===
--- django/branches/releases/1.2.X/tests/modeltests/get_latest/tests.py 
(rev 0)
+++ django/branches/releases/1.2.X/tests/modeltests/get_latest/tests.py 
2010-09-12 20:11:17 UTC (rev 13800)
@@ -0,0 +1,53 @@
+from datetime import datetime
+
+from django.test import TestCase
+
+from models import Article, Person
+
+
+class LatestTests(TestCase):
+def test_latest(self):
+# Because no Articles exist yet, latest() raises ArticleDoesNotExist.
+self.assertRaises(Article.DoesNotExist, Article.objects.latest)
+
+a1 = Article.objects.create(
+headline="Article 1", pub_date=datetime(2005, 7, 26),
+expire_date=datetime(2005, 9, 1)
+)
+a2 = Article.objects.create(
+headline="Article 2", pub_date=datetime(2005, 7, 27),
+expire_date=datetime(2005, 7, 28)
+)
+a3 = Article.objects.create(
+headline="Article 3", pub_date=datetime(2005, 7, 27),
+expire_date=datetime(2005, 8, 27)
+)
+a4 = Article.objects.create(
+headline="Article 4", pub_date=datetime(2005, 7, 28),
+expire_date=datetime(2005, 7, 30)
+)
+
+# Get the latest Article.
+self.assertEqual(Article.objects.latest(), a4)
+# Get the latest Article that matches certain filters.
+self.assertEqual(
+Article.objects.filter(pub_date__lt=datetime(2005, 7, 
27)).latest(),
+a1
+)
+
+# Pass a custom field name to latest() to change the field that's used
+# to determine the latest object.
+self.assertEqual(Article.objects.latest('expire_date'), a1)
+self.assertEqual(
+Article.objects.filter(pub_date__gt=datetime(2005, 7, 
26)).latest('expire_date'),
+a3,
+)
+
+def test_latest_manual(self):
+# You can still use latest() with a model that doesn't have
+# "get_latest_by" set -- just pass in the field name manually.
+p1 = Person.objects.create(name="Ralph", birthday=datetime(1950, 1, 1))
+p2 = Person.objects.create(name="Stephanie", birthday=datetime(1960, 
2, 3))
+self.assertRaises(AssertionError, Person.objects.latest)
+
+self.assertEqual(Person.objects.latest("birthday"), 

[Changeset] r13799 - django/branches/releases/1.2.X/tests/modeltests/force_insert_update

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:11:06 -0500 (Sun, 12 Sep 2010)
New Revision: 13799

Added:
   django/branches/releases/1.2.X/tests/modeltests/force_insert_update/tests.py
Modified:
   django/branches/releases/1.2.X/tests/modeltests/force_insert_update/models.py
Log:
[1.2.X] Migrated the force_insert_update tests. Thanks to Alex Gaynor.

Backport of r13782 from trunk.

Modified: 
django/branches/releases/1.2.X/tests/modeltests/force_insert_update/models.py
===
--- 
django/branches/releases/1.2.X/tests/modeltests/force_insert_update/models.py   
2010-09-12 20:10:54 UTC (rev 13798)
+++ 
django/branches/releases/1.2.X/tests/modeltests/force_insert_update/models.py   
2010-09-12 20:11:06 UTC (rev 13799)
@@ -11,54 +11,3 @@
 class WithCustomPK(models.Model):
 name = models.IntegerField(primary_key=True)
 value = models.IntegerField()
-
-__test__ = {"API_TESTS": """
->>> c = Counter.objects.create(name="one", value=1)
-
-# The normal case
->>> c.value = 2
->>> c.save()
-
-# Same thing, via an update
->>> c.value = 3
->>> c.save(force_update=True)
-
-# Won't work because force_update and force_insert are mutually exclusive
->>> c.value = 4
->>> c.save(force_insert=True, force_update=True)
-Traceback (most recent call last):
-...
-ValueError: Cannot force both insert and updating in model saving.
-
-# Try to update something that doesn't have a primary key in the first place.
->>> c1 = Counter(name="two", value=2)
->>> c1.save(force_update=True)
-Traceback (most recent call last):
-...
-ValueError: Cannot force an update in save() with no primary key.
-
->>> c1.save(force_insert=True)
-
-# Won't work because we can't insert a pk of the same value.
->>> sid = transaction.savepoint()
->>> c.value = 5
->>> try:
-... c.save(force_insert=True)
-... except Exception, e:
-... if isinstance(e, IntegrityError):
-... print "Pass"
-... else:
-... print "Fail with %s" % type(e)
-Pass
->>> transaction.savepoint_rollback(sid)
-
-# Trying to update should still fail, even with manual primary keys, if the
-# data isn't in the database already.
->>> obj = WithCustomPK(name=1, value=1)
->>> obj.save(force_update=True)
-Traceback (most recent call last):
-...
-DatabaseError: ...
-
-"""
-}

Added: 
django/branches/releases/1.2.X/tests/modeltests/force_insert_update/tests.py
===
--- 
django/branches/releases/1.2.X/tests/modeltests/force_insert_update/tests.py
(rev 0)
+++ 
django/branches/releases/1.2.X/tests/modeltests/force_insert_update/tests.py
2010-09-12 20:11:06 UTC (rev 13799)
@@ -0,0 +1,38 @@
+from django.db import transaction, IntegrityError, DatabaseError
+from django.test import TestCase
+
+from models import Counter, WithCustomPK
+
+
+class ForceTests(TestCase):
+def test_force_update(self):
+c = Counter.objects.create(name="one", value=1)
+# The normal case
+
+c.value = 2
+c.save()
+# Same thing, via an update
+c.value = 3
+c.save(force_update=True)
+
+# Won't work because force_update and force_insert are mutually
+# exclusive
+c.value = 4
+self.assertRaises(ValueError, c.save, force_insert=True, 
force_update=True)
+
+# Try to update something that doesn't have a primary key in the first
+# place.
+c1 = Counter(name="two", value=2)
+self.assertRaises(ValueError, c1.save, force_update=True)
+c1.save(force_insert=True)
+
+# Won't work because we can't insert a pk of the same value.
+sid = transaction.savepoint()
+c.value = 5
+self.assertRaises(IntegrityError, c.save, force_insert=True)
+transaction.savepoint_rollback(sid)
+
+# Trying to update should still fail, even with manual primary keys, if
+# the data isn't in the database already.
+obj = WithCustomPK(name=1, value=1)
+self.assertRaises(DatabaseError, obj.save, force_update=True)

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13798 - django/branches/releases/1.2.X/tests/modeltests/files

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:10:54 -0500 (Sun, 12 Sep 2010)
New Revision: 13798

Added:
   django/branches/releases/1.2.X/tests/modeltests/files/tests.py
Modified:
   django/branches/releases/1.2.X/tests/modeltests/files/models.py
Log:
[1.2.X] Migrate the files doctests. Thanks to Alex Gaynor.

Backport of r13781 from trunk.

Modified: django/branches/releases/1.2.X/tests/modeltests/files/models.py
===
--- django/branches/releases/1.2.X/tests/modeltests/files/models.py 
2010-09-12 20:10:43 UTC (rev 13797)
+++ django/branches/releases/1.2.X/tests/modeltests/files/models.py 
2010-09-12 20:10:54 UTC (rev 13798)
@@ -7,10 +7,12 @@
 
 import random
 import tempfile
+
 from django.db import models
 from django.core.files.base import ContentFile
 from django.core.files.storage import FileSystemStorage
 
+
 temp_storage_location = tempfile.mkdtemp()
 temp_storage = FileSystemStorage(location=temp_storage_location)
 
@@ -30,125 +32,3 @@
 custom = models.FileField(storage=temp_storage, upload_to=custom_upload_to)
 random = models.FileField(storage=temp_storage, upload_to=random_upload_to)
 default = models.FileField(storage=temp_storage, upload_to='tests', 
default='tests/default.txt')
-
-__test__ = {'API_TESTS':"""
-# Attempting to access a FileField from the class raises a descriptive error
->>> Storage.normal
-Traceback (most recent call last):
-...
-AttributeError: The 'normal' attribute can only be accessed from Storage 
instances.
-
-# An object without a file has limited functionality.
-
->>> obj1 = Storage()
->>> obj1.normal
-
->>> obj1.normal.size
-Traceback (most recent call last):
-...
-ValueError: The 'normal' attribute has no file associated with it.
-
-# Saving a file enables full functionality.
-
->>> obj1.normal.save('django_test.txt', ContentFile('content'))
->>> obj1.normal
-
->>> obj1.normal.size
-7
->>> obj1.normal.read()
-'content'
-
-# File objects can be assigned to FileField attributes,  but shouldn't get
-# committed until the model it's attached to is saved.
-
->>> from django.core.files.uploadedfile import SimpleUploadedFile
->>> obj1.normal = SimpleUploadedFile('assignment.txt', 'content')
->>> dirs, files = temp_storage.listdir('tests')
->>> dirs
-[]
->>> files.sort()
->>> files == ['default.txt', 'django_test.txt']
-True
-
->>> obj1.save()
->>> dirs, files = temp_storage.listdir('tests')
->>> files.sort()
->>> files == ['assignment.txt', 'default.txt', 'django_test.txt']
-True
-
-# Files can be read in a little at a time, if necessary.
-
->>> obj1.normal.open()
->>> obj1.normal.read(3)
-'con'
->>> obj1.normal.read()
-'tent'
->>> '-'.join(obj1.normal.chunks(chunk_size=2))
-'co-nt-en-t'
-
-# Save another file with the same name.
-
->>> obj2 = Storage()
->>> obj2.normal.save('django_test.txt', ContentFile('more content'))
->>> obj2.normal
-
->>> obj2.normal.size
-12
-
-# Push the objects into the cache to make sure they pickle properly
-
->>> from django.core.cache import cache
->>> cache.set('obj1', obj1)
->>> cache.set('obj2', obj2)
->>> cache.get('obj2').normal
-
-
-# Deleting an object deletes the file it uses, if there are no other objects
-# still using that file.
-
->>> obj2.delete()
->>> obj2.normal.save('django_test.txt', ContentFile('more content'))
->>> obj2.normal
-
-
-# Multiple files with the same name get _N appended to them.
-
->>> objs = [Storage() for i in range(3)]
->>> for o in objs:
-... o.normal.save('multiple_files.txt', ContentFile('Same Content'))
->>> [o.normal for o in objs]
-[, , ]
->>> for o in objs:
-... o.delete()
-
-# Default values allow an object to access a single file.
-
->>> obj3 = Storage.objects.create()
->>> obj3.default
-
->>> obj3.default.read()
-'default content'
-
-# But it shouldn't be deleted, even if there are no more objects using it.
-
->>> obj3.delete()
->>> obj3 = Storage()
->>> obj3.default.read()
-'default content'
-
-# Verify the fix for #5655, making sure the directory is only determined once.
-
->>> obj4 = Storage()
->>> obj4.random.save('random_file', ContentFile('random content'))
->>> obj4.random
-
-
-# Clean up the temporary files and dir.
->>> obj1.normal.delete()
->>> obj2.normal.delete()
->>> obj3.default.delete()
->>> obj4.random.delete()
-
->>> import shutil
->>> shutil.rmtree(temp_storage_location)
-"""}

Added: django/branches/releases/1.2.X/tests/modeltests/files/tests.py
===
--- django/branches/releases/1.2.X/tests/modeltests/files/tests.py  
(rev 0)
+++ django/branches/releases/1.2.X/tests/modeltests/files/tests.py  
2010-09-12 20:10:54 UTC (rev 13798)
@@ -0,0 +1,100 @@
+import shutil
+
+from django.core.cache import cache
+from django.core.files.base import ContentFile
+from django.core.files.uploadedfile import SimpleUploadedFile
+from django.test import TestCase
+
+from models import Storage, temp_storage, 

[Changeset] r13797 - django/branches/releases/1.2.X/tests/modeltests/field_subclassing

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:10:43 -0500 (Sun, 12 Sep 2010)
New Revision: 13797

Modified:
   django/branches/releases/1.2.X/tests/modeltests/field_subclassing/fields.py
   django/branches/releases/1.2.X/tests/modeltests/field_subclassing/models.py
   django/branches/releases/1.2.X/tests/modeltests/field_subclassing/tests.py
Log:
[1.2.X] Migrated the field_subclsasing doctests. Thanks to Alex Gaynor.

Backport of r13780 from trunk.

Modified: 
django/branches/releases/1.2.X/tests/modeltests/field_subclassing/fields.py
===
--- django/branches/releases/1.2.X/tests/modeltests/field_subclassing/fields.py 
2010-09-12 20:10:30 UTC (rev 13796)
+++ django/branches/releases/1.2.X/tests/modeltests/field_subclassing/fields.py 
2010-09-12 20:10:43 UTC (rev 13797)
@@ -53,18 +53,18 @@
 
 class JSONField(models.TextField):
 __metaclass__ = models.SubfieldBase
-
+
 description = ("JSONField automatically serializes and desializes values 
to "
 "and from JSON.")
-
+
 def to_python(self, value):
 if not value:
 return None
-
+
 if isinstance(value, basestring):
 value = json.loads(value)
 return value
-
+
 def get_db_prep_save(self, value):
 if value is None:
 return None

Modified: 
django/branches/releases/1.2.X/tests/modeltests/field_subclassing/models.py
===
--- django/branches/releases/1.2.X/tests/modeltests/field_subclassing/models.py 
2010-09-12 20:10:30 UTC (rev 13796)
+++ django/branches/releases/1.2.X/tests/modeltests/field_subclassing/models.py 
2010-09-12 20:10:43 UTC (rev 13797)
@@ -2,7 +2,6 @@
 Tests for field subclassing.
 """
 
-from django.core import serializers
 from django.db import models
 from django.utils.encoding import force_unicode
 
@@ -18,56 +17,3 @@
 
 class DataModel(models.Model):
 data = JSONField()
-
-__test__ = {'API_TESTS': ur"""
-# Creating a model with custom fields is done as per normal.
->>> s = Small(1, 2)
->>> print s
-12
->>> m = MyModel(name='m', data=s)
->>> m.save()
-
-# Custom fields still have normal field's attributes.
->>> m._meta.get_field('data').verbose_name
-'small field'
-
-# The m.data attribute has been initialised correctly. It's a Small object.
->>> m.data.first, m.data.second
-(1, 2)
-
-# The data loads back from the database correctly and 'data' has the right 
type.
->>> m1 = MyModel.objects.get(pk=m.pk)
->>> isinstance(m1.data, Small)
-True
->>> print m1.data
-12
-
-# We can do normal filtering on the custom field (and will get an error when we
-# use a lookup type that does not make sense).
->>> s1 = Small(1, 3)
->>> s2 = Small('a', 'b')
->>> MyModel.objects.filter(data__in=[s, s1, s2])
-[]
->>> MyModel.objects.filter(data__lt=s)
-Traceback (most recent call last):
-...
-TypeError: Invalid lookup type: 'lt'
-
-# Serialization works, too.
->>> stream = serializers.serialize("json", MyModel.objects.all())
->>> stream
-'[{"pk": 1, "model": "field_subclassing.mymodel", "fields": {"data": "12", 
"name": "m"}}]'
->>> obj = list(serializers.deserialize("json", stream))[0]
->>> obj.object == m
-True
-
-# Test retrieving custom field data
->>> m.delete()
->>> m1 = MyModel(name="1", data=Small(1, 2))
->>> m1.save()
->>> m2 = MyModel(name="2", data=Small(2, 3))
->>> m2.save()
->>> for m in MyModel.objects.all(): print unicode(m.data)
-12
-23
-"""}

Modified: 
django/branches/releases/1.2.X/tests/modeltests/field_subclassing/tests.py
===
--- django/branches/releases/1.2.X/tests/modeltests/field_subclassing/tests.py  
2010-09-12 20:10:30 UTC (rev 13796)
+++ django/branches/releases/1.2.X/tests/modeltests/field_subclassing/tests.py  
2010-09-12 20:10:43 UTC (rev 13797)
@@ -1,21 +1,75 @@
+from django.core import serializers
 from django.test import TestCase
 
-from models import DataModel
+from fields import Small
+from models import DataModel, MyModel
 
 
 class CustomField(TestCase):
 def test_defer(self):
 d = DataModel.objects.create(data=[1, 2, 3])
-
+
 self.assertTrue(isinstance(d.data, list))
-
+
 d = DataModel.objects.get(pk=d.pk)
 self.assertTrue(isinstance(d.data, list))
 self.assertEqual(d.data, [1, 2, 3])
-
+
 d = DataModel.objects.defer("data").get(pk=d.pk)
 d.save()
-
+
 d = DataModel.objects.get(pk=d.pk)
 self.assertTrue(isinstance(d.data, list))
 self.assertEqual(d.data, [1, 2, 3])
+
+def test_custom_field(self):
+# Creating a model with custom fields is done as per normal.
+s = Small(1, 2)
+self.assertEqual(str(s), "12")
+
+m = MyModel.objects.create(name="m", data=s)
+# Custom fields still have normal field's attributes.
+self.assertEqual(m._meta.get_field("data").verbose_name, "small 

[Changeset] r13796 - in django/branches/releases/1.2.X/tests: modeltests/field_defaults regressiontests/i18n

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:10:30 -0500 (Sun, 12 Sep 2010)
New Revision: 13796

Added:
   django/branches/releases/1.2.X/tests/modeltests/field_defaults/tests.py
Modified:
   django/branches/releases/1.2.X/tests/modeltests/field_defaults/models.py
   django/branches/releases/1.2.X/tests/regressiontests/i18n/models.py
   django/branches/releases/1.2.X/tests/regressiontests/i18n/tests.py
Log:
[1.2.X] Migrated i18n and field_defaults doctests. Thanks to Alex Gaynor.

Backport of r13779 from trunk.

Modified: 
django/branches/releases/1.2.X/tests/modeltests/field_defaults/models.py
===
--- django/branches/releases/1.2.X/tests/modeltests/field_defaults/models.py
2010-09-12 20:10:17 UTC (rev 13795)
+++ django/branches/releases/1.2.X/tests/modeltests/field_defaults/models.py
2010-09-12 20:10:30 UTC (rev 13796)
@@ -19,41 +19,3 @@
 
 def __unicode__(self):
 return self.headline
-
-__test__ = {'API_TESTS': u"""
->>> from datetime import datetime
-
-# No articles are in the system yet.
->>> Article.objects.all()
-[]
-
-# Create an Article.
->>> a = Article(id=None)
-
-# Grab the current datetime it should be very close to the default that just
-# got saved as a.pub_date
->>> now = datetime.now()
-
-# Save it into the database. You have to call save() explicitly.
->>> a.save()
-
-# Now it has an ID. Note it's a long integer, as designated by the trailing 
"L".
->>> a.id
-1L
-
-# Access database columns via Python attributes.
->>> a.headline
-u'Default headline'
-
-# make sure the two dates are sufficiently close
->>> d = now - a.pub_date
->>> d.seconds < 5
-True
-
-# make sure that SafeString/SafeUnicode fields work
->>> from django.utils.safestring import SafeUnicode, SafeString
->>> a.headline = SafeUnicode(u'Iñtërnâtiônàlizætiøn1')
->>> a.save()
->>> a.headline = SafeString(u'Iñtërnâtiônàlizætiøn1'.encode('utf-8'))
->>> a.save()
-"""}

Added: django/branches/releases/1.2.X/tests/modeltests/field_defaults/tests.py
===
--- django/branches/releases/1.2.X/tests/modeltests/field_defaults/tests.py 
(rev 0)
+++ django/branches/releases/1.2.X/tests/modeltests/field_defaults/tests.py 
2010-09-12 20:10:30 UTC (rev 13796)
@@ -0,0 +1,16 @@
+from datetime import datetime
+
+from django.test import TestCase
+
+from models import Article
+
+
+class DefaultTests(TestCase):
+def test_field_defaults(self):
+a = Article()
+now = datetime.now()
+a.save()
+
+self.assertTrue(isinstance(a.id, (int, long)))
+self.assertEqual(a.headline, "Default headline")
+self.assertTrue((now - a.pub_date).seconds < 5)

Modified: django/branches/releases/1.2.X/tests/regressiontests/i18n/models.py
===
--- django/branches/releases/1.2.X/tests/regressiontests/i18n/models.py 
2010-09-12 20:10:17 UTC (rev 13795)
+++ django/branches/releases/1.2.X/tests/regressiontests/i18n/models.py 
2010-09-12 20:10:30 UTC (rev 13796)
@@ -10,9 +10,3 @@
 date_added = models.DateTimeField(default=datetime(1799,1,31,23,59,59,0))
 cents_payed = models.DecimalField(max_digits=4, decimal_places=2)
 products_delivered = models.IntegerField()
-
-__test__ = {'API_TESTS': '''
->>> tm = TestModel()
->>> tm.save()
-'''
-}

Modified: django/branches/releases/1.2.X/tests/regressiontests/i18n/tests.py
===
--- django/branches/releases/1.2.X/tests/regressiontests/i18n/tests.py  
2010-09-12 20:10:17 UTC (rev 13795)
+++ django/branches/releases/1.2.X/tests/regressiontests/i18n/tests.py  
2010-09-12 20:10:30 UTC (rev 13796)
@@ -5,14 +5,17 @@
 import sys
 import pickle
 
+from django.conf import settings
 from django.template import Template, Context
-from django.conf import settings
+from django.test import TestCase
 from django.utils.formats import get_format, date_format, time_format, 
localize, localize_input
 from django.utils.numberformat import format as nformat
-from django.test import TestCase
+from django.utils.safestring import mark_safe, SafeString, SafeUnicode
 from django.utils.translation import ugettext, ugettext_lazy, activate, 
deactivate, gettext_lazy, to_locale
 
+
 from forms import I18nForm, SelectDateForm, SelectDateWidget, CompanyForm
+from models import Company, TestModel
 
 
 class TranslationTests(TestCase):
@@ -59,7 +62,6 @@
 """
 Translating a string requiring no auto-escaping shouldn't change the 
"safe" status.
 """
-from django.utils.safestring import mark_safe, SafeString, SafeUnicode
 s = mark_safe('Password')
 self.assertEqual(SafeString, type(s))
 activate('de')
@@ -620,3 +622,16 @@
 
 def test_django_fallback(self):
 self.assertUgettext('Date/time', 'Datum/Zeit')
+
+
+class TestModels(TestCase):
+def 

[Changeset] r13795 - django/branches/releases/1.2.X/tests/modeltests/delete

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:10:17 -0500 (Sun, 12 Sep 2010)
New Revision: 13795

Added:
   django/branches/releases/1.2.X/tests/modeltests/delete/tests.py
Modified:
   django/branches/releases/1.2.X/tests/modeltests/delete/models.py
Log:
[1.2.X] Migrated delete doctests. Thanks to Alex Gaynor.

Backport of r13778 from trunk.

Modified: django/branches/releases/1.2.X/tests/modeltests/delete/models.py
===
--- django/branches/releases/1.2.X/tests/modeltests/delete/models.py
2010-09-12 20:10:03 UTC (rev 13794)
+++ django/branches/releases/1.2.X/tests/modeltests/delete/models.py
2010-09-12 20:10:17 UTC (rev 13795)
@@ -40,168 +40,3 @@
 class F(DefaultRepr, models.Model):
 e = models.ForeignKey(E, related_name='f_rel')
 
-
-__test__ = {'API_TESTS': """
-### Tests for models A,B,C,D ###
-
-## First, test the CollectedObjects data structure directly
-
->>> from django.db.models.query import CollectedObjects
-
->>> g = CollectedObjects()
->>> g.add("key1", 1, "item1", None)
-False
->>> g["key1"]
-{1: 'item1'}
->>> g.add("key2", 1, "item1", "key1")
-False
->>> g.add("key2", 2, "item2", "key1")
-False
->>> g["key2"]
-{1: 'item1', 2: 'item2'}
->>> g.add("key3", 1, "item1", "key1")
-False
->>> g.add("key3", 1, "item1", "key2")
-True
->>> g.ordered_keys()
-['key3', 'key2', 'key1']
-
->>> g.add("key2", 1, "item1", "key3")
-True
->>> g.ordered_keys()
-Traceback (most recent call last):
-...
-CyclicDependency: There is a cyclic dependency of items to be processed.
-
-
-## Second, test the usage of CollectedObjects by Model.delete()
-
-# Due to the way that transactions work in the test harness,
-# doing m.delete() here can work but fail in a real situation,
-# since it may delete all objects, but not in the right order.
-# So we manually check that the order of deletion is correct.
-
-# Also, it is possible that the order is correct 'accidentally', due
-# solely to order of imports etc.  To check this, we set the order
-# that 'get_models()' will retrieve to a known 'nice' order, and
-# then try again with a known 'tricky' order.  Slightly naughty
-# access to internals here :-)
-
-# If implementation changes, then the tests may need to be simplified:
-#  - remove the lines that set the .keyOrder and clear the related
-#object caches
-#  - remove the second set of tests (with a2, b2 etc)
-
->>> from django.db.models.loading import cache
-
->>> def clear_rel_obj_caches(models):
-... for m in models:
-... if hasattr(m._meta, '_related_objects_cache'):
-... del m._meta._related_objects_cache
-
-# Nice order
->>> cache.app_models['delete'].keyOrder = ['a', 'b', 'c', 'd']
->>> clear_rel_obj_caches([A, B, C, D])
-
->>> a1 = A()
->>> a1.save()
->>> b1 = B(a=a1)
->>> b1.save()
->>> c1 = C(b=b1)
->>> c1.save()
->>> d1 = D(c=c1, a=a1)
->>> d1.save()
-
->>> o = CollectedObjects()
->>> a1._collect_sub_objects(o)
->>> o.keys()
-[, , 
, ]
->>> a1.delete()
-
-# Same again with a known bad order
->>> cache.app_models['delete'].keyOrder = ['d', 'c', 'b', 'a']
->>> clear_rel_obj_caches([A, B, C, D])
-
->>> a2 = A()
->>> a2.save()
->>> b2 = B(a=a2)
->>> b2.save()
->>> c2 = C(b=b2)
->>> c2.save()
->>> d2 = D(c=c2, a=a2)
->>> d2.save()
-
->>> o = CollectedObjects()
->>> a2._collect_sub_objects(o)
->>> o.keys()
-[, , 
, ]
->>> a2.delete()
-
-### Tests for models E,F - nullable related fields ###
-
-## First, test the CollectedObjects data structure directly
-
->>> g = CollectedObjects()
->>> g.add("key1", 1, "item1", None)
-False
->>> g.add("key2", 1, "item1", "key1", nullable=True)
-False
->>> g.add("key1", 1, "item1", "key2")
-True
->>> g.ordered_keys()
-['key1', 'key2']
-
-## Second, test the usage of CollectedObjects by Model.delete()
-
->>> e1 = E()
->>> e1.save()
->>> f1 = F(e=e1)
->>> f1.save()
->>> e1.f = f1
->>> e1.save()
-
-# Since E.f is nullable, we should delete F first (after nulling out
-# the E.f field), then E.
-
->>> o = CollectedObjects()
->>> e1._collect_sub_objects(o)
->>> o.keys()
-[, ]
-
-# temporarily replace the UpdateQuery class to verify that E.f is actually 
nulled out first
->>> import django.db.models.sql
->>> class LoggingUpdateQuery(django.db.models.sql.UpdateQuery):
-... def clear_related(self, related_field, pk_list, using):
-... print "CLEARING FIELD",related_field.name
-... return super(LoggingUpdateQuery, 
self).clear_related(related_field, pk_list, using)
->>> original_class = django.db.models.sql.UpdateQuery
->>> django.db.models.sql.UpdateQuery = LoggingUpdateQuery
->>> e1.delete()
-CLEARING FIELD f
-
->>> e2 = E()
->>> e2.save()
->>> f2 = F(e=e2)
->>> f2.save()
->>> e2.f = f2
->>> e2.save()
-
-# Same deal as before, though we are starting from the other object.
-
->>> o = CollectedObjects()
->>> f2._collect_sub_objects(o)
->>> o.keys()
-[, ]
-
->>> f2.delete()
-CLEARING FIELD f
-
-# Put this back to normal
->>> django.db.models.sql.UpdateQuery = original_class
-
-# 

[Changeset] r13794 - django/branches/releases/1.2.X/tests/modeltests/defer

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:10:03 -0500 (Sun, 12 Sep 2010)
New Revision: 13794

Added:
   django/branches/releases/1.2.X/tests/modeltests/defer/tests.py
Modified:
   django/branches/releases/1.2.X/tests/modeltests/defer/models.py
Log:
[1.2.X] Migrated defer doctests. Thanks to Alex Gaynor.

Backport of r13777 from trunk.

Modified: django/branches/releases/1.2.X/tests/modeltests/defer/models.py
===
--- django/branches/releases/1.2.X/tests/modeltests/defer/models.py 
2010-09-12 20:09:49 UTC (rev 13793)
+++ django/branches/releases/1.2.X/tests/modeltests/defer/models.py 
2010-09-12 20:10:03 UTC (rev 13794)
@@ -3,8 +3,8 @@
 """
 
 from django.db import models
-from django.db.models.query_utils import DeferredAttribute
 
+
 class Secondary(models.Model):
 first = models.CharField(max_length=50)
 second = models.CharField(max_length=50)
@@ -22,165 +22,3 @@
 
 class BigChild(Primary):
 other = models.CharField(max_length=50)
-
-def count_delayed_fields(obj, debug=False):
-"""
-Returns the number of delayed attributes on the given model instance.
-"""
-count = 0
-for field in obj._meta.fields:
-if isinstance(obj.__class__.__dict__.get(field.attname),
-DeferredAttribute):
-if debug:
-print field.name, field.attname
-count += 1
-return count
-
-
-__test__ = {"API_TEST": """
-To all outward appearances, instances with deferred fields look the same as
-normal instances when we examine attribute values. Therefore we test for the
-number of deferred fields on returned instances (by poking at the internals),
-as a way to observe what is going on.
-
->>> s1 = Secondary.objects.create(first="x1", second="y1")
->>> p1 = Primary.objects.create(name="p1", value="xx", related=s1)
-
->>> qs = Primary.objects.all()
-
->>> count_delayed_fields(qs.defer('name')[0])
-1
->>> count_delayed_fields(qs.only('name')[0])
-2
->>> count_delayed_fields(qs.defer('related__first')[0])
-0
->>> obj = qs.select_related().only('related__first')[0]
->>> count_delayed_fields(obj)
-2
->>> obj.related_id == s1.pk
-True
->>> count_delayed_fields(qs.defer('name').extra(select={'a': 1})[0])
-1
->>> count_delayed_fields(qs.extra(select={'a': 1}).defer('name')[0])
-1
->>> count_delayed_fields(qs.defer('name').defer('value')[0])
-2
->>> count_delayed_fields(qs.only('name').only('value')[0])
-2
->>> count_delayed_fields(qs.only('name').defer('value')[0])
-2
->>> count_delayed_fields(qs.only('name', 'value').defer('value')[0])
-2
->>> count_delayed_fields(qs.defer('name').only('value')[0])
-2
->>> obj = qs.only()[0]
->>> count_delayed_fields(qs.defer(None)[0])
-0
->>> count_delayed_fields(qs.only('name').defer(None)[0])
-0
-
-User values() won't defer anything (you get the full list of dictionaries
-back), but it still works.
->>> qs.defer('name').values()[0] == {'id': p1.id, 'name': u'p1', 'value': 
'xx', 'related_id': s1.id}
-True
->>> qs.only('name').values()[0] == {'id': p1.id, 'name': u'p1', 'value': 'xx', 
'related_id': s1.id}
-True
-
-Using defer() and only() with get() is also valid.
->>> count_delayed_fields(qs.defer('name').get(pk=p1.pk))
-1
->>> count_delayed_fields(qs.only('name').get(pk=p1.pk))
-2
-
-# KNOWN NOT TO WORK: >>> 
count_delayed_fields(qs.only('name').select_related('related')[0])
-# KNOWN NOT TO WORK >>> 
count_delayed_fields(qs.defer('related').select_related('related')[0])
-
-# Saving models with deferred fields is possible (but inefficient, since every
-# field has to be retrieved first).
-
->>> obj = Primary.objects.defer("value").get(name="p1")
->>> obj.name = "a new name"
->>> obj.save()
->>> Primary.objects.all()
-[]
-
-# Regression for #10572 - A subclass with no extra fields can defer fields 
from the base class
->>> _ = Child.objects.create(name="c1", value="foo", related=s1)
-
-# You can defer a field on a baseclass when the subclass has no fields
->>> obj = Child.objects.defer("value").get(name="c1")
->>> count_delayed_fields(obj)
-1
->>> obj.name
-u"c1"
->>> obj.value
-u"foo"
->>> obj.name = "c2"
->>> obj.save()
-
-# You can retrive a single column on a base class with no fields
->>> obj = Child.objects.only("name").get(name="c2")
->>> count_delayed_fields(obj)
-3
->>> obj.name
-u"c2"
->>> obj.value
-u"foo"
->>> obj.name = "cc"
->>> obj.save()
-
->>> _ = BigChild.objects.create(name="b1", value="foo", related=s1, 
other="bar")
-
-# You can defer a field on a baseclass
->>> obj = BigChild.objects.defer("value").get(name="b1")
->>> count_delayed_fields(obj)
-1
->>> obj.name
-u"b1"
->>> obj.value
-u"foo"
->>> obj.other
-u"bar"
->>> obj.name = "b2"
->>> obj.save()
-
-# You can defer a field on a subclass
->>> obj = BigChild.objects.defer("other").get(name="b2")
->>> count_delayed_fields(obj)
-1
->>> obj.name
-u"b2"
->>> obj.value
-u"foo"
->>> obj.other
-u"bar"
->>> obj.name = "b3"
->>> obj.save()
-
-# You can retrieve a single field on a 

[Changeset] r13793 - django/branches/releases/1.2.X/tests/modeltests/custom_pk

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:09:49 -0500 (Sun, 12 Sep 2010)
New Revision: 13793

Added:
   django/branches/releases/1.2.X/tests/modeltests/custom_pk/tests.py
Modified:
   django/branches/releases/1.2.X/tests/modeltests/custom_pk/fields.py
   django/branches/releases/1.2.X/tests/modeltests/custom_pk/models.py
Log:
[1.2.X] Migrated custom_pk doctests. Thanks to Alex Gaynor.

Backport of r13776 from trunk.

Modified: django/branches/releases/1.2.X/tests/modeltests/custom_pk/fields.py
===
--- django/branches/releases/1.2.X/tests/modeltests/custom_pk/fields.py 
2010-09-12 20:09:37 UTC (rev 13792)
+++ django/branches/releases/1.2.X/tests/modeltests/custom_pk/fields.py 
2010-09-12 20:09:49 UTC (rev 13793)
@@ -3,6 +3,7 @@
 
 from django.db import models
 
+
 class MyWrapper(object):
 def __init__(self, value):
 self.value = value

Modified: django/branches/releases/1.2.X/tests/modeltests/custom_pk/models.py
===
--- django/branches/releases/1.2.X/tests/modeltests/custom_pk/models.py 
2010-09-12 20:09:37 UTC (rev 13792)
+++ django/branches/releases/1.2.X/tests/modeltests/custom_pk/models.py 
2010-09-12 20:09:49 UTC (rev 13793)
@@ -40,138 +40,3 @@
 class Foo(models.Model):
 bar = models.ForeignKey(Bar)
 
-__test__ = {'API_TESTS':"""
->>> dan = Employee(employee_code=123, first_name='Dan', last_name='Jones')
->>> dan.save()
->>> Employee.objects.all()
-[]
-
->>> fran = Employee(employee_code=456, first_name='Fran', last_name='Bones')
->>> fran.save()
->>> Employee.objects.all()
-[, ]
-
->>> Employee.objects.get(pk=123)
-
->>> Employee.objects.get(pk=456)
-
->>> Employee.objects.get(pk=42)
-Traceback (most recent call last):
-...
-DoesNotExist: Employee matching query does not exist.
-
-# Use the name of the primary key, rather than pk.
->>> Employee.objects.get(employee_code__exact=123)
-
-
-# pk can be used as a substitute for the primary key.
->>> Employee.objects.filter(pk__in=[123, 456])
-[, ]
-
-# The primary key can be accessed via the pk property on the model.
->>> e = Employee.objects.get(pk=123)
->>> e.pk
-123
-
-# Or we can use the real attribute name for the primary key:
->>> e.employee_code
-123
-
-# Fran got married and changed her last name.
->>> fran = Employee.objects.get(pk=456)
->>> fran.last_name = 'Jones'
->>> fran.save()
->>> Employee.objects.filter(last_name__exact='Jones')
-[, ]
->>> emps = Employee.objects.in_bulk([123, 456])
->>> emps[123]
-
-
->>> b = Business(name='Sears')
->>> b.save()
->>> b.employees.add(dan, fran)
->>> b.employees.all()
-[, ]
->>> fran.business_set.all()
-[]
->>> Business.objects.in_bulk(['Sears'])
-{u'Sears': }
-
->>> Business.objects.filter(name__exact='Sears')
-[]
->>> Business.objects.filter(pk='Sears')
-[]
-
-# Queries across tables, involving primary key
->>> Employee.objects.filter(business__name__exact='Sears')
-[, ]
->>> Employee.objects.filter(business__pk='Sears')
-[, ]
-
->>> Business.objects.filter(employees__employee_code__exact=123)
-[]
->>> Business.objects.filter(employees__pk=123)
-[]
->>> Business.objects.filter(employees__first_name__startswith='Fran')
-[]
-
-# Primary key may be unicode string
->>> bus = Business(name=u'jaźń')
->>> bus.save()
-
-# The primary key must also obviously be unique, so trying to create a new
-# object with the same primary key will fail.
->>> try:
-...sid = transaction.savepoint()
-...Employee.objects.create(employee_code=123, first_name='Fred', 
last_name='Jones')
-...transaction.savepoint_commit(sid)
-... except Exception, e:
-...if isinstance(e, IntegrityError):
-...transaction.savepoint_rollback(sid)
-...print "Pass"
-...else:
-...print "Fail with %s" % type(e)
-Pass
-
-# Regression for #10785 -- Custom fields can be used for primary keys.
->>> new_bar = Bar.objects.create()
->>> new_foo = Foo.objects.create(bar=new_bar)
-
-# FIXME: This still doesn't work, but will require some changes in
-# get_db_prep_lookup to fix it.
-# >>> f = Foo.objects.get(bar=new_bar.pk)
-# >>> f == new_foo
-# True
-# >>> f.bar == new_bar
-# True
-
->>> f = Foo.objects.get(bar=new_bar)
->>> f == new_foo
-True
->>> f.bar == new_bar
-True
-
-"""}
-
-# SQLite lets objects be saved with an empty primary key, even though an
-# integer is expected. So we can't check for an error being raised in that case
-# for SQLite. Remove it from the suite for this next bit.
-if settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'] != 
'django.db.backends.sqlite3':
-__test__["API_TESTS"] += """
-# The primary key must be specified, so an error is raised if you try to create
-# an object without it.
->>> try:
-... sid = transaction.savepoint()
-... Employee.objects.create(first_name='Tom', last_name='Smith')
-... print 'hello'
-... transaction.savepoint_commit(sid)
-... print 'hello2'
-... except Exception, e:
-... if isinstance(e, 

[Changeset] r13792 - django/branches/releases/1.2.X/tests/modeltests/custom_methods

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:09:37 -0500 (Sun, 12 Sep 2010)
New Revision: 13792

Added:
   django/branches/releases/1.2.X/tests/modeltests/custom_methods/tests.py
Modified:
   django/branches/releases/1.2.X/tests/modeltests/custom_methods/models.py
Log:
[1.2.X] Migrated custom_methods doctests. Thanks to Alex Gaynor.

Backport of r13775 from trunk.

Modified: 
django/branches/releases/1.2.X/tests/modeltests/custom_methods/models.py
===
--- django/branches/releases/1.2.X/tests/modeltests/custom_methods/models.py
2010-09-12 20:09:23 UTC (rev 13791)
+++ django/branches/releases/1.2.X/tests/modeltests/custom_methods/models.py
2010-09-12 20:09:37 UTC (rev 13792)
@@ -33,27 +33,4 @@
 WHERE pub_date = %s
 AND id != %s""", 
[connection.ops.value_to_db_date(self.pub_date),
   self.id])
-# The asterisk in "(*row)" tells Python to expand the list into
-# positional arguments to Article().
 return [self.__class__(*row) for row in cursor.fetchall()]
-
-__test__ = {'API_TESTS':"""
-# Create a couple of Articles.
->>> from datetime import date
->>> a = Article(id=None, headline='Area man programs in Python', 
pub_date=date(2005, 7, 27))
->>> a.save()
->>> b = Article(id=None, headline='Beatles reunite', pub_date=date(2005, 7, 
27))
->>> b.save()
-
-# Test the custom methods.
->>> a.was_published_today()
-False
->>> a.articles_from_same_day_1()
-[]
->>> a.articles_from_same_day_2()
-[]
->>> b.articles_from_same_day_1()
-[]
->>> b.articles_from_same_day_2()
-[]
-"""}

Added: django/branches/releases/1.2.X/tests/modeltests/custom_methods/tests.py
===
--- django/branches/releases/1.2.X/tests/modeltests/custom_methods/tests.py 
(rev 0)
+++ django/branches/releases/1.2.X/tests/modeltests/custom_methods/tests.py 
2010-09-12 20:09:37 UTC (rev 13792)
@@ -0,0 +1,42 @@
+from datetime import date
+
+from django.test import TestCase
+
+from models import Article
+
+
+class MethodsTests(TestCase):
+def test_custom_methods(self):
+a = Article.objects.create(
+headline="Area man programs in Python", pub_date=date(2005, 7, 27)
+)
+b = Article.objects.create(
+headline="Beatles reunite", pub_date=date(2005, 7, 27)
+)
+
+self.assertFalse(a.was_published_today())
+self.assertQuerysetEqual(
+a.articles_from_same_day_1(), [
+"Beatles reunite",
+],
+lambda a: a.headline,
+)
+self.assertQuerysetEqual(
+a.articles_from_same_day_2(), [
+"Beatles reunite",
+],
+lambda a: a.headline
+)
+
+self.assertQuerysetEqual(
+b.articles_from_same_day_1(), [
+"Area man programs in Python",
+],
+lambda a: a.headline,
+)
+self.assertQuerysetEqual(
+b.articles_from_same_day_2(), [
+"Area man programs in Python",
+],
+lambda a: a.headline
+)

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13791 - django/branches/releases/1.2.X/tests/modeltests/custom_managers

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:09:23 -0500 (Sun, 12 Sep 2010)
New Revision: 13791

Added:
   django/branches/releases/1.2.X/tests/modeltests/custom_managers/tests.py
Modified:
   django/branches/releases/1.2.X/tests/modeltests/custom_managers/models.py
Log:
[1.2.X] Migrated the custom_managers tests. Thanks to Alex Gaynor.

Backport of r13774 from trunk.

Modified: 
django/branches/releases/1.2.X/tests/modeltests/custom_managers/models.py
===
--- django/branches/releases/1.2.X/tests/modeltests/custom_managers/models.py   
2010-09-12 20:05:17 UTC (rev 13790)
+++ django/branches/releases/1.2.X/tests/modeltests/custom_managers/models.py   
2010-09-12 20:09:23 UTC (rev 13791)
@@ -57,51 +57,3 @@
 
 def __unicode__(self):
 return self.name
-
-__test__ = {'API_TESTS':"""
->>> p1 = Person(first_name='Bugs', last_name='Bunny', fun=True)
->>> p1.save()
->>> p2 = Person(first_name='Droopy', last_name='Dog', fun=False)
->>> p2.save()
->>> Person.objects.get_fun_people()
-[]
-
-# The RelatedManager used on the 'books' descriptor extends the default manager
->>> from modeltests.custom_managers.models import PublishedBookManager
->>> isinstance(p2.books, PublishedBookManager)
-True
-
->>> b1 = Book(title='How to program', author='Rodney Dangerfield', 
is_published=True)
->>> b1.save()
->>> b2 = Book(title='How to be smart', author='Albert Einstein', 
is_published=False)
->>> b2.save()
-
-# The default manager, "objects", doesn't exist,
-# because a custom one was provided.
->>> Book.objects
-Traceback (most recent call last):
-...
-AttributeError: type object 'Book' has no attribute 'objects'
-
-# The RelatedManager used on the 'authors' descriptor extends the default 
manager
->>> from modeltests.custom_managers.models import PersonManager
->>> isinstance(b2.authors, PersonManager)
-True
-
->>> Book.published_objects.all()
-[]
-
->>> c1 = Car(name='Corvette', mileage=21, top_speed=180)
->>> c1.save()
->>> c2 = Car(name='Neon', mileage=31, top_speed=100)
->>> c2.save()
->>> Car.cars.order_by('name')
-[, ]
->>> Car.fast_cars.all()
-[]
-
-# Each model class gets a "_default_manager" attribute, which is a reference
-# to the first manager defined in the class. In this case, it's "cars".
->>> Car._default_manager.order_by('name')
-[, ]
-"""}

Added: django/branches/releases/1.2.X/tests/modeltests/custom_managers/tests.py
===
--- django/branches/releases/1.2.X/tests/modeltests/custom_managers/tests.py
(rev 0)
+++ django/branches/releases/1.2.X/tests/modeltests/custom_managers/tests.py
2010-09-12 20:09:23 UTC (rev 13791)
@@ -0,0 +1,71 @@
+from django.test import TestCase
+
+from models import Person, Book, Car, PersonManager, PublishedBookManager
+
+
+class CustomManagerTests(TestCase):
+def test_manager(self):
+p1 = Person.objects.create(first_name="Bugs", last_name="Bunny", 
fun=True)
+p2 = Person.objects.create(first_name="Droopy", last_name="Dog", 
fun=False)
+
+self.assertQuerysetEqual(
+Person.objects.get_fun_people(), [
+"Bugs Bunny"
+],
+unicode
+)
+# The RelatedManager used on the 'books' descriptor extends the default
+# manager
+self.assertTrue(isinstance(p2.books, PublishedBookManager))
+
+b1 = Book.published_objects.create(
+title="How to program", author="Rodney Dangerfield", 
is_published=True
+)
+b2 = Book.published_objects.create(
+title="How to be smart", author="Albert Einstein", 
is_published=False
+)
+
+# The default manager, "objects", doesn't exist, because a custom one
+# was provided.
+self.assertRaises(AttributeError, lambda: Book.objects)
+
+# The RelatedManager used on the 'authors' descriptor extends the
+# default manager
+self.assertTrue(isinstance(b2.authors, PersonManager))
+
+self.assertQuerysetEqual(
+Book.published_objects.all(), [
+"How to program",
+],
+lambda b: b.title
+)
+
+c1 = Car.cars.create(name="Corvette", mileage=21, top_speed=180)
+c2 = Car.cars.create(name="Neon", mileage=31, top_speed=100)
+
+self.assertQuerysetEqual(
+Car.cars.order_by("name"), [
+"Corvette",
+"Neon",
+],
+lambda c: c.name
+)
+
+self.assertQuerysetEqual(
+Car.fast_cars.all(), [
+"Corvette",
+],
+lambda c: c.name
+)
+
+# Each model class gets a "_default_manager" attribute, which is a
+# reference to the first manager defined in the class. In this case,
+# it's "cars".
+
+self.assertQuerysetEqual(
+Car._default_manager.order_by("name"), [
+  

[Changeset] r13790 - django/trunk/tests/modeltests/expressions

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:05:17 -0500 (Sun, 12 Sep 2010)
New Revision: 13790

Added:
   django/trunk/tests/modeltests/expressions/tests.py
Modified:
   django/trunk/tests/modeltests/expressions/models.py
Log:
Migrated expressions doctests. Thanks to Alex Gaynor.

Modified: django/trunk/tests/modeltests/expressions/models.py
===
--- django/trunk/tests/modeltests/expressions/models.py 2010-09-12 20:05:07 UTC 
(rev 13789)
+++ django/trunk/tests/modeltests/expressions/models.py 2010-09-12 20:05:17 UTC 
(rev 13790)
@@ -25,108 +25,3 @@
 
 def __unicode__(self):
 return self.name
-
-
-__test__ = {'API_TESTS': """
->>> from django.db.models import F
-
->>> Company(name='Example Inc.', num_employees=2300, num_chairs=5,
-... ceo=Employee.objects.create(firstname='Joe', lastname='Smith')).save()
->>> Company(name='Foobar Ltd.', num_employees=3, num_chairs=3,
-... ceo=Employee.objects.create(firstname='Frank', 
lastname='Meyer')).save()
->>> Company(name='Test GmbH', num_employees=32, num_chairs=1,
-... ceo=Employee.objects.create(firstname='Max', 
lastname='Mustermann')).save()
-
->>> company_query = 
Company.objects.values('name','num_employees','num_chairs').order_by('name','num_employees','num_chairs')
-
-# We can filter for companies where the number of employees is greater than the
-# number of chairs.
->>> company_query.filter(num_employees__gt=F('num_chairs'))
-[{'num_chairs': 5, 'name': u'Example Inc.', 'num_employees': 2300}, 
{'num_chairs': 1, 'name': u'Test GmbH', 'num_employees': 32}]
-
-# We can set one field to have the value of another field
-# Make sure we have enough chairs
->>> _ = company_query.update(num_chairs=F('num_employees'))
->>> company_query
-[{'num_chairs': 2300, 'name': u'Example Inc.', 'num_employees': 2300}, 
{'num_chairs': 3, 'name': u'Foobar Ltd.', 'num_employees': 3}, {'num_chairs': 
32, 'name': u'Test GmbH', 'num_employees': 32}]
-
-# We can perform arithmetic operations in expressions
-# Make sure we have 2 spare chairs
->>> _ =company_query.update(num_chairs=F('num_employees')+2)
->>> company_query
-[{'num_chairs': 2302, 'name': u'Example Inc.', 'num_employees': 2300}, 
{'num_chairs': 5, 'name': u'Foobar Ltd.', 'num_employees': 3}, {'num_chairs': 
34, 'name': u'Test GmbH', 'num_employees': 32}]
-
-# Law of order of operations is followed
->>> _ =company_query.update(num_chairs=F('num_employees') + 2 * 
F('num_employees'))
->>> company_query
-[{'num_chairs': 6900, 'name': u'Example Inc.', 'num_employees': 2300}, 
{'num_chairs': 9, 'name': u'Foobar Ltd.', 'num_employees': 3}, {'num_chairs': 
96, 'name': u'Test GmbH', 'num_employees': 32}]
-
-# Law of order of operations can be overridden by parentheses
->>> _ =company_query.update(num_chairs=((F('num_employees') + 2) * 
F('num_employees')))
->>> company_query
-[{'num_chairs': 5294600, 'name': u'Example Inc.', 'num_employees': 2300}, 
{'num_chairs': 15, 'name': u'Foobar Ltd.', 'num_employees': 3}, {'num_chairs': 
1088, 'name': u'Test GmbH', 'num_employees': 32}]
-
-# The relation of a foreign key can become copied over to an other foreign key.
->>> Company.objects.update(point_of_contact=F('ceo'))
-3
-
->>> [c.point_of_contact for c in Company.objects.all()]
-[, , ]
-
->>> c = Company.objects.all()[0]
->>> c.point_of_contact = Employee.objects.create(firstname="Guido", 
lastname="van Rossum")
->>> c.save()
-
-# F Expressions can also span joins
->>> 
Company.objects.filter(ceo__firstname=F('point_of_contact__firstname')).distinct().order_by('name')
-[, ]
-
->>> _ = 
Company.objects.exclude(ceo__firstname=F('point_of_contact__firstname')).update(name='foo')
->>> 
Company.objects.exclude(ceo__firstname=F('point_of_contact__firstname')).get().name
-u'foo'
-
->>> _ = 
Company.objects.exclude(ceo__firstname=F('point_of_contact__firstname')).update(name=F('point_of_contact__lastname'))
-Traceback (most recent call last):
-...
-FieldError: Joined field references are not permitted in this query
-
-# F expressions can be used to update attributes on single objects
->>> test_gmbh = Company.objects.get(name='Test GmbH')
->>> test_gmbh.num_employees
-32
->>> test_gmbh.num_employees = F('num_employees') + 4
->>> test_gmbh.save()
->>> test_gmbh = Company.objects.get(pk=test_gmbh.pk)
->>> test_gmbh.num_employees
-36
-
-# F expressions cannot be used to update attributes which are foreign keys, or
-# attributes which involve joins.
->>> test_gmbh.point_of_contact = None
->>> test_gmbh.save()
->>> test_gmbh.point_of_contact is None
-True
->>> test_gmbh.point_of_contact = F('ceo')
-Traceback (most recent call last):
-...
-ValueError: Cannot assign "": 
"Company.point_of_contact" must be a "Employee" instance.
-
->>> test_gmbh.point_of_contact = test_gmbh.ceo
->>> test_gmbh.save()
->>> test_gmbh.name = F('ceo__last_name')
->>> test_gmbh.save()
-Traceback (most recent call last):
-...
-FieldError: Joined field references are not permitted in this query

[Changeset] r13789 - django/trunk/tests/modeltests/empty

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:05:07 -0500 (Sun, 12 Sep 2010)
New Revision: 13789

Added:
   django/trunk/tests/modeltests/empty/tests.py
Modified:
   django/trunk/tests/modeltests/empty/models.py
Log:
Migrated empty doctests. Thanks to Alex Gaynor.

Modified: django/trunk/tests/modeltests/empty/models.py
===
--- django/trunk/tests/modeltests/empty/models.py   2010-09-12 20:04:57 UTC 
(rev 13788)
+++ django/trunk/tests/modeltests/empty/models.py   2010-09-12 20:05:07 UTC 
(rev 13789)
@@ -7,20 +7,6 @@
 
 from django.db import models
 
+
 class Empty(models.Model):
 pass
-
-__test__ = {'API_TESTS':"""
->>> m = Empty()
->>> m.id
->>> m.save()
->>> m2 = Empty()
->>> m2.save()
->>> len(Empty.objects.all())
-2
->>> m.id is not None
-True
->>> existing = Empty(m.id)
->>> existing.save()
-
-"""}

Added: django/trunk/tests/modeltests/empty/tests.py
===
--- django/trunk/tests/modeltests/empty/tests.py
(rev 0)
+++ django/trunk/tests/modeltests/empty/tests.py2010-09-12 20:05:07 UTC 
(rev 13789)
@@ -0,0 +1,15 @@
+from django.test import TestCase
+
+from models import Empty
+
+
+class EmptyModelTests(TestCase):
+def test_empty(self):
+m = Empty()
+self.assertEqual(m.id, None)
+m.save()
+m2 = Empty.objects.create()
+self.assertEqual(len(Empty.objects.all()), 2)
+self.assertTrue(m.id is not None)
+existing = Empty(m.id)
+existing.save()

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13788 - django/trunk/tests/modeltests/m2m_multiple

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:04:57 -0500 (Sun, 12 Sep 2010)
New Revision: 13788

Added:
   django/trunk/tests/modeltests/m2m_multiple/tests.py
Modified:
   django/trunk/tests/modeltests/m2m_multiple/models.py
Log:
Migrated m2m_multiple doctests. Thanks to Alex Gaynor.

Modified: django/trunk/tests/modeltests/m2m_multiple/models.py
===
--- django/trunk/tests/modeltests/m2m_multiple/models.py2010-09-12 
20:04:48 UTC (rev 13787)
+++ django/trunk/tests/modeltests/m2m_multiple/models.py2010-09-12 
20:04:57 UTC (rev 13788)
@@ -28,52 +28,3 @@
 def __unicode__(self):
 return self.headline
 
-__test__ = {'API_TESTS':"""
->>> from datetime import datetime
-
->>> c1 = Category(name='Sports')
->>> c1.save()
->>> c2 = Category(name='News')
->>> c2.save()
->>> c3 = Category(name='Crime')
->>> c3.save()
->>> c4 = Category(name='Life')
->>> c4.save()
-
->>> a1 = Article(headline='Area man steals', pub_date=datetime(2005, 11, 27))
->>> a1.save()
->>> a1.primary_categories.add(c2, c3)
->>> a1.secondary_categories.add(c4)
-
->>> a2 = Article(headline='Area man runs', pub_date=datetime(2005, 11, 28))
->>> a2.save()
->>> a2.primary_categories.add(c1, c2)
->>> a2.secondary_categories.add(c4)
-
->>> a1.primary_categories.all()
-[, ]
-
->>> a2.primary_categories.all()
-[, ]
-
->>> a1.secondary_categories.all()
-[]
-
-
->>> c1.primary_article_set.all()
-[]
->>> c1.secondary_article_set.all()
-[]
->>> c2.primary_article_set.all()
-[, ]
->>> c2.secondary_article_set.all()
-[]
->>> c3.primary_article_set.all()
-[]
->>> c3.secondary_article_set.all()
-[]
->>> c4.primary_article_set.all()
-[]
->>> c4.secondary_article_set.all()
-[, ]
-"""}

Added: django/trunk/tests/modeltests/m2m_multiple/tests.py
===
--- django/trunk/tests/modeltests/m2m_multiple/tests.py 
(rev 0)
+++ django/trunk/tests/modeltests/m2m_multiple/tests.py 2010-09-12 20:04:57 UTC 
(rev 13788)
@@ -0,0 +1,84 @@
+from datetime import datetime
+
+from django.test import TestCase
+
+from models import Article, Category
+
+
+class M2MMultipleTests(TestCase):
+def test_multiple(self):
+c1, c2, c3, c4 = [
+Category.objects.create(name=name)
+for name in ["Sports", "News", "Crime", "Life"]
+]
+
+a1 = Article.objects.create(
+headline="Area man steals", pub_date=datetime(2005, 11, 27)
+)
+a1.primary_categories.add(c2, c3)
+a1.secondary_categories.add(c4)
+
+a2 = Article.objects.create(
+headline="Area man runs", pub_date=datetime(2005, 11, 28)
+)
+a2.primary_categories.add(c1, c2)
+a2.secondary_categories.add(c4)
+
+self.assertQuerysetEqual(
+a1.primary_categories.all(), [
+"Crime",
+"News",
+],
+lambda c: c.name
+)
+self.assertQuerysetEqual(
+a2.primary_categories.all(), [
+"News",
+"Sports",
+],
+lambda c: c.name
+)
+self.assertQuerysetEqual(
+a1.secondary_categories.all(), [
+"Life",
+],
+lambda c: c.name
+)
+self.assertQuerysetEqual(
+c1.primary_article_set.all(), [
+"Area man runs",
+],
+lambda a: a.headline
+)
+self.assertQuerysetEqual(
+c1.secondary_article_set.all(), []
+)
+self.assertQuerysetEqual(
+c2.primary_article_set.all(), [
+"Area man steals",
+"Area man runs",
+],
+lambda a: a.headline
+)
+self.assertQuerysetEqual(
+c2.secondary_article_set.all(), []
+)
+self.assertQuerysetEqual(
+c3.primary_article_set.all(), [
+"Area man steals",
+],
+lambda a: a.headline
+)
+self.assertQuerysetEqual(
+c3.secondary_article_set.all(), []
+)
+self.assertQuerysetEqual(
+c4.primary_article_set.all(), []
+)
+self.assertQuerysetEqual(
+c4.secondary_article_set.all(), [
+"Area man steals",
+"Area man runs",
+],
+lambda a: a.headline
+)

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13787 - in django/trunk/tests/modeltests: m2m_and_m2o m2m_intermediary

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:04:48 -0500 (Sun, 12 Sep 2010)
New Revision: 13787

Added:
   django/trunk/tests/modeltests/m2m_intermediary/tests.py
Modified:
   django/trunk/tests/modeltests/m2m_and_m2o/tests.py
   django/trunk/tests/modeltests/m2m_intermediary/models.py
Log:
Migrated m2m_intermediary doctests. Thanks to Alex Gaynor.

Modified: django/trunk/tests/modeltests/m2m_and_m2o/tests.py
===
--- django/trunk/tests/modeltests/m2m_and_m2o/tests.py  2010-09-12 20:04:38 UTC 
(rev 13786)
+++ django/trunk/tests/modeltests/m2m_and_m2o/tests.py  2010-09-12 20:04:48 UTC 
(rev 13787)
@@ -8,21 +8,21 @@
 def test_m2m_and_m2o(self):
 r = User.objects.create(username="russell")
 g = User.objects.create(username="gustav")
-
+
 i1 = Issue(num=1)
 i1.client = r
 i1.save()
-
+
 i2 = Issue(num=2)
 i2.client = r
 i2.save()
 i2.cc.add(r)
-
+
 i3 = Issue(num=3)
 i3.client = g
 i3.save()
 i3.cc.add(r)
-
+
 self.assertQuerysetEqual(
 Issue.objects.filter(client=r.id), [
 1,
@@ -46,7 +46,7 @@
 ],
 lambda i: i.num
 )
-
+
 # These queries combine results from the m2m and the m2o relationships.
 # They're three ways of saying the same thing.
 self.assertQuerysetEqual(

Modified: django/trunk/tests/modeltests/m2m_intermediary/models.py
===
--- django/trunk/tests/modeltests/m2m_intermediary/models.py2010-09-12 
20:04:38 UTC (rev 13786)
+++ django/trunk/tests/modeltests/m2m_intermediary/models.py2010-09-12 
20:04:48 UTC (rev 13787)
@@ -34,35 +34,3 @@
 def __unicode__(self):
 return u'%s (%s)' % (self.reporter, self.position)
 
-__test__ = {'API_TESTS':"""
-# Create a few Reporters.
->>> r1 = Reporter(first_name='John', last_name='Smith')
->>> r1.save()
->>> r2 = Reporter(first_name='Jane', last_name='Doe')
->>> r2.save()
-
-# Create an Article.
->>> from datetime import datetime
->>> a = Article(headline='This is a test', pub_date=datetime(2005, 7, 27))
->>> a.save()
-
-# Create a few Writers.
->>> w1 = Writer(reporter=r1, article=a, position='Main writer')
->>> w1.save()
->>> w2 = Writer(reporter=r2, article=a, position='Contributor')
->>> w2.save()
-
-# Play around with the API.
->>> a.writer_set.select_related().order_by('-position')
-[, ]
->>> w1.reporter
-
->>> w2.reporter
-
->>> w1.article
-
->>> w2.article
-
->>> r1.writer_set.all()
-[]
-"""}

Added: django/trunk/tests/modeltests/m2m_intermediary/tests.py
===
--- django/trunk/tests/modeltests/m2m_intermediary/tests.py 
(rev 0)
+++ django/trunk/tests/modeltests/m2m_intermediary/tests.py 2010-09-12 
20:04:48 UTC (rev 13787)
@@ -0,0 +1,38 @@
+from datetime import datetime
+
+from django.test import TestCase
+
+from models import Reporter, Article, Writer
+
+
+class M2MIntermediaryTests(TestCase):
+def test_intermeiary(self):
+r1 = Reporter.objects.create(first_name="John", last_name="Smith")
+r2 = Reporter.objects.create(first_name="Jane", last_name="Doe")
+
+a = Article.objects.create(
+headline="This is a test", pub_date=datetime(2005, 7, 27)
+)
+
+w1 = Writer.objects.create(reporter=r1, article=a, position="Main 
writer")
+w2 = Writer.objects.create(reporter=r2, article=a, 
position="Contributor")
+
+self.assertQuerysetEqual(
+a.writer_set.select_related().order_by("-position"), [
+("John Smith", "Main writer"),
+("Jane Doe", "Contributor"),
+],
+lambda w: (unicode(w.reporter), w.position)
+)
+self.assertEqual(w1.reporter, r1)
+self.assertEqual(w2.reporter, r2)
+
+self.assertEqual(w1.article, a)
+self.assertEqual(w2.article, a)
+
+self.assertQuerysetEqual(
+r1.writer_set.all(), [
+("John Smith", "Main writer")
+],
+lambda w: (unicode(w.reporter), w.position)
+)

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13786 - django/trunk/tests/modeltests/m2m_and_m2o

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:04:38 -0500 (Sun, 12 Sep 2010)
New Revision: 13786

Added:
   django/trunk/tests/modeltests/m2m_and_m2o/tests.py
Modified:
   django/trunk/tests/modeltests/m2m_and_m2o/models.py
Log:
Migrate m2m_and_m2o doctests. Thanks to Alex Gaynor.

Modified: django/trunk/tests/modeltests/m2m_and_m2o/models.py
===
--- django/trunk/tests/modeltests/m2m_and_m2o/models.py 2010-09-12 20:04:30 UTC 
(rev 13785)
+++ django/trunk/tests/modeltests/m2m_and_m2o/models.py 2010-09-12 20:04:38 UTC 
(rev 13786)
@@ -19,47 +19,3 @@
 
 class Meta:
 ordering = ('num',)
-
-
-__test__ = {'API_TESTS':"""
->>> Issue.objects.all()
-[]
->>> r = User(username='russell')
->>> r.save()
->>> g = User(username='gustav')
->>> g.save()
-
->>> i = Issue(num=1)
->>> i.client = r
->>> i.save()
-
->>> i2 = Issue(num=2)
->>> i2.client = r
->>> i2.save()
->>> i2.cc.add(r)
-
->>> i3 = Issue(num=3)
->>> i3.client = g
->>> i3.save()
->>> i3.cc.add(r)
-
->>> from django.db.models.query import Q
-
->>> Issue.objects.filter(client=r.id)
-[, ]
->>> Issue.objects.filter(client=g.id)
-[]
->>> Issue.objects.filter(cc__id__exact=g.id)
-[]
->>> Issue.objects.filter(cc__id__exact=r.id)
-[, ]
-
-# These queries combine results from the m2m and the m2o relationships.
-# They're three ways of saying the same thing.
->>> Issue.objects.filter(Q(cc__id__exact=r.id) | Q(client=r.id))
-[, , ]
->>> Issue.objects.filter(cc__id__exact=r.id) | 
Issue.objects.filter(client=r.id)
-[, , ]
->>> Issue.objects.filter(Q(client=r.id) | Q(cc__id__exact=r.id))
-[, , ]
-"""}

Added: django/trunk/tests/modeltests/m2m_and_m2o/tests.py
===
--- django/trunk/tests/modeltests/m2m_and_m2o/tests.py  
(rev 0)
+++ django/trunk/tests/modeltests/m2m_and_m2o/tests.py  2010-09-12 20:04:38 UTC 
(rev 13786)
@@ -0,0 +1,75 @@
+from django.db.models import Q
+from django.test import TestCase
+
+from models import Issue, User
+
+
+class RelatedObjectTests(TestCase):
+def test_m2m_and_m2o(self):
+r = User.objects.create(username="russell")
+g = User.objects.create(username="gustav")
+
+i1 = Issue(num=1)
+i1.client = r
+i1.save()
+
+i2 = Issue(num=2)
+i2.client = r
+i2.save()
+i2.cc.add(r)
+
+i3 = Issue(num=3)
+i3.client = g
+i3.save()
+i3.cc.add(r)
+
+self.assertQuerysetEqual(
+Issue.objects.filter(client=r.id), [
+1,
+2,
+],
+lambda i: i.num
+)
+self.assertQuerysetEqual(
+Issue.objects.filter(client=g.id), [
+3,
+],
+lambda i: i.num
+)
+self.assertQuerysetEqual(
+Issue.objects.filter(cc__id__exact=g.id), []
+)
+self.assertQuerysetEqual(
+Issue.objects.filter(cc__id__exact=r.id), [
+2,
+3,
+],
+lambda i: i.num
+)
+
+# These queries combine results from the m2m and the m2o relationships.
+# They're three ways of saying the same thing.
+self.assertQuerysetEqual(
+Issue.objects.filter(Q(cc__id__exact = r.id) | Q(client=r.id)), [
+1,
+2,
+3,
+],
+lambda i: i.num
+)
+self.assertQuerysetEqual(
+Issue.objects.filter(cc__id__exact=r.id) | 
Issue.objects.filter(client=r.id), [
+1,
+2,
+3,
+],
+lambda i: i.num
+)
+self.assertQuerysetEqual(
+Issue.objects.filter(Q(client=r.id) | Q(cc__id__exact=r.id)), [
+1,
+2,
+3,
+],
+lambda i: i.num
+)

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13785 - django/trunk/tests/modeltests/get_or_create

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:04:30 -0500 (Sun, 12 Sep 2010)
New Revision: 13785

Added:
   django/trunk/tests/modeltests/get_or_create/tests.py
Modified:
   django/trunk/tests/modeltests/get_or_create/models.py
Log:
Migrate get_or_create doctests. Thanks to Alex Gaynor.

Modified: django/trunk/tests/modeltests/get_or_create/models.py
===
--- django/trunk/tests/modeltests/get_or_create/models.py   2010-09-12 
20:04:21 UTC (rev 13784)
+++ django/trunk/tests/modeltests/get_or_create/models.py   2010-09-12 
20:04:30 UTC (rev 13785)
@@ -19,65 +19,3 @@
 class ManualPrimaryKeyTest(models.Model):
 id = models.IntegerField(primary_key=True)
 data = models.CharField(max_length=100)
-
-__test__ = {'API_TESTS':"""
-# Acting as a divine being, create an Person.
->>> from datetime import date
->>> p = Person(first_name='John', last_name='Lennon', birthday=date(1940, 10, 
9))
->>> p.save()
-
-# Only one Person is in the database at this point.
->>> Person.objects.count()
-1
-
-# get_or_create() a person with similar first names.
->>> p, created = Person.objects.get_or_create(first_name='John', 
last_name='Lennon', defaults={'birthday': date(1940, 10, 9)})
-
-# get_or_create() didn't have to create an object.
->>> created
-False
-
-# There's still only one Person in the database.
->>> Person.objects.count()
-1
-
-# get_or_create() a Person with a different name.
->>> p, created = Person.objects.get_or_create(first_name='George', 
last_name='Harrison', defaults={'birthday': date(1943, 2, 25)})
->>> created
-True
->>> Person.objects.count()
-2
-
-# If we execute the exact same statement, it won't create a Person.
->>> p, created = Person.objects.get_or_create(first_name='George', 
last_name='Harrison', defaults={'birthday': date(1943, 2, 25)})
->>> created
-False
->>> Person.objects.count()
-2
-
-# If you don't specify a value or default value for all required fields, you
-# will get an error.
->>> try:
-... p, created = Person.objects.get_or_create(first_name='Tom', 
last_name='Smith')
-... except Exception, e:
-... if isinstance(e, IntegrityError):
-... print "Pass"
-... else:
-... print "Fail with %s" % type(e)
-Pass
-
-# If you specify an existing primary key, but different other fields, then you
-# will get an error and data will not be updated.
->>> m = ManualPrimaryKeyTest(id=1, data='Original')
->>> m.save()
->>> try:
-...m, created = ManualPrimaryKeyTest.objects.get_or_create(id=1, 
data='Different')
-... except Exception, e:
-...if isinstance(e, IntegrityError):
-...print "Pass"
-...else:
-...print "Fail with %s" % type(e)
-Pass
->>> ManualPrimaryKeyTest.objects.get(id=1).data == 'Original'
-True
-"""}

Added: django/trunk/tests/modeltests/get_or_create/tests.py
===
--- django/trunk/tests/modeltests/get_or_create/tests.py
(rev 0)
+++ django/trunk/tests/modeltests/get_or_create/tests.py2010-09-12 
20:04:30 UTC (rev 13785)
@@ -0,0 +1,52 @@
+from datetime import date
+
+from django.db import IntegrityError
+from django.test import TestCase
+
+from models import Person, ManualPrimaryKeyTest
+
+
+class GetOrCreateTests(TestCase):
+def test_get_or_create(self):
+p = Person.objects.create(
+first_name='John', last_name='Lennon', birthday=date(1940, 10, 9)
+)
+
+p, created = Person.objects.get_or_create(
+first_name="John", last_name="Lennon", defaults={
+"birthday": date(1940, 10, 9)
+}
+)
+self.assertFalse(created)
+self.assertEqual(Person.objects.count(), 1)
+
+p, created = Person.objects.get_or_create(
+first_name='George', last_name='Harrison', defaults={
+'birthday': date(1943, 2, 25)
+}
+)
+self.assertTrue(created)
+self.assertEqual(Person.objects.count(), 2)
+
+# If we execute the exact same statement, it won't create a Person.
+p, created = Person.objects.get_or_create(
+first_name='George', last_name='Harrison', defaults={
+'birthday': date(1943, 2, 25)
+}
+)
+self.assertFalse(created)
+self.assertEqual(Person.objects.count(), 2)
+
+# If you don't specify a value or default value for all required
+# fields, you will get an error.
+self.assertRaises(IntegrityError,
+Person.objects.get_or_create, first_name="Tom", last_name="Smith"
+)
+
+# If you specify an existing primary key, but different other fields,
+# then you will get an error and data will not be updated.
+m = ManualPrimaryKeyTest.objects.create(id=1, data="Original")
+self.assertRaises(IntegrityError,
+ManualPrimaryKeyTest.objects.get_or_create, id=1, data="Different"
+   

[Changeset] r13784 - django/trunk/tests/modeltests/get_object_or_404

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:04:21 -0500 (Sun, 12 Sep 2010)
New Revision: 13784

Added:
   django/trunk/tests/modeltests/get_object_or_404/tests.py
Modified:
   django/trunk/tests/modeltests/get_object_or_404/models.py
Log:
Migrated get_object_or_404 doctests. Thanks to Alex Gaynor.

Modified: django/trunk/tests/modeltests/get_object_or_404/models.py
===
--- django/trunk/tests/modeltests/get_object_or_404/models.py   2010-09-12 
20:04:12 UTC (rev 13783)
+++ django/trunk/tests/modeltests/get_object_or_404/models.py   2010-09-12 
20:04:21 UTC (rev 13784)
@@ -32,76 +32,3 @@
 
 def __unicode__(self):
 return self.title
-
-__test__ = {'API_TESTS':"""
-# Create some Authors.
->>> a = Author.objects.create(name="Brave Sir Robin")
->>> a.save()
->>> a2 = Author.objects.create(name="Patsy")
->>> a2.save()
-
-# No Articles yet, so we should get a Http404 error.
->>> get_object_or_404(Article, title="Foo")
-Traceback (most recent call last):
-...
-Http404: No Article matches the given query.
-
-# Create an Article.
->>> article = Article.objects.create(title="Run away!")
->>> article.authors = [a, a2]
->>> article.save()
-
-# get_object_or_404 can be passed a Model to query.
->>> get_object_or_404(Article, title__contains="Run")
-
-
-# We can also use the Article manager through an Author object.
->>> get_object_or_404(a.article_set, title__contains="Run")
-
-
-# No articles containing "Camelot".  This should raise a Http404 error.
->>> get_object_or_404(a.article_set, title__contains="Camelot")
-Traceback (most recent call last):
-...
-Http404: No Article matches the given query.
-
-# Custom managers can be used too.
->>> get_object_or_404(Article.by_a_sir, title="Run away!")
-
-
-# QuerySets can be used too.
->>> get_object_or_404(Article.objects.all(), title__contains="Run")
-
-
-# Just as when using a get() lookup, you will get an error if more than one
-# object is returned.
->>> get_object_or_404(Author.objects.all())
-Traceback (most recent call last):
-...
-MultipleObjectsReturned: get() returned more than one Author -- it returned 
...! Lookup parameters were {}
-
-# Using an EmptyQuerySet raises a Http404 error.
->>> get_object_or_404(Article.objects.none(), title__contains="Run")
-Traceback (most recent call last):
-...
-Http404: No Article matches the given query.
-
-# get_list_or_404 can be used to get lists of objects
->>> get_list_or_404(a.article_set, title__icontains='Run')
-[]
-
-# Http404 is returned if the list is empty.
->>> get_list_or_404(a.article_set, title__icontains='Shrubbery')
-Traceback (most recent call last):
-...
-Http404: No Article matches the given query.
-
-# Custom managers can be used too.
->>> get_list_or_404(Article.by_a_sir, title__icontains="Run")
-[]
-
-# QuerySets can be used too.
->>> get_list_or_404(Article.objects.all(), title__icontains="Run")
-[]
-
-"""}

Added: django/trunk/tests/modeltests/get_object_or_404/tests.py
===
--- django/trunk/tests/modeltests/get_object_or_404/tests.py
(rev 0)
+++ django/trunk/tests/modeltests/get_object_or_404/tests.py2010-09-12 
20:04:21 UTC (rev 13784)
@@ -0,0 +1,80 @@
+from django.http import Http404
+from django.shortcuts import get_object_or_404, get_list_or_404
+from django.test import TestCase
+
+from models import Author, Article
+
+
+class GetObjectOr404Tests(TestCase):
+def test_get_object_or_404(self):
+a1 = Author.objects.create(name="Brave Sir Robin")
+a2 = Author.objects.create(name="Patsy")
+
+# No Articles yet, so we should get a Http404 error.
+self.assertRaises(Http404, get_object_or_404, Article, title="Foo")
+
+article = Article.objects.create(title="Run away!")
+article.authors = [a1, a2]
+# get_object_or_404 can be passed a Model to query.
+self.assertEqual(
+get_object_or_404(Article, title__contains="Run"),
+article
+)
+
+# We can also use the Article manager through an Author object.
+self.assertEqual(
+get_object_or_404(a1.article_set, title__contains="Run"),
+article
+)
+
+# No articles containing "Camelot".  This should raise a Http404 error.
+self.assertRaises(Http404,
+get_object_or_404, a1.article_set, title__contains="Camelot"
+)
+
+# Custom managers can be used too.
+self.assertEqual(
+get_object_or_404(Article.by_a_sir, title="Run away!"),
+article
+)
+
+# QuerySets can be used too.
+self.assertEqual(
+get_object_or_404(Article.objects.all(), title__contains="Run"),
+article
+)
+
+# Just as when using a get() lookup, you will get an error if more than
+# one object is returned.
+
+

[Changeset] r13783 - django/trunk/tests/modeltests/get_latest

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:04:12 -0500 (Sun, 12 Sep 2010)
New Revision: 13783

Added:
   django/trunk/tests/modeltests/get_latest/tests.py
Modified:
   django/trunk/tests/modeltests/get_latest/models.py
Log:
Migrate get_latest doctests. Thanks to Alex Gaynor.

Modified: django/trunk/tests/modeltests/get_latest/models.py
===
--- django/trunk/tests/modeltests/get_latest/models.py  2010-09-12 20:04:04 UTC 
(rev 13782)
+++ django/trunk/tests/modeltests/get_latest/models.py  2010-09-12 20:04:12 UTC 
(rev 13783)
@@ -28,52 +28,3 @@
 
 def __unicode__(self):
 return self.name
-
-__test__ = {'API_TESTS':"""
-# Because no Articles exist yet, latest() raises ArticleDoesNotExist.
->>> Article.objects.latest()
-Traceback (most recent call last):
-...
-DoesNotExist: Article matching query does not exist.
-
-# Create a couple of Articles.
->>> from datetime import datetime
->>> a1 = Article(headline='Article 1', pub_date=datetime(2005, 7, 26), 
expire_date=datetime(2005, 9, 1))
->>> a1.save()
->>> a2 = Article(headline='Article 2', pub_date=datetime(2005, 7, 27), 
expire_date=datetime(2005, 7, 28))
->>> a2.save()
->>> a3 = Article(headline='Article 3', pub_date=datetime(2005, 7, 27), 
expire_date=datetime(2005, 8, 27))
->>> a3.save()
->>> a4 = Article(headline='Article 4', pub_date=datetime(2005, 7, 28), 
expire_date=datetime(2005, 7, 30))
->>> a4.save()
-
-# Get the latest Article.
->>> Article.objects.latest()
-
-
-# Get the latest Article that matches certain filters.
->>> Article.objects.filter(pub_date__lt=datetime(2005, 7, 27)).latest()
-
-
-# Pass a custom field name to latest() to change the field that's used to
-# determine the latest object.
->>> Article.objects.latest('expire_date')
-
-
->>> Article.objects.filter(pub_date__gt=datetime(2005, 7, 
26)).latest('expire_date')
-
-
-# You can still use latest() with a model that doesn't have "get_latest_by"
-# set -- just pass in the field name manually.
->>> p1 = Person(name='Ralph', birthday=datetime(1950, 1, 1))
->>> p1.save()
->>> p2 = Person(name='Stephanie', birthday=datetime(1960, 2, 3))
->>> p2.save()
->>> Person.objects.latest()
-Traceback (most recent call last):
-...
-AssertionError: latest() requires either a field_name parameter or 
'get_latest_by' in the model
-
->>> Person.objects.latest('birthday')
-
-"""}

Added: django/trunk/tests/modeltests/get_latest/tests.py
===
--- django/trunk/tests/modeltests/get_latest/tests.py   
(rev 0)
+++ django/trunk/tests/modeltests/get_latest/tests.py   2010-09-12 20:04:12 UTC 
(rev 13783)
@@ -0,0 +1,53 @@
+from datetime import datetime
+
+from django.test import TestCase
+
+from models import Article, Person
+
+
+class LatestTests(TestCase):
+def test_latest(self):
+# Because no Articles exist yet, latest() raises ArticleDoesNotExist.
+self.assertRaises(Article.DoesNotExist, Article.objects.latest)
+
+a1 = Article.objects.create(
+headline="Article 1", pub_date=datetime(2005, 7, 26),
+expire_date=datetime(2005, 9, 1)
+)
+a2 = Article.objects.create(
+headline="Article 2", pub_date=datetime(2005, 7, 27),
+expire_date=datetime(2005, 7, 28)
+)
+a3 = Article.objects.create(
+headline="Article 3", pub_date=datetime(2005, 7, 27),
+expire_date=datetime(2005, 8, 27)
+)
+a4 = Article.objects.create(
+headline="Article 4", pub_date=datetime(2005, 7, 28),
+expire_date=datetime(2005, 7, 30)
+)
+
+# Get the latest Article.
+self.assertEqual(Article.objects.latest(), a4)
+# Get the latest Article that matches certain filters.
+self.assertEqual(
+Article.objects.filter(pub_date__lt=datetime(2005, 7, 
27)).latest(),
+a1
+)
+
+# Pass a custom field name to latest() to change the field that's used
+# to determine the latest object.
+self.assertEqual(Article.objects.latest('expire_date'), a1)
+self.assertEqual(
+Article.objects.filter(pub_date__gt=datetime(2005, 7, 
26)).latest('expire_date'),
+a3,
+)
+
+def test_latest_manual(self):
+# You can still use latest() with a model that doesn't have
+# "get_latest_by" set -- just pass in the field name manually.
+p1 = Person.objects.create(name="Ralph", birthday=datetime(1950, 1, 1))
+p2 = Person.objects.create(name="Stephanie", birthday=datetime(1960, 
2, 3))
+self.assertRaises(AssertionError, Person.objects.latest)
+
+self.assertEqual(Person.objects.latest("birthday"), p2)

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To 

[Changeset] r13782 - django/trunk/tests/modeltests/force_insert_update

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:04:04 -0500 (Sun, 12 Sep 2010)
New Revision: 13782

Added:
   django/trunk/tests/modeltests/force_insert_update/tests.py
Modified:
   django/trunk/tests/modeltests/force_insert_update/models.py
Log:
Migrated the force_insert_update tests. Thanks to Alex Gaynor.

Modified: django/trunk/tests/modeltests/force_insert_update/models.py
===
--- django/trunk/tests/modeltests/force_insert_update/models.py 2010-09-12 
20:03:55 UTC (rev 13781)
+++ django/trunk/tests/modeltests/force_insert_update/models.py 2010-09-12 
20:04:04 UTC (rev 13782)
@@ -11,54 +11,3 @@
 class WithCustomPK(models.Model):
 name = models.IntegerField(primary_key=True)
 value = models.IntegerField()
-
-__test__ = {"API_TESTS": """
->>> c = Counter.objects.create(name="one", value=1)
-
-# The normal case
->>> c.value = 2
->>> c.save()
-
-# Same thing, via an update
->>> c.value = 3
->>> c.save(force_update=True)
-
-# Won't work because force_update and force_insert are mutually exclusive
->>> c.value = 4
->>> c.save(force_insert=True, force_update=True)
-Traceback (most recent call last):
-...
-ValueError: Cannot force both insert and updating in model saving.
-
-# Try to update something that doesn't have a primary key in the first place.
->>> c1 = Counter(name="two", value=2)
->>> c1.save(force_update=True)
-Traceback (most recent call last):
-...
-ValueError: Cannot force an update in save() with no primary key.
-
->>> c1.save(force_insert=True)
-
-# Won't work because we can't insert a pk of the same value.
->>> sid = transaction.savepoint()
->>> c.value = 5
->>> try:
-... c.save(force_insert=True)
-... except Exception, e:
-... if isinstance(e, IntegrityError):
-... print "Pass"
-... else:
-... print "Fail with %s" % type(e)
-Pass
->>> transaction.savepoint_rollback(sid)
-
-# Trying to update should still fail, even with manual primary keys, if the
-# data isn't in the database already.
->>> obj = WithCustomPK(name=1, value=1)
->>> obj.save(force_update=True)
-Traceback (most recent call last):
-...
-DatabaseError: ...
-
-"""
-}

Added: django/trunk/tests/modeltests/force_insert_update/tests.py
===
--- django/trunk/tests/modeltests/force_insert_update/tests.py  
(rev 0)
+++ django/trunk/tests/modeltests/force_insert_update/tests.py  2010-09-12 
20:04:04 UTC (rev 13782)
@@ -0,0 +1,38 @@
+from django.db import transaction, IntegrityError, DatabaseError
+from django.test import TestCase
+
+from models import Counter, WithCustomPK
+
+
+class ForceTests(TestCase):
+def test_force_update(self):
+c = Counter.objects.create(name="one", value=1)
+# The normal case
+
+c.value = 2
+c.save()
+# Same thing, via an update
+c.value = 3
+c.save(force_update=True)
+
+# Won't work because force_update and force_insert are mutually
+# exclusive
+c.value = 4
+self.assertRaises(ValueError, c.save, force_insert=True, 
force_update=True)
+
+# Try to update something that doesn't have a primary key in the first
+# place.
+c1 = Counter(name="two", value=2)
+self.assertRaises(ValueError, c1.save, force_update=True)
+c1.save(force_insert=True)
+
+# Won't work because we can't insert a pk of the same value.
+sid = transaction.savepoint()
+c.value = 5
+self.assertRaises(IntegrityError, c.save, force_insert=True)
+transaction.savepoint_rollback(sid)
+
+# Trying to update should still fail, even with manual primary keys, if
+# the data isn't in the database already.
+obj = WithCustomPK(name=1, value=1)
+self.assertRaises(DatabaseError, obj.save, force_update=True)

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



[Changeset] r13781 - django/trunk/tests/modeltests/files

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:03:55 -0500 (Sun, 12 Sep 2010)
New Revision: 13781

Added:
   django/trunk/tests/modeltests/files/tests.py
Modified:
   django/trunk/tests/modeltests/files/models.py
Log:
Migrate the files doctests. Thanks to Alex Gaynor.

Modified: django/trunk/tests/modeltests/files/models.py
===
--- django/trunk/tests/modeltests/files/models.py   2010-09-12 20:03:48 UTC 
(rev 13780)
+++ django/trunk/tests/modeltests/files/models.py   2010-09-12 20:03:55 UTC 
(rev 13781)
@@ -7,10 +7,12 @@
 
 import random
 import tempfile
+
 from django.db import models
 from django.core.files.base import ContentFile
 from django.core.files.storage import FileSystemStorage
 
+
 temp_storage_location = tempfile.mkdtemp()
 temp_storage = FileSystemStorage(location=temp_storage_location)
 
@@ -30,125 +32,3 @@
 custom = models.FileField(storage=temp_storage, upload_to=custom_upload_to)
 random = models.FileField(storage=temp_storage, upload_to=random_upload_to)
 default = models.FileField(storage=temp_storage, upload_to='tests', 
default='tests/default.txt')
-
-__test__ = {'API_TESTS':"""
-# Attempting to access a FileField from the class raises a descriptive error
->>> Storage.normal
-Traceback (most recent call last):
-...
-AttributeError: The 'normal' attribute can only be accessed from Storage 
instances.
-
-# An object without a file has limited functionality.
-
->>> obj1 = Storage()
->>> obj1.normal
-
->>> obj1.normal.size
-Traceback (most recent call last):
-...
-ValueError: The 'normal' attribute has no file associated with it.
-
-# Saving a file enables full functionality.
-
->>> obj1.normal.save('django_test.txt', ContentFile('content'))
->>> obj1.normal
-
->>> obj1.normal.size
-7
->>> obj1.normal.read()
-'content'
-
-# File objects can be assigned to FileField attributes,  but shouldn't get
-# committed until the model it's attached to is saved.
-
->>> from django.core.files.uploadedfile import SimpleUploadedFile
->>> obj1.normal = SimpleUploadedFile('assignment.txt', 'content')
->>> dirs, files = temp_storage.listdir('tests')
->>> dirs
-[]
->>> files.sort()
->>> files == ['default.txt', 'django_test.txt']
-True
-
->>> obj1.save()
->>> dirs, files = temp_storage.listdir('tests')
->>> files.sort()
->>> files == ['assignment.txt', 'default.txt', 'django_test.txt']
-True
-
-# Files can be read in a little at a time, if necessary.
-
->>> obj1.normal.open()
->>> obj1.normal.read(3)
-'con'
->>> obj1.normal.read()
-'tent'
->>> '-'.join(obj1.normal.chunks(chunk_size=2))
-'co-nt-en-t'
-
-# Save another file with the same name.
-
->>> obj2 = Storage()
->>> obj2.normal.save('django_test.txt', ContentFile('more content'))
->>> obj2.normal
-
->>> obj2.normal.size
-12
-
-# Push the objects into the cache to make sure they pickle properly
-
->>> from django.core.cache import cache
->>> cache.set('obj1', obj1)
->>> cache.set('obj2', obj2)
->>> cache.get('obj2').normal
-
-
-# Deleting an object deletes the file it uses, if there are no other objects
-# still using that file.
-
->>> obj2.delete()
->>> obj2.normal.save('django_test.txt', ContentFile('more content'))
->>> obj2.normal
-
-
-# Multiple files with the same name get _N appended to them.
-
->>> objs = [Storage() for i in range(3)]
->>> for o in objs:
-... o.normal.save('multiple_files.txt', ContentFile('Same Content'))
->>> [o.normal for o in objs]
-[, , ]
->>> for o in objs:
-... o.delete()
-
-# Default values allow an object to access a single file.
-
->>> obj3 = Storage.objects.create()
->>> obj3.default
-
->>> obj3.default.read()
-'default content'
-
-# But it shouldn't be deleted, even if there are no more objects using it.
-
->>> obj3.delete()
->>> obj3 = Storage()
->>> obj3.default.read()
-'default content'
-
-# Verify the fix for #5655, making sure the directory is only determined once.
-
->>> obj4 = Storage()
->>> obj4.random.save('random_file', ContentFile('random content'))
->>> obj4.random
-
-
-# Clean up the temporary files and dir.
->>> obj1.normal.delete()
->>> obj2.normal.delete()
->>> obj3.default.delete()
->>> obj4.random.delete()
-
->>> import shutil
->>> shutil.rmtree(temp_storage_location)
-"""}

Added: django/trunk/tests/modeltests/files/tests.py
===
--- django/trunk/tests/modeltests/files/tests.py
(rev 0)
+++ django/trunk/tests/modeltests/files/tests.py2010-09-12 20:03:55 UTC 
(rev 13781)
@@ -0,0 +1,100 @@
+import shutil
+
+from django.core.cache import cache
+from django.core.files.base import ContentFile
+from django.core.files.uploadedfile import SimpleUploadedFile
+from django.test import TestCase
+
+from models import Storage, temp_storage, temp_storage_location
+
+
+class FileTests(TestCase):
+def tearDown(self):
+shutil.rmtree(temp_storage_location)
+
+def test_files(self):
+# Attempting to access a 

[Changeset] r13780 - django/trunk/tests/modeltests/field_subclassing

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:03:48 -0500 (Sun, 12 Sep 2010)
New Revision: 13780

Modified:
   django/trunk/tests/modeltests/field_subclassing/fields.py
   django/trunk/tests/modeltests/field_subclassing/models.py
   django/trunk/tests/modeltests/field_subclassing/tests.py
Log:
Migrated the field_subclsasing doctests. Thanks to Alex Gaynor.

Modified: django/trunk/tests/modeltests/field_subclassing/fields.py
===
--- django/trunk/tests/modeltests/field_subclassing/fields.py   2010-09-12 
20:03:39 UTC (rev 13779)
+++ django/trunk/tests/modeltests/field_subclassing/fields.py   2010-09-12 
20:03:48 UTC (rev 13780)
@@ -53,18 +53,18 @@
 
 class JSONField(models.TextField):
 __metaclass__ = models.SubfieldBase
-
+
 description = ("JSONField automatically serializes and desializes values 
to "
 "and from JSON.")
-
+
 def to_python(self, value):
 if not value:
 return None
-
+
 if isinstance(value, basestring):
 value = json.loads(value)
 return value
-
+
 def get_db_prep_save(self, value):
 if value is None:
 return None

Modified: django/trunk/tests/modeltests/field_subclassing/models.py
===
--- django/trunk/tests/modeltests/field_subclassing/models.py   2010-09-12 
20:03:39 UTC (rev 13779)
+++ django/trunk/tests/modeltests/field_subclassing/models.py   2010-09-12 
20:03:48 UTC (rev 13780)
@@ -2,7 +2,6 @@
 Tests for field subclassing.
 """
 
-from django.core import serializers
 from django.db import models
 from django.utils.encoding import force_unicode
 
@@ -18,56 +17,3 @@
 
 class DataModel(models.Model):
 data = JSONField()
-
-__test__ = {'API_TESTS': ur"""
-# Creating a model with custom fields is done as per normal.
->>> s = Small(1, 2)
->>> print s
-12
->>> m = MyModel(name='m', data=s)
->>> m.save()
-
-# Custom fields still have normal field's attributes.
->>> m._meta.get_field('data').verbose_name
-'small field'
-
-# The m.data attribute has been initialised correctly. It's a Small object.
->>> m.data.first, m.data.second
-(1, 2)
-
-# The data loads back from the database correctly and 'data' has the right 
type.
->>> m1 = MyModel.objects.get(pk=m.pk)
->>> isinstance(m1.data, Small)
-True
->>> print m1.data
-12
-
-# We can do normal filtering on the custom field (and will get an error when we
-# use a lookup type that does not make sense).
->>> s1 = Small(1, 3)
->>> s2 = Small('a', 'b')
->>> MyModel.objects.filter(data__in=[s, s1, s2])
-[]
->>> MyModel.objects.filter(data__lt=s)
-Traceback (most recent call last):
-...
-TypeError: Invalid lookup type: 'lt'
-
-# Serialization works, too.
->>> stream = serializers.serialize("json", MyModel.objects.all())
->>> stream
-'[{"pk": 1, "model": "field_subclassing.mymodel", "fields": {"data": "12", 
"name": "m"}}]'
->>> obj = list(serializers.deserialize("json", stream))[0]
->>> obj.object == m
-True
-
-# Test retrieving custom field data
->>> m.delete()
->>> m1 = MyModel(name="1", data=Small(1, 2))
->>> m1.save()
->>> m2 = MyModel(name="2", data=Small(2, 3))
->>> m2.save()
->>> for m in MyModel.objects.all(): print unicode(m.data)
-12
-23
-"""}

Modified: django/trunk/tests/modeltests/field_subclassing/tests.py
===
--- django/trunk/tests/modeltests/field_subclassing/tests.py2010-09-12 
20:03:39 UTC (rev 13779)
+++ django/trunk/tests/modeltests/field_subclassing/tests.py2010-09-12 
20:03:48 UTC (rev 13780)
@@ -1,21 +1,75 @@
+from django.core import serializers
 from django.test import TestCase
 
-from models import DataModel
+from fields import Small
+from models import DataModel, MyModel
 
 
 class CustomField(TestCase):
 def test_defer(self):
 d = DataModel.objects.create(data=[1, 2, 3])
-
+
 self.assertTrue(isinstance(d.data, list))
-
+
 d = DataModel.objects.get(pk=d.pk)
 self.assertTrue(isinstance(d.data, list))
 self.assertEqual(d.data, [1, 2, 3])
-
+
 d = DataModel.objects.defer("data").get(pk=d.pk)
 d.save()
-
+
 d = DataModel.objects.get(pk=d.pk)
 self.assertTrue(isinstance(d.data, list))
 self.assertEqual(d.data, [1, 2, 3])
+
+def test_custom_field(self):
+# Creating a model with custom fields is done as per normal.
+s = Small(1, 2)
+self.assertEqual(str(s), "12")
+
+m = MyModel.objects.create(name="m", data=s)
+# Custom fields still have normal field's attributes.
+self.assertEqual(m._meta.get_field("data").verbose_name, "small field")
+
+# The m.data attribute has been initialised correctly. It's a Small
+# object.
+self.assertEqual((m.data.first, m.data.second), (1, 2))
+
+# The data loads back from the database correctly and 'data' has 

[Changeset] r13776 - django/trunk/tests/modeltests/custom_pk

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:03:12 -0500 (Sun, 12 Sep 2010)
New Revision: 13776

Added:
   django/trunk/tests/modeltests/custom_pk/tests.py
Modified:
   django/trunk/tests/modeltests/custom_pk/fields.py
   django/trunk/tests/modeltests/custom_pk/models.py
Log:
Migrated custom_pk doctests. Thanks to Alex Gaynor.

Modified: django/trunk/tests/modeltests/custom_pk/fields.py
===
--- django/trunk/tests/modeltests/custom_pk/fields.py   2010-09-12 20:03:03 UTC 
(rev 13775)
+++ django/trunk/tests/modeltests/custom_pk/fields.py   2010-09-12 20:03:12 UTC 
(rev 13776)
@@ -3,6 +3,7 @@
 
 from django.db import models
 
+
 class MyWrapper(object):
 def __init__(self, value):
 self.value = value

Modified: django/trunk/tests/modeltests/custom_pk/models.py
===
--- django/trunk/tests/modeltests/custom_pk/models.py   2010-09-12 20:03:03 UTC 
(rev 13775)
+++ django/trunk/tests/modeltests/custom_pk/models.py   2010-09-12 20:03:12 UTC 
(rev 13776)
@@ -40,138 +40,3 @@
 class Foo(models.Model):
 bar = models.ForeignKey(Bar)
 
-__test__ = {'API_TESTS':"""
->>> dan = Employee(employee_code=123, first_name='Dan', last_name='Jones')
->>> dan.save()
->>> Employee.objects.all()
-[]
-
->>> fran = Employee(employee_code=456, first_name='Fran', last_name='Bones')
->>> fran.save()
->>> Employee.objects.all()
-[, ]
-
->>> Employee.objects.get(pk=123)
-
->>> Employee.objects.get(pk=456)
-
->>> Employee.objects.get(pk=42)
-Traceback (most recent call last):
-...
-DoesNotExist: Employee matching query does not exist.
-
-# Use the name of the primary key, rather than pk.
->>> Employee.objects.get(employee_code__exact=123)
-
-
-# pk can be used as a substitute for the primary key.
->>> Employee.objects.filter(pk__in=[123, 456])
-[, ]
-
-# The primary key can be accessed via the pk property on the model.
->>> e = Employee.objects.get(pk=123)
->>> e.pk
-123
-
-# Or we can use the real attribute name for the primary key:
->>> e.employee_code
-123
-
-# Fran got married and changed her last name.
->>> fran = Employee.objects.get(pk=456)
->>> fran.last_name = 'Jones'
->>> fran.save()
->>> Employee.objects.filter(last_name__exact='Jones')
-[, ]
->>> emps = Employee.objects.in_bulk([123, 456])
->>> emps[123]
-
-
->>> b = Business(name='Sears')
->>> b.save()
->>> b.employees.add(dan, fran)
->>> b.employees.all()
-[, ]
->>> fran.business_set.all()
-[]
->>> Business.objects.in_bulk(['Sears'])
-{u'Sears': }
-
->>> Business.objects.filter(name__exact='Sears')
-[]
->>> Business.objects.filter(pk='Sears')
-[]
-
-# Queries across tables, involving primary key
->>> Employee.objects.filter(business__name__exact='Sears')
-[, ]
->>> Employee.objects.filter(business__pk='Sears')
-[, ]
-
->>> Business.objects.filter(employees__employee_code__exact=123)
-[]
->>> Business.objects.filter(employees__pk=123)
-[]
->>> Business.objects.filter(employees__first_name__startswith='Fran')
-[]
-
-# Primary key may be unicode string
->>> bus = Business(name=u'jaźń')
->>> bus.save()
-
-# The primary key must also obviously be unique, so trying to create a new
-# object with the same primary key will fail.
->>> try:
-...sid = transaction.savepoint()
-...Employee.objects.create(employee_code=123, first_name='Fred', 
last_name='Jones')
-...transaction.savepoint_commit(sid)
-... except Exception, e:
-...if isinstance(e, IntegrityError):
-...transaction.savepoint_rollback(sid)
-...print "Pass"
-...else:
-...print "Fail with %s" % type(e)
-Pass
-
-# Regression for #10785 -- Custom fields can be used for primary keys.
->>> new_bar = Bar.objects.create()
->>> new_foo = Foo.objects.create(bar=new_bar)
-
-# FIXME: This still doesn't work, but will require some changes in
-# get_db_prep_lookup to fix it.
-# >>> f = Foo.objects.get(bar=new_bar.pk)
-# >>> f == new_foo
-# True
-# >>> f.bar == new_bar
-# True
-
->>> f = Foo.objects.get(bar=new_bar)
->>> f == new_foo
-True
->>> f.bar == new_bar
-True
-
-"""}
-
-# SQLite lets objects be saved with an empty primary key, even though an
-# integer is expected. So we can't check for an error being raised in that case
-# for SQLite. Remove it from the suite for this next bit.
-if settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'] != 
'django.db.backends.sqlite3':
-__test__["API_TESTS"] += """
-# The primary key must be specified, so an error is raised if you try to create
-# an object without it.
->>> try:
-... sid = transaction.savepoint()
-... Employee.objects.create(first_name='Tom', last_name='Smith')
-... print 'hello'
-... transaction.savepoint_commit(sid)
-... print 'hello2'
-... except Exception, e:
-... if isinstance(e, IntegrityError):
-... transaction.savepoint_rollback(sid)
-... print "Pass"
-... else:
-... print "Fail with %s" % type(e)
-Pass
-
-"""

Added: 

[Changeset] r13779 - in django/trunk/tests: modeltests/field_defaults regressiontests/i18n

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:03:39 -0500 (Sun, 12 Sep 2010)
New Revision: 13779

Added:
   django/trunk/tests/modeltests/field_defaults/tests.py
Modified:
   django/trunk/tests/modeltests/field_defaults/models.py
   django/trunk/tests/regressiontests/i18n/models.py
   django/trunk/tests/regressiontests/i18n/tests.py
Log:
Migrated i18n and field_defaults doctests. Thanks to Alex Gaynor.

Modified: django/trunk/tests/modeltests/field_defaults/models.py
===
--- django/trunk/tests/modeltests/field_defaults/models.py  2010-09-12 
20:03:28 UTC (rev 13778)
+++ django/trunk/tests/modeltests/field_defaults/models.py  2010-09-12 
20:03:39 UTC (rev 13779)
@@ -19,41 +19,3 @@
 
 def __unicode__(self):
 return self.headline
-
-__test__ = {'API_TESTS': u"""
->>> from datetime import datetime
-
-# No articles are in the system yet.
->>> Article.objects.all()
-[]
-
-# Create an Article.
->>> a = Article(id=None)
-
-# Grab the current datetime it should be very close to the default that just
-# got saved as a.pub_date
->>> now = datetime.now()
-
-# Save it into the database. You have to call save() explicitly.
->>> a.save()
-
-# Now it has an ID. Note it's a long integer, as designated by the trailing 
"L".
->>> a.id
-1L
-
-# Access database columns via Python attributes.
->>> a.headline
-u'Default headline'
-
-# make sure the two dates are sufficiently close
->>> d = now - a.pub_date
->>> d.seconds < 5
-True
-
-# make sure that SafeString/SafeUnicode fields work
->>> from django.utils.safestring import SafeUnicode, SafeString
->>> a.headline = SafeUnicode(u'Iñtërnâtiônàlizætiøn1')
->>> a.save()
->>> a.headline = SafeString(u'Iñtërnâtiônàlizætiøn1'.encode('utf-8'))
->>> a.save()
-"""}

Added: django/trunk/tests/modeltests/field_defaults/tests.py
===
--- django/trunk/tests/modeltests/field_defaults/tests.py   
(rev 0)
+++ django/trunk/tests/modeltests/field_defaults/tests.py   2010-09-12 
20:03:39 UTC (rev 13779)
@@ -0,0 +1,16 @@
+from datetime import datetime
+
+from django.test import TestCase
+
+from models import Article
+
+
+class DefaultTests(TestCase):
+def test_field_defaults(self):
+a = Article()
+now = datetime.now()
+a.save()
+
+self.assertTrue(isinstance(a.id, (int, long)))
+self.assertEqual(a.headline, "Default headline")
+self.assertTrue((now - a.pub_date).seconds < 5)

Modified: django/trunk/tests/regressiontests/i18n/models.py
===
--- django/trunk/tests/regressiontests/i18n/models.py   2010-09-12 20:03:28 UTC 
(rev 13778)
+++ django/trunk/tests/regressiontests/i18n/models.py   2010-09-12 20:03:39 UTC 
(rev 13779)
@@ -10,9 +10,3 @@
 date_added = models.DateTimeField(default=datetime(1799,1,31,23,59,59,0))
 cents_payed = models.DecimalField(max_digits=4, decimal_places=2)
 products_delivered = models.IntegerField()
-
-__test__ = {'API_TESTS': '''
->>> tm = TestModel()
->>> tm.save()
-'''
-}

Modified: django/trunk/tests/regressiontests/i18n/tests.py
===
--- django/trunk/tests/regressiontests/i18n/tests.py2010-09-12 20:03:28 UTC 
(rev 13778)
+++ django/trunk/tests/regressiontests/i18n/tests.py2010-09-12 20:03:39 UTC 
(rev 13779)
@@ -5,14 +5,17 @@
 import sys
 import pickle
 
+from django.conf import settings
 from django.template import Template, Context
-from django.conf import settings
+from django.test import TestCase
 from django.utils.formats import get_format, date_format, time_format, 
localize, localize_input
 from django.utils.numberformat import format as nformat
-from django.test import TestCase
+from django.utils.safestring import mark_safe, SafeString, SafeUnicode
 from django.utils.translation import ugettext, ugettext_lazy, activate, 
deactivate, gettext_lazy, to_locale
 
+
 from forms import I18nForm, SelectDateForm, SelectDateWidget, CompanyForm
+from models import Company, TestModel
 
 
 class TranslationTests(TestCase):
@@ -59,7 +62,6 @@
 """
 Translating a string requiring no auto-escaping shouldn't change the 
"safe" status.
 """
-from django.utils.safestring import mark_safe, SafeString, SafeUnicode
 s = mark_safe('Password')
 self.assertEqual(SafeString, type(s))
 activate('de')
@@ -620,3 +622,16 @@
 
 def test_django_fallback(self):
 self.assertUgettext('Date/time', 'Datum/Zeit')
+
+
+class TestModels(TestCase):
+def test_lazy(self):
+tm = TestModel()
+tm.save()
+
+def test_safestr(self):
+c = Company(cents_payed=12, products_delivered=1)
+c.name = SafeUnicode(u'Iñtërnâtiônàlizætiøn1')
+c.save()
+c.name = SafeString(u'Iñtërnâtiônàlizætiøn1'.encode('utf-8'))
+c.save()

-- 
You 

[Changeset] r13778 - django/trunk/tests/modeltests/delete

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:03:28 -0500 (Sun, 12 Sep 2010)
New Revision: 13778

Added:
   django/trunk/tests/modeltests/delete/tests.py
Modified:
   django/trunk/tests/modeltests/delete/models.py
Log:
Migrated delete doctests. Thanks to Alex Gaynor.

Modified: django/trunk/tests/modeltests/delete/models.py
===
--- django/trunk/tests/modeltests/delete/models.py  2010-09-12 20:03:20 UTC 
(rev 13777)
+++ django/trunk/tests/modeltests/delete/models.py  2010-09-12 20:03:28 UTC 
(rev 13778)
@@ -40,168 +40,3 @@
 class F(DefaultRepr, models.Model):
 e = models.ForeignKey(E, related_name='f_rel')
 
-
-__test__ = {'API_TESTS': """
-### Tests for models A,B,C,D ###
-
-## First, test the CollectedObjects data structure directly
-
->>> from django.db.models.query import CollectedObjects
-
->>> g = CollectedObjects()
->>> g.add("key1", 1, "item1", None)
-False
->>> g["key1"]
-{1: 'item1'}
->>> g.add("key2", 1, "item1", "key1")
-False
->>> g.add("key2", 2, "item2", "key1")
-False
->>> g["key2"]
-{1: 'item1', 2: 'item2'}
->>> g.add("key3", 1, "item1", "key1")
-False
->>> g.add("key3", 1, "item1", "key2")
-True
->>> g.ordered_keys()
-['key3', 'key2', 'key1']
-
->>> g.add("key2", 1, "item1", "key3")
-True
->>> g.ordered_keys()
-Traceback (most recent call last):
-...
-CyclicDependency: There is a cyclic dependency of items to be processed.
-
-
-## Second, test the usage of CollectedObjects by Model.delete()
-
-# Due to the way that transactions work in the test harness,
-# doing m.delete() here can work but fail in a real situation,
-# since it may delete all objects, but not in the right order.
-# So we manually check that the order of deletion is correct.
-
-# Also, it is possible that the order is correct 'accidentally', due
-# solely to order of imports etc.  To check this, we set the order
-# that 'get_models()' will retrieve to a known 'nice' order, and
-# then try again with a known 'tricky' order.  Slightly naughty
-# access to internals here :-)
-
-# If implementation changes, then the tests may need to be simplified:
-#  - remove the lines that set the .keyOrder and clear the related
-#object caches
-#  - remove the second set of tests (with a2, b2 etc)
-
->>> from django.db.models.loading import cache
-
->>> def clear_rel_obj_caches(models):
-... for m in models:
-... if hasattr(m._meta, '_related_objects_cache'):
-... del m._meta._related_objects_cache
-
-# Nice order
->>> cache.app_models['delete'].keyOrder = ['a', 'b', 'c', 'd']
->>> clear_rel_obj_caches([A, B, C, D])
-
->>> a1 = A()
->>> a1.save()
->>> b1 = B(a=a1)
->>> b1.save()
->>> c1 = C(b=b1)
->>> c1.save()
->>> d1 = D(c=c1, a=a1)
->>> d1.save()
-
->>> o = CollectedObjects()
->>> a1._collect_sub_objects(o)
->>> o.keys()
-[, , 
, ]
->>> a1.delete()
-
-# Same again with a known bad order
->>> cache.app_models['delete'].keyOrder = ['d', 'c', 'b', 'a']
->>> clear_rel_obj_caches([A, B, C, D])
-
->>> a2 = A()
->>> a2.save()
->>> b2 = B(a=a2)
->>> b2.save()
->>> c2 = C(b=b2)
->>> c2.save()
->>> d2 = D(c=c2, a=a2)
->>> d2.save()
-
->>> o = CollectedObjects()
->>> a2._collect_sub_objects(o)
->>> o.keys()
-[, , 
, ]
->>> a2.delete()
-
-### Tests for models E,F - nullable related fields ###
-
-## First, test the CollectedObjects data structure directly
-
->>> g = CollectedObjects()
->>> g.add("key1", 1, "item1", None)
-False
->>> g.add("key2", 1, "item1", "key1", nullable=True)
-False
->>> g.add("key1", 1, "item1", "key2")
-True
->>> g.ordered_keys()
-['key1', 'key2']
-
-## Second, test the usage of CollectedObjects by Model.delete()
-
->>> e1 = E()
->>> e1.save()
->>> f1 = F(e=e1)
->>> f1.save()
->>> e1.f = f1
->>> e1.save()
-
-# Since E.f is nullable, we should delete F first (after nulling out
-# the E.f field), then E.
-
->>> o = CollectedObjects()
->>> e1._collect_sub_objects(o)
->>> o.keys()
-[, ]
-
-# temporarily replace the UpdateQuery class to verify that E.f is actually 
nulled out first
->>> import django.db.models.sql
->>> class LoggingUpdateQuery(django.db.models.sql.UpdateQuery):
-... def clear_related(self, related_field, pk_list, using):
-... print "CLEARING FIELD",related_field.name
-... return super(LoggingUpdateQuery, 
self).clear_related(related_field, pk_list, using)
->>> original_class = django.db.models.sql.UpdateQuery
->>> django.db.models.sql.UpdateQuery = LoggingUpdateQuery
->>> e1.delete()
-CLEARING FIELD f
-
->>> e2 = E()
->>> e2.save()
->>> f2 = F(e=e2)
->>> f2.save()
->>> e2.f = f2
->>> e2.save()
-
-# Same deal as before, though we are starting from the other object.
-
->>> o = CollectedObjects()
->>> f2._collect_sub_objects(o)
->>> o.keys()
-[, ]
-
->>> f2.delete()
-CLEARING FIELD f
-
-# Put this back to normal
->>> django.db.models.sql.UpdateQuery = original_class
-
-# Restore the app cache to previous condition so that all models are accounted 
for.
->>> cache.app_models['delete'].keyOrder = ['a', 

[Changeset] r13777 - django/trunk/tests/modeltests/defer

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:03:20 -0500 (Sun, 12 Sep 2010)
New Revision: 13777

Added:
   django/trunk/tests/modeltests/defer/tests.py
Modified:
   django/trunk/tests/modeltests/defer/models.py
Log:
Migrated defer doctests. Thanks to Alex Gaynor.

Modified: django/trunk/tests/modeltests/defer/models.py
===
--- django/trunk/tests/modeltests/defer/models.py   2010-09-12 20:03:12 UTC 
(rev 13776)
+++ django/trunk/tests/modeltests/defer/models.py   2010-09-12 20:03:20 UTC 
(rev 13777)
@@ -3,8 +3,8 @@
 """
 
 from django.db import models
-from django.db.models.query_utils import DeferredAttribute
 
+
 class Secondary(models.Model):
 first = models.CharField(max_length=50)
 second = models.CharField(max_length=50)
@@ -22,165 +22,3 @@
 
 class BigChild(Primary):
 other = models.CharField(max_length=50)
-
-def count_delayed_fields(obj, debug=False):
-"""
-Returns the number of delayed attributes on the given model instance.
-"""
-count = 0
-for field in obj._meta.fields:
-if isinstance(obj.__class__.__dict__.get(field.attname),
-DeferredAttribute):
-if debug:
-print field.name, field.attname
-count += 1
-return count
-
-
-__test__ = {"API_TEST": """
-To all outward appearances, instances with deferred fields look the same as
-normal instances when we examine attribute values. Therefore we test for the
-number of deferred fields on returned instances (by poking at the internals),
-as a way to observe what is going on.
-
->>> s1 = Secondary.objects.create(first="x1", second="y1")
->>> p1 = Primary.objects.create(name="p1", value="xx", related=s1)
-
->>> qs = Primary.objects.all()
-
->>> count_delayed_fields(qs.defer('name')[0])
-1
->>> count_delayed_fields(qs.only('name')[0])
-2
->>> count_delayed_fields(qs.defer('related__first')[0])
-0
->>> obj = qs.select_related().only('related__first')[0]
->>> count_delayed_fields(obj)
-2
->>> obj.related_id == s1.pk
-True
->>> count_delayed_fields(qs.defer('name').extra(select={'a': 1})[0])
-1
->>> count_delayed_fields(qs.extra(select={'a': 1}).defer('name')[0])
-1
->>> count_delayed_fields(qs.defer('name').defer('value')[0])
-2
->>> count_delayed_fields(qs.only('name').only('value')[0])
-2
->>> count_delayed_fields(qs.only('name').defer('value')[0])
-2
->>> count_delayed_fields(qs.only('name', 'value').defer('value')[0])
-2
->>> count_delayed_fields(qs.defer('name').only('value')[0])
-2
->>> obj = qs.only()[0]
->>> count_delayed_fields(qs.defer(None)[0])
-0
->>> count_delayed_fields(qs.only('name').defer(None)[0])
-0
-
-User values() won't defer anything (you get the full list of dictionaries
-back), but it still works.
->>> qs.defer('name').values()[0] == {'id': p1.id, 'name': u'p1', 'value': 
'xx', 'related_id': s1.id}
-True
->>> qs.only('name').values()[0] == {'id': p1.id, 'name': u'p1', 'value': 'xx', 
'related_id': s1.id}
-True
-
-Using defer() and only() with get() is also valid.
->>> count_delayed_fields(qs.defer('name').get(pk=p1.pk))
-1
->>> count_delayed_fields(qs.only('name').get(pk=p1.pk))
-2
-
-# KNOWN NOT TO WORK: >>> 
count_delayed_fields(qs.only('name').select_related('related')[0])
-# KNOWN NOT TO WORK >>> 
count_delayed_fields(qs.defer('related').select_related('related')[0])
-
-# Saving models with deferred fields is possible (but inefficient, since every
-# field has to be retrieved first).
-
->>> obj = Primary.objects.defer("value").get(name="p1")
->>> obj.name = "a new name"
->>> obj.save()
->>> Primary.objects.all()
-[]
-
-# Regression for #10572 - A subclass with no extra fields can defer fields 
from the base class
->>> _ = Child.objects.create(name="c1", value="foo", related=s1)
-
-# You can defer a field on a baseclass when the subclass has no fields
->>> obj = Child.objects.defer("value").get(name="c1")
->>> count_delayed_fields(obj)
-1
->>> obj.name
-u"c1"
->>> obj.value
-u"foo"
->>> obj.name = "c2"
->>> obj.save()
-
-# You can retrive a single column on a base class with no fields
->>> obj = Child.objects.only("name").get(name="c2")
->>> count_delayed_fields(obj)
-3
->>> obj.name
-u"c2"
->>> obj.value
-u"foo"
->>> obj.name = "cc"
->>> obj.save()
-
->>> _ = BigChild.objects.create(name="b1", value="foo", related=s1, 
other="bar")
-
-# You can defer a field on a baseclass
->>> obj = BigChild.objects.defer("value").get(name="b1")
->>> count_delayed_fields(obj)
-1
->>> obj.name
-u"b1"
->>> obj.value
-u"foo"
->>> obj.other
-u"bar"
->>> obj.name = "b2"
->>> obj.save()
-
-# You can defer a field on a subclass
->>> obj = BigChild.objects.defer("other").get(name="b2")
->>> count_delayed_fields(obj)
-1
->>> obj.name
-u"b2"
->>> obj.value
-u"foo"
->>> obj.other
-u"bar"
->>> obj.name = "b3"
->>> obj.save()
-
-# You can retrieve a single field on a baseclass
->>> obj = BigChild.objects.only("name").get(name="b3")
->>> count_delayed_fields(obj)
-4
->>> obj.name
-u"b3"
->>> 

[Changeset] r13775 - django/trunk/tests/modeltests/custom_methods

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:03:03 -0500 (Sun, 12 Sep 2010)
New Revision: 13775

Added:
   django/trunk/tests/modeltests/custom_methods/tests.py
Modified:
   django/trunk/tests/modeltests/custom_methods/models.py
Log:
Migrated custom_methods doctests. Thanks to Alex Gaynor.

Modified: django/trunk/tests/modeltests/custom_methods/models.py
===
--- django/trunk/tests/modeltests/custom_methods/models.py  2010-09-12 
20:02:57 UTC (rev 13774)
+++ django/trunk/tests/modeltests/custom_methods/models.py  2010-09-12 
20:03:03 UTC (rev 13775)
@@ -33,27 +33,4 @@
 WHERE pub_date = %s
 AND id != %s""", 
[connection.ops.value_to_db_date(self.pub_date),
   self.id])
-# The asterisk in "(*row)" tells Python to expand the list into
-# positional arguments to Article().
 return [self.__class__(*row) for row in cursor.fetchall()]
-
-__test__ = {'API_TESTS':"""
-# Create a couple of Articles.
->>> from datetime import date
->>> a = Article(id=None, headline='Area man programs in Python', 
pub_date=date(2005, 7, 27))
->>> a.save()
->>> b = Article(id=None, headline='Beatles reunite', pub_date=date(2005, 7, 
27))
->>> b.save()
-
-# Test the custom methods.
->>> a.was_published_today()
-False
->>> a.articles_from_same_day_1()
-[]
->>> a.articles_from_same_day_2()
-[]
->>> b.articles_from_same_day_1()
-[]
->>> b.articles_from_same_day_2()
-[]
-"""}

Added: django/trunk/tests/modeltests/custom_methods/tests.py
===
--- django/trunk/tests/modeltests/custom_methods/tests.py   
(rev 0)
+++ django/trunk/tests/modeltests/custom_methods/tests.py   2010-09-12 
20:03:03 UTC (rev 13775)
@@ -0,0 +1,42 @@
+from datetime import date
+
+from django.test import TestCase
+
+from models import Article
+
+
+class MethodsTests(TestCase):
+def test_custom_methods(self):
+a = Article.objects.create(
+headline="Area man programs in Python", pub_date=date(2005, 7, 27)
+)
+b = Article.objects.create(
+headline="Beatles reunite", pub_date=date(2005, 7, 27)
+)
+
+self.assertFalse(a.was_published_today())
+self.assertQuerysetEqual(
+a.articles_from_same_day_1(), [
+"Beatles reunite",
+],
+lambda a: a.headline,
+)
+self.assertQuerysetEqual(
+a.articles_from_same_day_2(), [
+"Beatles reunite",
+],
+lambda a: a.headline
+)
+
+self.assertQuerysetEqual(
+b.articles_from_same_day_1(), [
+"Area man programs in Python",
+],
+lambda a: a.headline,
+)
+self.assertQuerysetEqual(
+b.articles_from_same_day_2(), [
+"Area man programs in Python",
+],
+lambda a: a.headline
+)

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.




[Changeset] r13774 - django/trunk/tests/modeltests/custom_managers

2010-09-12 Thread noreply
Author: russellm
Date: 2010-09-12 15:02:57 -0500 (Sun, 12 Sep 2010)
New Revision: 13774

Added:
   django/trunk/tests/modeltests/custom_managers/tests.py
Modified:
   django/trunk/tests/modeltests/custom_managers/models.py
Log:
Migrated the custom_managers tests. Thanks to Alex Gaynor.

Modified: django/trunk/tests/modeltests/custom_managers/models.py
===
--- django/trunk/tests/modeltests/custom_managers/models.py 2010-09-12 
19:58:05 UTC (rev 13773)
+++ django/trunk/tests/modeltests/custom_managers/models.py 2010-09-12 
20:02:57 UTC (rev 13774)
@@ -57,51 +57,3 @@
 
 def __unicode__(self):
 return self.name
-
-__test__ = {'API_TESTS':"""
->>> p1 = Person(first_name='Bugs', last_name='Bunny', fun=True)
->>> p1.save()
->>> p2 = Person(first_name='Droopy', last_name='Dog', fun=False)
->>> p2.save()
->>> Person.objects.get_fun_people()
-[]
-
-# The RelatedManager used on the 'books' descriptor extends the default manager
->>> from modeltests.custom_managers.models import PublishedBookManager
->>> isinstance(p2.books, PublishedBookManager)
-True
-
->>> b1 = Book(title='How to program', author='Rodney Dangerfield', 
is_published=True)
->>> b1.save()
->>> b2 = Book(title='How to be smart', author='Albert Einstein', 
is_published=False)
->>> b2.save()
-
-# The default manager, "objects", doesn't exist,
-# because a custom one was provided.
->>> Book.objects
-Traceback (most recent call last):
-...
-AttributeError: type object 'Book' has no attribute 'objects'
-
-# The RelatedManager used on the 'authors' descriptor extends the default 
manager
->>> from modeltests.custom_managers.models import PersonManager
->>> isinstance(b2.authors, PersonManager)
-True
-
->>> Book.published_objects.all()
-[]
-
->>> c1 = Car(name='Corvette', mileage=21, top_speed=180)
->>> c1.save()
->>> c2 = Car(name='Neon', mileage=31, top_speed=100)
->>> c2.save()
->>> Car.cars.order_by('name')
-[, ]
->>> Car.fast_cars.all()
-[]
-
-# Each model class gets a "_default_manager" attribute, which is a reference
-# to the first manager defined in the class. In this case, it's "cars".
->>> Car._default_manager.order_by('name')
-[, ]
-"""}

Added: django/trunk/tests/modeltests/custom_managers/tests.py
===
--- django/trunk/tests/modeltests/custom_managers/tests.py  
(rev 0)
+++ django/trunk/tests/modeltests/custom_managers/tests.py  2010-09-12 
20:02:57 UTC (rev 13774)
@@ -0,0 +1,71 @@
+from django.test import TestCase
+
+from models import Person, Book, Car, PersonManager, PublishedBookManager
+
+
+class CustomManagerTests(TestCase):
+def test_manager(self):
+p1 = Person.objects.create(first_name="Bugs", last_name="Bunny", 
fun=True)
+p2 = Person.objects.create(first_name="Droopy", last_name="Dog", 
fun=False)
+
+self.assertQuerysetEqual(
+Person.objects.get_fun_people(), [
+"Bugs Bunny"
+],
+unicode
+)
+# The RelatedManager used on the 'books' descriptor extends the default
+# manager
+self.assertTrue(isinstance(p2.books, PublishedBookManager))
+
+b1 = Book.published_objects.create(
+title="How to program", author="Rodney Dangerfield", 
is_published=True
+)
+b2 = Book.published_objects.create(
+title="How to be smart", author="Albert Einstein", 
is_published=False
+)
+
+# The default manager, "objects", doesn't exist, because a custom one
+# was provided.
+self.assertRaises(AttributeError, lambda: Book.objects)
+
+# The RelatedManager used on the 'authors' descriptor extends the
+# default manager
+self.assertTrue(isinstance(b2.authors, PersonManager))
+
+self.assertQuerysetEqual(
+Book.published_objects.all(), [
+"How to program",
+],
+lambda b: b.title
+)
+
+c1 = Car.cars.create(name="Corvette", mileage=21, top_speed=180)
+c2 = Car.cars.create(name="Neon", mileage=31, top_speed=100)
+
+self.assertQuerysetEqual(
+Car.cars.order_by("name"), [
+"Corvette",
+"Neon",
+],
+lambda c: c.name
+)
+
+self.assertQuerysetEqual(
+Car.fast_cars.all(), [
+"Corvette",
+],
+lambda c: c.name
+)
+
+# Each model class gets a "_default_manager" attribute, which is a
+# reference to the first manager defined in the class. In this case,
+# it's "cars".
+
+self.assertQuerysetEqual(
+Car._default_manager.order_by("name"), [
+"Corvette",
+"Neon",
+],
+lambda c: c.name
+)

-- 
You received this message because you are subscribed to the Google 

[Changeset] r13773 - in django/trunk: django/dispatch docs/topics tests/modeltests/signals

2010-09-12 Thread noreply
Author: brosner
Date: 2010-09-12 14:58:05 -0500 (Sun, 12 Sep 2010)
New Revision: 13773

Modified:
   django/trunk/django/dispatch/__init__.py
   django/trunk/django/dispatch/dispatcher.py
   django/trunk/docs/topics/signals.txt
   django/trunk/tests/modeltests/signals/models.py
Log:
Fixed #9015 -- added a signal decorator for simplifying signal connections

Modified: django/trunk/django/dispatch/__init__.py
===
--- django/trunk/django/dispatch/__init__.py2010-09-12 19:44:19 UTC (rev 
13772)
+++ django/trunk/django/dispatch/__init__.py2010-09-12 19:58:05 UTC (rev 
13773)
@@ -6,4 +6,4 @@
 Heavily modified for Django's purposes.
 """
 
-from django.dispatch.dispatcher import Signal
\ No newline at end of file
+from django.dispatch.dispatcher import Signal, receiver
\ No newline at end of file

Modified: django/trunk/django/dispatch/dispatcher.py
===
--- django/trunk/django/dispatch/dispatcher.py  2010-09-12 19:44:19 UTC (rev 
13772)
+++ django/trunk/django/dispatch/dispatcher.py  2010-09-12 19:58:05 UTC (rev 
13773)
@@ -235,3 +235,19 @@
 for idx, (r_key, _) in enumerate(self.receivers):
 if r_key == key:
 del self.receivers[idx]
+
+
+def receiver(signal, **kwargs):
+"""
+A decorator for connecting receivers to signals. Used by passing in the
+signal and keyword arguments to connect::
+
+@receiver(post_save, sender=MyModel)
+def signal_receiver(sender, **kwargs):
+...
+
+"""
+def _decorator(func):
+signal.connect(func, **kwargs)
+return func
+return _decorator

Modified: django/trunk/docs/topics/signals.txt
===
--- django/trunk/docs/topics/signals.txt2010-09-12 19:44:19 UTC (rev 
13772)
+++ django/trunk/docs/topics/signals.txt2010-09-12 19:58:05 UTC (rev 
13773)
@@ -80,7 +80,8 @@
 Connecting receiver functions
 -
 
-Next, we'll need to connect our receiver to the signal:
+There are two ways you can connect a receiever to a signal. You can take the
+manual connect route:
 
 .. code-block:: python
 
@@ -88,6 +89,17 @@
 
 request_finished.connect(my_callback)
 
+Alternatively, you can use a decorator used when you define your receiver:
+
+.. code-block:: python
+
+from django.core.signals import request_finished
+from django.dispatch import receiver
+
+@receiver(request_finished)
+def my_callback(sender, **kwargs):
+print "Request finished!"
+
 Now, our ``my_callback`` function will be called each time a request finishes.
 
 .. admonition:: Where should this code live?
@@ -115,13 +127,13 @@
 .. code-block:: python
 
 from django.db.models.signals import pre_save
+from django.dispatch import receiver
 from myapp.models import MyModel
 
+@receiver(pre_save, sender=MyModel)
 def my_handler(sender, **kwargs):
 ...
 
-pre_save.connect(my_handler, sender=MyModel)
-
 The ``my_handler`` function will only be called when an instance of ``MyModel``
 is saved.
 

Modified: django/trunk/tests/modeltests/signals/models.py
===
--- django/trunk/tests/modeltests/signals/models.py 2010-09-12 19:44:19 UTC 
(rev 13772)
+++ django/trunk/tests/modeltests/signals/models.py 2010-09-12 19:58:05 UTC 
(rev 13773)
@@ -3,6 +3,7 @@
 """
 
 from django.db import models
+from django.dispatch import receiver
 
 class Person(models.Model):
 first_name = models.CharField(max_length=20)
@@ -11,6 +12,13 @@
 def __unicode__(self):
 return u"%s %s" % (self.first_name, self.last_name)
 
+class Car(models.Model):
+make = models.CharField(max_length=20)
+model = models.CharField(max_length=20)
+
+def __unicode__(self):
+return u"%s %s" % (self.make, self.model)
+
 def pre_save_test(signal, sender, instance, **kwargs):
 print 'pre_save signal,', instance
 if kwargs.get('raw'):
@@ -52,22 +60,44 @@
 >>> models.signals.pre_delete.connect(pre_delete_test)
 >>> models.signals.post_delete.connect(post_delete_test)
 
+# throw a decorator syntax receiver into the mix
+>>> @receiver(models.signals.pre_save)
+... def pre_save_decorator_test(signal, sender, instance, **kwargs):
+... print "pre_save signal decorator,", instance
+
+# throw a decorator syntax receiver into the mix
+>>> @receiver(models.signals.pre_save, sender=Car)
+... def pre_save_decorator_sender_test(signal, sender, instance, **kwargs):
+... print "pre_save signal decorator sender,", instance
+
 >>> p1 = Person(first_name='John', last_name='Smith')
 >>> p1.save()
 pre_save signal, John Smith
+pre_save signal decorator, John Smith
 post_save signal, John Smith
 Is created
 
 >>> p1.first_name = 'Tom'
 >>> p1.save()
 pre_save signal, Tom Smith
+pre_save signal 

Re: [Django] #6218: Require trailing slash always on MEDIA_URL

2010-09-12 Thread Django
#6218: Require trailing slash always on MEDIA_URL
+---
  Reporter:  Michael Toomim   | 
Owner:  cmheisel 
Status:  assigned   | 
Milestone:   
 Component:  Core framework |   
Version:  SVN  
Resolution: |  
Keywords:  easy-pickings
 Stage:  Accepted   | 
Has_patch:  1
Needs_docs:  0  |   
Needs_tests:  0
Needs_better_patch:  1  |  
+---
Changes (by cmheisel):

  * owner:  => cmheisel
  * status:  new => assigned

Comment:

 Thanks SmileyChris! I'll work up a patch.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #6218: Require trailing slash always on MEDIA_URL

2010-09-12 Thread Django
#6218: Require trailing slash always on MEDIA_URL
+---
  Reporter:  Michael Toomim   | 
Owner:   
Status:  new| 
Milestone:   
 Component:  Core framework |   
Version:  SVN  
Resolution: |  
Keywords:  easy-pickings
 Stage:  Accepted   | 
Has_patch:  1
Needs_docs:  0  |   
Needs_tests:  0
Needs_better_patch:  1  |  
+---
Comment (by toomim):

 Thanks SmileyChris

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #6218: Require trailing slash always on MEDIA_URL

2010-09-12 Thread Django
#6218: Require trailing slash always on MEDIA_URL
+---
  Reporter:  Michael Toomim   | 
Owner:   
Status:  new| 
Milestone:   
 Component:  Core framework |   
Version:  SVN  
Resolution: |  
Keywords:  easy-pickings
 Stage:  Accepted   | 
Has_patch:  1
Needs_docs:  0  |   
Needs_tests:  0
Needs_better_patch:  1  |  
+---
Changes (by SmileyChris):

  * stage:  Design decision needed => Accepted

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



Re: [Django] #14267: Trac Upgrade Tracking Ticket

2010-09-12 Thread Django
#14267: Trac Upgrade Tracking Ticket
--+-
  Reporter:  mitsuhiko| Owner:  mitsuhiko
Status:  new  | Milestone:   
 Component:  Django Web site  |   Version:  1.2  
Resolution:   |  Keywords:   
 Stage:  Accepted | Has_patch:  0
Needs_docs:  0|   Needs_tests:  0
Needs_better_patch:  0|  
--+-
Comment (by ramiro):

 It might be worth considering going straight to a 0.12.x checkout of Trac.
 The 0.12.1 stabilization release seems to be near (5 of 53 tickets left
 open): http://trac.edgewall.org/milestone/0.12.1

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.



  1   2   >