hash stringlengths 64 64 | content stringlengths 0 1.51M |
|---|---|
2e4c511a45bddab54aec9e6225b7abc4b539be61c79da766c6e8a30f980c6146 | import os
from django.contrib.auth import validators
from django.contrib.auth.models import User
from django.contrib.auth.password_validation import (
CommonPasswordValidator, MinimumLengthValidator, NumericPasswordValidator,
UserAttributeSimilarityValidator, get_default_password_validators,
get_password_v... |
27a7b7443b8dfa3ffaa23b929b432a45538587ce365e3e9f9245b0403c693334 | import os
AUTH_MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
]
AUTH_TEMPLATES = [{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(os.path.dirname(__file__), 'templates')],
'APP_... |
112f4b8de955706f8fe56b49d9e90edfc7d0e8b46bf4be37523c83f48d63a46b | import datetime
import re
from importlib import reload
from unittest import mock
import django
from django import forms
from django.contrib.auth.forms import (
AdminPasswordChangeForm, AuthenticationForm, PasswordChangeForm,
PasswordResetForm, ReadOnlyPasswordHashField, ReadOnlyPasswordHashWidget,
SetPassw... |
87f1480705a183be979ceb9255ea87004c1aed870ce67fbb7dd601cb59c3bde2 | from django.contrib.auth import authenticate
from django.contrib.auth.models import User
from django.contrib.auth.tokens import PasswordResetTokenGenerator
from django.contrib.auth.views import (
PasswordChangeDoneView, PasswordChangeView, PasswordResetCompleteView,
PasswordResetDoneView, PasswordResetView,
)
f... |
c60f2e08e997405fd48faf85b8fbb73e5ecf3da61358341faa6aebd3410b4c21 | from django.conf import settings
from django.contrib.auth import models
from django.contrib.auth.decorators import login_required, permission_required
from django.core.exceptions import PermissionDenied
from django.http import HttpResponse
from django.test import TestCase, override_settings
from django.test.client impo... |
0f1058830be0b54bcc3398ff2a3dd2fa84d8047acff50ebb9826161269edeed6 | from unittest import mock, skipUnless
from django.conf.global_settings import PASSWORD_HASHERS
from django.contrib.auth.hashers import (
UNUSABLE_PASSWORD_PREFIX, UNUSABLE_PASSWORD_SUFFIX_LENGTH,
BasePasswordHasher, PBKDF2PasswordHasher, PBKDF2SHA1PasswordHasher,
check_password, get_hasher, identify_hasher... |
bdef21558cf8b601c517bd6a5c6cadf16db6eb24f0ce816a1cd913161c7cbfc0 | from django.contrib.auth.middleware import AuthenticationMiddleware
from django.contrib.auth.models import User
from django.http import HttpRequest
from django.test import TestCase
class TestAuthenticationMiddleware(TestCase):
def setUp(self):
self.user = User.objects.create_user('test_user', 'test@exampl... |
b6b73c8862ee7150df15794501ba376743382acf66f9ceb18a7fa10cf028cb54 | import os
from django.core.files.base import ContentFile
from django.core.files.storage import Storage
from django.db.models import FileField
from django.test import SimpleTestCase
class AWSS3Storage(Storage):
"""
Simulate an AWS S3 storage which uses Unix-like paths and allows any
characters in file nam... |
13f33df48e37a6cc480250243d1415f210cdeac20385d5aa91ff3fc2b58c00a5 | import os
import shutil
import sys
import tempfile
import threading
import time
import unittest
from datetime import datetime, timedelta
from io import StringIO
from urllib.request import urlopen
from django.core.cache import cache
from django.core.exceptions import SuspiciousFileOperation
from django.core.files.base ... |
52afd9317bd51adadf9eb50a9760aca3aea029e5320350faab314066907b0fae | """
Storing files according to a custom storage system
``FileField`` and its variations can take a ``storage`` argument to specify how
and where files should be stored.
"""
import random
import tempfile
from django.core.files.storage import FileSystemStorage
from django.db import models
class CustomValidNameStorag... |
b000c34dd882b02592aa4c815f7a879d7e4fc3636db2eb13c14367c4590a9db2 | from django.conf.urls import url
from django.http import HttpResponse
urlpatterns = [
url(r'^$', lambda req: HttpResponse('example view')),
]
|
54b10f914b2a0efd98aadb5d0316d28ef9c08239eaefb5ea918ef9258d9541a1 | import base64
class Base64Converter:
regex = r'[a-zA-Z0-9+/]*={0,2}'
def to_python(self, value):
return base64.b64decode(value)
def to_url(self, value):
return base64.b64encode(value).decode('ascii')
class DynamicConverter:
_dynamic_to_python = None
_dynamic_to_url = None
... |
dab3ac294c32017264f4b310aa6a5725b4c14119f377b409a8a8cfb68f441e8e | import uuid
from django.core.exceptions import ImproperlyConfigured
from django.test import SimpleTestCase
from django.test.utils import override_settings
from django.urls import Resolver404, path, resolve, reverse
from .converters import DynamicConverter
from .views import empty_view
included_kwargs = {'base': b'he... |
d7737be0b391e911c90905f08ca688ad65da6e423021a200b357395df8429edb | from django.test import SimpleTestCase
from django.urls.resolvers import RegexPattern, RoutePattern
from django.utils.translation import gettext_lazy as _
class RegexPatternTests(SimpleTestCase):
def test_str(self):
self.assertEqual(str(RegexPattern(_('^translated/$'))), '^translated/$')
class RoutePat... |
19aac0a0bbfedcc6f0dc76cecd4380efb6d17291b447b926033cd6282eafefbb | from django.urls import path
from . import views
urlpatterns = [
path('{x}/<{x}:{x}>/'.format(x=name), views.empty_view, name=name)
for name in ('int', 'path', 'slug', 'str', 'uuid')
]
|
dc781a3db42ff6565863cee1f51d1712cad68dfc9145113642cf535e09856a16 | from django.urls import include, path, register_converter
from . import converters, views
register_converter(converters.Base64Converter, 'base64')
subpatterns = [
path('<base64:value>/', views.empty_view, name='subpattern-base64'),
]
urlpatterns = [
path('base64/<base64:value>/', views.empty_view, name='bas... |
6164c07b68eba49871814abcb516d4de05a9fb7f133ecfd1c70699e5de80d5f8 | from django.conf.urls import include
from django.urls import path
from . import views
urlpatterns = [
path('articles/2003/', views.empty_view, name='articles-2003'),
path('articles/<int:year>/', views.empty_view, name='articles-year'),
path('articles/<int:year>/<int:month>/', views.empty_view, name='artic... |
3dc32f858b0871395474cecad0f41595c06c6f397d697cdb88398a8248eb5bcf | from django.urls import path, register_converter
from . import converters, views
register_converter(converters.DynamicConverter, 'dynamic')
urlpatterns = [
path('dynamic/<dynamic:value>/', views.empty_view, name='dynamic'),
]
|
a8114a8c012cb2c98123c3650a11d2e3c498f9f95b6e1eab83a20c5752e8ced6 | from django.http import HttpResponse
def empty_view(request, *args, **kwargs):
return HttpResponse('')
|
d1c011d830c979f57d2818fe2cbfe8bef727e61ca01fa6f1cb53e34c5bbbb4dc | import gc
import sys
import time
import weakref
from types import TracebackType
from django.dispatch import Signal, receiver
from django.test import SimpleTestCase
from django.test.utils import override_settings
if sys.platform.startswith('java'):
def garbage_collect():
# Some JVM GCs will execute finaliz... |
362b10bb901021e6853bbd01b21b26ea8868479d29b3bd663636b034eed57de1 | from django.db import connection, models
from django.db.backends.utils import truncate_name
from django.test import TestCase
from .models.article import Article, Site
from .models.publication import Publication
class Advertisement(models.Model):
customer = models.CharField(max_length=100)
publications = mode... |
6251f673c9cc0566f2a46ba7c2d8a0cc41fce8d422a510129786764c4b196d5b | import threading
import time
from unittest import mock
from multiple_database.routers import TestRouter
from django.core.exceptions import FieldError
from django.db import (
DatabaseError, NotSupportedError, connection, connections, router,
transaction,
)
from django.test import (
TransactionTestCase, ove... |
0581fad61a6a58a85ab8cfb425f9feba3be4dc2f86709bd17dd2c534479b47ed | from django.db import models
class Country(models.Model):
name = models.CharField(max_length=30)
class City(models.Model):
name = models.CharField(max_length=30)
country = models.ForeignKey(Country, models.CASCADE)
class Person(models.Model):
name = models.CharField(max_length=30)
born = model... |
4f560c0da56f7e519d8f17100ac29224b7e90312004b991ded28d057149d35fa | import re
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.http import HttpRequest
from django.middleware.csrf import (
CSRF_SESSION_KEY, CSRF_TOKEN_LENGTH, REASON_BAD_TOKEN,
REASON_NO_CSRF_COOKIE, CsrfViewMiddleware,
_compare_salted_tokens as equivalent_... |
a1787eb06017e7dfde979be3100408d26355bf21b63cb13c2cdc196c4d9c3ca2 | urlpatterns = []
handler404 = 'csrf_tests.views.csrf_token_error_handler'
|
94e28d87d6c1511925c0e2ad6ce41a13499036798b6f20ab5dd81aa8acbc8c8b | from django.http import HttpResponse
from django.middleware.csrf import get_token
from django.template import Context, RequestContext, Template
from django.template.context_processors import csrf
from django.views.decorators.csrf import ensure_csrf_cookie
def post_form_view(request):
"""Return a POST form (withou... |
e84338e821c363b72fc2114662bb0b87656ebba62ed258286650b5185836ca93 | from django.http import HttpRequest
from django.middleware.csrf import _compare_salted_tokens as equivalent_tokens
from django.template.context_processors import csrf
from django.test import SimpleTestCase
class TestContextProcessor(SimpleTestCase):
def test_force_token_to_string(self):
request = HttpReq... |
edd043fc0dfd645c72d0db94aa61baf997f12af9cd30ffb38833699b9e8dcc3f | from django.db import connection
from django.test import TestCase
from .models import A01, A02, B01, B02, C01, C02, Managed1, Unmanaged2
class SimpleTests(TestCase):
def test_simple(self):
"""
The main test here is that the all the models can be created without
any database errors. We ca... |
009e5ec657dd91ff978412468796687d15519f21f6977211d4a43c68a5887e90 | """
Models can have a ``managed`` attribute, which specifies whether the SQL code
is generated for the table on various manage.py operations.
"""
from django.db import models
# All of these models are created in the database by Django.
class A01(models.Model):
f_a = models.CharField(max_length=10, db_index=Tru... |
4abf9d66a7a0a504f7bd8220ec1ffeb2affb834be1fd1caffe68dac9c5d8446f | from django.db import models
from django.test import SimpleTestCase
from django.test.utils import isolate_apps
@isolate_apps('model_meta')
class TestManagerInheritanceFromFuture(SimpleTestCase):
def test_defined(self):
"""
Meta.manager_inheritance_from_future can be defined for backwards
c... |
708f013744d08e474379969202c014052b1dcb40335f827ab3d5beccb81f2106 | from django.apps import apps
from django.contrib.contenttypes.fields import (
GenericForeignKey, GenericRelation,
)
from django.core.exceptions import FieldDoesNotExist
from django.db.models.fields import CharField, Field, related
from django.db.models.options import EMPTY_RELATION_TREE, IMMUTABLE_WARNING
from djan... |
2244c31c8cf86b7f91f5fb1171d16093bdb4e87babbdfc901f7837cee3679252 | from django.contrib.contenttypes.fields import (
GenericForeignKey, GenericRelation,
)
from django.contrib.contenttypes.models import ContentType
from django.db import models
class Relation(models.Model):
pass
class InstanceOnlyDescriptor:
def __get__(self, instance, cls=None):
if instance is No... |
84136fcc842b72fbf759552cf5042e6e8f07dde09a30e3cbb0d9c65f54fba71e | from .models import (
AbstractPerson, BasePerson, Person, ProxyPerson, Relating, Relation,
)
TEST_RESULTS = {
'get_all_field_names': {
Person: [
'baseperson_ptr',
'baseperson_ptr_id',
'content_type_abstract',
'content_type_abstract_id',
'conte... |
f55611418e57a5b578833c2b38603f2d80937aece0d2eade0149c68cd08c446e | import datetime
import re
from decimal import Decimal
from django.core.exceptions import FieldError
from django.db import connection
from django.db.models import (
Avg, Count, DecimalField, DurationField, F, FloatField, Func, IntegerField,
Max, Min, Sum, Value,
)
from django.test import TestCase
from django.te... |
8b4690e2ae658d4d56473abae053dda61121525243f0d37003c133419cec06ea | from django.db import models
class Author(models.Model):
name = models.CharField(max_length=100)
age = models.IntegerField()
friends = models.ManyToManyField('self', blank=True)
def __str__(self):
return self.name
class Publisher(models.Model):
name = models.CharField(max_length=255)
... |
3bd497aa7ced6fc82beb8ac9c7b0c57b6cfa861d529629e9dc4eb5031e37a55c | import datetime
from decimal import Decimal
from django.db.models import Case, Count, F, Q, Sum, When
from django.test import TestCase
from .models import Author, Book, Publisher
class FilteredAggregateTests(TestCase):
@classmethod
def setUpTestData(cls):
cls.a1 = Author.objects.create(name='test', ... |
5ade7d9d13982a7baa1fe17a2e16fe2c6ea1734a38e653d50536711c2728f149 | from django.test import TestCase
from .models import Article, Author, Comment, Forum, Post, SystemInfo
class NullFkOrderingTests(TestCase):
def test_ordering_across_null_fk(self):
"""
Regression test for #7512
ordering across nullable Foreign Keys shouldn't exclude results
"""
... |
5dca515a64653b50b76528a9d95334bb9002cea2f0a49903e90db6bab0afb4c9 | """
Regression tests for proper working of ForeignKey(null=True). Tests these bugs:
* #7512: including a nullable foreign key reference in Meta ordering has
unexpected results
"""
from django.db import models
# The first two models represent a very simple null FK ordering case.
class Author(models.Model):
n... |
9256eba651a19fdaf04ec638ea59221f77a4f205ecd6634ff9facf35207a3692 | from django.core.exceptions import FieldError
from django.db.models import FilteredRelation
from django.test import SimpleTestCase, TestCase
from .models import (
AdvancedUserStat, Child1, Child2, Child3, Child4, Image, LinkedList,
Parent1, Parent2, Product, StatDetails, User, UserProfile, UserStat,
UserSt... |
4b390ddf47314feeff6ae6db230b3df9003e7d6acfc9f00a751bcd73fbece64a | from django.db import models
class User(models.Model):
username = models.CharField(max_length=100)
email = models.EmailField()
def __str__(self):
return self.username
class UserProfile(models.Model):
user = models.OneToOneField(User, models.CASCADE)
city = models.CharField(max_length=10... |
2edf29d097fcd3cacbd5881e44ee8e420061cb58f53b7776a31f695dba1aad92 | from django.contrib import admin
from django.contrib.admin import sites
from django.test import SimpleTestCase, override_settings
@override_settings(INSTALLED_APPS=[
'admin_default_site.apps.MyCustomAdminConfig',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'dja... |
498068d54561e8dab64fb98c5d9d092879abea07ca88ecfce2a188caa2b8696b | from django.contrib import admin
class CustomAdminSite(admin.AdminSite):
pass
|
d1a3b8dc9d43dfb2436b88ec5e3698b86a8f5c57752affd18259090edbe36e25 | from django.contrib.admin.apps import SimpleAdminConfig
class MyCustomAdminConfig(SimpleAdminConfig):
verbose_name = 'My custom default admin site.'
default_site = 'admin_default_site.sites.CustomAdminSite'
|
13edd93e1f5b87bb855d6ed9f37f19cd60d09538bb0b171c84ff1d223132d6c1 | # Unit tests for typecast functions in django.db.backends.util
import datetime
import unittest
from django.db.backends import utils as typecasts
TEST_CASES = {
'typecast_date': (
('', None),
(None, None),
('2005-08-11', datetime.date(2005, 8, 11)),
('1990-01-01', datetime.date(199... |
14b6e900b31b9c3a7411173c6ee3efc9346186f43a74584ad01a65cfcf4d2aec | from django.db import IntegrityError, transaction
from django.test import TestCase, skipUnlessDBFeature
from .models import PossessedCar
class TestTestCase(TestCase):
@skipUnlessDBFeature('can_defer_constraint_checks')
@skipUnlessDBFeature('supports_foreign_keys')
def test_fixture_teardown_checks_constr... |
661808fccbe1dbb881daca54894e450c7109fcff4f185246cad2929ba744e2fe | import os
import unittest
import warnings
from io import StringIO
from unittest import mock
from django.conf import settings
from django.conf.urls import url
from django.contrib.staticfiles.finders import get_finder, get_finders
from django.contrib.staticfiles.storage import staticfiles_storage
from django.core.files.... |
529e0cadbc9cc8765d19e2203d2d04e9c445ecf9858f98c659a6cd8725e8c67c | from django.db import models
class Car(models.Model):
name = models.CharField(max_length=100)
def __str__(self):
return self.name
class Person(models.Model):
name = models.CharField(max_length=100)
cars = models.ManyToManyField(Car, through='PossessedCar')
def __str__(self):
re... |
a205414854d289c22ea974c0aa1ea6d1a50baba0e89dcfc300bd6a5cb0e289c3 | from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^test_utils/get_person/([0-9]+)/$', views.get_person),
url(r'^test_utils/no_template_used/$', views.no_template_used),
]
|
050ee19a7aa5d64f2c96050fca8335f20e183494b9fa3fab1cb82f1f599e4c26 | from unittest import mock
from django.db import connections
from django.test import TestCase, TransactionTestCase, override_settings
class TestSerializedRollbackInhibitsPostMigrate(TransactionTestCase):
"""
TransactionTestCase._fixture_teardown() inhibits the post_migrate signal
for test classes with ser... |
12398fdc24733b9490ec3b0739fd97a28c4131a89adc3f6be64178f71fa04cc1 | from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.template import Context, Template
from .models import Person
def get_person(request, pk):
person = get_object_or_404(Person, pk=pk)
return HttpResponse(person.name)
def no_template_used(request):
template = ... |
1ae07bfafd04b7f04e25a73bf503b700e02eec15edc609b159ffef0b2da1665a | """
A second, custom AdminSite -- see tests.CustomAdminSiteTests.
"""
from django.conf.urls import url
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from django.http import HttpResponse
from . import admin as base_admin, forms, models
cla... |
fb904c7961616fd3934aad4ae39a864880ebd938ee62fb819af625ed7f816a03 | import datetime
import os
import re
import unittest
from urllib.parse import parse_qsl, urljoin, urlparse
import pytz
from django.contrib.admin import AdminSite, ModelAdmin
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
from django.contrib.admin.models import ADDITION, DELETION, LogEntry
from django.co... |
db56402a8f97bc1a717637bc17cc0aca0f99a9c8739eb1e73dce1a171b15de33 | import datetime
import os
import tempfile
import uuid
from django.contrib.auth.models import User
from django.contrib.contenttypes.fields import (
GenericForeignKey, GenericRelation,
)
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
from django.core.fil... |
33dfec681250089f22c500c38696af3542f08a046e98e163fcae8493c6a9ec94 | """
A custom AdminSite for AdminViewPermissionsTest.test_login_has_permission().
"""
from django.contrib import admin
from django.contrib.auth import get_permission_codename
from django.contrib.auth.forms import AuthenticationForm
from . import admin as base_admin, models
PERMISSION_NAME = 'admin_views.%s' % get_perm... |
7eb84b616a9b049bd5ec5004919f4edf6285d2f41a10de593caf65158ce14573 | import datetime
import os
import tempfile
from io import StringIO
from wsgiref.util import FileWrapper
from django import forms
from django.conf.urls import url
from django.contrib import admin
from django.contrib.admin import BooleanFieldListFilter
from django.contrib.admin.views.main import ChangeList
from django.co... |
d2bf6f071254369fb1623de3ad3a1e755066ba8bb281196e55392f1013af8e34 | import json
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
from django.contrib.admin.views.main import IS_POPUP_VAR
from django.contrib.auth.models import Permission, User
from django.core import mail
from django.template.loader import render_to_string
from django.template.response import TemplateRespon... |
a7905d2ad11005c0a3b29121224638f690b5b21098618193ca4816e9eab8ac07 | from unittest import mock
from django.conf.urls import url
from django.contrib import admin
from django.contrib.auth.models import User
from django.db import connections
from django.test import TestCase, override_settings
from django.urls import reverse
from .models import Book
class Router:
target_db = None
... |
51270051f0eadbe785432bc5d5f38ca65c35ce1c6f784d8d01006e7347a14bc8 | from django.conf.urls import include, url
from . import admin, custom_has_permission_admin, customadmin, views
from .test_autocomplete_view import site as autocomplete_site
urlpatterns = [
url(r'^test_admin/admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^test_admin/admin/secure-view/$', views.s... |
bf1aabe89f0d021bb24f317e0fcc6fa1b48b27994a88ee093fbd1baa87b472c8 | from django.conf.urls import url
from django.contrib import admin
from django.contrib.admin.actions import delete_selected
from django.contrib.auth.models import User
from django.test import SimpleTestCase, TestCase, override_settings
from django.test.client import RequestFactory
from django.urls import reverse
from .... |
7f6e7257dc71c5552055e8cf9f17f432cbfaef25616635b51cf74c4ccf2492b3 | from django import forms
from django.contrib.admin.forms import AdminAuthenticationForm
from django.contrib.admin.helpers import ActionForm
class CustomAdminAuthenticationForm(AdminAuthenticationForm):
class Media:
css = {'all': ('path/to/media.css',)}
def clean_username(self):
username = se... |
397d1164ea8d53c017e24f4688ac299279e0c201ec887e16b633819a4d462232 | from django.contrib.admin.forms import AdminAuthenticationForm
from django.contrib.auth.models import User
from django.test import TestCase, override_settings
# To verify that the login form rejects inactive users, use an authentication
# backend that allows them.
@override_settings(AUTHENTICATION_BACKENDS=['django.c... |
6f9d4e2e8c1e12f1f68c50d8ce211e017054f26f60e0fef88df8b07ceccf7af1 | from django.contrib.admin.templatetags.admin_static import static
from django.contrib.staticfiles.storage import staticfiles_storage
from django.test import SimpleTestCase
from django.utils.deprecation import RemovedInDjango30Warning
class AdminStaticDeprecationTests(SimpleTestCase):
def test(self):
"""
... |
ff92d4b5ac854ee1624998cd2fc7387c60c54d1edb56fd48d8d793502274d483 | from django.contrib.admin.views.decorators import staff_member_required
from django.http import HttpResponse
@staff_member_required
def secure_view(request):
return HttpResponse('%s' % request.POST)
@staff_member_required(redirect_field_name='myfield')
def secure_view2(request):
return HttpResponse('%s' % r... |
76c2c24e09ee44356dfd02dd6076d04613f1debf51f5840065d04cc3c9abaf72 | import json
from django.contrib import admin
from django.contrib.admin.tests import AdminSeleniumTestCase
from django.contrib.admin.views.autocomplete import AutocompleteJsonView
from django.contrib.auth.models import Permission, User
from django.contrib.contenttypes.models import ContentType
from django.http import H... |
c6ede863e72b704fdf6797d31e283806f397a468eaff3e26136909362686b0ea | import datetime
from django.contrib.admin import ModelAdmin
from django.contrib.admin.templatetags.admin_list import date_hierarchy
from django.contrib.admin.templatetags.admin_modify import submit_row
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from django.test import R... |
14dd799340435b3bf7b29c96dab7477706bbe1befae9a07a48984bf508429c6b | import datetime
import pickle
from django.db import models
from django.test import TestCase
from django.utils.version import get_version
from .models import Container, Event, Group, Happening, M2MModel
class PickleabilityTestCase(TestCase):
def setUp(self):
Happening.objects.create() # make sure the de... |
7c8df72485e1485686f53b7dee9e761bdecbe788a037bea3a6c03727a8ed4a18 | import datetime
from django.db import DJANGO_VERSION_PICKLE_KEY, models
from django.utils.translation import gettext_lazy as _
def standalone_number():
return 1
class Numbers:
@staticmethod
def get_static_number():
return 2
class PreviousDjangoVersionQuerySet(models.QuerySet):
def __getst... |
ffb02fd068fe11002b443f91d751c1ba60c95eecdcffb738af6f4f46a5ce7819 | from django.test import TestCase
from .models import (
Event, Movie, Package, PackageNullFK, Person, Screening, ScreeningNullFK,
)
# These are tests for #16715. The basic scheme is always the same: 3 models with
# 2 relations. The first relation may be null, while the second is non-nullable.
# In some cases, Dja... |
65c796c4a4aeb21a0c040f125a0defd51f07f6a04eb9e19c15ec90d5d10a9869 | from django.db import models
class Person(models.Model):
name = models.CharField(max_length=200)
class Movie(models.Model):
title = models.CharField(max_length=200)
director = models.ForeignKey(Person, models.CASCADE)
class Event(models.Model):
pass
class Screening(Event):
movie = models.For... |
a9786c9e9612d53d584688e7ea7d80b5d18d23668c3a7056aa7c6e7afbe44c2e | from django.test import TestCase
from .models import Article, Bar, Base, Child, Foo, Whiz
class StringLookupTests(TestCase):
def test_string_form_referencing(self):
"""
Regression test for #1661 and #1662
String form referencing of models works, both as pre and post
reference, o... |
5e4274af0b201a047da71d33e7a8cee414f9b0e3be8996b5d4da98785f73cfd9 | from django.db import models
class Foo(models.Model):
name = models.CharField(max_length=50)
friend = models.CharField(max_length=50, blank=True)
def __str__(self):
return "Foo %s" % self.name
class Bar(models.Model):
name = models.CharField(max_length=50)
normal = models.ForeignKey(Foo... |
f4f2c3c9b9c40b8565bf9f0dcae8225d093d9f321d6df2bf007a757a7da976cf | import datetime
import sys
import unittest
from django.contrib.admin import (
AllValuesFieldListFilter, BooleanFieldListFilter, ModelAdmin,
RelatedOnlyFieldListFilter, SimpleListFilter, site,
)
from django.contrib.admin.options import IncorrectLookupParameters
from django.contrib.auth.admin import UserAdmin
fr... |
0450a77e96724da280e25f11bd32356fa9cb8899c7a4f4670b1c3a0606b5eec7 | from django.contrib.auth.models import User
from django.contrib.contenttypes.fields import (
GenericForeignKey, GenericRelation,
)
from django.contrib.contenttypes.models import ContentType
from django.db import models
class Book(models.Model):
title = models.CharField(max_length=50)
year = models.Positiv... |
5f7b11efb3a3ab4822543a716d1875c99e1cbb27a6ffa4cd7fa85e2cbd9be968 | from django.apps import apps
from django.apps.registry import Apps
from django.conf import settings
from django.contrib.sites import models
from django.contrib.sites.management import create_default_site
from django.contrib.sites.middleware import CurrentSiteMiddleware
from django.contrib.sites.models import Site, clea... |
9dea0ae3ffcec24593f14a235226c0569d12f69d4963963f2ddece718809d4d9 | from django import get_version
from django.test import SimpleTestCase
from django.utils.version import get_version_tuple
class VersionTests(SimpleTestCase):
def test_development(self):
ver_tuple = (1, 4, 0, 'alpha', 0)
# This will return a different result when it's run within or outside
... |
85355c702013aaf8c807236c8ae929bdafd5421a37ca70e964b8c9d4a45c28c7 | from django.core.exceptions import FieldError
from django.test import TestCase
from .models import Article, Author
class CustomColumnsTests(TestCase):
def setUp(self):
self.a1 = Author.objects.create(first_name="John", last_name="Smith")
self.a2 = Author.objects.create(first_name="Peter", last_n... |
b7992b67579de7ae3caeed9cf69b2e876dc8cea5763f994da106e69ec1b341b3 | """
Custom column/table names
If your database column name is different than your model attribute, use the
``db_column`` parameter. Note that you'll use the field's name, not its column
name, in API usage.
If your database table name is different than your model name, use the
``db_table`` Meta attribute. This has no ... |
08ff836d96909721b0054e1365c89b437b82ed860f5e3f64506fd8c9cc916142 | import logging
from contextlib import contextmanager
from io import StringIO
from admin_scripts.tests import AdminScriptTestCase
from django.conf import settings
from django.core import mail
from django.core.exceptions import PermissionDenied
from django.core.files.temp import NamedTemporaryFile
from django.core.mana... |
50971abb13b8a49d27bd836198fb7a95408b252dace1a88dc82b410da37ce2b9 | from django.conf.urls import url
from django.conf.urls.i18n import i18n_patterns
from django.http import HttpResponse
urlpatterns = i18n_patterns(
url(r'^exists/$', lambda r: HttpResponse()),
)
|
eded23a80d2d0c2d3a41b40a290d710e9ff905ac0bbdddecb6613610171b7bb7 | import logging
from django.conf import settings
from django.core.mail.backends.base import BaseEmailBackend
class MyHandler(logging.Handler):
def __init__(self):
logging.Handler.__init__(self)
self.config = settings.LOGGING
class MyEmailBackend(BaseEmailBackend):
def send_messages(self, ema... |
2815d247b79384c832f87e7e570e37384669c4a3e608e4d39fad050135edbedc | from django.conf.urls import url
from django.urls import path
from . import views
urlpatterns = [
url(r'^innocent/$', views.innocent),
path('redirect/', views.redirect),
url(r'^suspicious/$', views.suspicious),
url(r'^suspicious_spec/$', views.suspicious_spec),
path('internal_server_error/', views... |
e3b7f1f579d50cf9bbcac80c6d17eee3f639b4b6f6375f9bb8440ea869c9de11 | from django.core.exceptions import (
DisallowedHost, PermissionDenied, SuspiciousOperation,
)
from django.http import (
Http404, HttpResponse, HttpResponseRedirect, HttpResponseServerError,
)
from django.http.multipartparser import MultiPartParserError
def innocent(request):
return HttpResponse('innocent'... |
8d9e39e34989fee4671c09076d6606eb963f0222b8daa26162c9f38c88b23233 | from django.db.models.signals import post_save, pre_save
from django.test import TestCase
from .models import Account, Employee, Person, Profile, ProxyEmployee
class UpdateOnlyFieldsTests(TestCase):
msg = 'The following fields do not exist in this model or are m2m fields: %s'
def test_update_fields_basic(se... |
df62efbf0b5510053978e98c696e59e9dcfad7b45cd17f55b1ef7f5cf1e3c671 |
from django.db import models
GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
)
class Account(models.Model):
num = models.IntegerField()
class Person(models.Model):
name = models.CharField(max_length=20)
gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
pid = models.Integer... |
c5fdcf562d10df4decab4e1e89f915d1795e2f220e697aeac5c17c7702dd1ce4 | import datetime
import pickle
from decimal import Decimal
from operator import attrgetter
from unittest import mock
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import FieldError
from django.db import connection
from django.db.models import (
Avg, Case, Count, DecimalField... |
1a45513745780da390c3cd52ad363f9fbf167a586b2996c55ad1f9af4fede9a9 | from django.contrib.contenttypes.fields import (
GenericForeignKey, GenericRelation,
)
from django.contrib.contenttypes.models import ContentType
from django.db import models
class Author(models.Model):
name = models.CharField(max_length=100)
age = models.IntegerField()
friends = models.ManyToManyFiel... |
46ffcb23269230ab7c4114eae35b2a0b3706e5c4a696391de427b578d197b7c5 | import datetime
from django.core import signing
from django.test import SimpleTestCase
from django.test.utils import freeze_time
class TestSigner(SimpleTestCase):
def test_signature(self):
"signature() method should generate a signature"
signer = signing.Signer('predictable-secret')
sign... |
a0b258c8bf4f0f367fa23587a06acae0d24d78c7ea004fe206024257e4f8e731 | from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import FieldError
from django.db import IntegrityError
from django.db.models import Q
from django.test import SimpleTestCase, TestCase
from .models import (
AllowsNullGFK, Animal, Carrot, Comparison, ConcreteRelatedModel,
Fo... |
66dc2f028acb06a09b4248220905cde5fe8ae6c360585974986be0625672aef3 | """
Generic relations
Generic relations let an object have a foreign key to any object through a
content-type/object-id field. A ``GenericForeignKey`` field can point to any
object, be it animal, vegetable, or mineral.
The canonical example is tags (although this example implementation is *far*
from complete).
"""
f... |
721f982ff6be87519c947949acd53f574b30a47b3b413db47f4b022bfe189a5b | from django import forms
from django.contrib.contenttypes.forms import generic_inlineformset_factory
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.test import TestCase
from django.test.utils import isolate_apps
from .models import (
Animal, ForProxyModelModel, ... |
040e1aae4e0b634c821774ba5ed53b53dfe5465ce089b65d15aea064f4e4b2a9 | from django.test import TestCase, TransactionTestCase
from .models import Book
class MigrationDataPersistenceTestCase(TransactionTestCase):
"""
Data loaded in migrations is available if
TransactionTestCase.serialized_rollback = True.
"""
available_apps = ["migration_test_data_persistence"]
s... |
7f749d7aa4b6e3833353cae688ec900bf6e08097ea19efe27cb6b5c20647342a | from django.db import models
class Book(models.Model):
title = models.CharField(max_length=100)
class Unmanaged(models.Model):
title = models.CharField(max_length=100)
class Meta:
managed = False
|
d1f8aa555643ef8dc18db974393131b207d1a0a04a89d670b59719550d84f3b2 | import os
from io import StringIO
from unittest import mock
from admin_scripts.tests import AdminScriptTestCase
from django.apps import apps
from django.core import management
from django.core.management import BaseCommand, CommandError, find_commands
from django.core.management.utils import find_command, popen_wrapp... |
b272307065a673aa8fb2e1da5775ed619b963dbbb0141c662db8ac851a0e4a0d | """
User-registered management commands
The ``manage.py`` utility provides a number of useful commands for managing a
Django project. If you want to add a utility command of your own, you can.
The user-defined command ``dance`` is defined in the management/commands
subdirectory of this test application. It is a simpl... |
85d87f2cafe58dbc1ba04f7a81300cc42d0ca1e51dbcef1b317d8c042392f0bc | from django.conf.urls import url
urlpatterns = [
url(r'^some/url/$', lambda req:req, name='some_url'),
]
|
d4e729e46e9d26477ab68ed03b1d937afd5d34f5c4c8cadc522dc65b9ba03624 | from django.shortcuts import resolve_url
from django.test import SimpleTestCase, override_settings
from django.urls import NoReverseMatch, reverse_lazy
from .models import UnimportantThing
from .urls import some_view
@override_settings(ROOT_URLCONF='resolve_url.urls')
class ResolveUrlTests(SimpleTestCase):
"""
... |
592605cf936b73855ba590f56d20706386cae88a5e6a182d989263ad7dbea393 | """
Regression tests for the resolve_url function.
"""
from django.db import models
class UnimportantThing(models.Model):
importance = models.IntegerField()
def get_absolute_url(self):
return '/importance/%d/' % (self.importance,)
|
cf7d879edfd177ddc2d82aa1c38bc8adab55f758df19283652b9e90a7433ca50 | from django.conf.urls import url
def some_view(request):
pass
urlpatterns = [
url(r'^some-url/$', some_view, name='some-view'),
]
|
24ae9185e5628a3729fcde2ac8db9ab098a59838b56dd6647f0ea18b059586ea | import os
from django.apps import AppConfig, apps
from django.apps.registry import Apps
from django.contrib.admin.models import LogEntry
from django.core.exceptions import AppRegistryNotReady, ImproperlyConfigured
from django.db import models
from django.test import SimpleTestCase, override_settings
from django.test.u... |
c3edb7b80ca6736f906fb8390d7b21891c0ce95fdf853d1d22fd79e255b3f639 | from django.apps.registry import Apps
from django.db import models
# We're testing app registry presence on load, so this is handy.
new_apps = Apps(['apps'])
class TotallyNormal(models.Model):
name = models.CharField(max_length=255)
class SoAlternative(models.Model):
name = models.CharField(max_length=255... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.