From d2c03a37798adf1975d96c12e927bed75db7feed Mon Sep 17 00:00:00 2001 From: Boulder Sprinters Date: Wed, 28 Mar 2007 21:28:59 +0000 Subject: [PATCH] boulder-oracle-sprint: Merged to [4839]. git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@4841 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/modeltests/empty/models.py | 2 +- tests/modeltests/field_defaults/models.py | 2 +- tests/modeltests/fixtures/models.py | 2 +- tests/modeltests/generic_relations/models.py | 2 +- tests/modeltests/get_object_or_404/models.py | 2 +- tests/modeltests/get_or_create/models.py | 2 +- tests/modeltests/m2m_and_m2o/models.py | 2 +- tests/modeltests/m2m_recursive/models.py | 2 +- tests/modeltests/manipulators/models.py | 2 +- tests/modeltests/model_forms/models.py | 2 +- tests/modeltests/pagination/models.py | 2 +- tests/modeltests/select_related/models.py | 2 +- tests/modeltests/serializers/models.py | 2 +- tests/modeltests/test_client/models.py | 2 +- tests/modeltests/validation/models.py | 2 +- tests/regressiontests/forms/tests.py | 323 +++++++++++++++++++ tests/regressiontests/templates/tests.py | 4 + 17 files changed, 342 insertions(+), 15 deletions(-) diff --git a/tests/modeltests/empty/models.py b/tests/modeltests/empty/models.py index 0e5d572504..2493b53837 100644 --- a/tests/modeltests/empty/models.py +++ b/tests/modeltests/empty/models.py @@ -1,5 +1,5 @@ """ -Empty model tests +39. Empty model tests These test that things behave sensibly for the rare corner-case of a model with no fields. diff --git a/tests/modeltests/field_defaults/models.py b/tests/modeltests/field_defaults/models.py index da4cd38974..8e803d00d8 100644 --- a/tests/modeltests/field_defaults/models.py +++ b/tests/modeltests/field_defaults/models.py @@ -1,5 +1,5 @@ """ -31. Callable defaults +32. Callable defaults You can pass callable objects as the ``default`` parameter to a field. When the object is created without an explicit value passed in, Django will call diff --git a/tests/modeltests/fixtures/models.py b/tests/modeltests/fixtures/models.py index afef6a7389..c75e6723fd 100644 --- a/tests/modeltests/fixtures/models.py +++ b/tests/modeltests/fixtures/models.py @@ -1,5 +1,5 @@ """ -39. Fixtures. +37. Fixtures. Fixtures are a way of loading data into the database in bulk. Fixure data can be stored in any serializable format (including JSON and XML). Fixtures diff --git a/tests/modeltests/generic_relations/models.py b/tests/modeltests/generic_relations/models.py index 2bfb55e618..2b2f64165f 100644 --- a/tests/modeltests/generic_relations/models.py +++ b/tests/modeltests/generic_relations/models.py @@ -1,5 +1,5 @@ """ -33. Generic relations +34. Generic relations Generic relations let an object have a foreign key to any object through a content-type/object-id field. A generic foreign key can point to any object, diff --git a/tests/modeltests/get_object_or_404/models.py b/tests/modeltests/get_object_or_404/models.py index 0aefd40fdf..2ad459669f 100644 --- a/tests/modeltests/get_object_or_404/models.py +++ b/tests/modeltests/get_object_or_404/models.py @@ -1,5 +1,5 @@ """ -34. DB-API Shortcuts +35. DB-API Shortcuts get_object_or_404 is a shortcut function to be used in view functions for performing a get() lookup and raising a Http404 exception if a DoesNotExist diff --git a/tests/modeltests/get_or_create/models.py b/tests/modeltests/get_or_create/models.py index b4f39ceded..f974a82dee 100644 --- a/tests/modeltests/get_or_create/models.py +++ b/tests/modeltests/get_or_create/models.py @@ -1,5 +1,5 @@ """ -32. get_or_create() +33. get_or_create() get_or_create() does what it says: it tries to look up an object with the given parameters. If an object isn't found, it creates one with the given parameters. diff --git a/tests/modeltests/m2m_and_m2o/models.py b/tests/modeltests/m2m_and_m2o/models.py index 7fc66ed5a0..09affb002f 100644 --- a/tests/modeltests/m2m_and_m2o/models.py +++ b/tests/modeltests/m2m_and_m2o/models.py @@ -1,5 +1,5 @@ """ -28. Many-to-many and many-to-one relationships to the same table +29. Many-to-many and many-to-one relationships to the same table Make sure to set ``related_name`` if you use relationships to the same table. """ diff --git a/tests/modeltests/m2m_recursive/models.py b/tests/modeltests/m2m_recursive/models.py index 9f31cf92c0..15c713a759 100644 --- a/tests/modeltests/m2m_recursive/models.py +++ b/tests/modeltests/m2m_recursive/models.py @@ -1,5 +1,5 @@ """ -27. Many-to-many relationships between the same two tables +28. Many-to-many relationships between the same two tables In this example, A Person can have many friends, who are also people. Friendship is a symmetrical relationship - if I am your friend, you are my friend. diff --git a/tests/modeltests/manipulators/models.py b/tests/modeltests/manipulators/models.py index e5b8be55b5..1a44cfe7f4 100644 --- a/tests/modeltests/manipulators/models.py +++ b/tests/modeltests/manipulators/models.py @@ -1,5 +1,5 @@ """ -26. Default manipulators +27. Default manipulators Each model gets an AddManipulator and ChangeManipulator by default. """ diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py index e64174a23f..d91f1d2d45 100644 --- a/tests/modeltests/model_forms/models.py +++ b/tests/modeltests/model_forms/models.py @@ -1,5 +1,5 @@ """ -34. Generating HTML forms from models +36. Generating HTML forms from models Django provides shortcuts for creating Form objects from a model class and a model instance. diff --git a/tests/modeltests/pagination/models.py b/tests/modeltests/pagination/models.py index 3319b5cafa..94deb885f5 100644 --- a/tests/modeltests/pagination/models.py +++ b/tests/modeltests/pagination/models.py @@ -1,5 +1,5 @@ """ -29. Object pagination +30. Object pagination Django provides a framework for paginating a list of objects in a few lines of code. This is often useful for dividing search results or long lists of diff --git a/tests/modeltests/select_related/models.py b/tests/modeltests/select_related/models.py index 8a19267870..cd34bd1d84 100644 --- a/tests/modeltests/select_related/models.py +++ b/tests/modeltests/select_related/models.py @@ -1,5 +1,5 @@ """ -XXX. Tests for ``select_related()`` +40. Tests for select_related() ``select_related()`` follows all relationships and pre-caches any foreign key values so that complex trees can be fetched in a single query. However, this diff --git a/tests/modeltests/serializers/models.py b/tests/modeltests/serializers/models.py index e86546c6fe..339303fc0a 100644 --- a/tests/modeltests/serializers/models.py +++ b/tests/modeltests/serializers/models.py @@ -1,5 +1,5 @@ """ -XXX. Serialization +41. Serialization ``django.core.serializers`` provides interfaces to converting Django querysets to and from "flat" data (i.e. strings). diff --git a/tests/modeltests/test_client/models.py b/tests/modeltests/test_client/models.py index 75f3c49908..44ddffb55f 100644 --- a/tests/modeltests/test_client/models.py +++ b/tests/modeltests/test_client/models.py @@ -1,5 +1,5 @@ """ -39. Testing using the Test Client +38. Testing using the Test Client The test client is a class that can act like a simple browser for testing purposes. diff --git a/tests/modeltests/validation/models.py b/tests/modeltests/validation/models.py index 1066faca4f..b31f981aac 100644 --- a/tests/modeltests/validation/models.py +++ b/tests/modeltests/validation/models.py @@ -1,5 +1,5 @@ """ -30. Validation +31. Validation This is an experimental feature! diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py index a9ce8d23b3..f805a221aa 100644 --- a/tests/regressiontests/forms/tests.py +++ b/tests/regressiontests/forms/tests.py @@ -3556,6 +3556,329 @@ u'' >>> f.clean('') u'' +# FRZipCodeField ############################################################# + +FRZipCodeField validates that the data is a valid FR zipcode. +>>> from django.contrib.localflavor.fr.forms import FRZipCodeField +>>> f = FRZipCodeField() +>>> f.clean('75001') +u'75001' +>>> f.clean('93200') +u'93200' +>>> f.clean('2A200') +Traceback (most recent call last): +... +ValidationError: [u'Enter a zip code in the format XXXXX.'] +>>> f.clean('980001') +Traceback (most recent call last): +... +ValidationError: [u'Enter a zip code in the format XXXXX.'] +>>> f.clean(None) +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] +>>> f.clean('') +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] + +>>> f = FRZipCodeField(required=False) +>>> f.clean('75001') +u'75001' +>>> f.clean('93200') +u'93200' +>>> f.clean('2A200') +Traceback (most recent call last): +... +ValidationError: [u'Enter a zip code in the format XXXXX.'] +>>> f.clean('980001') +Traceback (most recent call last): +... +ValidationError: [u'Enter a zip code in the format XXXXX.'] +>>> f.clean(None) +u'' +>>> f.clean('') +u'' + + +# FRPhoneNumberField ########################################################## + +FRPhoneNumberField validates that the data is a valid french phone number. +It's normalized to 0X XX XX XX XX format. Dots are valid too. +>>> from django.contrib.localflavor.fr.forms import FRPhoneNumberField +>>> f = FRPhoneNumberField() +>>> f.clean('01 55 44 58 64') +u'01 55 44 58 64' +>>> f.clean('0155445864') +u'01 55 44 58 64' +>>> f.clean('01 5544 5864') +u'01 55 44 58 64' +>>> f.clean('01 55.44.58.64') +u'01 55 44 58 64' +>>> f.clean('01.55.44.58.64') +u'01 55 44 58 64' +>>> f.clean('01,55,44,58,64') +Traceback (most recent call last): +... +ValidationError: [u'Phone numbers must be in 0X XX XX XX XX format.'] +>>> f.clean('555 015 544') +Traceback (most recent call last): +... +ValidationError: [u'Phone numbers must be in 0X XX XX XX XX format.'] +>>> f.clean(None) +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] +>>> f.clean('') +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] + +>>> f = FRPhoneNumberField(required=False) +>>> f.clean('01 55 44 58 64') +u'01 55 44 58 64' +>>> f.clean('0155445864') +u'01 55 44 58 64' +>>> f.clean('01 5544 5864') +u'01 55 44 58 64' +>>> f.clean('01 55.44.58.64') +u'01 55 44 58 64' +>>> f.clean('01.55.44.58.64') +u'01 55 44 58 64' +>>> f.clean('01,55,44,58,64') +Traceback (most recent call last): +... +ValidationError: [u'Phone numbers must be in 0X XX XX XX XX format.'] +>>> f.clean('555 015 544') +Traceback (most recent call last): +... +ValidationError: [u'Phone numbers must be in 0X XX XX XX XX format.'] +>>> f.clean(None) +u'' +>>> f.clean('') +u'' + +# FRDepartmentSelect ############################################################### + +FRDepartmentSelect is a Select widget that uses a list of french departments +including DOM TOM +>>> from django.contrib.localflavor.fr.forms import FRDepartmentSelect +>>> w = FRDepartmentSelect() +>>> print w.render('dep', 'Paris') + + +# JPPostalCodeField ############################################################### + +A form field that validates its input is a Japanese postcode. + +Accepts 7 digits(with/out hyphen). +>>> from django.contrib.localflavor.jp.forms import JPPostalCodeField +>>> f = JPPostalCodeField() +>>> f.clean('251-0032') +u'2510032' +>>> f.clean('2510032') +u'2510032' +>>> f.clean('2510-032') +Traceback (most recent call last): +... +ValidationError: [u'Enter a postal code in the format XXXXXXX or XXX-XXXX.'] +>>> f.clean('251a0032') +Traceback (most recent call last): +... +ValidationError: [u'Enter a postal code in the format XXXXXXX or XXX-XXXX.'] +>>> f.clean('a51-0032') +Traceback (most recent call last): +... +ValidationError: [u'Enter a postal code in the format XXXXXXX or XXX-XXXX.'] +>>> f.clean('25100321') +Traceback (most recent call last): +... +ValidationError: [u'Enter a postal code in the format XXXXXXX or XXX-XXXX.'] +>>> f.clean('') +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] + +>>> f = JPPostalCodeField(required=False) +>>> f.clean('251-0032') +u'2510032' +>>> f.clean('2510032') +u'2510032' +>>> f.clean('2510-032') +Traceback (most recent call last): +... +ValidationError: [u'Enter a postal code in the format XXXXXXX or XXX-XXXX.'] +>>> f.clean('') +u'' +>>> f.clean(None) +u'' + +# JPPrefectureSelect ############################################################### + +A Select widget that uses a list of Japanese prefectures as its choices. +>>> from django.contrib.localflavor.jp.forms import JPPrefectureSelect +>>> w = JPPrefectureSelect() +>>> print w.render('prefecture', 'kanagawa') + + + ################################# # Tests of underlying functions # ################################# diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py index 375fd36196..967767ee50 100644 --- a/tests/regressiontests/templates/tests.py +++ b/tests/regressiontests/templates/tests.py @@ -650,6 +650,10 @@ class Templates(unittest.TestCase): 'widthratio09': ('{% widthratio a b %}', {'a':50,'b':100}, template.TemplateSyntaxError), 'widthratio10': ('{% widthratio a b 100.0 %}', {'a':50,'b':100}, template.TemplateSyntaxError), + ### WITH TAG ######################################################## + 'with01': ('{% with dict.key as key %}{{ key }}{% endwith %}', {'dict': {'key':50}}, '50'), + 'with02': ('{{ key }}{% with dict.key as key %}{{ key }}-{{ dict.key }}-{{ key }}{% endwith %}{{ key }}', {'dict': {'key':50}}, ('50-50-50', 'INVALID50-50-50INVALID')), + ### NOW TAG ######################################################## # Simple case 'now01' : ('{% now "j n Y"%}', {}, str(datetime.now().day) + ' ' + str(datetime.now().month) + ' ' + str(datetime.now().year)),