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
This commit is contained in:
Alex Gaynor 2011-10-13 18:04:12 +00:00
parent 99512d3544
commit d5a45d79fe
119 changed files with 380 additions and 187 deletions

View File

@ -1,10 +1,12 @@
from __future__ import absolute_import
import datetime import datetime
from decimal import Decimal from decimal import Decimal
from django.db.models import Avg, Sum, Count, Max, Min from django.db.models import Avg, Sum, Count, Max, Min
from django.test import TestCase, Approximate from django.test import TestCase, Approximate
from models import Author, Publisher, Book, Store from .models import Author, Publisher, Book, Store
class BaseAggregateTestCase(TestCase): class BaseAggregateTestCase(TestCase):

View File

@ -6,6 +6,7 @@ This is a basic model with only two non-primary-key fields.
""" """
from django.db import models from django.db import models
class Article(models.Model): class Article(models.Model):
headline = models.CharField(max_length=100, default='Default headline') headline = models.CharField(max_length=100, default='Default headline')
pub_date = models.DateTimeField() pub_date = models.DateTimeField()

View File

@ -1,10 +1,12 @@
from __future__ import absolute_import
from datetime import datetime from datetime import datetime
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.db.models.fields import FieldDoesNotExist from django.db.models.fields import FieldDoesNotExist
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
from models import Article from .models import Article
class ModelTest(TestCase): class ModelTest(TestCase):

View File

@ -11,6 +11,7 @@ field. This method returns the "human-readable" value of the field.
from django.db import models from django.db import models
GENDER_CHOICES = ( GENDER_CHOICES = (
('M', 'Male'), ('M', 'Male'),
('F', 'Female'), ('F', 'Female'),

View File

@ -1,6 +1,8 @@
from __future__ import absolute_import
from django.test import TestCase from django.test import TestCase
from models import Person from .models import Person
class ChoicesTests(TestCase): class ChoicesTests(TestCase):

View File

@ -17,6 +17,7 @@ from the default generated name, use the ``db_table`` parameter on the
from django.db import models from django.db import models
class Author(models.Model): class Author(models.Model):
first_name = models.CharField(max_length=30, db_column='firstname') first_name = models.CharField(max_length=30, db_column='firstname')
last_name = models.CharField(max_length=30, db_column='last') last_name = models.CharField(max_length=30, db_column='last')

View File

@ -1,7 +1,9 @@
from __future__ import absolute_import
from django.core.exceptions import FieldError from django.core.exceptions import FieldError
from django.test import TestCase from django.test import TestCase
from models import Author, Article from .models import Author, Article
class CustomColumnsTests(TestCase): class CustomColumnsTests(TestCase):

View File

@ -1,6 +1,8 @@
from __future__ import absolute_import
from django.test import TestCase from django.test import TestCase
from models import Person, Book, Car, PersonManager, PublishedBookManager from .models import Person, Book, Car, PersonManager, PublishedBookManager
class CustomManagerTests(TestCase): class CustomManagerTests(TestCase):

View File

@ -4,9 +4,11 @@
Any method you add to a model will be available to instances. Any method you add to a model will be available to instances.
""" """
from django.db import models
import datetime import datetime
from django.db import models
class Article(models.Model): class Article(models.Model):
headline = models.CharField(max_length=100) headline = models.CharField(max_length=100)
pub_date = models.DateField() pub_date = models.DateField()

View File

@ -1,8 +1,10 @@
from __future__ import absolute_import
from datetime import date from datetime import date
from django.test import TestCase from django.test import TestCase
from models import Article from .models import Article
class MethodsTests(TestCase): class MethodsTests(TestCase):

View File

@ -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. this behavior by explicitly adding ``primary_key=True`` to a field.
""" """
from __future__ import absolute_import
from django.db import models from django.db import models
from fields import MyAutoField from .fields import MyAutoField
class Employee(models.Model): class Employee(models.Model):
employee_code = models.IntegerField(primary_key=True, db_column = 'code') employee_code = models.IntegerField(primary_key=True, db_column = 'code')

View File

@ -1,8 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
from django.db import transaction, IntegrityError from django.db import transaction, IntegrityError
from django.test import TestCase, skipIfDBFeature from django.test import TestCase, skipIfDBFeature
from models import Employee, Business, Bar, Foo from .models import Employee, Business, Bar, Foo
class CustomPKTests(TestCase): class CustomPKTests(TestCase):

View File

@ -1,7 +1,9 @@
from __future__ import absolute_import
from django.db.models.query_utils import DeferredAttribute from django.db.models.query_utils import DeferredAttribute
from django.test import TestCase from django.test import TestCase
from models import Secondary, Primary, Child, BigChild from .models import Secondary, Primary, Child, BigChild
class DeferTests(TestCase): class DeferTests(TestCase):

View File

@ -1,7 +1,9 @@
from __future__ import absolute_import
from django.db import models, IntegrityError from django.db import models, IntegrityError
from django.test import TestCase, skipUnlessDBFeature, skipIfDBFeature 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) create_a, get_default_r, User, Avatar, HiddenUser, HiddenUserProfile)

View File

@ -1,5 +1,6 @@
from django.test import TestCase from django.test import TestCase
class NoModelTests(TestCase): class NoModelTests(TestCase):
""" A placeholder test case. See modeltests.empty.tests for more info. """ """ A placeholder test case. See modeltests.empty.tests for more info. """
pass pass

View File

@ -1,4 +1,4 @@
from __future__ import with_statement from __future__ import with_statement, absolute_import
from django.conf import settings from django.conf import settings
from django.core.exceptions import ImproperlyConfigured 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 import TestCase
from django.test.utils import override_settings from django.test.utils import override_settings
from models import Empty from .models import Empty
class EmptyModelTests(TestCase): class EmptyModelTests(TestCase):

View File

@ -4,6 +4,7 @@ Tests for F() query expression syntax.
from django.db import models from django.db import models
class Employee(models.Model): class Employee(models.Model):
firstname = models.CharField(max_length=50) firstname = models.CharField(max_length=50)
lastname = models.CharField(max_length=50) lastname = models.CharField(max_length=50)

View File

@ -1,8 +1,10 @@
from __future__ import absolute_import
from django.core.exceptions import FieldError from django.core.exceptions import FieldError
from django.db.models import F from django.db.models import F
from django.test import TestCase from django.test import TestCase
from models import Company, Employee from .models import Company, Employee
class ExpressionsTests(TestCase): class ExpressionsTests(TestCase):

View File

@ -10,9 +10,11 @@ This example uses ``datetime.datetime.now`` as the default for the ``pub_date``
field. field.
""" """
from django.db import models
from datetime import datetime from datetime import datetime
from django.db import models
class Article(models.Model): class Article(models.Model):
headline = models.CharField(max_length=100, default='Default headline') headline = models.CharField(max_length=100, default='Default headline')
pub_date = models.DateTimeField(default=datetime.now) pub_date = models.DateTimeField(default=datetime.now)

View File

@ -1,8 +1,10 @@
from __future__ import absolute_import
from datetime import datetime from datetime import datetime
from django.test import TestCase from django.test import TestCase
from models import Article from .models import Article
class DefaultTests(TestCase): class DefaultTests(TestCase):

View File

@ -2,6 +2,7 @@ from django.db import models
from django.utils import simplejson as json from django.utils import simplejson as json
from django.utils.encoding import force_unicode from django.utils.encoding import force_unicode
class Small(object): class Small(object):
""" """
A simple class to show that non-trivial Python objects can be used as A simple class to show that non-trivial Python objects can be used as

View File

@ -2,10 +2,12 @@
Tests for field subclassing. Tests for field subclassing.
""" """
from __future__ import absolute_import
from django.db import models from django.db import models
from django.utils.encoding import force_unicode from django.utils.encoding import force_unicode
from fields import SmallField, SmallerField, JSONField from .fields import SmallField, SmallerField, JSONField
class MyModel(models.Model): class MyModel(models.Model):

View File

@ -1,8 +1,10 @@
from __future__ import absolute_import
from django.core import serializers from django.core import serializers
from django.test import TestCase from django.test import TestCase
from fields import Small from .fields import Small
from models import DataModel, MyModel, OtherModel from .models import DataModel, MyModel, OtherModel
class CustomField(TestCase): class CustomField(TestCase):

View File

@ -1,4 +1,4 @@
from __future__ import with_statement from __future__ import with_statement, absolute_import
import shutil import shutil
import tempfile import tempfile
@ -9,7 +9,7 @@ from django.core.files.base import ContentFile
from django.core.files.uploadedfile import SimpleUploadedFile from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import TestCase 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): class FileTests(TestCase):

View File

@ -8,10 +8,10 @@ in the application directory, or in one of the directories named in the
``FIXTURE_DIRS`` setting. ``FIXTURE_DIRS`` setting.
""" """
from django.db import models
from django.contrib.auth.models import Permission from django.contrib.auth.models import Permission
from django.contrib.contenttypes import generic from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.db import models
class Category(models.Model): class Category(models.Model):

View File

@ -1,10 +1,12 @@
from __future__ import absolute_import
import StringIO import StringIO
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.core import management from django.core import management
from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature 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): class TestCaseFixtureLoadingTests(TestCase):

View File

@ -1,5 +1,6 @@
from django.db import models from django.db import models
class Article(models.Model): class Article(models.Model):
headline = models.CharField(max_length=100, default='Default headline') headline = models.CharField(max_length=100, default='Default headline')
pub_date = models.DateTimeField() pub_date = models.DateTimeField()

View File

@ -1,7 +1,7 @@
from django.core import management from django.core import management
from django.test import TestCase from django.test import TestCase
from models import Article from .models import Article
class SampleTestCase(TestCase): class SampleTestCase(TestCase):

View File

@ -4,6 +4,7 @@ automatic behaviour).
""" """
from django.db import models from django.db import models
class Counter(models.Model): class Counter(models.Model):
name = models.CharField(max_length = 10) name = models.CharField(max_length = 10)
value = models.IntegerField() value = models.IntegerField()

View File

@ -1,7 +1,9 @@
from __future__ import absolute_import
from django.db import transaction, IntegrityError, DatabaseError from django.db import transaction, IntegrityError, DatabaseError
from django.test import TestCase from django.test import TestCase
from models import Counter, WithCustomPK from .models import Counter, WithCustomPK
class ForceTests(TestCase): class ForceTests(TestCase):

View File

@ -1,9 +1,11 @@
from __future__ import absolute_import
from django import forms from django import forms
from django.contrib.contenttypes.generic import generic_inlineformset_factory from django.contrib.contenttypes.generic import generic_inlineformset_factory
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.test import TestCase from django.test import TestCase
from models import (TaggedItem, ValuableTaggedItem, Comparison, Animal, from .models import (TaggedItem, ValuableTaggedItem, Comparison, Animal,
Vegetable, Mineral, Gecko) Vegetable, Mineral, Gecko)

View File

@ -10,6 +10,7 @@ farthest into the future."
from django.db import models from django.db import models
class Article(models.Model): class Article(models.Model):
headline = models.CharField(max_length=100) headline = models.CharField(max_length=100)
pub_date = models.DateField() pub_date = models.DateField()

View File

@ -1,8 +1,10 @@
from __future__ import absolute_import
from datetime import datetime from datetime import datetime
from django.test import TestCase from django.test import TestCase
from models import Article, Person from .models import Article, Person
class LatestTests(TestCase): class LatestTests(TestCase):

View File

@ -12,6 +12,7 @@ performing a ``filter()`` lookup and raising a ``Http404`` exception if a
from django.db import models from django.db import models
class Author(models.Model): class Author(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)

View File

@ -1,8 +1,10 @@
from __future__ import absolute_import
from django.http import Http404 from django.http import Http404
from django.shortcuts import get_object_or_404, get_list_or_404 from django.shortcuts import get_object_or_404, get_list_or_404
from django.test import TestCase from django.test import TestCase
from models import Author, Article from .models import Author, Article
class GetObjectOr404Tests(TestCase): class GetObjectOr404Tests(TestCase):

View File

@ -8,6 +8,7 @@ parameters.
from django.db import models from django.db import models
class Person(models.Model): class Person(models.Model):
first_name = models.CharField(max_length=100) first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100) last_name = models.CharField(max_length=100)

View File

@ -1,9 +1,11 @@
from __future__ import absolute_import
from datetime import date from datetime import date
from django.db import IntegrityError from django.db import IntegrityError
from django.test import TestCase from django.test import TestCase
from models import Person, ManualPrimaryKeyTest from .models import Person, ManualPrimaryKeyTest
class GetOrCreateTests(TestCase): class GetOrCreateTests(TestCase):

View File

@ -7,6 +7,7 @@ This example exists purely to point out errors in models.
from django.db import connection, models from django.db import connection, models
class FieldErrors(models.Model): class FieldErrors(models.Model):
charfield = models.CharField() charfield = models.CharField()
charfield2 = models.CharField(max_length=-1) charfield2 = models.CharField(max_length=-1)

View File

@ -1,9 +1,9 @@
import copy import copy
import sys
from cStringIO import StringIO
from django.core.management.validation import get_validation_errors from django.core.management.validation import get_validation_errors
from django.db.models.loading import cache, load_app from django.db.models.loading import cache, load_app
from cStringIO import StringIO
import sys
from django.utils import unittest from django.utils import unittest

View File

@ -6,6 +6,7 @@ This demonstrates features of the database API.
from django.db import models from django.db import models
class Author(models.Model): class Author(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
class Meta: class Meta:

View File

@ -1,8 +1,12 @@
from __future__ import absolute_import
from datetime import datetime from datetime import datetime
from operator import attrgetter from operator import attrgetter
from django.core.exceptions import FieldError from django.core.exceptions import FieldError
from django.test import TestCase, skipUnlessDBFeature from django.test import TestCase, skipUnlessDBFeature
from models import Author, Article, Tag
from .models import Author, Article, Tag
class LookupTests(TestCase): class LookupTests(TestCase):

View File

@ -6,6 +6,7 @@ Make sure to set ``related_name`` if you use relationships to the same table.
from django.db import models from django.db import models
class User(models.Model): class User(models.Model):
username = models.CharField(max_length=20) username = models.CharField(max_length=20)

View File

@ -1,7 +1,9 @@
from __future__ import absolute_import
from django.db.models import Q from django.db.models import Q
from django.test import TestCase from django.test import TestCase
from models import Issue, User, UnicodeReferenceModel from .models import Issue, User, UnicodeReferenceModel
class RelatedObjectTests(TestCase): class RelatedObjectTests(TestCase):

View File

@ -12,6 +12,7 @@ field, which specifies the ``Reporter``'s position for the given article
from django.db import models from django.db import models
class Reporter(models.Model): class Reporter(models.Model):
first_name = models.CharField(max_length=30) first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30)

View File

@ -1,8 +1,10 @@
from __future__ import absolute_import
from datetime import datetime from datetime import datetime
from django.test import TestCase from django.test import TestCase
from models import Reporter, Article, Writer from .models import Reporter, Article, Writer
class M2MIntermediaryTests(TestCase): class M2MIntermediaryTests(TestCase):

View File

@ -9,6 +9,7 @@ Set ``related_name`` to designate what the reverse relationship is called.
from django.db import models from django.db import models
class Category(models.Model): class Category(models.Model):
name = models.CharField(max_length=20) name = models.CharField(max_length=20)
class Meta: class Meta:

View File

@ -1,8 +1,10 @@
from __future__ import absolute_import
from datetime import datetime from datetime import datetime
from django.test import TestCase from django.test import TestCase
from models import Article, Category from .models import Article, Category
class M2MMultipleTests(TestCase): class M2MMultipleTests(TestCase):

View File

@ -1,8 +1,10 @@
from __future__ import absolute_import
from operator import attrgetter from operator import attrgetter
from django.test import TestCase from django.test import TestCase
from models import Person from .models import Person
class RecursiveM2MTests(TestCase): class RecursiveM2MTests(TestCase):

View File

@ -2,10 +2,12 @@
Testing signals emitted on changing m2m relations. Testing signals emitted on changing m2m relations.
""" """
from .models import Person
from django.db import models from django.db import models
from django.test import TestCase from django.test import TestCase
from models import Part, Car, SportsCar, Person from .models import Part, Car, SportsCar, Person
class ManyToManySignalsTest(TestCase): class ManyToManySignalsTest(TestCase):

View File

@ -1,6 +1,8 @@
from django.db import models
from datetime import datetime from datetime import datetime
from django.db import models
# M2M described on one of the models # M2M described on one of the models
class Person(models.Model): class Person(models.Model):
name = models.CharField(max_length=128) name = models.CharField(max_length=128)

View File

@ -1,9 +1,11 @@
from __future__ import absolute_import
from datetime import datetime from datetime import datetime
from operator import attrgetter from operator import attrgetter
from django.test import TestCase from django.test import TestCase
from models import (Person, Group, Membership, CustomMembership, from .models import (Person, Group, Membership, CustomMembership,
PersonSelfRefM2M, Friendship) PersonSelfRefM2M, Friendship)

View File

@ -12,6 +12,7 @@ Set ``related_name`` to designate what the reverse relationship is called.
from django.db import models from django.db import models
class Category(models.Model): class Category(models.Model):
name = models.CharField(max_length=20) name = models.CharField(max_length=20)
parent = models.ForeignKey('self', blank=True, null=True, related_name='child_set') parent = models.ForeignKey('self', blank=True, null=True, related_name='child_set')

View File

@ -1,5 +1,9 @@
from __future__ import absolute_import
from django.test import TestCase from django.test import TestCase
from models import Category, Person
from .models import Category, Person
class ManyToOneRecursiveTests(TestCase): class ManyToOneRecursiveTests(TestCase):

View File

@ -9,6 +9,7 @@ objects, and a ``Publication`` has multiple ``Article`` objects.
from django.db import models from django.db import models
class Publication(models.Model): class Publication(models.Model):
title = models.CharField(max_length=30) title = models.CharField(max_length=30)

View File

@ -1,5 +1,9 @@
from __future__ import absolute_import
from django.test import TestCase from django.test import TestCase
from models import Article, Publication
from .models import Article, Publication
class ManyToManyTests(TestCase): class ManyToManyTests(TestCase):

View File

@ -6,6 +6,7 @@ To define a many-to-one relationship, use ``ForeignKey()``.
from django.db import models from django.db import models
class Reporter(models.Model): class Reporter(models.Model):
first_name = models.CharField(max_length=30) first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30)

View File

@ -1,10 +1,12 @@
from __future__ import absolute_import
from copy import deepcopy from copy import deepcopy
from datetime import datetime from datetime import datetime
from django.test import TestCase
from django.core.exceptions import MultipleObjectsReturned from django.core.exceptions import MultipleObjectsReturned
from django.test import TestCase
from models import Article, Reporter from .models import Article, Reporter
class ManyToOneTests(TestCase): class ManyToOneTests(TestCase):

View File

@ -7,6 +7,7 @@ To define a many-to-one relationship that can have a null foreign key, use
from django.db import models from django.db import models
class Reporter(models.Model): class Reporter(models.Model):
name = models.CharField(max_length=30) name = models.CharField(max_length=30)

View File

@ -1,7 +1,8 @@
from __future__ import with_statement from __future__ import with_statement, absolute_import
from django.test import TestCase from django.test import TestCase
from models import Reporter, Article
from .models import Reporter, Article
class ManyToOneNullTests(TestCase): class ManyToOneNullTests(TestCase):

View File

@ -9,8 +9,9 @@ words, most of these tests should be rewritten.
import tempfile import tempfile
from django.db import models
from django.core.files.storage import FileSystemStorage from django.core.files.storage import FileSystemStorage
from django.db import models
temp_storage_dir = tempfile.mkdtemp() temp_storage_dir = tempfile.mkdtemp()
temp_storage = FileSystemStorage(temp_storage_dir) temp_storage = FileSystemStorage(temp_storage_dir)

View File

@ -1,26 +1,25 @@
from __future__ import with_statement from __future__ import with_statement, absolute_import
import datetime import datetime
import os import os
from decimal import Decimal from decimal import Decimal
from django import forms from django import forms
from django.test import TestCase
from django.core.files.uploadedfile import SimpleUploadedFile from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.validators import ValidationError from django.core.validators import ValidationError
from django.db import connection from django.db import connection
from django.forms.models import model_to_dict from django.forms.models import model_to_dict
from django.utils.unittest import skipUnless from django.utils.unittest import skipUnless
from django.test import TestCase
from modeltests.model_forms.models import (Article, ArticleStatus, from .models import (Article, ArticleStatus, BetterWriter, BigInt, Book,
BetterWriter, BigInt, Book, Category, CommaSeparatedInteger, Category, CommaSeparatedInteger, CustomFieldForExclusionModel, DerivedBook,
CustomFieldForExclusionModel, DerivedBook, DerivedPost, ExplicitPK, DerivedPost, ExplicitPK, FlexibleDatePost, ImprovedArticle,
FlexibleDatePost, ImprovedArticle, ImprovedArticleWithParentLink, ImprovedArticleWithParentLink, Inventory, PhoneNumber, Post, Price,
Inventory, PhoneNumber, Post, Price, Product, TextFile, Writer, Product, TextFile, Writer, WriterProfile, test_images)
WriterProfile, test_images)
if test_images: if test_images:
from modeltests.model_forms.models import ImageFile, OptionalImageFile from .models import ImageFile, OptionalImageFile
class ImageFileForm(forms.ModelForm): class ImageFileForm(forms.ModelForm):
class Meta: class Meta:
model = ImageFile model = ImageFile

View File

@ -1,6 +1,8 @@
import datetime import datetime
from django.db import models from django.db import models
class Author(models.Model): class Author(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)

View File

@ -1,3 +1,5 @@
from __future__ import absolute_import
import datetime import datetime
import re import re
from datetime import date from datetime import date
@ -9,13 +11,13 @@ from django.forms.models import (_get_foreign_key, inlineformset_factory,
modelformset_factory) modelformset_factory)
from django.test import TestCase, skipUnlessDBFeature from django.test import TestCase, skipUnlessDBFeature
from modeltests.model_formsets.models import ( from .models import (Author, BetterAuthor, Book, BookWithCustomPK,
Author, BetterAuthor, Book, BookWithCustomPK,
BookWithOptionalAltEditor, AlternateBook, AuthorMeeting, CustomPrimaryKey, BookWithOptionalAltEditor, AlternateBook, AuthorMeeting, CustomPrimaryKey,
Place, Owner, Location, OwnerProfile, Restaurant, Product, Price, Place, Owner, Location, OwnerProfile, Restaurant, Product, Price,
MexicanRestaurant, ClassyMexicanRestaurant, Repository, Revision, MexicanRestaurant, ClassyMexicanRestaurant, Repository, Revision,
Person, Membership, Team, Player, Poet, Poem, Post) Person, Membership, Team, Player, Poet, Poem, Post)
class DeletionTests(TestCase): class DeletionTests(TestCase):
def test_deletion(self): def test_deletion(self):
PoetFormSet = modelformset_factory(Poet, can_delete=True) PoetFormSet = modelformset_factory(Poet, can_delete=True)

View File

@ -1,9 +1,11 @@
from __future__ import absolute_import
from operator import attrgetter from operator import attrgetter
from django.core.exceptions import FieldError from django.core.exceptions import FieldError
from django.test import TestCase 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) Post, Restaurant, Student, StudentWorker, Supplier, Worker, MixinModel)

View File

@ -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 this feature by redefining the Copy model from model_inheritance/models.py
""" """
from __future__ import absolute_import
from django.db import models from django.db import models
from modeltests.model_inheritance.models import NamedURL
from ..model_inheritance.models import NamedURL
# #
# Abstract base classes with related models # Abstract base classes with related models

View File

@ -1,5 +1,9 @@
from __future__ import absolute_import
from django.test import TestCase from django.test import TestCase
from modeltests.model_inheritance.models import Title
from ..model_inheritance.models import Title
class InheritanceSameModelNameTests(TestCase): class InheritanceSameModelNameTests(TestCase):

View File

@ -1,3 +1,5 @@
# Import all the models from subpackages # Import all the models from subpackages
from article import Article from __future__ import absolute_import
from publication import Publication
from .article import Article
from .publication import Publication

View File

@ -1,5 +1,6 @@
from django.db import models
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.db import models
class Article(models.Model): class Article(models.Model):
sites = models.ManyToManyField(Site) sites = models.ManyToManyField(Site)

View File

@ -1,5 +1,6 @@
from django.db import models from django.db import models
class Publication(models.Model): class Publication(models.Model):
title = models.CharField(max_length=30) title = models.CharField(max_length=30)

View File

@ -1,9 +1,11 @@
from __future__ import absolute_import
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.db import models from django.db import models
from django.test import TestCase from django.test import TestCase
from models.publication import Publication from .models.publication import Publication
from models.article import Article from .models.article import Article
class Advertisment(models.Model): class Advertisment(models.Model):

View File

@ -1,5 +1,9 @@
from __future__ import absolute_import
from django.test import TestCase from django.test import TestCase
from models import Parent
from .models import Parent
class MutuallyReferentialTests(TestCase): class MutuallyReferentialTests(TestCase):

View File

@ -8,6 +8,7 @@ In this example, a ``Place`` optionally can be a ``Restaurant``.
from django.db import models from django.db import models
class Place(models.Model): class Place(models.Model):
name = models.CharField(max_length=50) name = models.CharField(max_length=50)
address = models.CharField(max_length=80) address = models.CharField(max_length=80)

View File

@ -1,6 +1,10 @@
from django.test import TestCase from __future__ import absolute_import
from django.db import transaction, IntegrityError 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): class OneToOneTests(TestCase):

View File

@ -11,6 +11,7 @@ clauses using the variable ``django.db.models.Q`` (or any object with an
from django.db import models from django.db import models
class Article(models.Model): class Article(models.Model):
headline = models.CharField(max_length=50) headline = models.CharField(max_length=50)
pub_date = models.DateTimeField() pub_date = models.DateTimeField()

View File

@ -1,10 +1,12 @@
from __future__ import absolute_import
from datetime import datetime from datetime import datetime
from operator import attrgetter from operator import attrgetter
from django.db.models import Q from django.db.models import Q
from django.test import TestCase from django.test import TestCase
from models import Article from .models import Article
class OrLookupsTests(TestCase): class OrLookupsTests(TestCase):

View File

@ -1,8 +1,10 @@
from __future__ import absolute_import
from operator import attrgetter from operator import attrgetter
from django.test import TestCase from django.test import TestCase
from models import Post, Question, Answer from .models import Post, Question, Answer
class OrderWithRespectToTests(TestCase): class OrderWithRespectToTests(TestCase):

View File

@ -1,9 +1,11 @@
from __future__ import absolute_import
from datetime import datetime from datetime import datetime
from operator import attrgetter from operator import attrgetter
from django.test import TestCase from django.test import TestCase
from models import Article from .models import Article
class OrderingTests(TestCase): class OrderingTests(TestCase):

View File

@ -1,9 +1,11 @@
from __future__ import absolute_import
from datetime import datetime from datetime import datetime
from django.core.paginator import Paginator, InvalidPage, EmptyPage from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.test import TestCase from django.test import TestCase
from models import Article from .models import Article
class CountContainer(object): class CountContainer(object):

View File

@ -1,5 +1,5 @@
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.db import models from django.db import models
## Basic tests ## Basic tests

View File

@ -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.contrib.contenttypes.models import ContentType
from django.test import TestCase from django.test import TestCase
from django.utils import unittest
from models import (Author, Book, Reader, Qualification, Teacher, Department, from .models import (Author, Book, Reader, Qualification, Teacher, Department,
TaggedItem, Bookmark, AuthorAddress, FavoriteAuthors, TaggedItem, Bookmark, AuthorAddress, FavoriteAuthors, AuthorWithAge,
AuthorWithAge, BookWithYear, Person, House, Room, BookWithYear, Person, House, Room, Employee)
Employee)
class PrefetchRelatedTests(TestCase): class PrefetchRelatedTests(TestCase):

View File

@ -6,6 +6,7 @@ Use properties on models just like on any other Python object.
from django.db import models from django.db import models
class Person(models.Model): class Person(models.Model):
first_name = models.CharField(max_length=30) first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30)

View File

@ -1,5 +1,9 @@
from __future__ import with_statement, absolute_import
from django.test import TestCase from django.test import TestCase
from models import Person
from .models import Person
class PropertyTests(TestCase): class PropertyTests(TestCase):

View File

@ -1,5 +1,9 @@
from __future__ import absolute_import
# TODO: why can't I make this ..app2
from app2.models import NiceModel from app2.models import NiceModel
class ProxyModel(NiceModel): class ProxyModel(NiceModel):
class Meta: class Meta:
proxy = True proxy = True

View File

@ -1,4 +1,5 @@
from django.db import models from django.db import models
class NiceModel(models.Model): class NiceModel(models.Model):
pass pass

View File

@ -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. apps and calls syncdb, then verifies that the table has been created.
""" """
from __future__ import absolute_import
import os import os
import sys import sys
@ -15,6 +17,7 @@ from django.db.models.loading import load_app
from django.test import TransactionTestCase from django.test import TransactionTestCase
from django.test.utils import override_settings from django.test.utils import override_settings
# @override_settings(INSTALLED_APPS=('app1', 'app2')) # @override_settings(INSTALLED_APPS=('app1', 'app2'))
class ProxyModelInheritanceTests(TransactionTestCase): class ProxyModelInheritanceTests(TransactionTestCase):
@ -28,9 +31,8 @@ class ProxyModelInheritanceTests(TransactionTestCase):
def test_table_exists(self): def test_table_exists(self):
call_command('syncdb', verbosity=0) call_command('syncdb', verbosity=0)
global ProxyModel, NiceModel from .app1.models import ProxyModel
from app1.models import ProxyModel from .app2.models import NiceModel
from app2.models import NiceModel
self.assertEqual(NiceModel.objects.all().count(), 0) self.assertEqual(NiceModel.objects.all().count(), 0)
self.assertEqual(ProxyModel.objects.all().count(), 0) self.assertEqual(ProxyModel.objects.all().count(), 0)

View File

@ -1,16 +1,17 @@
from django.test import TestCase from __future__ import absolute_import
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 django.contrib.contenttypes.models import ContentType 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 (MyPerson, Person, StatusPerson, LowerStatusPerson,
from models import UserProxyProxy, Country, State, StateProxy, TrackerUser MyPersonProxy, Abstract, OtherPerson, User, UserProxy, UserProxyProxy,
from models import BaseUser, Bug, ProxyTrackerUser, Improvement, ProxyProxyBug Country, State, StateProxy, TrackerUser, BaseUser, Bug, ProxyTrackerUser,
from models import ProxyBug, ProxyImprovement Improvement, ProxyProxyBug, ProxyBug, ProxyImprovement)
class ProxyModelTests(TestCase): class ProxyModelTests(TestCase):
def test_same_manager_queries(self): def test_same_manager_queries(self):

View File

@ -1,5 +1,6 @@
from django.db import models from django.db import models
class Author(models.Model): class Author(models.Model):
first_name = models.CharField(max_length=255) first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255) last_name = models.CharField(max_length=255)

View File

@ -1,9 +1,11 @@
from __future__ import absolute_import
from datetime import date from datetime import date
from django.db.models.sql.query import InvalidQuery from django.db.models.sql.query import InvalidQuery
from django.test import TestCase from django.test import TestCase
from models import Author, Book, Coffee, Reviewer, FriendlyAuthor from .models import Author, Book, Coffee, Reviewer, FriendlyAuthor
class RawQueryTests(TestCase): class RawQueryTests(TestCase):

View File

@ -9,6 +9,7 @@ reserved-name usage.
from django.db import models from django.db import models
class Thing(models.Model): class Thing(models.Model):
when = models.CharField(max_length=1, primary_key=True) when = models.CharField(max_length=1, primary_key=True)
join = models.CharField(max_length=1) join = models.CharField(max_length=1)

View File

@ -1,8 +1,11 @@
from __future__ import absolute_import
import datetime import datetime
from django.test import TestCase from django.test import TestCase
from models import Thing from .models import Thing
class ReservedNameTests(TestCase): class ReservedNameTests(TestCase):
def generate(self): def generate(self):

View File

@ -6,6 +6,7 @@ This demonstrates the reverse lookup features of the database API.
from django.db import models from django.db import models
class User(models.Model): class User(models.Model):
name = models.CharField(max_length=200) name = models.CharField(max_length=200)

View File

@ -1,7 +1,10 @@
from django.test import TestCase from __future__ import absolute_import
from django.core.exceptions import FieldError
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): class ReverseLookupTests(TestCase):

View File

@ -1,6 +1,8 @@
from __future__ import absolute_import
from django.test import TestCase from django.test import TestCase
from models import Person from .models import Person
class SaveDeleteHookTests(TestCase): class SaveDeleteHookTests(TestCase):

View File

@ -1,4 +1,5 @@
from django.db import models from django.db import models
class Person(models.Model): class Person(models.Model):
name = models.CharField(max_length=30) name = models.CharField(max_length=30)

View File

@ -1,6 +1,8 @@
from __future__ import absolute_import
import sys import sys
import time import time
import unittest
from django.conf import settings from django.conf import settings
from django.db import transaction, connection from django.db import transaction, connection
from django.db.utils import ConnectionHandler, DEFAULT_DB_ALIAS, DatabaseError from django.db.utils import ConnectionHandler, DEFAULT_DB_ALIAS, DatabaseError
@ -8,7 +10,7 @@ from django.test import (TransactionTestCase, skipIfDBFeature,
skipUnlessDBFeature) skipUnlessDBFeature)
from django.utils import unittest 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 # Some tests require threading, which might not be available. So create a
# skip-test decorator for those test functions. # skip-test decorator for those test functions.
@ -18,6 +20,7 @@ except ImportError:
threading = None threading = None
requires_threading = unittest.skipUnless(threading, 'requires threading') requires_threading = unittest.skipUnless(threading, 'requires threading')
class SelectForUpdateTests(TransactionTestCase): class SelectForUpdateTests(TransactionTestCase):
def setUp(self): def setUp(self):

View File

@ -1,6 +1,8 @@
from __future__ import absolute_import
from django.test import TestCase 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): class SelectRelatedTests(TestCase):

View File

@ -7,6 +7,7 @@
""" """
from decimal import Decimal from decimal import Decimal
from django.db import models from django.db import models

View File

@ -1,11 +1,11 @@
# This is necessary in Python 2.5 to enable the with statement, in 2.6 # This is necessary in Python 2.5 to enable the with statement, in 2.6
# and up it is no longer necessary. # and up it is no longer necessary.
from __future__ import with_statement from __future__ import with_statement, absolute_import
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from datetime import datetime from datetime import datetime
from StringIO import StringIO
from xml.dom import minidom from xml.dom import minidom
from StringIO import StringIO
from django.conf import settings from django.conf import settings
from django.core import serializers from django.core import serializers
@ -13,8 +13,9 @@ from django.db import transaction, connection
from django.test import TestCase, TransactionTestCase, Approximate from django.test import TestCase, TransactionTestCase, Approximate
from django.utils import simplejson, unittest from django.utils import simplejson, unittest
from models import (Category, Author, Article, AuthorProfile, from .models import (Category, Author, Article, AuthorProfile, Actor, Movie,
Actor, Movie, Score, Player, Team) Score, Player, Team)
class SerializerRegistrationTests(unittest.TestCase): class SerializerRegistrationTests(unittest.TestCase):
def setUp(self): def setUp(self):

View File

@ -1,8 +1,10 @@
from __future__ import absolute_import
from django.db.models import signals from django.db.models import signals
from django.dispatch import receiver from django.dispatch import receiver
from django.test import TestCase from django.test import TestCase
from models import Person, Car from .models import Person, Car
# #8285: signals can be any callable # #8285: signals can be any callable

View File

@ -16,6 +16,7 @@ if you prefer. You must be careful to encode the results correctly, though.
from django.db import models from django.db import models
class Article(models.Model): class Article(models.Model):
headline = models.CharField(max_length=100) headline = models.CharField(max_length=100)
pub_date = models.DateTimeField() pub_date = models.DateTimeField()

Some files were not shown because too many files have changed in this diff Show More