From d5a45d79fe03cad93ab5761860e9bb6fc1db4c86 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Thu, 13 Oct 2011 18:04:12 +0000 Subject: [PATCH] Convert all modeltests to use absolute imports, rather than relative ones. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16975 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/modeltests/aggregation/tests.py | 4 ++- tests/modeltests/basic/models.py | 1 + tests/modeltests/basic/tests.py | 4 ++- tests/modeltests/choices/models.py | 1 + tests/modeltests/choices/tests.py | 8 +++-- tests/modeltests/custom_columns/models.py | 1 + tests/modeltests/custom_columns/tests.py | 4 ++- tests/modeltests/custom_managers/tests.py | 4 ++- tests/modeltests/custom_methods/models.py | 4 ++- tests/modeltests/custom_methods/tests.py | 4 ++- tests/modeltests/custom_pk/models.py | 5 +++- tests/modeltests/custom_pk/tests.py | 4 ++- tests/modeltests/defer/tests.py | 4 ++- tests/modeltests/delete/tests.py | 4 ++- tests/modeltests/empty/no_models/tests.py | 1 + tests/modeltests/empty/tests.py | 4 +-- tests/modeltests/expressions/models.py | 1 + tests/modeltests/expressions/tests.py | 4 ++- tests/modeltests/field_defaults/models.py | 4 ++- tests/modeltests/field_defaults/tests.py | 4 ++- tests/modeltests/field_subclassing/fields.py | 1 + tests/modeltests/field_subclassing/models.py | 4 ++- tests/modeltests/field_subclassing/tests.py | 6 ++-- tests/modeltests/files/tests.py | 4 +-- tests/modeltests/fixtures/models.py | 2 +- tests/modeltests/fixtures/tests.py | 4 ++- .../fixtures_model_package/models/__init__.py | 1 + .../fixtures_model_package/tests.py | 2 +- .../modeltests/force_insert_update/models.py | 1 + tests/modeltests/force_insert_update/tests.py | 4 ++- tests/modeltests/generic_relations/tests.py | 4 ++- tests/modeltests/get_latest/models.py | 1 + tests/modeltests/get_latest/tests.py | 4 ++- tests/modeltests/get_object_or_404/models.py | 1 + tests/modeltests/get_object_or_404/tests.py | 4 ++- tests/modeltests/get_or_create/models.py | 1 + tests/modeltests/get_or_create/tests.py | 4 ++- .../invalid_models/invalid_models/models.py | 1 + tests/modeltests/invalid_models/tests.py | 4 +-- tests/modeltests/lookup/models.py | 1 + tests/modeltests/lookup/tests.py | 8 +++-- tests/modeltests/m2m_and_m2o/models.py | 5 ++-- tests/modeltests/m2m_and_m2o/tests.py | 16 +++++----- tests/modeltests/m2m_intermediary/models.py | 1 + tests/modeltests/m2m_intermediary/tests.py | 4 ++- tests/modeltests/m2m_multiple/models.py | 1 + tests/modeltests/m2m_multiple/tests.py | 4 ++- tests/modeltests/m2m_recursive/tests.py | 12 ++++---- tests/modeltests/m2m_signals/tests.py | 4 ++- tests/modeltests/m2m_through/models.py | 4 ++- tests/modeltests/m2m_through/tests.py | 4 ++- tests/modeltests/m2o_recursive/models.py | 1 + tests/modeltests/m2o_recursive/tests.py | 6 +++- tests/modeltests/many_to_many/models.py | 1 + tests/modeltests/many_to_many/tests.py | 6 +++- tests/modeltests/many_to_one/models.py | 1 + tests/modeltests/many_to_one/tests.py | 6 ++-- tests/modeltests/many_to_one_null/models.py | 1 + tests/modeltests/many_to_one_null/tests.py | 5 ++-- tests/modeltests/model_forms/models.py | 3 +- tests/modeltests/model_forms/tests.py | 17 +++++------ tests/modeltests/model_formsets/models.py | 2 ++ tests/modeltests/model_formsets/tests.py | 6 ++-- tests/modeltests/model_inheritance/tests.py | 4 ++- .../models.py | 5 +++- .../tests.py | 6 +++- .../model_package/models/__init__.py | 6 ++-- .../model_package/models/article.py | 3 +- .../model_package/models/publication.py | 1 + tests/modeltests/model_package/tests.py | 6 ++-- .../modeltests/mutually_referential/tests.py | 6 +++- tests/modeltests/one_to_one/models.py | 1 + tests/modeltests/one_to_one/tests.py | 8 +++-- tests/modeltests/or_lookups/models.py | 1 + tests/modeltests/or_lookups/tests.py | 4 ++- .../modeltests/order_with_respect_to/tests.py | 18 ++++++----- tests/modeltests/ordering/tests.py | 4 ++- tests/modeltests/pagination/tests.py | 30 ++++++++++--------- tests/modeltests/prefetch_related/models.py | 2 +- tests/modeltests/prefetch_related/tests.py | 10 +++---- tests/modeltests/properties/models.py | 1 + tests/modeltests/properties/tests.py | 6 +++- .../proxy_model_inheritance/app1/models.py | 4 +++ .../proxy_model_inheritance/app2/models.py | 1 + .../proxy_model_inheritance/tests.py | 8 +++-- tests/modeltests/proxy_models/tests.py | 21 ++++++------- tests/modeltests/raw_query/models.py | 1 + tests/modeltests/raw_query/tests.py | 4 ++- tests/modeltests/reserved_names/models.py | 1 + tests/modeltests/reserved_names/tests.py | 5 +++- tests/modeltests/reverse_lookup/models.py | 1 + tests/modeltests/reverse_lookup/tests.py | 9 ++++-- tests/modeltests/save_delete_hooks/tests.py | 4 ++- tests/modeltests/select_for_update/models.py | 1 + tests/modeltests/select_for_update/tests.py | 7 +++-- tests/modeltests/select_related/tests.py | 4 ++- tests/modeltests/serializers/models.py | 1 + tests/modeltests/serializers/tests.py | 9 +++--- tests/modeltests/signals/tests.py | 4 ++- tests/modeltests/str/models.py | 1 + tests/modeltests/str/tests.py | 5 +++- tests/modeltests/test_client/models.py | 4 ++- tests/modeltests/test_client/tests.py | 7 +++-- tests/modeltests/test_client/urls.py | 6 +++- tests/modeltests/test_client/views.py | 9 +++--- tests/modeltests/transactions/models.py | 1 + tests/modeltests/transactions/tests.py | 4 +-- tests/modeltests/unmanaged_models/tests.py | 8 +++-- tests/modeltests/update/models.py | 1 + tests/modeltests/update/tests.py | 4 ++- .../management/commands/dance.py | 2 ++ tests/modeltests/user_commands/tests.py | 3 +- tests/modeltests/validation/__init__.py | 21 ++++++------- tests/modeltests/validation/models.py | 1 + .../validation/test_custom_messages.py | 6 ++-- .../validation/test_error_messages.py | 2 +- tests/modeltests/validation/test_unique.py | 7 +++-- tests/modeltests/validation/tests.py | 20 +++++++------ tests/modeltests/validation/validators.py | 6 ++-- 119 files changed, 380 insertions(+), 187 deletions(-) diff --git a/tests/modeltests/aggregation/tests.py b/tests/modeltests/aggregation/tests.py index 6f68800ad2..6c1c608d80 100644 --- a/tests/modeltests/aggregation/tests.py +++ b/tests/modeltests/aggregation/tests.py @@ -1,10 +1,12 @@ +from __future__ import absolute_import + import datetime from decimal import Decimal from django.db.models import Avg, Sum, Count, Max, Min from django.test import TestCase, Approximate -from models import Author, Publisher, Book, Store +from .models import Author, Publisher, Book, Store class BaseAggregateTestCase(TestCase): diff --git a/tests/modeltests/basic/models.py b/tests/modeltests/basic/models.py index 26fddf0706..06aa9cf3c3 100644 --- a/tests/modeltests/basic/models.py +++ b/tests/modeltests/basic/models.py @@ -6,6 +6,7 @@ This is a basic model with only two non-primary-key fields. """ from django.db import models + class Article(models.Model): headline = models.CharField(max_length=100, default='Default headline') pub_date = models.DateTimeField() diff --git a/tests/modeltests/basic/tests.py b/tests/modeltests/basic/tests.py index ff09d9b5a1..30ed3de564 100644 --- a/tests/modeltests/basic/tests.py +++ b/tests/modeltests/basic/tests.py @@ -1,10 +1,12 @@ +from __future__ import absolute_import + from datetime import datetime from django.core.exceptions import ObjectDoesNotExist from django.db.models.fields import FieldDoesNotExist from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature -from models import Article +from .models import Article class ModelTest(TestCase): diff --git a/tests/modeltests/choices/models.py b/tests/modeltests/choices/models.py index 27316f5dea..ee01911573 100644 --- a/tests/modeltests/choices/models.py +++ b/tests/modeltests/choices/models.py @@ -11,6 +11,7 @@ field. This method returns the "human-readable" value of the field. from django.db import models + GENDER_CHOICES = ( ('M', 'Male'), ('F', 'Female'), diff --git a/tests/modeltests/choices/tests.py b/tests/modeltests/choices/tests.py index 09023d8113..03a7d3340d 100644 --- a/tests/modeltests/choices/tests.py +++ b/tests/modeltests/choices/tests.py @@ -1,6 +1,8 @@ +from __future__ import absolute_import + from django.test import TestCase -from models import Person +from .models import Person class ChoicesTests(TestCase): @@ -9,10 +11,10 @@ class ChoicesTests(TestCase): s = Person.objects.create(name='Sara', gender='F') self.assertEqual(a.gender, 'M') self.assertEqual(s.gender, 'F') - + self.assertEqual(a.get_gender_display(), 'Male') self.assertEqual(s.get_gender_display(), 'Female') - + # If the value for the field doesn't correspond to a valid choice, # the value itself is provided as a display value. a.gender = '' diff --git a/tests/modeltests/custom_columns/models.py b/tests/modeltests/custom_columns/models.py index 651f8a61b2..17d3d79f7b 100644 --- a/tests/modeltests/custom_columns/models.py +++ b/tests/modeltests/custom_columns/models.py @@ -17,6 +17,7 @@ from the default generated name, use the ``db_table`` parameter on the from django.db import models + class Author(models.Model): first_name = models.CharField(max_length=30, db_column='firstname') last_name = models.CharField(max_length=30, db_column='last') diff --git a/tests/modeltests/custom_columns/tests.py b/tests/modeltests/custom_columns/tests.py index f38f087c89..c1bb6f0a01 100644 --- a/tests/modeltests/custom_columns/tests.py +++ b/tests/modeltests/custom_columns/tests.py @@ -1,7 +1,9 @@ +from __future__ import absolute_import + from django.core.exceptions import FieldError from django.test import TestCase -from models import Author, Article +from .models import Author, Article class CustomColumnsTests(TestCase): diff --git a/tests/modeltests/custom_managers/tests.py b/tests/modeltests/custom_managers/tests.py index 8721e9ac52..bdba3d0733 100644 --- a/tests/modeltests/custom_managers/tests.py +++ b/tests/modeltests/custom_managers/tests.py @@ -1,6 +1,8 @@ +from __future__ import absolute_import + from django.test import TestCase -from models import Person, Book, Car, PersonManager, PublishedBookManager +from .models import Person, Book, Car, PersonManager, PublishedBookManager class CustomManagerTests(TestCase): diff --git a/tests/modeltests/custom_methods/models.py b/tests/modeltests/custom_methods/models.py index 15150a6c3f..4e3da58851 100644 --- a/tests/modeltests/custom_methods/models.py +++ b/tests/modeltests/custom_methods/models.py @@ -4,9 +4,11 @@ Any method you add to a model will be available to instances. """ -from django.db import models import datetime +from django.db import models + + class Article(models.Model): headline = models.CharField(max_length=100) pub_date = models.DateField() diff --git a/tests/modeltests/custom_methods/tests.py b/tests/modeltests/custom_methods/tests.py index 90a7f0da29..9d7444ba62 100644 --- a/tests/modeltests/custom_methods/tests.py +++ b/tests/modeltests/custom_methods/tests.py @@ -1,8 +1,10 @@ +from __future__ import absolute_import + from datetime import date from django.test import TestCase -from models import Article +from .models import Article class MethodsTests(TestCase): diff --git a/tests/modeltests/custom_pk/models.py b/tests/modeltests/custom_pk/models.py index c514fd74c3..e8647800cd 100644 --- a/tests/modeltests/custom_pk/models.py +++ b/tests/modeltests/custom_pk/models.py @@ -6,9 +6,12 @@ By default, Django adds an ``"id"`` field to each model. But you can override this behavior by explicitly adding ``primary_key=True`` to a field. """ +from __future__ import absolute_import + from django.db import models -from fields import MyAutoField +from .fields import MyAutoField + class Employee(models.Model): employee_code = models.IntegerField(primary_key=True, db_column = 'code') diff --git a/tests/modeltests/custom_pk/tests.py b/tests/modeltests/custom_pk/tests.py index 6b94b6d33f..1e3ca8e58c 100644 --- a/tests/modeltests/custom_pk/tests.py +++ b/tests/modeltests/custom_pk/tests.py @@ -1,8 +1,10 @@ # -*- coding: utf-8 -*- +from __future__ import absolute_import + from django.db import transaction, IntegrityError from django.test import TestCase, skipIfDBFeature -from models import Employee, Business, Bar, Foo +from .models import Employee, Business, Bar, Foo class CustomPKTests(TestCase): diff --git a/tests/modeltests/defer/tests.py b/tests/modeltests/defer/tests.py index ccf19fd5ae..542162c3b2 100644 --- a/tests/modeltests/defer/tests.py +++ b/tests/modeltests/defer/tests.py @@ -1,7 +1,9 @@ +from __future__ import absolute_import + from django.db.models.query_utils import DeferredAttribute from django.test import TestCase -from models import Secondary, Primary, Child, BigChild +from .models import Secondary, Primary, Child, BigChild class DeferTests(TestCase): diff --git a/tests/modeltests/delete/tests.py b/tests/modeltests/delete/tests.py index 2a209b1630..d681a76fd2 100644 --- a/tests/modeltests/delete/tests.py +++ b/tests/modeltests/delete/tests.py @@ -1,7 +1,9 @@ +from __future__ import absolute_import + from django.db import models, IntegrityError from django.test import TestCase, skipUnlessDBFeature, skipIfDBFeature -from modeltests.delete.models import (R, RChild, S, T, U, A, M, MR, MRNull, +from .models import (R, RChild, S, T, U, A, M, MR, MRNull, create_a, get_default_r, User, Avatar, HiddenUser, HiddenUserProfile) diff --git a/tests/modeltests/empty/no_models/tests.py b/tests/modeltests/empty/no_models/tests.py index 7b892bcaca..6292ca9f74 100644 --- a/tests/modeltests/empty/no_models/tests.py +++ b/tests/modeltests/empty/no_models/tests.py @@ -1,5 +1,6 @@ from django.test import TestCase + class NoModelTests(TestCase): """ A placeholder test case. See modeltests.empty.tests for more info. """ pass diff --git a/tests/modeltests/empty/tests.py b/tests/modeltests/empty/tests.py index bff3a81e70..255b80eb8f 100644 --- a/tests/modeltests/empty/tests.py +++ b/tests/modeltests/empty/tests.py @@ -1,4 +1,4 @@ -from __future__ import with_statement +from __future__ import with_statement, absolute_import from django.conf import settings from django.core.exceptions import ImproperlyConfigured @@ -6,7 +6,7 @@ from django.db.models.loading import get_app from django.test import TestCase from django.test.utils import override_settings -from models import Empty +from .models import Empty class EmptyModelTests(TestCase): diff --git a/tests/modeltests/expressions/models.py b/tests/modeltests/expressions/models.py index b004408536..dd504999ff 100644 --- a/tests/modeltests/expressions/models.py +++ b/tests/modeltests/expressions/models.py @@ -4,6 +4,7 @@ Tests for F() query expression syntax. from django.db import models + class Employee(models.Model): firstname = models.CharField(max_length=50) lastname = models.CharField(max_length=50) diff --git a/tests/modeltests/expressions/tests.py b/tests/modeltests/expressions/tests.py index 0a136ae5d8..8f4f5461a5 100644 --- a/tests/modeltests/expressions/tests.py +++ b/tests/modeltests/expressions/tests.py @@ -1,8 +1,10 @@ +from __future__ import absolute_import + from django.core.exceptions import FieldError from django.db.models import F from django.test import TestCase -from models import Company, Employee +from .models import Company, Employee class ExpressionsTests(TestCase): diff --git a/tests/modeltests/field_defaults/models.py b/tests/modeltests/field_defaults/models.py index 0dd1f72934..18840c8b4b 100644 --- a/tests/modeltests/field_defaults/models.py +++ b/tests/modeltests/field_defaults/models.py @@ -10,9 +10,11 @@ This example uses ``datetime.datetime.now`` as the default for the ``pub_date`` field. """ -from django.db import models from datetime import datetime +from django.db import models + + class Article(models.Model): headline = models.CharField(max_length=100, default='Default headline') pub_date = models.DateTimeField(default=datetime.now) diff --git a/tests/modeltests/field_defaults/tests.py b/tests/modeltests/field_defaults/tests.py index a23f64404a..206d380e1e 100644 --- a/tests/modeltests/field_defaults/tests.py +++ b/tests/modeltests/field_defaults/tests.py @@ -1,8 +1,10 @@ +from __future__ import absolute_import + from datetime import datetime from django.test import TestCase -from models import Article +from .models import Article class DefaultTests(TestCase): diff --git a/tests/modeltests/field_subclassing/fields.py b/tests/modeltests/field_subclassing/fields.py index d6e4980c90..f74470686d 100644 --- a/tests/modeltests/field_subclassing/fields.py +++ b/tests/modeltests/field_subclassing/fields.py @@ -2,6 +2,7 @@ from django.db import models from django.utils import simplejson as json from django.utils.encoding import force_unicode + class Small(object): """ A simple class to show that non-trivial Python objects can be used as diff --git a/tests/modeltests/field_subclassing/models.py b/tests/modeltests/field_subclassing/models.py index c59c0d5d2c..5e3c376976 100644 --- a/tests/modeltests/field_subclassing/models.py +++ b/tests/modeltests/field_subclassing/models.py @@ -2,10 +2,12 @@ Tests for field subclassing. """ +from __future__ import absolute_import + from django.db import models from django.utils.encoding import force_unicode -from fields import SmallField, SmallerField, JSONField +from .fields import SmallField, SmallerField, JSONField class MyModel(models.Model): diff --git a/tests/modeltests/field_subclassing/tests.py b/tests/modeltests/field_subclassing/tests.py index ee32384f0c..c6a2335f37 100644 --- a/tests/modeltests/field_subclassing/tests.py +++ b/tests/modeltests/field_subclassing/tests.py @@ -1,8 +1,10 @@ +from __future__ import absolute_import + from django.core import serializers from django.test import TestCase -from fields import Small -from models import DataModel, MyModel, OtherModel +from .fields import Small +from .models import DataModel, MyModel, OtherModel class CustomField(TestCase): diff --git a/tests/modeltests/files/tests.py b/tests/modeltests/files/tests.py index e8e7a761f0..50017be359 100644 --- a/tests/modeltests/files/tests.py +++ b/tests/modeltests/files/tests.py @@ -1,4 +1,4 @@ -from __future__ import with_statement +from __future__ import with_statement, absolute_import import shutil import tempfile @@ -9,7 +9,7 @@ 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 +from .models import Storage, temp_storage, temp_storage_location class FileTests(TestCase): diff --git a/tests/modeltests/fixtures/models.py b/tests/modeltests/fixtures/models.py index 45f1f69d95..d2317d2c06 100644 --- a/tests/modeltests/fixtures/models.py +++ b/tests/modeltests/fixtures/models.py @@ -8,10 +8,10 @@ in the application directory, or in one of the directories named in the ``FIXTURE_DIRS`` setting. """ -from django.db import models from django.contrib.auth.models import Permission from django.contrib.contenttypes import generic from django.contrib.contenttypes.models import ContentType +from django.db import models class Category(models.Model): diff --git a/tests/modeltests/fixtures/tests.py b/tests/modeltests/fixtures/tests.py index de78d0b4fd..54ce4708e6 100644 --- a/tests/modeltests/fixtures/tests.py +++ b/tests/modeltests/fixtures/tests.py @@ -1,10 +1,12 @@ +from __future__ import absolute_import + import StringIO from django.contrib.sites.models import Site from django.core import management from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature -from models import Article, Book, Spy, Tag, Visa +from .models import Article, Book, Spy, Tag, Visa class TestCaseFixtureLoadingTests(TestCase): diff --git a/tests/modeltests/fixtures_model_package/models/__init__.py b/tests/modeltests/fixtures_model_package/models/__init__.py index 5cb0e4a759..29f1ac512f 100644 --- a/tests/modeltests/fixtures_model_package/models/__init__.py +++ b/tests/modeltests/fixtures_model_package/models/__init__.py @@ -1,5 +1,6 @@ from django.db import models + class Article(models.Model): headline = models.CharField(max_length=100, default='Default headline') pub_date = models.DateTimeField() diff --git a/tests/modeltests/fixtures_model_package/tests.py b/tests/modeltests/fixtures_model_package/tests.py index 1fae5ee807..8b568fa3aa 100644 --- a/tests/modeltests/fixtures_model_package/tests.py +++ b/tests/modeltests/fixtures_model_package/tests.py @@ -1,7 +1,7 @@ from django.core import management from django.test import TestCase -from models import Article +from .models import Article class SampleTestCase(TestCase): diff --git a/tests/modeltests/force_insert_update/models.py b/tests/modeltests/force_insert_update/models.py index e617aa228a..db4c5d29f3 100644 --- a/tests/modeltests/force_insert_update/models.py +++ b/tests/modeltests/force_insert_update/models.py @@ -4,6 +4,7 @@ automatic behaviour). """ from django.db import models + class Counter(models.Model): name = models.CharField(max_length = 10) value = models.IntegerField() diff --git a/tests/modeltests/force_insert_update/tests.py b/tests/modeltests/force_insert_update/tests.py index bd3eb7dcf6..ea0e55f4c2 100644 --- a/tests/modeltests/force_insert_update/tests.py +++ b/tests/modeltests/force_insert_update/tests.py @@ -1,7 +1,9 @@ +from __future__ import absolute_import + from django.db import transaction, IntegrityError, DatabaseError from django.test import TestCase -from models import Counter, WithCustomPK +from .models import Counter, WithCustomPK class ForceTests(TestCase): diff --git a/tests/modeltests/generic_relations/tests.py b/tests/modeltests/generic_relations/tests.py index 7596f77fbe..adfba82cd6 100644 --- a/tests/modeltests/generic_relations/tests.py +++ b/tests/modeltests/generic_relations/tests.py @@ -1,9 +1,11 @@ +from __future__ import absolute_import + from django import forms from django.contrib.contenttypes.generic import generic_inlineformset_factory from django.contrib.contenttypes.models import ContentType from django.test import TestCase -from models import (TaggedItem, ValuableTaggedItem, Comparison, Animal, +from .models import (TaggedItem, ValuableTaggedItem, Comparison, Animal, Vegetable, Mineral, Gecko) diff --git a/tests/modeltests/get_latest/models.py b/tests/modeltests/get_latest/models.py index 1eeb299267..d8a690f48c 100644 --- a/tests/modeltests/get_latest/models.py +++ b/tests/modeltests/get_latest/models.py @@ -10,6 +10,7 @@ farthest into the future." from django.db import models + class Article(models.Model): headline = models.CharField(max_length=100) pub_date = models.DateField() diff --git a/tests/modeltests/get_latest/tests.py b/tests/modeltests/get_latest/tests.py index 97cd22bf91..948af6045a 100644 --- a/tests/modeltests/get_latest/tests.py +++ b/tests/modeltests/get_latest/tests.py @@ -1,8 +1,10 @@ +from __future__ import absolute_import + from datetime import datetime from django.test import TestCase -from models import Article, Person +from .models import Article, Person class LatestTests(TestCase): diff --git a/tests/modeltests/get_object_or_404/models.py b/tests/modeltests/get_object_or_404/models.py index f62dd0cf30..f0c73ed94a 100644 --- a/tests/modeltests/get_object_or_404/models.py +++ b/tests/modeltests/get_object_or_404/models.py @@ -12,6 +12,7 @@ performing a ``filter()`` lookup and raising a ``Http404`` exception if a from django.db import models + class Author(models.Model): name = models.CharField(max_length=50) diff --git a/tests/modeltests/get_object_or_404/tests.py b/tests/modeltests/get_object_or_404/tests.py index b8c4f7510b..280720fd15 100644 --- a/tests/modeltests/get_object_or_404/tests.py +++ b/tests/modeltests/get_object_or_404/tests.py @@ -1,8 +1,10 @@ +from __future__ import absolute_import + 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 +from .models import Author, Article class GetObjectOr404Tests(TestCase): diff --git a/tests/modeltests/get_or_create/models.py b/tests/modeltests/get_or_create/models.py index 14f55f8d96..1de5a6ecec 100644 --- a/tests/modeltests/get_or_create/models.py +++ b/tests/modeltests/get_or_create/models.py @@ -8,6 +8,7 @@ parameters. from django.db import models + class Person(models.Model): first_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100) diff --git a/tests/modeltests/get_or_create/tests.py b/tests/modeltests/get_or_create/tests.py index 3323c88a82..4cf44507c8 100644 --- a/tests/modeltests/get_or_create/tests.py +++ b/tests/modeltests/get_or_create/tests.py @@ -1,9 +1,11 @@ +from __future__ import absolute_import + from datetime import date from django.db import IntegrityError from django.test import TestCase -from models import Person, ManualPrimaryKeyTest +from .models import Person, ManualPrimaryKeyTest class GetOrCreateTests(TestCase): diff --git a/tests/modeltests/invalid_models/invalid_models/models.py b/tests/modeltests/invalid_models/invalid_models/models.py index d45b28cd0b..422d70f21b 100644 --- a/tests/modeltests/invalid_models/invalid_models/models.py +++ b/tests/modeltests/invalid_models/invalid_models/models.py @@ -7,6 +7,7 @@ This example exists purely to point out errors in models. from django.db import connection, models + class FieldErrors(models.Model): charfield = models.CharField() charfield2 = models.CharField(max_length=-1) diff --git a/tests/modeltests/invalid_models/tests.py b/tests/modeltests/invalid_models/tests.py index d6a1a25f18..dac562c66e 100644 --- a/tests/modeltests/invalid_models/tests.py +++ b/tests/modeltests/invalid_models/tests.py @@ -1,9 +1,9 @@ import copy +import sys +from cStringIO import StringIO from django.core.management.validation import get_validation_errors from django.db.models.loading import cache, load_app -from cStringIO import StringIO -import sys from django.utils import unittest diff --git a/tests/modeltests/lookup/models.py b/tests/modeltests/lookup/models.py index 82434bb81d..7c264a40e4 100644 --- a/tests/modeltests/lookup/models.py +++ b/tests/modeltests/lookup/models.py @@ -6,6 +6,7 @@ This demonstrates features of the database API. from django.db import models + class Author(models.Model): name = models.CharField(max_length=100) class Meta: diff --git a/tests/modeltests/lookup/tests.py b/tests/modeltests/lookup/tests.py index 33eeae7435..9c2b0c6cea 100644 --- a/tests/modeltests/lookup/tests.py +++ b/tests/modeltests/lookup/tests.py @@ -1,8 +1,12 @@ +from __future__ import absolute_import + from datetime import datetime from operator import attrgetter + from django.core.exceptions import FieldError from django.test import TestCase, skipUnlessDBFeature -from models import Author, Article, Tag + +from .models import Author, Article, Tag class LookupTests(TestCase): @@ -243,7 +247,7 @@ class LookupTests(TestCase): self.assertQuerysetEqual(Article.objects.filter(id=self.a5.id).values(), [{ 'id': self.a5.id, - 'author_id': self.au2.id, + 'author_id': self.au2.id, 'headline': 'Article 5', 'pub_date': datetime(2005, 8, 1, 9, 0) }], transform=identity) diff --git a/tests/modeltests/m2m_and_m2o/models.py b/tests/modeltests/m2m_and_m2o/models.py index 6072bd4c5e..9368398f71 100644 --- a/tests/modeltests/m2m_and_m2o/models.py +++ b/tests/modeltests/m2m_and_m2o/models.py @@ -6,6 +6,7 @@ Make sure to set ``related_name`` if you use relationships to the same table. from django.db import models + class User(models.Model): username = models.CharField(max_length=20) @@ -20,6 +21,6 @@ class Issue(models.Model): class Meta: ordering = ('num',) -class UnicodeReferenceModel(models.Model): - others = models.ManyToManyField(u"UnicodeReferenceModel") +class UnicodeReferenceModel(models.Model): + others = models.ManyToManyField(u"UnicodeReferenceModel") diff --git a/tests/modeltests/m2m_and_m2o/tests.py b/tests/modeltests/m2m_and_m2o/tests.py index cb3dcc86bb..77f2eb3b09 100644 --- a/tests/modeltests/m2m_and_m2o/tests.py +++ b/tests/modeltests/m2m_and_m2o/tests.py @@ -1,7 +1,9 @@ +from __future__ import absolute_import + from django.db.models import Q from django.test import TestCase -from models import Issue, User, UnicodeReferenceModel +from .models import Issue, User, UnicodeReferenceModel class RelatedObjectTests(TestCase): @@ -74,15 +76,15 @@ class RelatedObjectTests(TestCase): lambda i: i.num ) -class RelatedObjectTests(TestCase): - def test_m2m_with_unicode_reference(self): +class RelatedObjectTests(TestCase): + def test_m2m_with_unicode_reference(self): """ Regression test for #6045: references to other models can be unicode strings, providing they are directly convertible to ASCII. """ - m1=UnicodeReferenceModel.objects.create() - m2=UnicodeReferenceModel.objects.create() - m2.others.add(m1) # used to cause an error (see ticket #6045) - m2.save() + m1=UnicodeReferenceModel.objects.create() + m2=UnicodeReferenceModel.objects.create() + m2.others.add(m1) # used to cause an error (see ticket #6045) + m2.save() list(m2.others.all()) # Force retrieval. diff --git a/tests/modeltests/m2m_intermediary/models.py b/tests/modeltests/m2m_intermediary/models.py index 8042a52b38..ea9b83ea14 100644 --- a/tests/modeltests/m2m_intermediary/models.py +++ b/tests/modeltests/m2m_intermediary/models.py @@ -12,6 +12,7 @@ field, which specifies the ``Reporter``'s position for the given article from django.db import models + class Reporter(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) diff --git a/tests/modeltests/m2m_intermediary/tests.py b/tests/modeltests/m2m_intermediary/tests.py index 5f357412a5..cdc762246a 100644 --- a/tests/modeltests/m2m_intermediary/tests.py +++ b/tests/modeltests/m2m_intermediary/tests.py @@ -1,8 +1,10 @@ +from __future__ import absolute_import + from datetime import datetime from django.test import TestCase -from models import Reporter, Article, Writer +from .models import Reporter, Article, Writer class M2MIntermediaryTests(TestCase): diff --git a/tests/modeltests/m2m_multiple/models.py b/tests/modeltests/m2m_multiple/models.py index e53f840653..3efe7108b9 100644 --- a/tests/modeltests/m2m_multiple/models.py +++ b/tests/modeltests/m2m_multiple/models.py @@ -9,6 +9,7 @@ Set ``related_name`` to designate what the reverse relationship is called. from django.db import models + class Category(models.Model): name = models.CharField(max_length=20) class Meta: diff --git a/tests/modeltests/m2m_multiple/tests.py b/tests/modeltests/m2m_multiple/tests.py index 1f4503a483..7bf88f99bb 100644 --- a/tests/modeltests/m2m_multiple/tests.py +++ b/tests/modeltests/m2m_multiple/tests.py @@ -1,8 +1,10 @@ +from __future__ import absolute_import + from datetime import datetime from django.test import TestCase -from models import Article, Category +from .models import Article, Category class M2MMultipleTests(TestCase): diff --git a/tests/modeltests/m2m_recursive/tests.py b/tests/modeltests/m2m_recursive/tests.py index 4251028093..5742836929 100644 --- a/tests/modeltests/m2m_recursive/tests.py +++ b/tests/modeltests/m2m_recursive/tests.py @@ -1,8 +1,10 @@ +from __future__ import absolute_import + from operator import attrgetter from django.test import TestCase -from models import Person +from .models import Person class RecursiveM2MTests(TestCase): @@ -11,14 +13,14 @@ class RecursiveM2MTests(TestCase): Person.objects.create(name=name) for name in ["Anne", "Bill", "Chuck", "David"] ] - + # Add some friends in the direction of field definition # Anne is friends with Bill and Chuck a.friends.add(b, c) # David is friends with Anne and Chuck - add in reverse direction d.friends.add(a,c) - + # Who is friends with Anne? self.assertQuerysetEqual( a.friends.all(), [ @@ -54,7 +56,7 @@ class RecursiveM2MTests(TestCase): # Bill is already friends with Anne - add Anne again, but in the # reverse direction b.friends.add(a) - + # Who is friends with Anne? self.assertQuerysetEqual( a.friends.all(), [ @@ -115,7 +117,7 @@ class RecursiveM2MTests(TestCase): b.idols.add(a) # David is idolized by Anne and Chuck - add in reverse direction d.stalkers.add(a, c) - + # Who are Anne's idols? self.assertQuerysetEqual( a.idols.all(), [ diff --git a/tests/modeltests/m2m_signals/tests.py b/tests/modeltests/m2m_signals/tests.py index 9e9158f571..d3d2a74c70 100644 --- a/tests/modeltests/m2m_signals/tests.py +++ b/tests/modeltests/m2m_signals/tests.py @@ -2,10 +2,12 @@ Testing signals emitted on changing m2m relations. """ +from .models import Person + from django.db import models from django.test import TestCase -from models import Part, Car, SportsCar, Person +from .models import Part, Car, SportsCar, Person class ManyToManySignalsTest(TestCase): diff --git a/tests/modeltests/m2m_through/models.py b/tests/modeltests/m2m_through/models.py index d41fe8d26d..aa71a049cb 100644 --- a/tests/modeltests/m2m_through/models.py +++ b/tests/modeltests/m2m_through/models.py @@ -1,6 +1,8 @@ -from django.db import models from datetime import datetime +from django.db import models + + # M2M described on one of the models class Person(models.Model): name = models.CharField(max_length=128) diff --git a/tests/modeltests/m2m_through/tests.py b/tests/modeltests/m2m_through/tests.py index 814e54fc25..94be628a42 100644 --- a/tests/modeltests/m2m_through/tests.py +++ b/tests/modeltests/m2m_through/tests.py @@ -1,9 +1,11 @@ +from __future__ import absolute_import + from datetime import datetime from operator import attrgetter from django.test import TestCase -from models import (Person, Group, Membership, CustomMembership, +from .models import (Person, Group, Membership, CustomMembership, PersonSelfRefM2M, Friendship) diff --git a/tests/modeltests/m2o_recursive/models.py b/tests/modeltests/m2o_recursive/models.py index ed9945a6c5..c0a4bdeec2 100644 --- a/tests/modeltests/m2o_recursive/models.py +++ b/tests/modeltests/m2o_recursive/models.py @@ -12,6 +12,7 @@ Set ``related_name`` to designate what the reverse relationship is called. from django.db import models + class Category(models.Model): name = models.CharField(max_length=20) parent = models.ForeignKey('self', blank=True, null=True, related_name='child_set') diff --git a/tests/modeltests/m2o_recursive/tests.py b/tests/modeltests/m2o_recursive/tests.py index 79dde8b5ea..fa04c74cca 100644 --- a/tests/modeltests/m2o_recursive/tests.py +++ b/tests/modeltests/m2o_recursive/tests.py @@ -1,5 +1,9 @@ +from __future__ import absolute_import + from django.test import TestCase -from models import Category, Person + +from .models import Category, Person + class ManyToOneRecursiveTests(TestCase): diff --git a/tests/modeltests/many_to_many/models.py b/tests/modeltests/many_to_many/models.py index 96636da2b2..5076e35653 100644 --- a/tests/modeltests/many_to_many/models.py +++ b/tests/modeltests/many_to_many/models.py @@ -9,6 +9,7 @@ objects, and a ``Publication`` has multiple ``Article`` objects. from django.db import models + class Publication(models.Model): title = models.CharField(max_length=30) diff --git a/tests/modeltests/many_to_many/tests.py b/tests/modeltests/many_to_many/tests.py index 39fe581252..b00d7da140 100644 --- a/tests/modeltests/many_to_many/tests.py +++ b/tests/modeltests/many_to_many/tests.py @@ -1,5 +1,9 @@ +from __future__ import absolute_import + from django.test import TestCase -from models import Article, Publication + +from .models import Article, Publication + class ManyToManyTests(TestCase): diff --git a/tests/modeltests/many_to_one/models.py b/tests/modeltests/many_to_one/models.py index b4a0f377ab..1e4afcf22f 100644 --- a/tests/modeltests/many_to_one/models.py +++ b/tests/modeltests/many_to_one/models.py @@ -6,6 +6,7 @@ To define a many-to-one relationship, use ``ForeignKey()``. from django.db import models + class Reporter(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) diff --git a/tests/modeltests/many_to_one/tests.py b/tests/modeltests/many_to_one/tests.py index 4f561b40ca..922506eac0 100644 --- a/tests/modeltests/many_to_one/tests.py +++ b/tests/modeltests/many_to_one/tests.py @@ -1,10 +1,12 @@ +from __future__ import absolute_import + from copy import deepcopy from datetime import datetime -from django.test import TestCase from django.core.exceptions import MultipleObjectsReturned +from django.test import TestCase -from models import Article, Reporter +from .models import Article, Reporter class ManyToOneTests(TestCase): diff --git a/tests/modeltests/many_to_one_null/models.py b/tests/modeltests/many_to_one_null/models.py index 5f824b4d21..be7e650c65 100644 --- a/tests/modeltests/many_to_one_null/models.py +++ b/tests/modeltests/many_to_one_null/models.py @@ -7,6 +7,7 @@ To define a many-to-one relationship that can have a null foreign key, use from django.db import models + class Reporter(models.Model): name = models.CharField(max_length=30) diff --git a/tests/modeltests/many_to_one_null/tests.py b/tests/modeltests/many_to_one_null/tests.py index 41341bee00..1e302ecada 100644 --- a/tests/modeltests/many_to_one_null/tests.py +++ b/tests/modeltests/many_to_one_null/tests.py @@ -1,7 +1,8 @@ -from __future__ import with_statement +from __future__ import with_statement, absolute_import from django.test import TestCase -from models import Reporter, Article + +from .models import Reporter, Article class ManyToOneNullTests(TestCase): diff --git a/tests/modeltests/model_forms/models.py b/tests/modeltests/model_forms/models.py index 5dcc0391ce..a960611ffa 100644 --- a/tests/modeltests/model_forms/models.py +++ b/tests/modeltests/model_forms/models.py @@ -9,8 +9,9 @@ words, most of these tests should be rewritten. import tempfile -from django.db import models from django.core.files.storage import FileSystemStorage +from django.db import models + temp_storage_dir = tempfile.mkdtemp() temp_storage = FileSystemStorage(temp_storage_dir) diff --git a/tests/modeltests/model_forms/tests.py b/tests/modeltests/model_forms/tests.py index 0ad3e06264..c4abdbbc6e 100644 --- a/tests/modeltests/model_forms/tests.py +++ b/tests/modeltests/model_forms/tests.py @@ -1,26 +1,25 @@ -from __future__ import with_statement +from __future__ import with_statement, absolute_import import datetime import os from decimal import Decimal from django import forms -from django.test import TestCase from django.core.files.uploadedfile import SimpleUploadedFile from django.core.validators import ValidationError from django.db import connection from django.forms.models import model_to_dict from django.utils.unittest import skipUnless +from django.test import TestCase -from modeltests.model_forms.models import (Article, ArticleStatus, - BetterWriter, BigInt, Book, Category, CommaSeparatedInteger, - CustomFieldForExclusionModel, DerivedBook, DerivedPost, ExplicitPK, - FlexibleDatePost, ImprovedArticle, ImprovedArticleWithParentLink, - Inventory, PhoneNumber, Post, Price, Product, TextFile, Writer, - WriterProfile, test_images) +from .models import (Article, ArticleStatus, BetterWriter, BigInt, Book, + Category, CommaSeparatedInteger, CustomFieldForExclusionModel, DerivedBook, + DerivedPost, ExplicitPK, FlexibleDatePost, ImprovedArticle, + ImprovedArticleWithParentLink, Inventory, PhoneNumber, Post, Price, + Product, TextFile, Writer, WriterProfile, test_images) if test_images: - from modeltests.model_forms.models import ImageFile, OptionalImageFile + from .models import ImageFile, OptionalImageFile class ImageFileForm(forms.ModelForm): class Meta: model = ImageFile diff --git a/tests/modeltests/model_formsets/models.py b/tests/modeltests/model_formsets/models.py index 3eca6964d1..b915c07eb2 100644 --- a/tests/modeltests/model_formsets/models.py +++ b/tests/modeltests/model_formsets/models.py @@ -1,6 +1,8 @@ import datetime + from django.db import models + class Author(models.Model): name = models.CharField(max_length=100) diff --git a/tests/modeltests/model_formsets/tests.py b/tests/modeltests/model_formsets/tests.py index 0e4f2f5991..2be3a0ddff 100644 --- a/tests/modeltests/model_formsets/tests.py +++ b/tests/modeltests/model_formsets/tests.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import + import datetime import re from datetime import date @@ -9,13 +11,13 @@ from django.forms.models import (_get_foreign_key, inlineformset_factory, modelformset_factory) from django.test import TestCase, skipUnlessDBFeature -from modeltests.model_formsets.models import ( - Author, BetterAuthor, Book, BookWithCustomPK, +from .models import (Author, BetterAuthor, Book, BookWithCustomPK, BookWithOptionalAltEditor, AlternateBook, AuthorMeeting, CustomPrimaryKey, Place, Owner, Location, OwnerProfile, Restaurant, Product, Price, MexicanRestaurant, ClassyMexicanRestaurant, Repository, Revision, Person, Membership, Team, Player, Poet, Poem, Post) + class DeletionTests(TestCase): def test_deletion(self): PoetFormSet = modelformset_factory(Poet, can_delete=True) diff --git a/tests/modeltests/model_inheritance/tests.py b/tests/modeltests/model_inheritance/tests.py index 334297ae12..2e1a7a5a9c 100644 --- a/tests/modeltests/model_inheritance/tests.py +++ b/tests/modeltests/model_inheritance/tests.py @@ -1,9 +1,11 @@ +from __future__ import absolute_import + from operator import attrgetter from django.core.exceptions import FieldError from django.test import TestCase -from models import (Chef, CommonInfo, ItalianRestaurant, ParkingLot, Place, +from .models import (Chef, CommonInfo, ItalianRestaurant, ParkingLot, Place, Post, Restaurant, Student, StudentWorker, Supplier, Worker, MixinModel) diff --git a/tests/modeltests/model_inheritance_same_model_name/models.py b/tests/modeltests/model_inheritance_same_model_name/models.py index 40de02764a..de7541694a 100644 --- a/tests/modeltests/model_inheritance_same_model_name/models.py +++ b/tests/modeltests/model_inheritance_same_model_name/models.py @@ -6,8 +6,11 @@ in the need for an %(app_label)s format string. This app specifically tests this feature by redefining the Copy model from model_inheritance/models.py """ +from __future__ import absolute_import + from django.db import models -from modeltests.model_inheritance.models import NamedURL + +from ..model_inheritance.models import NamedURL # # Abstract base classes with related models diff --git a/tests/modeltests/model_inheritance_same_model_name/tests.py b/tests/modeltests/model_inheritance_same_model_name/tests.py index 3d173e62a6..13d51f1a67 100644 --- a/tests/modeltests/model_inheritance_same_model_name/tests.py +++ b/tests/modeltests/model_inheritance_same_model_name/tests.py @@ -1,5 +1,9 @@ +from __future__ import absolute_import + from django.test import TestCase -from modeltests.model_inheritance.models import Title + +from ..model_inheritance.models import Title + class InheritanceSameModelNameTests(TestCase): diff --git a/tests/modeltests/model_package/models/__init__.py b/tests/modeltests/model_package/models/__init__.py index 91e1b02e7d..3c261aa444 100644 --- a/tests/modeltests/model_package/models/__init__.py +++ b/tests/modeltests/model_package/models/__init__.py @@ -1,3 +1,5 @@ # Import all the models from subpackages -from article import Article -from publication import Publication +from __future__ import absolute_import + +from .article import Article +from .publication import Publication diff --git a/tests/modeltests/model_package/models/article.py b/tests/modeltests/model_package/models/article.py index c8fae1c72d..f70c971c7e 100644 --- a/tests/modeltests/model_package/models/article.py +++ b/tests/modeltests/model_package/models/article.py @@ -1,5 +1,6 @@ -from django.db import models from django.contrib.sites.models import Site +from django.db import models + class Article(models.Model): sites = models.ManyToManyField(Site) diff --git a/tests/modeltests/model_package/models/publication.py b/tests/modeltests/model_package/models/publication.py index 4dc2d6a148..29828b9295 100644 --- a/tests/modeltests/model_package/models/publication.py +++ b/tests/modeltests/model_package/models/publication.py @@ -1,5 +1,6 @@ from django.db import models + class Publication(models.Model): title = models.CharField(max_length=30) diff --git a/tests/modeltests/model_package/tests.py b/tests/modeltests/model_package/tests.py index e63e2e63ea..5cf464858b 100644 --- a/tests/modeltests/model_package/tests.py +++ b/tests/modeltests/model_package/tests.py @@ -1,9 +1,11 @@ +from __future__ import absolute_import + from django.contrib.sites.models import Site from django.db import models from django.test import TestCase -from models.publication import Publication -from models.article import Article +from .models.publication import Publication +from .models.article import Article class Advertisment(models.Model): diff --git a/tests/modeltests/mutually_referential/tests.py b/tests/modeltests/mutually_referential/tests.py index 365c741ea5..b3deb0e75c 100644 --- a/tests/modeltests/mutually_referential/tests.py +++ b/tests/modeltests/mutually_referential/tests.py @@ -1,5 +1,9 @@ +from __future__ import absolute_import + from django.test import TestCase -from models import Parent + +from .models import Parent + class MutuallyReferentialTests(TestCase): diff --git a/tests/modeltests/one_to_one/models.py b/tests/modeltests/one_to_one/models.py index 246c3fc364..429c1d019f 100644 --- a/tests/modeltests/one_to_one/models.py +++ b/tests/modeltests/one_to_one/models.py @@ -8,6 +8,7 @@ In this example, a ``Place`` optionally can be a ``Restaurant``. from django.db import models + class Place(models.Model): name = models.CharField(max_length=50) address = models.CharField(max_length=80) diff --git a/tests/modeltests/one_to_one/tests.py b/tests/modeltests/one_to_one/tests.py index c3e1704452..6ee78520bd 100644 --- a/tests/modeltests/one_to_one/tests.py +++ b/tests/modeltests/one_to_one/tests.py @@ -1,6 +1,10 @@ -from django.test import TestCase +from __future__ import absolute_import + from django.db import transaction, IntegrityError -from models import Place, Restaurant, Waiter, ManualPrimaryKey, RelatedModel, MultiModel +from django.test import TestCase + +from .models import (Place, Restaurant, Waiter, ManualPrimaryKey, RelatedModel, + MultiModel) class OneToOneTests(TestCase): diff --git a/tests/modeltests/or_lookups/models.py b/tests/modeltests/or_lookups/models.py index 7f14ba50eb..0037b41afb 100644 --- a/tests/modeltests/or_lookups/models.py +++ b/tests/modeltests/or_lookups/models.py @@ -11,6 +11,7 @@ clauses using the variable ``django.db.models.Q`` (or any object with an from django.db import models + class Article(models.Model): headline = models.CharField(max_length=50) pub_date = models.DateTimeField() diff --git a/tests/modeltests/or_lookups/tests.py b/tests/modeltests/or_lookups/tests.py index ad218cd0b2..e1c6fcb32a 100644 --- a/tests/modeltests/or_lookups/tests.py +++ b/tests/modeltests/or_lookups/tests.py @@ -1,10 +1,12 @@ +from __future__ import absolute_import + from datetime import datetime from operator import attrgetter from django.db.models import Q from django.test import TestCase -from models import Article +from .models import Article class OrLookupsTests(TestCase): diff --git a/tests/modeltests/order_with_respect_to/tests.py b/tests/modeltests/order_with_respect_to/tests.py index 328d968fd4..559cb1d996 100644 --- a/tests/modeltests/order_with_respect_to/tests.py +++ b/tests/modeltests/order_with_respect_to/tests.py @@ -1,22 +1,24 @@ +from __future__ import absolute_import + from operator import attrgetter from django.test import TestCase -from models import Post, Question, Answer +from .models import Post, Question, Answer class OrderWithRespectToTests(TestCase): def test_basic(self): q1 = Question.objects.create(text="Which Beatle starts with the letter 'R'?") q2 = Question.objects.create(text="What is your name?") - + Answer.objects.create(text="John", question=q1) Answer.objects.create(text="Jonno", question=q2) Answer.objects.create(text="Paul", question=q1) Answer.objects.create(text="Paulo", question=q2) Answer.objects.create(text="George", question=q1) Answer.objects.create(text="Ringo", question=q1) - + # The answers will always be ordered in the order they were inserted. self.assertQuerysetEqual( q1.answer_set.all(), [ @@ -24,7 +26,7 @@ class OrderWithRespectToTests(TestCase): ], attrgetter("text"), ) - + # We can retrieve the answers related to a particular object, in the # order they were created, once we have a particular object. a1 = Answer.objects.filter(question=q1)[0] @@ -34,20 +36,20 @@ class OrderWithRespectToTests(TestCase): a4 = list(Answer.objects.filter(question=q1))[-1] self.assertEqual(a4.text, "Ringo") self.assertEqual(a4.get_previous_in_order().text, "George") - + # Determining (and setting) the ordering for a particular item is also # possible. id_list = [o.pk for o in q1.answer_set.all()] self.assertEqual(a2.question.get_answer_order(), id_list) - + a5 = Answer.objects.create(text="Number five", question=q1) - + # It doesn't matter which answer we use to check the order, it will # always be the same. self.assertEqual( a2.question.get_answer_order(), a5.question.get_answer_order() ) - + # The ordering can be altered: id_list = [o.pk for o in q1.answer_set.all()] x = id_list.pop() diff --git a/tests/modeltests/ordering/tests.py b/tests/modeltests/ordering/tests.py index 77862c528c..6a988b8398 100644 --- a/tests/modeltests/ordering/tests.py +++ b/tests/modeltests/ordering/tests.py @@ -1,9 +1,11 @@ +from __future__ import absolute_import + from datetime import datetime from operator import attrgetter from django.test import TestCase -from models import Article +from .models import Article class OrderingTests(TestCase): diff --git a/tests/modeltests/pagination/tests.py b/tests/modeltests/pagination/tests.py index 11290521bd..b7e217ebeb 100644 --- a/tests/modeltests/pagination/tests.py +++ b/tests/modeltests/pagination/tests.py @@ -1,9 +1,11 @@ +from __future__ import absolute_import + from datetime import datetime from django.core.paginator import Paginator, InvalidPage, EmptyPage from django.test import TestCase -from models import Article +from .models import Article class CountContainer(object): @@ -20,13 +22,13 @@ class PaginationTests(TestCase): for x in range(1, 10): a = Article(headline='Article %s' % x, pub_date=datetime(2005, 7, 29)) a.save() - + def test_paginator(self): paginator = Paginator(Article.objects.all(), 5) self.assertEqual(9, paginator.count) self.assertEqual(2, paginator.num_pages) self.assertEqual([1, 2], paginator.page_range) - + def test_first_page(self): paginator = Paginator(Article.objects.all(), 5) p = paginator.page(1) @@ -46,7 +48,7 @@ class PaginationTests(TestCase): self.assertEqual(0, p.previous_page_number()) self.assertEqual(1, p.start_index()) self.assertEqual(5, p.end_index()) - + def test_last_page(self): paginator = Paginator(Article.objects.all(), 5) p = paginator.page(2) @@ -65,41 +67,41 @@ class PaginationTests(TestCase): self.assertEqual(1, p.previous_page_number()) self.assertEqual(6, p.start_index()) self.assertEqual(9, p.end_index()) - + def test_empty_page(self): paginator = Paginator(Article.objects.all(), 5) self.assertRaises(EmptyPage, paginator.page, 0) self.assertRaises(EmptyPage, paginator.page, 3) - + # Empty paginators with allow_empty_first_page=True. paginator = Paginator(Article.objects.filter(id=0), 5, allow_empty_first_page=True) self.assertEqual(0, paginator.count) self.assertEqual(1, paginator.num_pages) self.assertEqual([1], paginator.page_range) - + # Empty paginators with allow_empty_first_page=False. paginator = Paginator(Article.objects.filter(id=0), 5, allow_empty_first_page=False) self.assertEqual(0, paginator.count) self.assertEqual(0, paginator.num_pages) self.assertEqual([], paginator.page_range) - + def test_invalid_page(self): paginator = Paginator(Article.objects.all(), 5) self.assertRaises(InvalidPage, paginator.page, 7) - + def test_orphans(self): # Add a few more records to test out the orphans feature. for x in range(10, 13): Article(headline="Article %s" % x, pub_date=datetime(2006, 10, 6)).save() - + # With orphans set to 3 and 10 items per page, we should get all 12 items on a single page. paginator = Paginator(Article.objects.all(), 10, orphans=3) self.assertEqual(1, paginator.num_pages) - + # With orphans only set to 1, we should get two pages. paginator = Paginator(Article.objects.all(), 10, orphans=1) self.assertEqual(2, paginator.num_pages) - + def test_paginate_list(self): # Paginators work with regular lists/tuples, too -- not just with QuerySets. paginator = Paginator([1, 2, 3, 4, 5, 6, 7, 8, 9], 5) @@ -116,14 +118,14 @@ class PaginationTests(TestCase): self.assertEqual(0, p.previous_page_number()) self.assertEqual(1, p.start_index()) self.assertEqual(5, p.end_index()) - + def test_paginate_misc_classes(self): # Paginator can be passed other objects with a count() method. paginator = Paginator(CountContainer(), 10) self.assertEqual(42, paginator.count) self.assertEqual(5, paginator.num_pages) self.assertEqual([1, 2, 3, 4, 5], paginator.page_range) - + # Paginator can be passed other objects that implement __len__. paginator = Paginator(LenContainer(), 10) self.assertEqual(42, paginator.count) diff --git a/tests/modeltests/prefetch_related/models.py b/tests/modeltests/prefetch_related/models.py index 1c14c88818..e6e4f89053 100644 --- a/tests/modeltests/prefetch_related/models.py +++ b/tests/modeltests/prefetch_related/models.py @@ -1,5 +1,5 @@ -from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic +from django.contrib.contenttypes.models import ContentType from django.db import models ## Basic tests diff --git a/tests/modeltests/prefetch_related/tests.py b/tests/modeltests/prefetch_related/tests.py index bdbb0568c3..5ecf6f4ad6 100644 --- a/tests/modeltests/prefetch_related/tests.py +++ b/tests/modeltests/prefetch_related/tests.py @@ -1,13 +1,11 @@ -from __future__ import with_statement +from __future__ import with_statement, absolute_import from django.contrib.contenttypes.models import ContentType from django.test import TestCase -from django.utils import unittest -from models import (Author, Book, Reader, Qualification, Teacher, Department, - TaggedItem, Bookmark, AuthorAddress, FavoriteAuthors, - AuthorWithAge, BookWithYear, Person, House, Room, - Employee) +from .models import (Author, Book, Reader, Qualification, Teacher, Department, + TaggedItem, Bookmark, AuthorAddress, FavoriteAuthors, AuthorWithAge, + BookWithYear, Person, House, Room, Employee) class PrefetchRelatedTests(TestCase): diff --git a/tests/modeltests/properties/models.py b/tests/modeltests/properties/models.py index 390efe3a22..5c2656570c 100644 --- a/tests/modeltests/properties/models.py +++ b/tests/modeltests/properties/models.py @@ -6,6 +6,7 @@ Use properties on models just like on any other Python object. from django.db import models + class Person(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) diff --git a/tests/modeltests/properties/tests.py b/tests/modeltests/properties/tests.py index e31ac58d4d..f01b22a4bb 100644 --- a/tests/modeltests/properties/tests.py +++ b/tests/modeltests/properties/tests.py @@ -1,5 +1,9 @@ +from __future__ import with_statement, absolute_import + from django.test import TestCase -from models import Person + +from .models import Person + class PropertyTests(TestCase): diff --git a/tests/modeltests/proxy_model_inheritance/app1/models.py b/tests/modeltests/proxy_model_inheritance/app1/models.py index 59a9ac7f6c..affcf140ac 100644 --- a/tests/modeltests/proxy_model_inheritance/app1/models.py +++ b/tests/modeltests/proxy_model_inheritance/app1/models.py @@ -1,5 +1,9 @@ +from __future__ import absolute_import + +# TODO: why can't I make this ..app2 from app2.models import NiceModel + class ProxyModel(NiceModel): class Meta: proxy = True diff --git a/tests/modeltests/proxy_model_inheritance/app2/models.py b/tests/modeltests/proxy_model_inheritance/app2/models.py index 549cd07bd2..1ad46d1088 100644 --- a/tests/modeltests/proxy_model_inheritance/app2/models.py +++ b/tests/modeltests/proxy_model_inheritance/app2/models.py @@ -1,4 +1,5 @@ from django.db import models + class NiceModel(models.Model): pass diff --git a/tests/modeltests/proxy_model_inheritance/tests.py b/tests/modeltests/proxy_model_inheritance/tests.py index eb8e47b726..82f4ea6821 100644 --- a/tests/modeltests/proxy_model_inheritance/tests.py +++ b/tests/modeltests/proxy_model_inheritance/tests.py @@ -6,6 +6,8 @@ for the proxied model (as described in #12286). This test creates two dummy apps and calls syncdb, then verifies that the table has been created. """ +from __future__ import absolute_import + import os import sys @@ -15,6 +17,7 @@ from django.db.models.loading import load_app from django.test import TransactionTestCase from django.test.utils import override_settings + # @override_settings(INSTALLED_APPS=('app1', 'app2')) class ProxyModelInheritanceTests(TransactionTestCase): @@ -28,9 +31,8 @@ class ProxyModelInheritanceTests(TransactionTestCase): def test_table_exists(self): call_command('syncdb', verbosity=0) - global ProxyModel, NiceModel - from app1.models import ProxyModel - from app2.models import NiceModel + from .app1.models import ProxyModel + from .app2.models import NiceModel self.assertEqual(NiceModel.objects.all().count(), 0) self.assertEqual(ProxyModel.objects.all().count(), 0) diff --git a/tests/modeltests/proxy_models/tests.py b/tests/modeltests/proxy_models/tests.py index 0a46a252c5..3ec8465689 100644 --- a/tests/modeltests/proxy_models/tests.py +++ b/tests/modeltests/proxy_models/tests.py @@ -1,16 +1,17 @@ -from django.test import TestCase -from django.db import models, DEFAULT_DB_ALIAS -from django.db.models import signals -from django.core import management -from django.core.exceptions import FieldError +from __future__ import absolute_import from django.contrib.contenttypes.models import ContentType +from django.core import management +from django.core.exceptions import FieldError +from django.db import models, DEFAULT_DB_ALIAS +from django.db.models import signals +from django.test import TestCase -from models import MyPerson, Person, StatusPerson, LowerStatusPerson -from models import MyPersonProxy, Abstract, OtherPerson, User, UserProxy -from models import UserProxyProxy, Country, State, StateProxy, TrackerUser -from models import BaseUser, Bug, ProxyTrackerUser, Improvement, ProxyProxyBug -from models import ProxyBug, ProxyImprovement + +from .models import (MyPerson, Person, StatusPerson, LowerStatusPerson, + MyPersonProxy, Abstract, OtherPerson, User, UserProxy, UserProxyProxy, + Country, State, StateProxy, TrackerUser, BaseUser, Bug, ProxyTrackerUser, + Improvement, ProxyProxyBug, ProxyBug, ProxyImprovement) class ProxyModelTests(TestCase): def test_same_manager_queries(self): diff --git a/tests/modeltests/raw_query/models.py b/tests/modeltests/raw_query/models.py index bb42b5be2b..823fc76eee 100644 --- a/tests/modeltests/raw_query/models.py +++ b/tests/modeltests/raw_query/models.py @@ -1,5 +1,6 @@ from django.db import models + class Author(models.Model): first_name = models.CharField(max_length=255) last_name = models.CharField(max_length=255) diff --git a/tests/modeltests/raw_query/tests.py b/tests/modeltests/raw_query/tests.py index aa6aec10b1..cef9e1be1a 100644 --- a/tests/modeltests/raw_query/tests.py +++ b/tests/modeltests/raw_query/tests.py @@ -1,9 +1,11 @@ +from __future__ import absolute_import + from datetime import date from django.db.models.sql.query import InvalidQuery from django.test import TestCase -from models import Author, Book, Coffee, Reviewer, FriendlyAuthor +from .models import Author, Book, Coffee, Reviewer, FriendlyAuthor class RawQueryTests(TestCase): diff --git a/tests/modeltests/reserved_names/models.py b/tests/modeltests/reserved_names/models.py index d8c1238ff1..010649e681 100644 --- a/tests/modeltests/reserved_names/models.py +++ b/tests/modeltests/reserved_names/models.py @@ -9,6 +9,7 @@ reserved-name usage. from django.db import models + class Thing(models.Model): when = models.CharField(max_length=1, primary_key=True) join = models.CharField(max_length=1) diff --git a/tests/modeltests/reserved_names/tests.py b/tests/modeltests/reserved_names/tests.py index b7e4867411..87f7a42ec4 100644 --- a/tests/modeltests/reserved_names/tests.py +++ b/tests/modeltests/reserved_names/tests.py @@ -1,8 +1,11 @@ +from __future__ import absolute_import + import datetime from django.test import TestCase -from models import Thing +from .models import Thing + class ReservedNameTests(TestCase): def generate(self): diff --git a/tests/modeltests/reverse_lookup/models.py b/tests/modeltests/reverse_lookup/models.py index 2ffdc39b3b..bb7a163327 100644 --- a/tests/modeltests/reverse_lookup/models.py +++ b/tests/modeltests/reverse_lookup/models.py @@ -6,6 +6,7 @@ This demonstrates the reverse lookup features of the database API. from django.db import models + class User(models.Model): name = models.CharField(max_length=200) diff --git a/tests/modeltests/reverse_lookup/tests.py b/tests/modeltests/reverse_lookup/tests.py index 9a6e3068fa..549ee66392 100644 --- a/tests/modeltests/reverse_lookup/tests.py +++ b/tests/modeltests/reverse_lookup/tests.py @@ -1,7 +1,10 @@ -from django.test import TestCase -from django.core.exceptions import FieldError +from __future__ import absolute_import + +from django.core.exceptions import FieldError +from django.test import TestCase + +from .models import User, Poll, Choice -from models import User, Poll, Choice class ReverseLookupTests(TestCase): diff --git a/tests/modeltests/save_delete_hooks/tests.py b/tests/modeltests/save_delete_hooks/tests.py index dc7b8ee12a..377d9eec03 100644 --- a/tests/modeltests/save_delete_hooks/tests.py +++ b/tests/modeltests/save_delete_hooks/tests.py @@ -1,6 +1,8 @@ +from __future__ import absolute_import + from django.test import TestCase -from models import Person +from .models import Person class SaveDeleteHookTests(TestCase): diff --git a/tests/modeltests/select_for_update/models.py b/tests/modeltests/select_for_update/models.py index a124d1f077..48ad58faa9 100644 --- a/tests/modeltests/select_for_update/models.py +++ b/tests/modeltests/select_for_update/models.py @@ -1,4 +1,5 @@ from django.db import models + class Person(models.Model): name = models.CharField(max_length=30) diff --git a/tests/modeltests/select_for_update/tests.py b/tests/modeltests/select_for_update/tests.py index f8b7bba0cb..efaffb9b87 100644 --- a/tests/modeltests/select_for_update/tests.py +++ b/tests/modeltests/select_for_update/tests.py @@ -1,6 +1,8 @@ +from __future__ import absolute_import + import sys import time -import unittest + from django.conf import settings from django.db import transaction, connection from django.db.utils import ConnectionHandler, DEFAULT_DB_ALIAS, DatabaseError @@ -8,7 +10,7 @@ from django.test import (TransactionTestCase, skipIfDBFeature, skipUnlessDBFeature) from django.utils import unittest -from models import Person +from .models import Person # Some tests require threading, which might not be available. So create a # skip-test decorator for those test functions. @@ -18,6 +20,7 @@ except ImportError: threading = None requires_threading = unittest.skipUnless(threading, 'requires threading') + class SelectForUpdateTests(TransactionTestCase): def setUp(self): diff --git a/tests/modeltests/select_related/tests.py b/tests/modeltests/select_related/tests.py index 1355c53221..6071875285 100644 --- a/tests/modeltests/select_related/tests.py +++ b/tests/modeltests/select_related/tests.py @@ -1,6 +1,8 @@ +from __future__ import absolute_import + from django.test import TestCase -from models import Domain, Kingdom, Phylum, Klass, Order, Family, Genus, Species +from .models import Domain, Kingdom, Phylum, Klass, Order, Family, Genus, Species class SelectRelatedTests(TestCase): diff --git a/tests/modeltests/serializers/models.py b/tests/modeltests/serializers/models.py index 7f0019fbcd..9948afd4e0 100644 --- a/tests/modeltests/serializers/models.py +++ b/tests/modeltests/serializers/models.py @@ -7,6 +7,7 @@ """ from decimal import Decimal + from django.db import models diff --git a/tests/modeltests/serializers/tests.py b/tests/modeltests/serializers/tests.py index def0254a9f..5e5a4b333a 100644 --- a/tests/modeltests/serializers/tests.py +++ b/tests/modeltests/serializers/tests.py @@ -1,11 +1,11 @@ # This is necessary in Python 2.5 to enable the with statement, in 2.6 # and up it is no longer necessary. -from __future__ import with_statement +from __future__ import with_statement, absolute_import # -*- coding: utf-8 -*- from datetime import datetime -from StringIO import StringIO from xml.dom import minidom +from StringIO import StringIO from django.conf import settings from django.core import serializers @@ -13,8 +13,9 @@ from django.db import transaction, connection from django.test import TestCase, TransactionTestCase, Approximate from django.utils import simplejson, unittest -from models import (Category, Author, Article, AuthorProfile, - Actor, Movie, Score, Player, Team) +from .models import (Category, Author, Article, AuthorProfile, Actor, Movie, + Score, Player, Team) + class SerializerRegistrationTests(unittest.TestCase): def setUp(self): diff --git a/tests/modeltests/signals/tests.py b/tests/modeltests/signals/tests.py index 9b8bce0417..29563dc363 100644 --- a/tests/modeltests/signals/tests.py +++ b/tests/modeltests/signals/tests.py @@ -1,8 +1,10 @@ +from __future__ import absolute_import + from django.db.models import signals from django.dispatch import receiver from django.test import TestCase -from models import Person, Car +from .models import Person, Car # #8285: signals can be any callable diff --git a/tests/modeltests/str/models.py b/tests/modeltests/str/models.py index 84b8d67d12..6f6b877c88 100644 --- a/tests/modeltests/str/models.py +++ b/tests/modeltests/str/models.py @@ -16,6 +16,7 @@ if you prefer. You must be careful to encode the results correctly, though. from django.db import models + class Article(models.Model): headline = models.CharField(max_length=100) pub_date = models.DateTimeField() diff --git a/tests/modeltests/str/tests.py b/tests/modeltests/str/tests.py index 4e4c76501f..9f6cf7ad96 100644 --- a/tests/modeltests/str/tests.py +++ b/tests/modeltests/str/tests.py @@ -1,9 +1,12 @@ # -*- coding: utf-8 -*- +from __future__ import absolute_import + import datetime from django.test import TestCase -from models import Article, InternationalArticle +from .models import Article, InternationalArticle + class SimpleTests(TestCase): def test_basic(self): diff --git a/tests/modeltests/test_client/models.py b/tests/modeltests/test_client/models.py index e7bb004ff4..df872cd190 100644 --- a/tests/modeltests/test_client/models.py +++ b/tests/modeltests/test_client/models.py @@ -20,11 +20,13 @@ testing against the contexts and templates produced by a view, rather than the HTML rendered to the end-user. """ +from __future__ import absolute_import + from django.conf import settings from django.core import mail from django.test import Client, TestCase, RequestFactory -from views import get_view +from .views import get_view class ClientTest(TestCase): diff --git a/tests/modeltests/test_client/tests.py b/tests/modeltests/test_client/tests.py index c669fdbadd..6ad51ac9a0 100644 --- a/tests/modeltests/test_client/tests.py +++ b/tests/modeltests/test_client/tests.py @@ -2,19 +2,20 @@ from django.utils import unittest + def suite(): """ Define a suite that deliberately ignores a test defined in this module. """ - + testSuite = unittest.TestSuite() testSuite.addTest(SampleTests('testGoodStuff')) return testSuite - + class SampleTests(unittest.TestCase): def testGoodStuff(self): pass - + def testBadStuff(self): self.fail("This test shouldn't run") diff --git a/tests/modeltests/test_client/urls.py b/tests/modeltests/test_client/urls.py index 6a2d0a96c1..67c475eaff 100644 --- a/tests/modeltests/test_client/urls.py +++ b/tests/modeltests/test_client/urls.py @@ -1,6 +1,10 @@ +from __future__ import absolute_import + from django.conf.urls import patterns from django.views.generic import RedirectView -import views + +from . import views + urlpatterns = patterns('', (r'^get_view/$', views.get_view), diff --git a/tests/modeltests/test_client/views.py b/tests/modeltests/test_client/views.py index 6f597c0911..a86064edf9 100644 --- a/tests/modeltests/test_client/views.py +++ b/tests/modeltests/test_client/views.py @@ -1,14 +1,15 @@ from xml.dom.minidom import parseString -from django.core import mail -from django.template import Context, Template -from django.http import HttpResponse, HttpResponseRedirect, HttpResponseNotFound from django.contrib.auth.decorators import login_required, permission_required -from django.forms.forms import Form +from django.core import mail from django.forms import fields +from django.forms.forms import Form +from django.http import HttpResponse, HttpResponseRedirect, HttpResponseNotFound from django.shortcuts import render_to_response +from django.template import Context, Template from django.utils.decorators import method_decorator + def get_view(request): "A simple view that expects a GET request, and returns a rendered template" t = Template('This is a test. {{ var }} is the value.', name='GET Template') diff --git a/tests/modeltests/transactions/models.py b/tests/modeltests/transactions/models.py index b2ae39648a..66acb9fc63 100644 --- a/tests/modeltests/transactions/models.py +++ b/tests/modeltests/transactions/models.py @@ -9,6 +9,7 @@ manually. from django.db import models + class Reporter(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) diff --git a/tests/modeltests/transactions/tests.py b/tests/modeltests/transactions/tests.py index 5cebe679a4..ed416e24b7 100644 --- a/tests/modeltests/transactions/tests.py +++ b/tests/modeltests/transactions/tests.py @@ -1,9 +1,9 @@ -from __future__ import with_statement +from __future__ import with_statement, absolute_import from django.db import connection, transaction, IntegrityError from django.test import TransactionTestCase, skipUnlessDBFeature -from models import Reporter +from .models import Reporter class TransactionTests(TransactionTestCase): diff --git a/tests/modeltests/unmanaged_models/tests.py b/tests/modeltests/unmanaged_models/tests.py index b9817efc08..64e33bbb47 100644 --- a/tests/modeltests/unmanaged_models/tests.py +++ b/tests/modeltests/unmanaged_models/tests.py @@ -1,6 +1,10 @@ -from django.test import TestCase +from __future__ import absolute_import + from django.db import connection -from models import A01, A02, B01, B02, C01, C02, Unmanaged2, Managed1 +from django.test import TestCase + +from .models import A01, A02, B01, B02, C01, C02, Unmanaged2, Managed1 + class SimpleTests(TestCase): diff --git a/tests/modeltests/update/models.py b/tests/modeltests/update/models.py index 7b633e28dc..92156a5553 100644 --- a/tests/modeltests/update/models.py +++ b/tests/modeltests/update/models.py @@ -5,6 +5,7 @@ updates. from django.db import models + class DataPoint(models.Model): name = models.CharField(max_length=20) value = models.CharField(max_length=20) diff --git a/tests/modeltests/update/tests.py b/tests/modeltests/update/tests.py index d0b6ea3ab0..c31f4dfaa9 100644 --- a/tests/modeltests/update/tests.py +++ b/tests/modeltests/update/tests.py @@ -1,6 +1,8 @@ +from __future__ import absolute_import + from django.test import TestCase -from models import A, B, C, D, DataPoint, RelatedPoint +from .models import A, B, C, D, DataPoint, RelatedPoint class SimpleTest(TestCase): diff --git a/tests/modeltests/user_commands/management/commands/dance.py b/tests/modeltests/user_commands/management/commands/dance.py index acefe09271..34eb277567 100644 --- a/tests/modeltests/user_commands/management/commands/dance.py +++ b/tests/modeltests/user_commands/management/commands/dance.py @@ -1,6 +1,8 @@ from optparse import make_option + from django.core.management.base import BaseCommand + class Command(BaseCommand): help = "Dance around like a madman." args = '' diff --git a/tests/modeltests/user_commands/tests.py b/tests/modeltests/user_commands/tests.py index aa1398f50f..bf74a98440 100644 --- a/tests/modeltests/user_commands/tests.py +++ b/tests/modeltests/user_commands/tests.py @@ -1,8 +1,9 @@ from StringIO import StringIO -from django.test import TestCase from django.core import management from django.core.management.base import CommandError +from django.test import TestCase + class CommandTests(TestCase): def test_command(self): diff --git a/tests/modeltests/validation/__init__.py b/tests/modeltests/validation/__init__.py index 31c5000ba6..4a1ad3ab56 100644 --- a/tests/modeltests/validation/__init__.py +++ b/tests/modeltests/validation/__init__.py @@ -1,21 +1,18 @@ -from django.test import TestCase +from __future__ import with_statement from django.core.exceptions import ValidationError +from django.test import TestCase + class ValidationTestCase(TestCase): def assertFailsValidation(self, clean, failed_fields): - self.assertRaises(ValidationError, clean) - try: + with self.assertRaises(ValidationError) as cm: clean() - except ValidationError, e: - self.assertEqual(sorted(failed_fields), sorted(e.message_dict.keys())) - + self.assertEqual(sorted(failed_fields), sorted(cm.exception.message_dict)) + def assertFieldFailsValidationWithMessage(self, clean, field_name, message): - self.assertRaises(ValidationError, clean) - try: + with self.assertRaises(ValidationError) as cm: clean() - except ValidationError, e: - self.assertTrue(field_name in e.message_dict) - self.assertEqual(message, e.message_dict[field_name]) - + self.assertIn(field_name, cm.exception.message_dict) + self.assertEqual(message, cm.exception.message_dict[field_name]) diff --git a/tests/modeltests/validation/models.py b/tests/modeltests/validation/models.py index 182e739daf..2c94fefccd 100644 --- a/tests/modeltests/validation/models.py +++ b/tests/modeltests/validation/models.py @@ -1,4 +1,5 @@ from datetime import datetime + from django.core.exceptions import ValidationError from django.db import models diff --git a/tests/modeltests/validation/test_custom_messages.py b/tests/modeltests/validation/test_custom_messages.py index 05bb651b7e..c5a1ee744f 100644 --- a/tests/modeltests/validation/test_custom_messages.py +++ b/tests/modeltests/validation/test_custom_messages.py @@ -1,5 +1,7 @@ -from modeltests.validation import ValidationTestCase -from models import CustomMessagesModel +from __future__ import absolute_import + +from . import ValidationTestCase +from .models import CustomMessagesModel class CustomMessagesTest(ValidationTestCase): diff --git a/tests/modeltests/validation/test_error_messages.py b/tests/modeltests/validation/test_error_messages.py index 299a93a41a..298f91d8b2 100644 --- a/tests/modeltests/validation/test_error_messages.py +++ b/tests/modeltests/validation/test_error_messages.py @@ -1,6 +1,6 @@ from django.core.exceptions import ValidationError -from django.utils.unittest import TestCase from django.db import models +from django.utils.unittest import TestCase class ValidationMessagesTest(TestCase): diff --git a/tests/modeltests/validation/test_unique.py b/tests/modeltests/validation/test_unique.py index c0a0530d6b..5482fe8bbe 100644 --- a/tests/modeltests/validation/test_unique.py +++ b/tests/modeltests/validation/test_unique.py @@ -1,4 +1,4 @@ -from __future__ import with_statement +from __future__ import with_statement, absolute_import import datetime @@ -6,8 +6,9 @@ from django.core.exceptions import ValidationError from django.test import TestCase from django.utils import unittest -from models import (CustomPKModel, UniqueTogetherModel, UniqueFieldsModel, - UniqueForDateModel, ModelToValidate, Post, FlexibleDatePost, UniqueErrorsModel) +from .models import (CustomPKModel, UniqueTogetherModel, UniqueFieldsModel, + UniqueForDateModel, ModelToValidate, Post, FlexibleDatePost, + UniqueErrorsModel) class GetUniqueCheckTests(unittest.TestCase): diff --git a/tests/modeltests/validation/tests.py b/tests/modeltests/validation/tests.py index 5b20df4ef3..a7e13e767f 100644 --- a/tests/modeltests/validation/tests.py +++ b/tests/modeltests/validation/tests.py @@ -1,18 +1,20 @@ +from __future__ import absolute_import + import warnings from django import forms -from django.test import TestCase from django.core.exceptions import NON_FIELD_ERRORS -from modeltests.validation import ValidationTestCase -from modeltests.validation.models import (Author, Article, ModelToValidate, - GenericIPAddressTestModel, GenericIPAddrUnpackUniqueTest) +from django.test import TestCase +from . import ValidationTestCase +from .models import (Author, Article, ModelToValidate, + GenericIPAddressTestModel, GenericIPAddrUnpackUniqueTest) # Import other tests for this package. -from modeltests.validation.validators import TestModelsWithValidators -from modeltests.validation.test_unique import (GetUniqueCheckTests, - PerformUniqueChecksTest) -from modeltests.validation.test_custom_messages import CustomMessagesTest -from modeltests.validation.test_error_messages import ValidationMessagesTest +from .test_custom_messages import CustomMessagesTest +from .test_error_messages import ValidationMessagesTest +from .test_unique import GetUniqueCheckTests, PerformUniqueChecksTest +from .validators import TestModelsWithValidators + class BaseModelValidationTests(ValidationTestCase): diff --git a/tests/modeltests/validation/validators.py b/tests/modeltests/validation/validators.py index 30ce66140f..d82b95e3ad 100644 --- a/tests/modeltests/validation/validators.py +++ b/tests/modeltests/validation/validators.py @@ -1,5 +1,7 @@ -from modeltests.validation import ValidationTestCase -from models import * +from __future__ import absolute_import + +from . import ValidationTestCase +from .models import ModelToValidate class TestModelsWithValidators(ValidationTestCase):