summaryrefslogtreecommitdiff
path: root/tests/modeltests
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2012-08-10 12:40:37 +0100
committerAndrew Godwin <andrew@aeracode.org>2012-08-10 12:40:37 +0100
commit184cf9ab798d5b25d855649ddb2ca580949778df (patch)
tree8512633ec04a6979b0953e32e73c9a43d09e5805 /tests/modeltests
parentc4b2a3262cc79383d6562cfc7e9af20135c8e0bf (diff)
parent7275576235ae2e87f3de7b0facb3f9b0a2368f28 (diff)
Merge branch 'master' into schema-alteration
Diffstat (limited to 'tests/modeltests')
-rw-r--r--tests/modeltests/field_subclassing/fields.py8
-rw-r--r--tests/modeltests/field_subclassing/models.py4
-rw-r--r--tests/modeltests/fixtures/tests.py9
-rw-r--r--tests/modeltests/model_forms/tests.py3
-rw-r--r--tests/modeltests/serializers/tests.py2
-rw-r--r--tests/modeltests/timezones/tests.py9
-rw-r--r--tests/modeltests/user_commands/tests.py2
-rw-r--r--tests/modeltests/validation/models.py4
8 files changed, 20 insertions, 21 deletions
diff --git a/tests/modeltests/field_subclassing/fields.py b/tests/modeltests/field_subclassing/fields.py
index a21085de9d..0d4ff98aa7 100644
--- a/tests/modeltests/field_subclassing/fields.py
+++ b/tests/modeltests/field_subclassing/fields.py
@@ -3,7 +3,7 @@ from __future__ import unicode_literals
import json
from django.db import models
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_text
from django.utils import six
@@ -16,7 +16,7 @@ class Small(object):
self.first, self.second = first, second
def __unicode__(self):
- return '%s%s' % (force_unicode(self.first), force_unicode(self.second))
+ return '%s%s' % (force_text(self.first), force_text(self.second))
def __str__(self):
return six.text_type(self).encode('utf-8')
@@ -46,9 +46,9 @@ class SmallField(models.Field):
def get_prep_lookup(self, lookup_type, value):
if lookup_type == 'exact':
- return force_unicode(value)
+ return force_text(value)
if lookup_type == 'in':
- return [force_unicode(v) for v in value]
+ return [force_text(v) for v in value]
if lookup_type == 'isnull':
return []
raise TypeError('Invalid lookup type: %r' % lookup_type)
diff --git a/tests/modeltests/field_subclassing/models.py b/tests/modeltests/field_subclassing/models.py
index 5e3c376976..2df9664cdc 100644
--- a/tests/modeltests/field_subclassing/models.py
+++ b/tests/modeltests/field_subclassing/models.py
@@ -5,7 +5,7 @@ Tests for field subclassing.
from __future__ import absolute_import
from django.db import models
-from django.utils.encoding import force_unicode
+from django.utils.encoding import force_text
from .fields import SmallField, SmallerField, JSONField
@@ -15,7 +15,7 @@ class MyModel(models.Model):
data = SmallField('small field')
def __unicode__(self):
- return force_unicode(self.name)
+ return force_text(self.name)
class OtherModel(models.Model):
data = SmallerField()
diff --git a/tests/modeltests/fixtures/tests.py b/tests/modeltests/fixtures/tests.py
index 1efa035e8a..b332348425 100644
--- a/tests/modeltests/fixtures/tests.py
+++ b/tests/modeltests/fixtures/tests.py
@@ -1,11 +1,10 @@
from __future__ import absolute_import
-import StringIO
-
from django.contrib.sites.models import Site
from django.core import management
from django.db import connection, IntegrityError
from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature
+from django.utils.six import StringIO
from .models import Article, Book, Spy, Tag, Visa
@@ -26,7 +25,7 @@ class FixtureLoadingTests(TestCase):
def _dumpdata_assert(self, args, output, format='json', natural_keys=False,
use_base_manager=False, exclude_list=[]):
- new_io = StringIO.StringIO()
+ new_io = StringIO()
management.call_command('dumpdata', *args, **{'format':format,
'stdout':new_io,
'stderr':new_io,
@@ -43,7 +42,7 @@ class FixtureLoadingTests(TestCase):
])
def test_loading_and_dumping(self):
- new_io = StringIO.StringIO()
+ new_io = StringIO()
Site.objects.all().delete()
# Load fixture 1. Single JSON file, with two objects.
@@ -293,7 +292,7 @@ class FixtureLoadingTests(TestCase):
class FixtureTransactionTests(TransactionTestCase):
def _dumpdata_assert(self, args, output, format='json'):
- new_io = StringIO.StringIO()
+ new_io = StringIO()
management.call_command('dumpdata', *args, **{'format':format, 'stdout':new_io})
command_output = new_io.getvalue().strip()
self.assertEqual(command_output, output)
diff --git a/tests/modeltests/model_forms/tests.py b/tests/modeltests/model_forms/tests.py
index fc37a25872..1da7f583be 100644
--- a/tests/modeltests/model_forms/tests.py
+++ b/tests/modeltests/model_forms/tests.py
@@ -638,8 +638,7 @@ class OldFormForXTests(TestCase):
f = BaseCategoryForm({'name': '', 'slug': 'not a slug!', 'url': 'foo'})
self.assertEqual(f.errors['name'], ['This field is required.'])
self.assertEqual(f.errors['slug'], ["Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens."])
- with self.assertRaises(AttributeError):
- f.cleaned_data
+ self.assertEqual(f.cleaned_data, {'url': 'foo'})
with self.assertRaises(ValueError):
f.save()
f = BaseCategoryForm({'name': '', 'slug': '', 'url': 'foo'})
diff --git a/tests/modeltests/serializers/tests.py b/tests/modeltests/serializers/tests.py
index 9177227539..ec3cc132db 100644
--- a/tests/modeltests/serializers/tests.py
+++ b/tests/modeltests/serializers/tests.py
@@ -4,13 +4,13 @@ from __future__ import absolute_import, unicode_literals
import json
from datetime import datetime
from xml.dom import minidom
-from StringIO import StringIO
from django.conf import settings
from django.core import serializers
from django.db import transaction, connection
from django.test import TestCase, TransactionTestCase, Approximate
from django.utils import six
+from django.utils.six import StringIO
from django.utils import unittest
from .models import (Category, Author, Article, AuthorProfile, Actor, Movie,
diff --git a/tests/modeltests/timezones/tests.py b/tests/modeltests/timezones/tests.py
index aadb8ba842..a38e4b3f75 100644
--- a/tests/modeltests/timezones/tests.py
+++ b/tests/modeltests/timezones/tests.py
@@ -20,6 +20,7 @@ from django.http import HttpRequest
from django.template import Context, RequestContext, Template, TemplateSyntaxError
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
from django.test.utils import override_settings
+from django.utils import six
from django.utils import timezone
from django.utils.tzinfo import FixedOffset
from django.utils.unittest import skipIf, skipUnless
@@ -690,8 +691,8 @@ class TemplateTests(TestCase):
}
}
- for k1, dt in datetimes.iteritems():
- for k2, tpl in templates.iteritems():
+ for k1, dt in six.iteritems(datetimes):
+ for k2, tpl in six.iteritems(templates):
ctx = Context({'dt': dt, 'ICT': ICT})
actual = tpl.render(ctx)
expected = results[k1][k2]
@@ -703,8 +704,8 @@ class TemplateTests(TestCase):
results['ict']['notag'] = t('ict', 'eat', 'utc', 'ict')
with self.settings(USE_TZ=False):
- for k1, dt in datetimes.iteritems():
- for k2, tpl in templates.iteritems():
+ for k1, dt in six.iteritems(datetimes):
+ for k2, tpl in six.iteritems(templates):
ctx = Context({'dt': dt, 'ICT': ICT})
actual = tpl.render(ctx)
expected = results[k1][k2]
diff --git a/tests/modeltests/user_commands/tests.py b/tests/modeltests/user_commands/tests.py
index 509f13f62f..d25911c09f 100644
--- a/tests/modeltests/user_commands/tests.py
+++ b/tests/modeltests/user_commands/tests.py
@@ -1,10 +1,10 @@
import sys
-from StringIO import StringIO
from django.core import management
from django.core.management.base import CommandError
from django.test import TestCase
from django.utils import translation
+from django.utils.six import StringIO
class CommandTests(TestCase):
diff --git a/tests/modeltests/validation/models.py b/tests/modeltests/validation/models.py
index 0adc9fec32..26fff4b863 100644
--- a/tests/modeltests/validation/models.py
+++ b/tests/modeltests/validation/models.py
@@ -101,6 +101,6 @@ try:
class MultipleAutoFields(models.Model):
auto1 = models.AutoField(primary_key=True)
auto2 = models.AutoField(primary_key=True)
-except AssertionError as assertion_error:
- pass # Fail silently
+except AssertionError as exc:
+ assertion_error = exc
assert str(assertion_error) == "A model can't have more than one AutoField."