Convert much of the regression tests to use absolute imports. There's still work to be done though.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16976 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Alex Gaynor 2011-10-13 18:51:33 +00:00
parent d5a45d79fe
commit d362c1546f
104 changed files with 396 additions and 220 deletions

View File

@ -1,9 +1,12 @@
from django.core.paginator import Paginator from __future__ import absolute_import
from django.contrib import admin
from models import (Child, Parent, Genre, Band, Musician, Group, Quartet, from django.contrib import admin
from django.core.paginator import Paginator
from .models import (Child, Parent, Genre, Band, Musician, Group, Quartet,
Membership, ChordsMusician, ChordsBand, Invitation) Membership, ChordsMusician, ChordsBand, Invitation)
site = admin.AdminSite(name="admin") site = admin.AdminSite(name="admin")
class CustomPaginator(Paginator): class CustomPaginator(Paginator):

View File

@ -1,5 +1,6 @@
from django.db import models from django.db import models
class Parent(models.Model): class Parent(models.Model):
name = models.CharField(max_length=128) name = models.CharField(max_length=128)

View File

@ -1,19 +1,18 @@
from __future__ import with_statement from __future__ import with_statement, absolute_import
from django.contrib import admin from django.contrib import admin
from django.contrib.admin.options import IncorrectLookupParameters from django.contrib.admin.options import IncorrectLookupParameters
from django.contrib.admin.views.main import ChangeList, SEARCH_VAR, ALL_VAR from django.contrib.admin.views.main import ChangeList, SEARCH_VAR, ALL_VAR
from django.contrib.auth.models import User
from django.template import Context, Template from django.template import Context, Template
from django.test import TestCase from django.test import TestCase
from django.test.client import RequestFactory from django.test.client import RequestFactory
from django.contrib.auth.models import User
from models import (Child, Parent, Genre, Band, Musician, Group, Quartet, from .admin import (ChildAdmin, QuartetAdmin, BandAdmin, ChordsBandAdmin,
Membership, ChordsMusician, ChordsBand, Invitation)
from admin import (ChildAdmin, QuartetAdmin, BandAdmin, ChordsBandAdmin,
GroupAdmin, ParentAdmin, DynamicListDisplayChildAdmin, CustomPaginationAdmin, GroupAdmin, ParentAdmin, DynamicListDisplayChildAdmin, CustomPaginationAdmin,
FilteredChildAdmin, CustomPaginator, site as custom_site) FilteredChildAdmin, CustomPaginator, site as custom_site)
from .models import (Child, Parent, Genre, Band, Musician, Group, Quartet,
Membership, ChordsMusician, ChordsBand, Invitation)
class ChangeListTests(TestCase): class ChangeListTests(TestCase):

View File

@ -1,6 +1,7 @@
from django.conf.urls import patterns, include from django.conf.urls import patterns, include
import admin from . import admin
urlpatterns = patterns('', urlpatterns = patterns('',
(r'^admin/', include(admin.site.urls)), (r'^admin/', include(admin.site.urls)),

View File

@ -1,8 +1,10 @@
from __future__ import absolute_import
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.test import TestCase from django.test import TestCase
from models import Action from .models import Action
class AdminCustomUrlsTest(TestCase): class AdminCustomUrlsTest(TestCase):

View File

@ -1,5 +1,6 @@
from django.db import models
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db import models
class Book(models.Model): class Book(models.Model):
title = models.CharField(max_length=50) title = models.CharField(max_length=50)

View File

@ -1,21 +1,23 @@
from __future__ import absolute_import
import datetime import datetime
from django.contrib.admin import (site, ModelAdmin, SimpleListFilter,
BooleanFieldListFilter)
from django.contrib.admin.options import IncorrectLookupParameters from django.contrib.admin.options import IncorrectLookupParameters
from django.contrib.admin.views.main import ChangeList
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase, RequestFactory from django.test import TestCase, RequestFactory
from django.utils.encoding import force_unicode from django.utils.encoding import force_unicode
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from django.contrib.admin.views.main import ChangeList
from django.contrib.admin import (site, ModelAdmin, SimpleListFilter,
BooleanFieldListFilter)
from models import Book from .models import Book
def select_by(dictlist, key, value): def select_by(dictlist, key, value):
return [x for x in dictlist if x[key] == value][0] return [x for x in dictlist if x[key] == value][0]
class DecadeListFilter(SimpleListFilter): class DecadeListFilter(SimpleListFilter):
def lookups(self, request, model_admin): def lookups(self, request, model_admin):

View File

@ -1,13 +1,14 @@
from __future__ import absolute_import
from django.contrib.admin.helpers import InlineAdminForm from django.contrib.admin.helpers import InlineAdminForm
from django.contrib.auth.models import User, Permission from django.contrib.auth.models import User, Permission
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.test import TestCase from django.test import TestCase
# local test models # local test models
from models import (Holder, Inner, Holder2, Inner2, Holder3, from .admin import InnerInline
Inner3, Person, OutfitItem, Fashionista, Teacher, Parent, Child, from .models import (Holder, Inner, Holder2, Inner2, Holder3, Inner3, Person,
Author, Book) OutfitItem, Fashionista, Teacher, Parent, Child, Author, Book)
from admin import InnerInline
class TestInline(TestCase): class TestInline(TestCase):

View File

@ -1,6 +1,9 @@
from __future__ import absolute_import
from django.conf.urls import patterns, include from django.conf.urls import patterns, include
import admin from . import admin
urlpatterns = patterns('', urlpatterns = patterns('',
(r'^admin/', include(admin.site.urls)), (r'^admin/', include(admin.site.urls)),

View File

@ -1,6 +1,7 @@
# coding: utf-8 # coding: utf-8
from django.db import models
from django.contrib import admin from django.contrib import admin
from django.db import models
class Band(models.Model): class Band(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)

View File

@ -1,8 +1,11 @@
from django.test import TestCase, RequestFactory from __future__ import absolute_import
from django.contrib.auth.models import User
from django.contrib.admin.options import ModelAdmin
from models import Band, Song, SongInlineDefaultOrdering, SongInlineNewOrdering, DynOrderingBandAdmin from django.test import TestCase, RequestFactory
from django.contrib.admin.options import ModelAdmin
from django.contrib.auth.models import User
from .models import (Band, Song, SongInlineDefaultOrdering,
SongInlineNewOrdering, DynOrderingBandAdmin)
class MockRequest(object): class MockRequest(object):

View File

@ -4,6 +4,7 @@ Tests for various ways of registering models with the admin site.
from django.db import models from django.db import models
class Person(models.Model): class Person(models.Model):
name = models.CharField(max_length=200) name = models.CharField(max_length=200)

View File

@ -1,8 +1,11 @@
from django.test import TestCase from __future__ import absolute_import
from django.core.exceptions import ImproperlyConfigured
from django.contrib import admin from django.contrib import admin
from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase
from .models import Person, Place, Location
from models import Person, Place, Location
class NameAdmin(admin.ModelAdmin): class NameAdmin(admin.ModelAdmin):
list_display = ['name'] list_display = ['name']

View File

@ -1,5 +1,6 @@
from django.contrib.comments.models import Comment
from django.db import models from django.db import models
from django.contrib.comments.models import Comment
# Regression for #13368. This is an example of a model # Regression for #13368. This is an example of a model
# that imports a class that has an abstract base class. # that imports a class that has an abstract base class.

View File

@ -1,3 +1,8 @@
from __future__ import absolute_import
from django.contrib import admin from django.contrib import admin
from admin_scripts.complex_app.models.foo import Foo
from ..models.foo import Foo
admin.site.register(Foo) admin.site.register(Foo)

View File

@ -1,4 +1,4 @@
from admin_scripts.complex_app.models.bar import Bar from .bar import Bar
from admin_scripts.complex_app.models.foo import Foo from .foo import Foo
__all__ = ['Foo', 'Bar'] __all__ = ['Foo', 'Bar']

View File

@ -1,6 +1,10 @@
from __future__ import absolute_import
from django.db import models from django.db import models
from admin_scripts.complex_app.admin import foo from ..admin import foo
class Bar(models.Model): class Bar(models.Model):
name = models.CharField(max_length=5) name = models.CharField(max_length=5)
class Meta: class Meta:

View File

@ -1,5 +1,6 @@
from django.db import models from django.db import models
class Foo(models.Model): class Foo(models.Model):
name = models.CharField(max_length=5) name = models.CharField(max_length=5)
class Meta: class Meta:

View File

@ -1,5 +1,6 @@
from django.core.management.base import AppCommand from django.core.management.base import AppCommand
class Command(AppCommand): class Command(AppCommand):
help = 'Test Application-based commands' help = 'Test Application-based commands'
requires_model_validation = False requires_model_validation = False
@ -7,4 +8,4 @@ class Command(AppCommand):
def handle_app(self, app, **options): def handle_app(self, app, **options):
print 'EXECUTE:AppCommand app=%s, options=%s' % (app, sorted(options.items())) print 'EXECUTE:AppCommand app=%s, options=%s' % (app, sorted(options.items()))

View File

@ -1,6 +1,8 @@
from django.core.management.base import BaseCommand
from optparse import make_option from optparse import make_option
from django.core.management.base import BaseCommand
class Command(BaseCommand): class Command(BaseCommand):
option_list = BaseCommand.option_list + ( option_list = BaseCommand.option_list + (
make_option('--option_a','-a', action='store', dest='option_a', default='1'), make_option('--option_a','-a', action='store', dest='option_a', default='1'),

View File

@ -1,5 +1,6 @@
from django.core.management.base import LabelCommand from django.core.management.base import LabelCommand
class Command(LabelCommand): class Command(LabelCommand):
help = "Test Label-based commands" help = "Test Label-based commands"
requires_model_validation = False requires_model_validation = False

View File

@ -1,5 +1,6 @@
from django.core.management.base import NoArgsCommand from django.core.management.base import NoArgsCommand
class Command(NoArgsCommand): class Command(NoArgsCommand):
help = "Test No-args commands" help = "Test No-args commands"
requires_model_validation = False requires_model_validation = False

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()
@ -9,4 +10,3 @@ class Article(models.Model):
class Meta: class Meta:
ordering = ('-pub_date', 'headline') ordering = ('-pub_date', 'headline')

View File

@ -1 +1,3 @@
from admin_scripts.complex_app.models.bar import Bar from __future__ import absolute_import
from ..complex_app.models.bar import Bar

View File

@ -1,5 +1,6 @@
from django.db import models from django.db import models
class Article(models.Model): class Article(models.Model):
""" """
A simple Article model for testing A simple Article model for testing

View File

@ -1,9 +1,11 @@
from __future__ import absolute_import
from datetime import datetime from datetime import datetime
from django.conf import settings from django.conf import settings
from django.contrib import admin from django.contrib import admin
from django.contrib.admin.util import display_for_field, label_for_field, lookup_field from django.contrib.admin.util import (display_for_field, label_for_field,
from django.contrib.admin.util import NestedObjects lookup_field, NestedObjects)
from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.db import models, DEFAULT_DB_ALIAS from django.db import models, DEFAULT_DB_ALIAS
@ -11,7 +13,7 @@ from django.test import TestCase
from django.utils import unittest from django.utils import unittest
from django.utils.formats import localize from django.utils.formats import localize
from models import Article, Count, Event, Location from .models import Article, Count, Event, Location
class NestedObjectsTests(TestCase): class NestedObjectsTests(TestCase):

View File

@ -1,11 +1,13 @@
from __future__ import absolute_import
from django import forms from django import forms
from django.contrib import admin
from django.contrib.admin.validation import validate, validate_inline
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase from django.test import TestCase
from django.contrib import admin from .models import Song, Book, Album, TwoAlbumFKAndAnE, State, City
from django.contrib.admin.validation import validate, validate_inline
from models import Song, Book, Album, TwoAlbumFKAndAnE, State, City
class SongForm(forms.ModelForm): class SongForm(forms.ModelForm):
pass pass

View File

@ -1,14 +1,28 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
import datetime import datetime
import tempfile import tempfile
import os import os
from django import forms
from django.contrib import admin from django.contrib import admin
from django.contrib.admin.views.main import ChangeList from django.contrib.admin.views.main import ChangeList
from django.forms.models import BaseModelFormSet from django.core.files.storage import FileSystemStorage
from django.core.mail import EmailMessage from django.core.mail import EmailMessage
from django.db import models
from django.forms.models import BaseModelFormSet
from models import * from .models import (Article, Chapter, Account, Media, Child, Parent, Picture,
Widget, DooHickey, Grommet, Whatsit, FancyDoodad, Category, Link,
PrePopulatedPost, PrePopulatedSubPost, CustomArticle, Section,
ModelWithStringPrimaryKey, Color, Thing, Actor, Inquisition, Sketch, Person,
Persona, Subscriber, ExternalSubscriber, OldSubscriber, Vodcast, EmptyModel,
Fabric, Gallery, Language, Recommendation, Recommender, Collector, Post,
Gadget, Villain, SuperVillain, Plot, PlotDetails, CyclicOne, CyclicTwo,
WorkHour, Reservation, FoodDelivery, RowLevelChangePermissionModel, Paper,
CoverLetter, Story, OtherStory, Book, Promo, ChapterXtra1, Pizza, Topping,
Album, Question, Answer, ComplexSortedPerson)
def callable_year(dt_value): def callable_year(dt_value):

View File

@ -1,11 +1,14 @@
""" """
A second, custom AdminSite -- see tests.CustomAdminSiteTests. A second, custom AdminSite -- see tests.CustomAdminSiteTests.
""" """
from __future__ import absolute_import
from django.conf.urls import patterns from django.conf.urls import patterns
from django.contrib import admin from django.contrib import admin
from django.http import HttpResponse from django.http import HttpResponse
import models, forms, admin as base_admin from . import models, forms, admin as base_admin
class Admin2(admin.AdminSite): class Admin2(admin.AdminSite):
login_form = forms.CustomAdminAuthenticationForm login_form = forms.CustomAdminAuthenticationForm

View File

@ -1,6 +1,7 @@
from django import forms from django import forms
from django.contrib.admin.forms import AdminAuthenticationForm from django.contrib.admin.forms import AdminAuthenticationForm
class CustomAdminAuthenticationForm(AdminAuthenticationForm): class CustomAdminAuthenticationForm(AdminAuthenticationForm):
def clean_username(self): def clean_username(self):

View File

@ -3,12 +3,12 @@ import datetime
import tempfile import tempfile
import os import os
from django.core.files.storage import FileSystemStorage
from django.db import models
from django import forms from django import forms
from django.contrib.auth.models import User from django.contrib.auth.models import User
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.core.files.storage import FileSystemStorage
from django.db import models
class Section(models.Model): class Section(models.Model):

View File

@ -1,5 +1,5 @@
# coding: utf-8 # coding: utf-8
from __future__ import with_statement from __future__ import with_statement, absolute_import
import re import re
import datetime import datetime
@ -11,39 +11,37 @@ from django.core.exceptions import SuspiciousOperation
from django.core.files import temp as tempfile from django.core.files import temp as tempfile
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
# Register auth models with the admin. # Register auth models with the admin.
from django.contrib.auth import REDIRECT_FIELD_NAME, admin from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
from django.contrib.auth.models import Group, User, Permission, UNUSABLE_PASSWORD
from django.contrib.contenttypes.models import ContentType
from django.contrib.admin.models import LogEntry, DELETION from django.contrib.admin.models import LogEntry, DELETION
from django.contrib.admin.sites import LOGIN_FORM_KEY from django.contrib.admin.sites import LOGIN_FORM_KEY
from django.contrib.admin.util import quote from django.contrib.admin.util import quote
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
from django.contrib.admin.views.main import IS_POPUP_VAR from django.contrib.admin.views.main import IS_POPUP_VAR
from django.contrib.auth import REDIRECT_FIELD_NAME, admin
from django.contrib.auth.models import Group, User, Permission, UNUSABLE_PASSWORD
from django.contrib.contenttypes.models import ContentType
from django.forms.util import ErrorList from django.forms.util import ErrorList
import django.template.context from django.template import context as context_module
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
from django.test import TestCase from django.test import TestCase
from django.utils import formats, translation from django.utils import formats, translation, unittest
from django.utils.cache import get_max_age from django.utils.cache import get_max_age
from django.utils.encoding import iri_to_uri from django.utils.encoding import iri_to_uri
from django.utils.html import escape from django.utils.html import escape
from django.utils.http import urlencode from django.utils.http import urlencode
from django.utils import unittest
# local test models # local test models
from models import (Article, BarAccount, CustomArticle, EmptyModel, from .models import (Article, BarAccount, CustomArticle, EmptyModel, FooAccount,
FooAccount, Gallery, ModelWithStringPrimaryKey, Gallery, ModelWithStringPrimaryKey, Person, Persona, Picture, Podcast,
Person, Persona, Picture, Podcast, Section, Subscriber, Vodcast, Section, Subscriber, Vodcast, Language, Collector, Widget, Grommet,
Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit, DooHickey, FancyDoodad, Whatsit, Category, Post, Plot, FunkyTag, Chapter,
Category, Post, Plot, FunkyTag, Chapter, Book, Promo, WorkHour, Employee, Book, Promo, WorkHour, Employee, Question, Answer, Inquisition, Actor,
Question, Answer, Inquisition, Actor, FoodDelivery, FoodDelivery, RowLevelChangePermissionModel, Paper, CoverLetter, Story,
RowLevelChangePermissionModel, Paper, CoverLetter, Story, OtherStory, OtherStory, ComplexSortedPerson, Parent, Child)
ComplexSortedPerson, Parent, Child)
ERROR_MESSAGE = "Please enter the correct username and password \ ERROR_MESSAGE = "Please enter the correct username and password \
for a staff account. Note that both fields are case-sensitive." for a staff account. Note that both fields are case-sensitive."
class AdminViewBasicTest(TestCase): class AdminViewBasicTest(TestCase):
fixtures = ['admin-views-users.xml', 'admin-views-colors.xml', fixtures = ['admin-views-users.xml', 'admin-views-colors.xml',
'admin-views-fabrics.xml', 'admin-views-books.xml'] 'admin-views-fabrics.xml', 'admin-views-books.xml']
@ -3073,7 +3071,7 @@ class ValidXHTMLTests(TestCase):
cp.remove('django.core.context_processors.i18n') cp.remove('django.core.context_processors.i18n')
settings.TEMPLATE_CONTEXT_PROCESSORS = tuple(cp) settings.TEMPLATE_CONTEXT_PROCESSORS = tuple(cp)
# Force re-evaluation of the contex processor list # Force re-evaluation of the contex processor list
django.template.context._standard_context_processors = None context_module._standard_context_processors = None
self.client.login(username='super', password='secret') self.client.login(username='super', password='secret')
def tearDown(self): def tearDown(self):
@ -3081,7 +3079,7 @@ class ValidXHTMLTests(TestCase):
if self._context_processors is not None: if self._context_processors is not None:
settings.TEMPLATE_CONTEXT_PROCESSORS = self._context_processors settings.TEMPLATE_CONTEXT_PROCESSORS = self._context_processors
# Force re-evaluation of the contex processor list # Force re-evaluation of the contex processor list
django.template.context._standard_context_processors = None context_module._standard_context_processors = None
settings.USE_I18N = self._use_i18n settings.USE_I18N = self._use_i18n
def testLangNamePresent(self): def testLangNamePresent(self):

View File

@ -1,7 +1,9 @@
from __future__ import absolute_import
from django.conf.urls import patterns, include from django.conf.urls import patterns, include
import views
import customadmin from . import views, customadmin, admin
import admin
urlpatterns = patterns('', urlpatterns = patterns('',
(r'^test_admin/admin/doc/', include('django.contrib.admindocs.urls')), (r'^test_admin/admin/doc/', include('django.contrib.admindocs.urls')),

View File

@ -1,5 +1,5 @@
# encoding: utf-8 # encoding: utf-8
from __future__ import with_statement from __future__ import with_statement, absolute_import
from datetime import datetime from datetime import datetime
@ -15,8 +15,9 @@ from django.utils import translation
from django.utils.html import conditional_escape from django.utils.html import conditional_escape
from django.utils.unittest import TestCase from django.utils.unittest import TestCase
import models from . import models
from widgetadmin import site as widget_admin_site from .widgetadmin import site as widget_admin_site
admin_media_prefix = lambda: { admin_media_prefix = lambda: {
'ADMIN_MEDIA_PREFIX': "%sadmin/" % settings.STATIC_URL, 'ADMIN_MEDIA_PREFIX': "%sadmin/" % settings.STATIC_URL,

View File

@ -1,5 +1,9 @@
from __future__ import absolute_import
from django.conf.urls import patterns, include from django.conf.urls import patterns, include
import widgetadmin
from . import widgetadmin
urlpatterns = patterns('', urlpatterns = patterns('',
(r'^', include(widgetadmin.site.urls)), (r'^', include(widgetadmin.site.urls)),

View File

@ -1,9 +1,12 @@
""" """
""" """
from __future__ import absolute_import
from django.contrib import admin from django.contrib import admin
import models from . import models
class WidgetAdmin(admin.AdminSite): class WidgetAdmin(admin.AdminSite):
pass pass

View File

@ -1,3 +1,5 @@
from __future__ import absolute_import
import datetime import datetime
import pickle import pickle
from decimal import Decimal from decimal import Decimal
@ -7,7 +9,7 @@ from django.core.exceptions import FieldError
from django.db.models import Count, Max, Avg, Sum, StdDev, Variance, F, Q from django.db.models import Count, Max, Avg, Sum, StdDev, Variance, F, Q
from django.test import TestCase, Approximate, skipUnlessDBFeature from django.test import TestCase, Approximate, skipUnlessDBFeature
from models import Author, Book, Publisher, Clues, Entries, HardbackBook from .models import Author, Book, Publisher, Clues, Entries, HardbackBook
class AggregationTests(TestCase): class AggregationTests(TestCase):

View File

@ -1,3 +1,5 @@
from __future__ import absolute_import
import copy import copy
import os import os
import sys import sys

View File

@ -1,7 +1,6 @@
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 from django.db import models, connection
from django.db import connection
class Square(models.Model): class Square(models.Model):

View File

@ -1,17 +1,20 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Unit and doctests for specific database backends. # Unit and doctests for specific database backends.
from __future__ import with_statement from __future__ import with_statement, absolute_import
import datetime import datetime
from django.conf import settings from django.conf import settings
from django.core.management.color import no_style from django.core.management.color import no_style
from django.db import backend, connection, connections, DEFAULT_DB_ALIAS, IntegrityError, transaction from django.db import (backend, connection, connections, DEFAULT_DB_ALIAS,
IntegrityError, transaction)
from django.db.backends.signals import connection_created from django.db.backends.signals import connection_created
from django.db.backends.postgresql_psycopg2 import version as pg_version from django.db.backends.postgresql_psycopg2 import version as pg_version
from django.test import TestCase, skipUnlessDBFeature, TransactionTestCase from django.test import TestCase, skipUnlessDBFeature, TransactionTestCase
from django.utils import unittest from django.utils import unittest
from regressiontests.backends import models from . import models
class OracleChecks(unittest.TestCase): class OracleChecks(unittest.TestCase):

View File

@ -9,6 +9,7 @@ from django.conf import settings
from django.core.management import ManagementUtility from django.core.management import ManagementUtility
from django.utils import unittest from django.utils import unittest
class BashCompletionTests(unittest.TestCase): class BashCompletionTests(unittest.TestCase):
""" """
Testing the Python level bash completion code. Testing the Python level bash completion code.

View File

@ -1,9 +1,10 @@
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
from django.forms import ModelForm from django.forms import ModelForm
temp_storage_dir = tempfile.mkdtemp() temp_storage_dir = tempfile.mkdtemp()
temp_storage = FileSystemStorage(temp_storage_dir) temp_storage = FileSystemStorage(temp_storage_dir)

View File

@ -4,13 +4,16 @@ gets called *again* for each FileField. This test will fail if calling a
ModelForm's save() method causes Model.save() to be called more than once. ModelForm's save() method causes Model.save() to be called more than once.
""" """
from __future__ import absolute_import
import os import os
import shutil import shutil
from django.core.files.uploadedfile import SimpleUploadedFile from django.core.files.uploadedfile import SimpleUploadedFile
from django.utils import unittest from django.utils import unittest
from regressiontests.bug639.models import Photo, PhotoForm, temp_storage_dir from .models import Photo, PhotoForm, temp_storage_dir
class Bug639Test(unittest.TestCase): class Bug639Test(unittest.TestCase):

View File

@ -1,6 +1,8 @@
from __future__ import absolute_import
from django.contrib import admin from django.contrib import admin
from models import Story from .models import Story
admin.site.register(Story) admin.site.register(Story)

View File

@ -1,4 +1,5 @@
from django.db import models from django.db import models
class Story(models.Model): class Story(models.Model):
title = models.CharField(max_length=10) title = models.CharField(max_length=10)

View File

@ -1,3 +1,5 @@
from __future__ import with_statement
from django.contrib import admin from django.contrib import admin
from django.utils.unittest import TestCase from django.utils.unittest import TestCase
@ -9,20 +11,12 @@ class Bug8245Test(TestCase):
""" """
def test_bug_8245(self): def test_bug_8245(self):
# The first time autodiscover is called, we should get our real error. # The first time autodiscover is called, we should get our real error.
try: with self.assertRaises(Exception) as cm:
admin.autodiscover() admin.autodiscover()
except Exception, e: self.assertEqual(str(cm.exception), "Bad admin module")
self.assertEqual(str(e), "Bad admin module")
else:
self.fail(
'autodiscover should have raised a "Bad admin module" error.')
# Calling autodiscover again should raise the very same error it did # Calling autodiscover again should raise the very same error it did
# the first time, not an AlreadyRegistered error. # the first time, not an AlreadyRegistered error.
try: with self.assertRaises(Exception) as cm:
admin.autodiscover() admin.autodiscover()
except Exception, e: self.assertEqual(str(cm.exception), "Bad admin module")
self.assertEqual(str(e), "Bad admin module")
else:
self.fail(
'autodiscover should have raised a "Bad admin module" error.')

View File

@ -1,10 +1,10 @@
from __future__ import with_statement from __future__ import with_statement, absolute_import
from operator import attrgetter from operator import attrgetter
from django.test import TestCase, skipUnlessDBFeature from django.test import TestCase, skipUnlessDBFeature
from models import Country, Restaurant, Pizzeria, State from .models import Country, Restaurant, Pizzeria, State
class BulkCreateTests(TestCase): class BulkCreateTests(TestCase):

View File

@ -1,5 +1,6 @@
from django.core.cache.backends.locmem import LocMemCache from django.core.cache.backends.locmem import LocMemCache
class LiberalKeyValidationMixin(object): class LiberalKeyValidationMixin(object):
def validate_key(self, key): def validate_key(self, key):
pass pass

View File

@ -1,6 +1,8 @@
from django.db import models
from datetime import datetime from datetime import datetime
from django.db import models
def expensive_calculation(): def expensive_calculation():
expensive_calculation.num_runs += 1 expensive_calculation.num_runs += 1
return datetime.now() return datetime.now()

View File

@ -2,7 +2,7 @@
# Unit tests for cache framework # Unit tests for cache framework
# Uses whatever cache backend is set in the test settings file. # Uses whatever cache backend is set in the test settings file.
from __future__ import with_statement from __future__ import with_statement, absolute_import
import hashlib import hashlib
import os import os
@ -29,7 +29,7 @@ from django.utils.cache import (patch_vary_headers, get_cache_key,
learn_cache_key, patch_cache_control, patch_response_headers) learn_cache_key, patch_cache_control, patch_response_headers)
from django.views.decorators.cache import cache_page from django.views.decorators.cache import cache_page
from regressiontests.cache.models import Poll, expensive_calculation from .models import Poll, expensive_calculation
# functions/classes for complex data type tests # functions/classes for complex data type tests
def f(): def f():

View File

@ -1,4 +1,5 @@
from django import forms from django import forms
class CustomCommentForm(forms.Form): class CustomCommentForm(forms.Form):
pass pass

View File

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

View File

@ -1,5 +1,6 @@
from django.http import HttpResponse from django.http import HttpResponse
def custom_submit_comment(request): def custom_submit_comment(request):
return HttpResponse("Hello from the custom submit comment view.") return HttpResponse("Hello from the custom submit comment view.")

View File

@ -4,7 +4,7 @@ more information.
""" """
from django.db import models from django.db import models
from django.test import TestCase
class Author(models.Model): class Author(models.Model):
first_name = models.CharField(max_length=30) first_name = models.CharField(max_length=30)
@ -31,4 +31,3 @@ class Entry(models.Model):
class Book(models.Model): class Book(models.Model):
dewey_decimal = models.DecimalField(primary_key=True, decimal_places=2, max_digits=5) dewey_decimal = models.DecimalField(primary_key=True, decimal_places=2, max_digits=5)

View File

@ -1,10 +1,13 @@
from __future__ import absolute_import
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.comments.forms import CommentForm from django.contrib.comments.forms import CommentForm
from django.contrib.comments.models import Comment from django.contrib.comments.models import Comment
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.test import TestCase from django.test import TestCase
from regressiontests.comment_tests.models import Article, Author
from ..models import Article, Author
# Shortcut # Shortcut
CT = ContentType.objects.get_for_model CT = ContentType.objects.get_for_model

View File

@ -1,8 +1,12 @@
from __future__ import absolute_import
from django.conf import settings from django.conf import settings
from django.contrib import comments from django.contrib import comments
from django.contrib.comments.models import Comment from django.contrib.comments.models import Comment
from django.contrib.comments.forms import CommentForm from django.contrib.comments.forms import CommentForm
from regressiontests.comment_tests.tests import CommentTestCase
from . import CommentTestCase
class CommentAppAPITests(CommentTestCase): class CommentAppAPITests(CommentTestCase):
"""Tests for the "comment app" API""" """Tests for the "comment app" API"""

View File

@ -1,11 +1,13 @@
from __future__ import absolute_import
import time import time
from django.conf import settings from django.conf import settings
from django.contrib.comments.forms import CommentForm from django.contrib.comments.forms import CommentForm
from django.contrib.comments.models import Comment from django.contrib.comments.models import Comment
from regressiontests.comment_tests.models import Article from . import CommentTestCase
from regressiontests.comment_tests.tests import CommentTestCase from ..models import Article
class CommentFormTests(CommentTestCase): class CommentFormTests(CommentTestCase):

View File

@ -1,11 +1,13 @@
from django.core import mail from __future__ import absolute_import
from django.contrib.comments.models import Comment from django.contrib.comments.models import Comment
from django.contrib.comments.moderation import (moderator, CommentModerator, from django.contrib.comments.moderation import (moderator, CommentModerator,
AlreadyModerated) AlreadyModerated)
from django.core import mail
from . import CommentTestCase
from ..models import Entry
from regressiontests.comment_tests.models import Entry
from regressiontests.comment_tests.tests import CommentTestCase
class EntryModerator1(CommentModerator): class EntryModerator1(CommentModerator):
email_notification = True email_notification = True

View File

@ -1,10 +1,15 @@
from __future__ import absolute_import
import re import re
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.comments import signals from django.contrib.comments import signals
from django.contrib.comments.models import Comment from django.contrib.comments.models import Comment
from regressiontests.comment_tests.models import Article, Book
from regressiontests.comment_tests.tests import CommentTestCase from . import CommentTestCase
from ..models import Article, Book
post_redirect_re = re.compile(r'^http://testserver/posted/\?c=(?P<pk>\d+$)') post_redirect_re = re.compile(r'^http://testserver/posted/\?c=(?P<pk>\d+$)')

View File

@ -1,4 +1,6 @@
from regressiontests.comment_tests.tests import CommentTestCase from __future__ import absolute_import
from . import CommentTestCase
class CommentFeedTests(CommentTestCase): class CommentFeedTests(CommentTestCase):

View File

@ -1,7 +1,9 @@
from __future__ import absolute_import
from django.contrib.comments.models import Comment from django.contrib.comments.models import Comment
from regressiontests.comment_tests.models import Author, Article from . import CommentTestCase
from regressiontests.comment_tests.tests import CommentTestCase from ..models import Author, Article
class CommentModelTests(CommentTestCase): class CommentModelTests(CommentTestCase):

View File

@ -1,9 +1,11 @@
from __future__ import absolute_import
from django.contrib.auth.models import User, Permission from django.contrib.auth.models import User, Permission
from django.contrib.comments import signals from django.contrib.comments import signals
from django.contrib.comments.models import Comment, CommentFlag from django.contrib.comments.models import Comment, CommentFlag
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from regressiontests.comment_tests.tests import CommentTestCase from . import CommentTestCase
class FlagViewTests(CommentTestCase): class FlagViewTests(CommentTestCase):

View File

@ -1,11 +1,13 @@
from __future__ import with_statement from __future__ import with_statement, absolute_import
from django.contrib.comments.forms import CommentForm from django.contrib.comments.forms import CommentForm
from django.contrib.comments.models import Comment from django.contrib.comments.models import Comment
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.template import Template, Context from django.template import Template, Context
from regressiontests.comment_tests.models import Article, Author
from regressiontests.comment_tests.tests import CommentTestCase from ..models import Article, Author
from . import CommentTestCase
class CommentTemplateTagTests(CommentTestCase): class CommentTemplateTagTests(CommentTestCase):

View File

@ -1,15 +1,20 @@
from __future__ import absolute_import
from django.conf.urls import patterns, url from django.conf.urls import patterns, url
from django.contrib.comments.feeds import LatestCommentFeed from django.contrib.comments.feeds import LatestCommentFeed
from .custom_comments import views
feeds = { feeds = {
'comments': LatestCommentFeed, 'comments': LatestCommentFeed,
} }
urlpatterns = patterns('regressiontests.comment_tests.custom_comments.views', urlpatterns = patterns('',
url(r'^post/$', 'custom_submit_comment'), url(r'^post/$', views.custom_submit_comment),
url(r'^flag/(\d+)/$', 'custom_flag_comment'), url(r'^flag/(\d+)/$', views.custom_flag_comment),
url(r'^delete/(\d+)/$', 'custom_delete_comment'), url(r'^delete/(\d+)/$', views.custom_delete_comment),
url(r'^approve/(\d+)/$', 'custom_approve_comment'), url(r'^approve/(\d+)/$', views.custom_approve_comment),
) )
urlpatterns += patterns('', urlpatterns += patterns('',

View File

@ -5,6 +5,7 @@ from django.test import TestCase
from django.utils import unittest from django.utils import unittest
from django.utils.http import parse_etags, quote_etag, parse_http_date from django.utils.http import parse_etags, quote_etag, parse_http_date
FULL_RESPONSE = 'Test conditional get response' FULL_RESPONSE = 'Test conditional get response'
LAST_MODIFIED = datetime(2007, 10, 21, 23, 21, 47) LAST_MODIFIED = datetime(2007, 10, 21, 23, 21, 47)
LAST_MODIFIED_STR = 'Sun, 21 Oct 2007 23:21:47 GMT' LAST_MODIFIED_STR = 'Sun, 21 Oct 2007 23:21:47 GMT'
@ -14,7 +15,6 @@ EXPIRED_LAST_MODIFIED_STR = 'Sat, 20 Oct 2007 23:21:47 GMT'
ETAG = 'b4246ffc4f62314ca13147c9d4f76974' ETAG = 'b4246ffc4f62314ca13147c9d4f76974'
EXPIRED_ETAG = '7fae4cd4b0f81e7d2914700043aa8ed6' EXPIRED_ETAG = '7fae4cd4b0f81e7d2914700043aa8ed6'
class ConditionalGet(TestCase): class ConditionalGet(TestCase):
urls = 'regressiontests.conditional_processing.urls' urls = 'regressiontests.conditional_processing.urls'

View File

@ -1,5 +1,7 @@
from django.conf.urls import patterns from django.conf.urls import patterns
import views
from . import views
urlpatterns = patterns('', urlpatterns = patterns('',
('^condition/$', views.index), ('^condition/$', views.index),

View File

@ -1,8 +1,11 @@
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
from __future__ import absolute_import
from django.views.decorators.http import condition, etag, last_modified from django.views.decorators.http import condition, etag, last_modified
from django.http import HttpResponse from django.http import HttpResponse
from models import FULL_RESPONSE, LAST_MODIFIED, ETAG from .models import FULL_RESPONSE, LAST_MODIFIED, ETAG
def index(request): def index(request):
return HttpResponse(FULL_RESPONSE) return HttpResponse(FULL_RESPONSE)

View File

@ -1,6 +1,8 @@
from __future__ import absolute_import
from django.conf.urls import patterns, url from django.conf.urls import patterns, url
import views from . import views
urlpatterns = patterns('', urlpatterns = patterns('',

View File

@ -1,13 +1,14 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import with_statement from __future__ import with_statement
from django.test import TestCase from django.conf import settings
from django.core.context_processors import csrf
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from django.middleware.csrf import CsrfViewMiddleware from django.middleware.csrf import CsrfViewMiddleware
from django.views.decorators.csrf import csrf_exempt, requires_csrf_token, ensure_csrf_cookie
from django.core.context_processors import csrf
from django.conf import settings
from django.template import RequestContext, Template from django.template import RequestContext, Template
from django.test import TestCase
from django.views.decorators.csrf import csrf_exempt, requires_csrf_token, ensure_csrf_cookie
# Response/views used for CsrfResponseMiddleware and CsrfViewMiddleware tests # Response/views used for CsrfResponseMiddleware and CsrfViewMiddleware tests
def post_form_response(): def post_form_response():

View File

@ -8,6 +8,7 @@ table creation or queries.
from django.db import models from django.db import models
class Article(models.Model): class Article(models.Model):
Article_ID = models.AutoField(primary_key=True, db_column='Article ID') Article_ID = models.AutoField(primary_key=True, db_column='Article ID')
headline = models.CharField(max_length=100) headline = models.CharField(max_length=100)

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 Author, Article
from models import Author, Article
def pks(objects): def pks(objects):
""" Return pks to be able to compare lists""" """ Return pks to be able to compare lists"""

View File

@ -4,6 +4,7 @@ Regression tests for custom manager classes.
from django.db import models from django.db import models
class RestrictedManager(models.Manager): class RestrictedManager(models.Manager):
""" """
A manager that filters out non-public instances. A manager that filters out non-public instances.

View File

@ -1,6 +1,9 @@
from __future__ import absolute_import
from django.test import TestCase from django.test import TestCase
from models import RelatedModel, RestrictedModel, OneToOneRestrictedModel from .models import RelatedModel, RestrictedModel, OneToOneRestrictedModel
class CustomManagersRegressTestCase(TestCase): class CustomManagersRegressTestCase(TestCase):
def test_filtered_default_manager(self): def test_filtered_default_manager(self):

View File

@ -5,6 +5,7 @@ types, which in the past were problematic for some database backends.
from django.db import models from django.db import models
class Donut(models.Model): class Donut(models.Model):
name = models.CharField(max_length=100) name = models.CharField(max_length=100)
is_frosted = models.BooleanField(default=False) is_frosted = models.BooleanField(default=False)

View File

@ -1,9 +1,12 @@
from __future__ import absolute_import
import datetime import datetime
from django.test import TestCase, skipIfDBFeature from django.test import TestCase, skipIfDBFeature
from django.utils import tzinfo from django.utils import tzinfo
from models import Donut, RumBaba from .models import Donut, RumBaba
class DataTypesTestCase(TestCase): class DataTypesTestCase(TestCase):

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, Comment, Category from .models import Article, Comment, Category
class DatesTests(TestCase): class DatesTests(TestCase):

View File

@ -1,18 +1,18 @@
from functools import wraps
import warnings import warnings
from functools import wraps
from django.contrib.auth.decorators import login_required, permission_required, user_passes_test
from django.contrib.admin.views.decorators import staff_member_required from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.auth.decorators import login_required, permission_required, user_passes_test
from django.http import HttpResponse, HttpRequest, HttpResponseNotAllowed from django.http import HttpResponse, HttpRequest, HttpResponseNotAllowed
from django.middleware.clickjacking import XFrameOptionsMiddleware
from django.test.utils import get_warnings_state, restore_warnings_state from django.test.utils import get_warnings_state, restore_warnings_state
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.utils.functional import allow_lazy, lazy, memoize from django.utils.functional import allow_lazy, lazy, memoize
from django.utils.unittest import TestCase from django.utils.unittest import TestCase
from django.views.decorators.http import require_http_methods, require_GET, require_POST, require_safe
from django.views.decorators.vary import vary_on_headers, vary_on_cookie
from django.views.decorators.cache import cache_page, never_cache, cache_control from django.views.decorators.cache import cache_page, never_cache, cache_control
from django.views.decorators.clickjacking import xframe_options_deny, xframe_options_sameorigin, xframe_options_exempt from django.views.decorators.clickjacking import xframe_options_deny, xframe_options_sameorigin, xframe_options_exempt
from django.middleware.clickjacking import XFrameOptionsMiddleware from django.views.decorators.http import require_http_methods, require_GET, require_POST, require_safe
from django.views.decorators.vary import vary_on_headers, vary_on_cookie
def fully_decorated(request): def fully_decorated(request):

View File

@ -1,10 +1,12 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import with_statement from __future__ import with_statement
import datetime import datetime
from django.template.defaultfilters import *
from django.test import TestCase from django.test import TestCase
from django.utils import unittest, translation from django.utils import unittest, translation
from django.template.defaultfilters import *
class DefaultFiltersTests(TestCase): class DefaultFiltersTests(TestCase):

View File

@ -4,6 +4,7 @@ Regression tests for defer() / only() behavior.
from django.db import models from django.db import models
class Item(models.Model): class Item(models.Model):
name = models.CharField(max_length=15) name = models.CharField(max_length=15)
text = models.TextField(default="xyzzy") text = models.TextField(default="xyzzy")

View File

@ -1,3 +1,5 @@
from __future__ import absolute_import
from operator import attrgetter from operator import attrgetter
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
@ -6,8 +8,8 @@ from django.db.models import Count
from django.db.models.loading import cache from django.db.models.loading import cache
from django.test import TestCase from django.test import TestCase
from models import (ResolveThis, Item, RelatedItem, Child, Leaf, Proxy, from .models import (ResolveThis, Item, RelatedItem, Child, Leaf, Proxy,
SimpleItem, Feature) SimpleItem, Feature)
class DeferRegressionTest(TestCase): class DeferRegressionTest(TestCase):

View File

@ -1,7 +1,7 @@
from django.db import models
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 Award(models.Model): class Award(models.Model):
name = models.CharField(max_length=25) name = models.CharField(max_length=25)

View File

@ -1,12 +1,14 @@
from __future__ import absolute_import
import datetime import datetime
from django.conf import settings from django.conf import settings
from django.db import backend, transaction, DEFAULT_DB_ALIAS from django.db import backend, transaction, DEFAULT_DB_ALIAS
from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature
from models import (Book, Award, AwardNote, Person, Child, Toy, PlayedWith, from .models import (Book, Award, AwardNote, Person, Child, Toy, PlayedWith,
PlayedWithNote, Email, Researcher, Food, Eaten, PlayedWithNote, Email, Researcher, Food, Eaten, Policy, Version, Location,
Policy, Version, Location, Item) Item)
# Can't run this test under SQLite, because you can't # Can't run this test under SQLite, because you can't

View File

@ -2,5 +2,7 @@
Unit-tests for the dispatch project Unit-tests for the dispatch project
""" """
from test_saferef import * from __future__ import absolute_import
from test_dispatcher import *
from .test_saferef import *
from .test_dispatcher import *

View File

@ -1,13 +1,14 @@
import gc import gc
import sys import sys
import time
from django.dispatch import Signal from django.dispatch import Signal
from django.utils import unittest from django.utils import unittest
if sys.platform.startswith('java'): if sys.platform.startswith('java'):
def garbage_collect(): def garbage_collect():
"""Run the garbage collector and wait a bit to let it do his work""" """Run the garbage collector and wait a bit to let it do his work"""
import time
gc.collect() gc.collect()
time.sleep(0.1) time.sleep(0.1)
else: else:

View File

@ -3,6 +3,7 @@ Model for testing arithmetic expressions.
""" """
from django.db import models from django.db import models
class Number(models.Model): class Number(models.Model):
integer = models.IntegerField(db_column='the_integer') integer = models.IntegerField(db_column='the_integer')
float = models.FloatField(null=True, db_column='the_float') float = models.FloatField(null=True, db_column='the_float')

View File

@ -1,13 +1,15 @@
""" """
Spanning tests for all the operations that F() expressions can perform. Spanning tests for all the operations that F() expressions can perform.
""" """
from __future__ import absolute_import
import datetime import datetime
from django.db import connection from django.db import connection
from django.db.models import F from django.db.models import F
from django.test import TestCase, Approximate, skipUnlessDBFeature from django.test import TestCase, Approximate, skipUnlessDBFeature
from regressiontests.expressions_regress.models import Number, Experiment from .models import Number, Experiment
class ExpressionsRegressTests(TestCase): class ExpressionsRegressTests(TestCase):
@ -240,7 +242,7 @@ class FTimeDeltaTests(TestCase):
# e2: started three days after assigned, small duration # e2: started three days after assigned, small duration
end = stime+delta2 end = stime+delta2
e2 = Experiment.objects.create(name='e2', e2 = Experiment.objects.create(name='e2',
assigned=sday-datetime.timedelta(3), start=stime, end=end, assigned=sday-datetime.timedelta(3), start=stime, end=end,
completed=end.date()) completed=end.date())
self.deltas.append(delta2) self.deltas.append(delta2)
self.delays.append(e2.start- self.delays.append(e2.start-
@ -293,22 +295,22 @@ class FTimeDeltaTests(TestCase):
def test_exclude(self): def test_exclude(self):
for i in range(len(self.deltas)): for i in range(len(self.deltas)):
delta = self.deltas[i] delta = self.deltas[i]
test_set = [e.name for e in test_set = [e.name for e in
Experiment.objects.exclude(end__lt=F('start')+delta)] Experiment.objects.exclude(end__lt=F('start')+delta)]
self.assertEqual(test_set, self.expnames[i:]) self.assertEqual(test_set, self.expnames[i:])
test_set = [e.name for e in test_set = [e.name for e in
Experiment.objects.exclude(end__lte=F('start')+delta)] Experiment.objects.exclude(end__lte=F('start')+delta)]
self.assertEqual(test_set, self.expnames[i+1:]) self.assertEqual(test_set, self.expnames[i+1:])
def test_date_comparison(self): def test_date_comparison(self):
for i in range(len(self.days_long)): for i in range(len(self.days_long)):
days = self.days_long[i] days = self.days_long[i]
test_set = [e.name for e in test_set = [e.name for e in
Experiment.objects.filter(completed__lt=F('assigned')+days)] Experiment.objects.filter(completed__lt=F('assigned')+days)]
self.assertEqual(test_set, self.expnames[:i]) self.assertEqual(test_set, self.expnames[:i])
test_set = [e.name for e in test_set = [e.name for e in
Experiment.objects.filter(completed__lte=F('assigned')+days)] Experiment.objects.filter(completed__lte=F('assigned')+days)]
self.assertEqual(test_set, self.expnames[:i+1]) self.assertEqual(test_set, self.expnames[:i+1])

View File

@ -4,6 +4,7 @@ import datetime
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db import models from django.db import models
class RevisionableModel(models.Model): class RevisionableModel(models.Model):
base = models.ForeignKey('self', null=True) base = models.ForeignKey('self', null=True)
title = models.CharField(blank=True, max_length=255) title = models.CharField(blank=True, max_length=255)

View File

@ -1,12 +1,14 @@
from django.test import TestCase from __future__ import absolute_import
from django.utils.datastructures import SortedDict
from django.contrib.auth.models import User
from regressiontests.extra_regress.models import TestObject, Order, RevisionableModel
import datetime import datetime
from django.contrib.auth.models import User
from django.test import TestCase
from django.utils.datastructures import SortedDict
from .models import TestObject, Order, RevisionableModel
class ExtraRegressTests(TestCase): class ExtraRegressTests(TestCase):
def setUp(self): def setUp(self):

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os
import errno import errno
import os
import shutil import shutil
import sys import sys
import tempfile import tempfile

View File

@ -1,7 +1,9 @@
import tempfile import tempfile
import os import os
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 = FileSystemStorage(tempfile.mkdtemp()) temp_storage = FileSystemStorage(tempfile.mkdtemp())
UPLOAD_TO = os.path.join(temp_storage.location, 'test_upload') UPLOAD_TO = os.path.join(temp_storage.location, 'test_upload')

View File

@ -1,5 +1,7 @@
#! -*- coding: utf-8 -*- #! -*- coding: utf-8 -*-
from __future__ import absolute_import
import base64 import base64
import errno import errno
import hashlib import hashlib
@ -11,11 +13,10 @@ from django.core.files import temp as tempfile
from django.core.files.uploadedfile import SimpleUploadedFile from django.core.files.uploadedfile import SimpleUploadedFile
from django.http.multipartparser import MultiPartParser from django.http.multipartparser import MultiPartParser
from django.test import TestCase, client from django.test import TestCase, client
from django.utils import simplejson from django.utils import simplejson, unittest
from django.utils import unittest
from models import FileModel, temp_storage, UPLOAD_TO from . import uploadhandler
import uploadhandler from .models import FileModel, temp_storage, UPLOAD_TO
UNICODE_FILENAME = u'test-0123456789_中文_Orléans.jpg' UNICODE_FILENAME = u'test-0123456789_中文_Orléans.jpg'

View File

@ -4,24 +4,25 @@ Upload handlers to test the upload API.
from django.core.files.uploadhandler import FileUploadHandler, StopUpload from django.core.files.uploadhandler import FileUploadHandler, StopUpload
class QuotaUploadHandler(FileUploadHandler): class QuotaUploadHandler(FileUploadHandler):
""" """
This test upload handler terminates the connection if more than a quota This test upload handler terminates the connection if more than a quota
(5MB) is uploaded. (5MB) is uploaded.
""" """
QUOTA = 5 * 2**20 # 5 MB QUOTA = 5 * 2**20 # 5 MB
def __init__(self, request=None): def __init__(self, request=None):
super(QuotaUploadHandler, self).__init__(request) super(QuotaUploadHandler, self).__init__(request)
self.total_upload = 0 self.total_upload = 0
def receive_data_chunk(self, raw_data, start): def receive_data_chunk(self, raw_data, start):
self.total_upload += len(raw_data) self.total_upload += len(raw_data)
if self.total_upload >= self.QUOTA: if self.total_upload >= self.QUOTA:
raise StopUpload(connection_reset=True) raise StopUpload(connection_reset=True)
return raw_data return raw_data
def file_complete(self, file_size): def file_complete(self, file_size):
return None return None

View File

@ -1,5 +1,9 @@
from __future__ import absolute_import
from django.conf.urls import patterns from django.conf.urls import patterns
import views
from . import views
urlpatterns = patterns('', urlpatterns = patterns('',
(r'^upload/$', views.file_upload_view), (r'^upload/$', views.file_upload_view),

View File

@ -1,11 +1,16 @@
from __future__ import absolute_import
import hashlib import hashlib
import os import os
from django.core.files.uploadedfile import UploadedFile from django.core.files.uploadedfile import UploadedFile
from django.http import HttpResponse, HttpResponseServerError from django.http import HttpResponse, HttpResponseServerError
from django.utils import simplejson from django.utils import simplejson
from models import FileModel, UPLOAD_TO
from uploadhandler import QuotaUploadHandler, ErroringUploadHandler from .models import FileModel, UPLOAD_TO
from tests import UNICODE_FILENAME from .tests import UNICODE_FILENAME
from .uploadhandler import QuotaUploadHandler, ErroringUploadHandler
def file_upload_view(request): def file_upload_view(request):
""" """

View File

@ -1,5 +1,7 @@
from django.db import models from __future__ import absolute_import
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db import models
class Animal(models.Model): class Animal(models.Model):

View File

@ -1,5 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Unittests for fixtures. # Unittests for fixtures.
from __future__ import absolute_import
import os import os
import re import re
try: try:
@ -8,21 +10,16 @@ except ImportError:
from StringIO import StringIO from StringIO import StringIO
from django.core import management from django.core import management
from django.core.management.commands.dumpdata import sort_dependencies
from django.core.management.base import CommandError from django.core.management.base import CommandError
from django.db.models import signals from django.core.management.commands.dumpdata import sort_dependencies
from django.db import transaction from django.db import transaction
from django.db.models import signals
from django.test import (TestCase, TransactionTestCase, skipIfDBFeature, from django.test import (TestCase, TransactionTestCase, skipIfDBFeature,
skipUnlessDBFeature) skipUnlessDBFeature)
from models import Animal, Stuff from .models import (Animal, Stuff, Absolute, Parent, Child, Article, Widget,
from models import Absolute, Parent, Child Store, Person, Book, NKChild, RefToNKChild, Circle1, Circle2, Circle3,
from models import Article, Widget ExternalDependency, Thingy)
from models import Store, Person, Book
from models import NKChild, RefToNKChild
from models import Circle1, Circle2, Circle3
from models import ExternalDependency
from models import Thingy
pre_save_checks = [] pre_save_checks = []

View File

@ -2,8 +2,8 @@
import datetime import datetime
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_location = tempfile.mkdtemp() temp_storage_location = tempfile.mkdtemp()

View File

@ -1,12 +1,14 @@
from error_messages import * from __future__ import absolute_import
from extra import *
from fields import FieldsTests from .error_messages import *
from forms import * from .extra import *
from formsets import * from .fields import FieldsTests
from input_formats import * from .forms import *
from media import * from .formsets import *
from models import * from .input_formats import *
from regressions import * from .media import *
from util import * from .models import *
from validators import TestFieldWithValidators from .regressions import *
from widgets import * from .util import *
from .validators import TestFieldWithValidators
from .widgets import *

View File

@ -1,11 +1,14 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
from django.core.files.uploadedfile import SimpleUploadedFile from django.core.files.uploadedfile import SimpleUploadedFile
from django.forms import * from django.forms import *
from django.test import TestCase from django.test import TestCase
from django.utils.safestring import mark_safe
from django.utils import unittest from django.utils import unittest
from django.utils.safestring import mark_safe
from regressiontests.forms.tests.fields import verify_exists_urls from .fields import verify_exists_urls
class AssertFormErrorsMixin(object): class AssertFormErrorsMixin(object):

View File

@ -1,15 +1,18 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import absolute_import
import datetime import datetime
from django.conf import settings from django.conf import settings
from django.forms import * from django.forms import *
from django.forms.extras import SelectDateWidget from django.forms.extras import SelectDateWidget
from django.forms.util import ErrorList from django.forms.util import ErrorList
from django.utils import translation from django.utils import translation, unittest
from django.utils import unittest from django.utils.encoding import force_unicode, smart_unicode
from django.utils.encoding import force_unicode
from django.utils.encoding import smart_unicode from .error_messages import AssertFormErrorsMixin
from error_messages import AssertFormErrorsMixin
class GetDate(Form): class GetDate(Form):
mydate = DateField(widget=SelectDateWidget) mydate = DateField(widget=SelectDateWidget)

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