diff options
| author | Boulder Sprinters <boulder-sprinters@djangoproject.com> | 2007-05-21 16:50:14 +0000 |
|---|---|---|
| committer | Boulder Sprinters <boulder-sprinters@djangoproject.com> | 2007-05-21 16:50:14 +0000 |
| commit | 97ccb9304ef578057640645013f5fb7eeafa246f (patch) | |
| tree | 0bb5dae3e16c9e26587c3e9b8e071791ade6633a /tests | |
| parent | e7cf3ed9890c03c31ea51f1b3c01cc741c2b26d5 (diff) | |
boulder-oracle-sprint: Merged to [5306]
git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@5307 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/modeltests/invalid_models/models.py | 10 | ||||
| -rw-r--r-- | tests/regressiontests/forms/tests.py | 140 | ||||
| -rw-r--r-- | tests/regressiontests/httpwrappers/tests.py | 3 | ||||
| -rw-r--r-- | tests/regressiontests/markup/__init__.py | 0 | ||||
| -rw-r--r-- | tests/regressiontests/markup/models.py | 0 | ||||
| -rw-r--r-- | tests/regressiontests/markup/tests.py | 69 | ||||
| -rw-r--r-- | tests/regressiontests/serializers_regress/models.py | 16 | ||||
| -rw-r--r-- | tests/regressiontests/serializers_regress/tests.py | 25 | ||||
| -rwxr-xr-x | tests/runtests.py | 14 |
9 files changed, 187 insertions, 90 deletions
diff --git a/tests/modeltests/invalid_models/models.py b/tests/modeltests/invalid_models/models.py index af54ec3d35..90f2f54632 100644 --- a/tests/modeltests/invalid_models/models.py +++ b/tests/modeltests/invalid_models/models.py @@ -8,7 +8,7 @@ from django.db import models class FieldErrors(models.Model): charfield = models.CharField() - floatfield = models.FloatField() + decimalfield = models.DecimalField() filefield = models.FileField() prepopulate = models.CharField(maxlength=10, prepopulate_from='bad') choices = models.CharField(maxlength=10, choices='bad') @@ -87,10 +87,10 @@ class SelfClashM2M(models.Model): src_safe = models.CharField(maxlength=10) selfclashm2m = models.CharField(maxlength=10) - # Non-symmetrical M2M fields _do_ have related accessors, so + # Non-symmetrical M2M fields _do_ have related accessors, so # there is potential for clashes. selfclashm2m_set = models.ManyToManyField("SelfClashM2M", symmetrical=False) - + m2m_1 = models.ManyToManyField("SelfClashM2M", related_name='id', symmetrical=False) m2m_2 = models.ManyToManyField("SelfClashM2M", related_name='src_safe', symmetrical=False) @@ -108,8 +108,8 @@ class Car(models.Model): model = models.ForeignKey(Model) model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "maxlength" attribute. -invalid_models.fielderrors: "floatfield": FloatFields require a "decimal_places" attribute. -invalid_models.fielderrors: "floatfield": FloatFields require a "max_digits" attribute. +invalid_models.fielderrors: "decimalfield": DecimalFields require a "decimal_places" attribute. +invalid_models.fielderrors: "decimalfield": DecimalFields require a "max_digits" attribute. invalid_models.fielderrors: "filefield": FileFields require an "upload_to" attribute. invalid_models.fielderrors: "prepopulate": prepopulate_from should be a list or tuple. invalid_models.fielderrors: "choices": "choices" should be iterable (e.g., a tuple or list). diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py index 5afa3d198d..ba5beed5e5 100644 --- a/tests/regressiontests/forms/tests.py +++ b/tests/regressiontests/forms/tests.py @@ -7,6 +7,10 @@ form_tests = r""" >>> import datetime >>> import time >>> import re +>>> try: +... from decimal import Decimal +... except ImportError: +... from django.utils._decimal import Decimal ########### # Widgets # @@ -1046,6 +1050,133 @@ Traceback (most recent call last): ... ValidationError: [u'Ensure this value is less than or equal to 20.'] +# FloatField ################################################################## + +>>> f = FloatField() +>>> f.clean('') +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] +>>> f.clean(None) +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] +>>> f.clean('1') +1.0 +>>> isinstance(f.clean('1'), float) +True +>>> f.clean('23') +23.0 +>>> f.clean('3.14') +3.1400000000000001 +>>> f.clean('a') +Traceback (most recent call last): +... +ValidationError: [u'Enter a number.'] +>>> f.clean('1.0 ') +1.0 +>>> f.clean(' 1.0') +1.0 +>>> f.clean(' 1.0 ') +1.0 +>>> f.clean('1.0a') +Traceback (most recent call last): +... +ValidationError: [u'Enter a number.'] + +>>> f = FloatField(required=False) +>>> f.clean('') + +>>> f.clean(None) + +>>> f.clean('1') +1.0 + +FloatField accepts min_value and max_value just like IntegerField: +>>> f = FloatField(max_value=1.5, min_value=0.5) + +>>> f.clean('1.6') +Traceback (most recent call last): +... +ValidationError: [u'Ensure this value is less than or equal to 1.5.'] +>>> f.clean('0.4') +Traceback (most recent call last): +... +ValidationError: [u'Ensure this value is greater than or equal to 0.5.'] +>>> f.clean('1.5') +1.5 +>>> f.clean('0.5') +0.5 + +# DecimalField ################################################################ + +>>> f = DecimalField(max_digits=4, decimal_places=2) +>>> f.clean('') +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] +>>> f.clean(None) +Traceback (most recent call last): +... +ValidationError: [u'This field is required.'] +>>> f.clean('1') +Decimal("1") +>>> isinstance(f.clean('1'), Decimal) +True +>>> f.clean('23') +Decimal("23") +>>> f.clean('3.14') +Decimal("3.14") +>>> f.clean('a') +Traceback (most recent call last): +... +ValidationError: [u'Enter a number.'] +>>> f.clean('1.0 ') +Decimal("1.0") +>>> f.clean(' 1.0') +Decimal("1.0") +>>> f.clean(' 1.0 ') +Decimal("1.0") +>>> f.clean('1.0a') +Traceback (most recent call last): +... +ValidationError: [u'Enter a number.'] +>>> f.clean('123.45') +Traceback (most recent call last): +... +ValidationError: [u'Ensure that there are no more than 4 digits in total.'] +>>> f.clean('1.234') +Traceback (most recent call last): +... +ValidationError: [u'Ensure that there are no more than 2 decimal places.'] +>>> f.clean('123.4') +Traceback (most recent call last): +... +ValidationError: [u'Ensure that there are no more than 2 digits before the decimal point.'] +>>> f = DecimalField(max_digits=4, decimal_places=2, required=False) +>>> f.clean('') + +>>> f.clean(None) + +>>> f.clean('1') +Decimal("1") + +DecimalField accepts min_value and max_value just like IntegerField: +>>> f = DecimalField(max_digits=4, decimal_places=2, max_value=Decimal('1.5'), min_value=Decimal('0.5')) + +>>> f.clean('1.6') +Traceback (most recent call last): +... +ValidationError: [u'Ensure this value is less than or equal to 1.5.'] +>>> f.clean('0.4') +Traceback (most recent call last): +... +ValidationError: [u'Ensure this value is greater than or equal to 0.5.'] +>>> f.clean('1.5') +Decimal("1.5") +>>> f.clean('0.5') +Decimal("0.5") + # DateField ################################################################### >>> import datetime @@ -3515,6 +3646,15 @@ u'\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111' u'1' >>> smart_unicode('foo') u'foo' + +# flatatt tests +>>> from django.newforms.util import flatatt +>>> flatatt({'id': "header"}) +u' id="header"' +>>> flatatt({'class': "news", 'title': "Read this"}) +u' class="news" title="Read this"' +>>> flatatt({}) +u'' """ __test__ = { diff --git a/tests/regressiontests/httpwrappers/tests.py b/tests/regressiontests/httpwrappers/tests.py index c8016bc5bd..e7245104e9 100644 --- a/tests/regressiontests/httpwrappers/tests.py +++ b/tests/regressiontests/httpwrappers/tests.py @@ -166,6 +166,9 @@ True >>> q.pop('foo') ['bar', 'baz', 'another', 'hello'] +>>> q.pop('foo', 'not there') +'not there' + >>> q.get('foo', 'not there') 'not there' diff --git a/tests/regressiontests/markup/__init__.py b/tests/regressiontests/markup/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 --- a/tests/regressiontests/markup/__init__.py +++ /dev/null diff --git a/tests/regressiontests/markup/models.py b/tests/regressiontests/markup/models.py deleted file mode 100644 index e69de29bb2..0000000000 --- a/tests/regressiontests/markup/models.py +++ /dev/null diff --git a/tests/regressiontests/markup/tests.py b/tests/regressiontests/markup/tests.py deleted file mode 100644 index bd3f52b9dd..0000000000 --- a/tests/regressiontests/markup/tests.py +++ /dev/null @@ -1,69 +0,0 @@ -# Quick tests for the markup templatetags (django.contrib.markup) - -from django.template import Template, Context, add_to_builtins -import re -import unittest - -add_to_builtins('django.contrib.markup.templatetags.markup') - -class Templates(unittest.TestCase): - def test_textile(self): - try: - import textile - except ImportError: - textile = None - - textile_content = """Paragraph 1 - -Paragraph 2 with "quotes" and @code@""" - - t = Template("{{ textile_content|textile }}") - rendered = t.render(Context(locals())).strip() - if textile: - self.assertEqual(rendered, """<p>Paragraph 1</p> - -<p>Paragraph 2 with “quotes” and <code>code</code></p>""") - else: - self.assertEqual(rendered, textile_content) - - def test_markdown(self): - try: - import markdown - except ImportError: - markdown = None - - markdown_content = """Paragraph 1 - -## An h2""" - - t = Template("{{ markdown_content|markdown }}") - rendered = t.render(Context(locals())).strip() - if markdown: - pattern = re.compile("""<p>Paragraph 1\s*</p>\s*<h2>\s*An h2</h2>""") - self.assert_(pattern.match(rendered)) - else: - self.assertEqual(rendered, markdown_content) - - def test_docutils(self): - try: - import docutils - except ImportError: - docutils = None - - rest_content = """Paragraph 1 - -Paragraph 2 with a link_ - -.. _link: http://www.example.com/""" - - t = Template("{{ rest_content|restructuredtext }}") - rendered = t.render(Context(locals())).strip() - if docutils: - self.assertEqual(rendered, """<p>Paragraph 1</p> -<p>Paragraph 2 with a <a class="reference" href="http://www.example.com/">link</a></p>""") - else: - self.assertEqual(rendered, rest_content) - - -if __name__ == '__main__': - unittest.main() diff --git a/tests/regressiontests/serializers_regress/models.py b/tests/regressiontests/serializers_regress/models.py index fea5c94cab..999b79ccaf 100644 --- a/tests/regressiontests/serializers_regress/models.py +++ b/tests/regressiontests/serializers_regress/models.py @@ -1,7 +1,7 @@ """ A test spanning all the capabilities of all the serializers. -This class sets up a model for each model field type +This class sets up a model for each model field type (except for image types, because of the PIL dependency). """ @@ -9,12 +9,12 @@ from django.db import models from django.contrib.contenttypes import generic from django.contrib.contenttypes.models import ContentType -# The following classes are for testing basic data +# The following classes are for testing basic data # marshalling, including NULL values. class BooleanData(models.Model): data = models.BooleanField(null=True) - + class CharData(models.Model): data = models.CharField(maxlength=30, null=True) @@ -24,6 +24,9 @@ class DateData(models.Model): class DateTimeData(models.Model): data = models.DateTimeField(null=True) +class DecimalData(models.Model): + data = models.DecimalField(null=True, decimal_places=3, max_digits=5) + class EmailData(models.Model): data = models.EmailField(null=True) @@ -34,7 +37,7 @@ class FilePathData(models.Model): data = models.FilePathField(null=True) class FloatData(models.Model): - data = models.FloatField(null=True, decimal_places=3, max_digits=5) + data = models.FloatField(null=True) class IntegerData(models.Model): data = models.IntegerField(null=True) @@ -145,6 +148,9 @@ class CharPKData(models.Model): # class DateTimePKData(models.Model): # data = models.DateTimeField(primary_key=True) +class DecimalPKData(models.Model): + data = models.DecimalField(primary_key=True, decimal_places=3, max_digits=5) + class EmailPKData(models.Model): data = models.EmailField(primary_key=True) @@ -155,7 +161,7 @@ class FilePathPKData(models.Model): data = models.FilePathField(primary_key=True) class FloatPKData(models.Model): - data = models.FloatField(primary_key=True, decimal_places=3, max_digits=5) + data = models.FloatField(primary_key=True) class IntegerPKData(models.Model): data = models.IntegerField(primary_key=True) diff --git a/tests/regressiontests/serializers_regress/tests.py b/tests/regressiontests/serializers_regress/tests.py index e98a5ce8ba..f7573e39c3 100644 --- a/tests/regressiontests/serializers_regress/tests.py +++ b/tests/regressiontests/serializers_regress/tests.py @@ -17,6 +17,10 @@ from django.core import management from django.conf import settings from models import * +try: + import decimal +except ImportError: + from django.utils import _decimal as decimal # A set of functions that can be used to recreate # test data objects of various kinds @@ -119,10 +123,14 @@ test_data = [ (data_obj, 60, FilePathData, "/foo/bar/whiz.txt"), (data_obj, 61, FilePathData, None), (data_obj, 62, FilePathData, ""), - (data_obj, 70, FloatData, 12.345), - (data_obj, 71, FloatData, -12.345), - (data_obj, 72, FloatData, 0.0), - (data_obj, 73, FloatData, None), + (data_obj, 70, DecimalData, decimal.Decimal('12.345')), + (data_obj, 71, DecimalData, decimal.Decimal('-12.345')), + (data_obj, 72, DecimalData, decimal.Decimal('0.0')), + (data_obj, 73, DecimalData, None), + (data_obj, 74, FloatData, 12.345), + (data_obj, 75, FloatData, -12.345), + (data_obj, 76, FloatData, 0.0), + (data_obj, 77, FloatData, None), (data_obj, 80, IntegerData, 123456789), (data_obj, 81, IntegerData, -123456789), (data_obj, 82, IntegerData, 0), @@ -209,9 +217,12 @@ The end."""), (pk_obj, 640, EmailPKData, "hovercraft@example.com"), (pk_obj, 650, FilePKData, 'file:///foo/bar/whiz.txt'), (pk_obj, 660, FilePathPKData, "/foo/bar/whiz.txt"), - (pk_obj, 670, FloatPKData, 12.345), - (pk_obj, 671, FloatPKData, -12.345), - (pk_obj, 672, FloatPKData, 0.0), + (pk_obj, 670, DecimalPKData, decimal.Decimal('12.345')), + (pk_obj, 671, DecimalPKData, decimal.Decimal('-12.345')), + (pk_obj, 672, DecimalPKData, decimal.Decimal('0.0')), + (pk_obj, 673, FloatPKData, 12.345), + (pk_obj, 674, FloatPKData, -12.345), + (pk_obj, 675, FloatPKData, 0.0), (pk_obj, 680, IntegerPKData, 123456789), (pk_obj, 681, IntegerPKData, -123456789), (pk_obj, 682, IntegerPKData, 0), diff --git a/tests/runtests.py b/tests/runtests.py index a111ef1436..7d1ee1e29c 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -3,11 +3,15 @@ import os, sys, traceback import unittest +import django.contrib as contrib +CONTRIB_DIR_NAME = 'django.contrib' MODEL_TESTS_DIR_NAME = 'modeltests' REGRESSION_TESTS_DIR_NAME = 'regressiontests' + TEST_DATABASE_NAME = 'django_test_db' TEST_TEMPLATE_DIR = 'templates' +CONTRIB_DIR = os.path.dirname(contrib.__file__) MODEL_TEST_DIR = os.path.join(os.path.dirname(__file__), MODEL_TESTS_DIR_NAME) REGRESSION_TEST_DIR = os.path.join(os.path.dirname(__file__), REGRESSION_TESTS_DIR_NAME) @@ -24,7 +28,7 @@ ALWAYS_INSTALLED_APPS = [ def get_test_models(): models = [] - for loc, dirpath in (MODEL_TESTS_DIR_NAME, MODEL_TEST_DIR), (REGRESSION_TESTS_DIR_NAME, REGRESSION_TEST_DIR): + for loc, dirpath in (MODEL_TESTS_DIR_NAME, MODEL_TEST_DIR), (REGRESSION_TESTS_DIR_NAME, REGRESSION_TEST_DIR), (CONTRIB_DIR_NAME, CONTRIB_DIR): for f in os.listdir(dirpath): if f.startswith('__init__') or f.startswith('.') or f.startswith('sql') or f.startswith('invalid'): continue @@ -33,7 +37,7 @@ def get_test_models(): def get_invalid_models(): models = [] - for loc, dirpath in (MODEL_TESTS_DIR_NAME, MODEL_TEST_DIR), (REGRESSION_TESTS_DIR_NAME, REGRESSION_TEST_DIR): + for loc, dirpath in (MODEL_TESTS_DIR_NAME, MODEL_TEST_DIR), (REGRESSION_TESTS_DIR_NAME, REGRESSION_TEST_DIR), (CONTRIB_DIR_NAME, CONTRIB_DIR): for f in os.listdir(dirpath): if f.startswith('__init__') or f.startswith('.') or f.startswith('sql'): continue @@ -109,8 +113,10 @@ def django_tests(verbosity, tests_to_run): if verbosity >= 1: print "Importing model %s" % model_name mod = load_app(model_label) - settings.INSTALLED_APPS.append(model_label) - test_models.append(mod) + if mod: + if model_label not in settings.INSTALLED_APPS: + settings.INSTALLED_APPS.append(model_label) + test_models.append(mod) except Exception, e: sys.stderr.write("Error while importing %s:" % model_name + ''.join(traceback.format_exception(*sys.exc_info())[1:])) continue |
