From 549b19af81099f3d2deb5cf15f1e55d75727d19e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Honza=20Kr=C3=A1l?= Date: Wed, 5 Aug 2009 01:27:37 +0000 Subject: [PATCH] [soc2009/model-validation] Update model_forms test to actually test model form git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@11396 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/modeltests/model_forms/models.py | 50 +++++++++++++++----------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py index e8b2a2c211..0c8dbb5c10 100644 --- a/tests/modeltests/model_forms/models.py +++ b/tests/modeltests/model_forms/models.py @@ -1338,27 +1338,35 @@ __test__['API_TESTS'] += """ ... class Meta: ... model = CommaSeparatedInteger ->>> f = CommaSeparatedIntegerForm().fields['field'] ->>> f.clean('1,2,3') -u'1,2,3' ->>> f.clean('1a,2') -Traceback (most recent call last): -... -ValidationError: [u'Enter only digits separated by commas.'] ->>> f.clean(',,,,') -u',,,,' ->>> f.clean('1.2') -Traceback (most recent call last): -... -ValidationError: [u'Enter only digits separated by commas.'] ->>> f.clean('1,a,2') -Traceback (most recent call last): -... -ValidationError: [u'Enter only digits separated by commas.'] ->>> f.clean('1,,2') -u'1,,2' ->>> f.clean('1') -u'1' +>>> f = CommaSeparatedIntegerForm({'field': '1,2,3'}) +>>> f.is_valid() +True +>>> f.cleaned_data +{'field': u'1,2,3'} +>>> f = CommaSeparatedIntegerForm({'field': '1a,2'}) +>>> f.errors +{'field': [u'Enter only digits separated by commas.']} +>>> f = CommaSeparatedIntegerForm({'field': ',,,,'}) +>>> f.is_valid() +True +>>> f.cleaned_data +{'field': u',,,,'} +>>> f = CommaSeparatedIntegerForm({'field': '1.2'}) +>>> f.errors +{'field': [u'Enter only digits separated by commas.']} +>>> f = CommaSeparatedIntegerForm({'field': '1,a,2'}) +>>> f.errors +{'field': [u'Enter only digits separated by commas.']} +>>> f = CommaSeparatedIntegerForm({'field': '1,,2'}) +>>> f.is_valid() +True +>>> f.cleaned_data +{'field': u'1,,2'} +>>> f = CommaSeparatedIntegerForm({'field': '1'}) +>>> f.is_valid() +True +>>> f.cleaned_data +{'field': u'1'} # unique/unique_together validation