hash
stringlengths
64
64
content
stringlengths
0
1.51M
c784df5968450676a9f17f2a6dc35a7179ac07a02be8e5e5de997e81fd7919a4
import datetime import re from decimal import Decimal from unittest import skipIf from django.core.exceptions import FieldError from django.db import connection from django.db.models import ( Avg, Case, Count, DecimalField, DurationField, Exists, F, FloatField, Func, IntegerField, Max, Min, OuterRef, Subquery,...
12eeeb9d084a5e31513659f77ef78011bf777831437a613d21ce980c298251c8
from django.db import models class Author(models.Model): name = models.CharField(max_length=100) age = models.IntegerField() friends = models.ManyToManyField('self', blank=True) rating = models.FloatField(null=True) def __str__(self): return self.name class Publisher(models.Model): ...
bf697957f10f98779b4c69b0b6903e514cca01f686b2d4f366813be25fb63e1a
""" 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...
711ed230fa85ae6e150f0df5b3b3595c4b9416bc37516fac348a1cefe551595f
from django.db import models class User(models.Model): username = models.CharField(max_length=100) email = models.EmailField() class UserProfile(models.Model): user = models.OneToOneField(User, models.CASCADE) city = models.CharField(max_length=100) state = models.CharField(max_length=2) class...
8983501a8dba05dcc07de1aee33432083bcc1158708feef2f36f5aa9bb8d3812
import os import unittest import warnings from io import StringIO from unittest import mock from django.conf import settings from django.contrib.staticfiles.finders import get_finder, get_finders from django.contrib.staticfiles.storage import staticfiles_storage from django.core.exceptions import ImproperlyConfigured ...
ed137f8d5ec07fbf3b65ff9f4b2cf6f03e4c3462421856d3887e7cb867e3bf31
from django.db import models class Car(models.Model): name = models.CharField(max_length=100) class Person(models.Model): name = models.CharField(max_length=100) cars = models.ManyToManyField(Car, through='PossessedCar') class PossessedCar(models.Model): car = models.ForeignKey(Car, models.CASCADE...
3a93c443b91c35e2f5acb611531d747304e7679d18a5c6fe70605994f3c4eff5
from unittest import mock from django.db import connections from django.test import TestCase, TransactionTestCase, override_settings from .models import Car class TestSerializedRollbackInhibitsPostMigrate(TransactionTestCase): """ TransactionTestCase._fixture_teardown() inhibits the post_migrate signal ...
dcf7b4cb2e04e7dea58fa92241067d863c7bcce4068334ffd48c9b0d83d90dd4
import datetime import os import re import unittest from unittest import mock 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, DELETIO...
90bded8e7f6b1beb668dc85d31a0310c1b1b13810489eed02a5538b600fdaafd
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...
1e5a3757a54b802fbf9f14e0a83e8d23c81d0e6f12f28613f38ab33ee05480b4
""" 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 django.core.exceptions import ValidationError from . import admin as base_admin, mo...
0b4f79bc0426f4110276222d953810114ffac1349c55649031e4cc00e06c493e
import datetime import os import tempfile from io import StringIO from wsgiref.util import FileWrapper from django import forms from django.contrib import admin from django.contrib.admin import BooleanFieldListFilter from django.contrib.admin.views.main import ChangeList from django.contrib.auth.admin import GroupAdmi...
471d5feaa98461857bda1458e89186aaa9a02935d59d5e8f711c26bd752b7ec4
from unittest import mock from django.contrib import admin from django.contrib.auth.models import User from django.test import TestCase, override_settings from django.urls import path, reverse from .models import Book class Router: target_db = None def db_for_read(self, model, **hints): return self...
0863418bbdaba9527ae3aef4ca1746e4b8fb5a7f75a75fa25e91d4dc3dbe732d
from django.contrib.admin.forms import AdminAuthenticationForm from django.contrib.admin.helpers import ActionForm from django.core.exceptions import ValidationError class CustomAdminAuthenticationForm(AdminAuthenticationForm): class Media: css = {'all': ('path/to/media.css',)} def clean_username(se...
25e5025a3fb4a0689857f1cf9f3eedf936c6eaa297e39d5eb7639e562a6f0a43
from django.contrib.admin.views.decorators import staff_member_required from django.http import HttpResponse @staff_member_required def secure_view(request): return HttpResponse(str(request.POST)) @staff_member_required(redirect_field_name='myfield') def secure_view2(request): return HttpResponse(str(reques...
0198c8ddbf811155db1ecb7e50e21ffcd7b76abc02a265f1c532eb5c016b6c90
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...
cb86d6a0f2164e1982984d6b0d9692997a195adfe0decacb5d50bbdf627f27ec
from django.db import models class Foo(models.Model): name = models.CharField(max_length=50) friend = models.CharField(max_length=50, blank=True) class Bar(models.Model): name = models.CharField(max_length=50) normal = models.ForeignKey(Foo, models.CASCADE, related_name='normal_foo') fwd = model...
861699df3789de622365001294d587c4024f02091f1c1764d79a87e18ea335a4
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...
faa3745555d27c3f6e5a670e74147a4cbd980af0d8f13156d7c32c807c1b74a6
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...
0e9e2f4f146efb4eb96f5066509a5bbeacebddca771b35477922f6eb88497e10
from django.db import models class Account(models.Model): num = models.IntegerField() class Person(models.Model): GENDER_CHOICES = ( ('M', 'Male'), ('F', 'Female'), ) name = models.CharField(max_length=20) gender = models.CharField(max_length=1, choices=GENDER_CHOICES) pid =...
96efe2a349ecb32ad2ecfcee1a3fe858590bee77b67dbbb22fb80d0573422a99
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 ( Aggregate, Avg, Case, Count, D...
e66b653debe27120926d841ddb24ec3115bd2e4d5a4a15d966139c2b91518730
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...
63c49987d6882963867d41b903f9ce9278c862058cd6cabd1e05995e9e206929
import datetime from django.core import signing from django.test import SimpleTestCase from django.test.utils import freeze_time from django.utils.crypto import InvalidAlgorithm class TestSigner(SimpleTestCase): def test_signature(self): "signature() method should generate a signature" signer = ...
c9f0065a2bf5b9894135379496abc511748c55d4fb64fa92dd6bd376550d2cac
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...
23e7c78acc5b70a87f4da931c0adc5ba198c8710030270fbeee01967b2fe30a0
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, get_r...
07b46f63ea034a0fd5ae73fbd0dfc1cb4a91b8296dd735e8d948156b99bdced2
""" 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
5a52c0e12fd45a2ab802d9149c3c6960e98710fb00b939a650ad0196b7725c40
from django.db import models class Building(models.Model): name = models.CharField(max_length=10) class Device(models.Model): building = models.ForeignKey('Building', models.CASCADE) name = models.CharField(max_length=10) class Port(models.Model): device = models.ForeignKey('Device', models.CASCAD...
3af9fe57957f9b8341c6bb155333d0e68acc234fde0d484a4e58c02dfc00a0f7
from django.conf import settings from django.core.exceptions import MiddlewareNotUsed from django.http import HttpResponse from django.test import RequestFactory, SimpleTestCase, override_settings from . import middleware as mw @override_settings(ROOT_URLCONF='middleware_exceptions.urls') class MiddlewareTests(Simpl...
06fa2c787f35969fea0eb443fa14519211f725e4a0200600c7436b192e2314e2
from django.urls import path from . import views urlpatterns = [ path('middleware_exceptions/view/', views.normal_view), path('middleware_exceptions/error/', views.server_error), path('middleware_exceptions/permission_denied/', views.permission_denied), path('middleware_exceptions/exception_in_render/...
f90df32ac6c456a2458bdc92990c2de1a261e2bda1c84b2251fa403f8d854127
from django.http import Http404, HttpResponse from django.template import engines from django.template.response import TemplateResponse from django.utils.decorators import ( async_only_middleware, sync_and_async_middleware, sync_only_middleware, ) log = [] class BaseMiddleware: def __init__(self, get_respons...
d6958b8c16501098989a4805c06199de38520a623305c776f830a40ab6c0c661
from django.core.exceptions import PermissionDenied from django.http import HttpResponse from django.template import engines from django.template.response import TemplateResponse def normal_view(request): return HttpResponse('OK') def template_response(request): template = engines['django'].from_string('tem...
44b7a059710aef87c076e50714bc53de1f8bc16f51b34838546d6ac4101f1f97
from django.db import IntegrityError from django.db.models import ProtectedError, Q, Sum from django.forms.models import modelform_factory from django.test import TestCase, skipIfDBFeature from .models import ( A, Address, B, Board, C, Cafe, CharLink, Company, Contact, Content, D, Developer, Guild, HasLinkThin...
1ee003bf736b38fd4c91aa4d651025e0374cae62c34b899a908313b07ff137cc
from django.contrib.contenttypes.fields import ( GenericForeignKey, GenericRelation, ) from django.contrib.contenttypes.models import ContentType from django.db import models __all__ = ('Link', 'Place', 'Restaurant', 'Person', 'Address', 'CharLink', 'TextLink', 'OddRelation1', 'OddRelation2', ...
1dc2623ce5be99e80ef724196f7518e14d0ab17c9b7b6ad200152d6d3f69f529
from django.core.exceptions import FieldError from django.test import SimpleTestCase, TestCase from .models import ( Bookmark, Domain, Family, Genus, HybridSpecies, Kingdom, Klass, Order, Phylum, Pizza, Species, TaggedItem, ) class SelectRelatedTests(TestCase): @classmethod def create_tree(cls, stri...
ab0db5e02b0d06108428218cc109524049e9125b7bc55dad336c60392695c203
""" Tests for select_related() ``select_related()`` follows all relationships and pre-caches any foreign key values so that complex trees can be fetched in a single query. However, this isn't always a good idea, so the ``depth`` argument control how many "levels" the select-related behavior will traverse. """ from dj...
05e99d03a6782ea835a2f4340dc4ae7ab84560758f86812af732742d43715bee
from django.db import connection from . import PostgreSQLTestCase try: from django.contrib.postgres.signals import ( get_citext_oids, get_hstore_oids, register_type_handlers, ) except ImportError: pass # pyscogp2 isn't installed. class OIDTests(PostgreSQLTestCase): def assertOIDs(self, oid...
e411f7b784141868ddf2923f704dbd63e65197880af72e6181bccea0f489cdb1
from django.test import modify_settings from . import PostgreSQLTestCase from .models import CharFieldModel, TextFieldModel try: from django.contrib.postgres.search import TrigramDistance, TrigramSimilarity except ImportError: pass @modify_settings(INSTALLED_APPS={'append': 'django.contrib.postgres'}) class...
f97e5196512e390b0b09976c9b9126614decbdaab2fee531b066ec03f306b8c1
import json from django.db.models import CharField, F, OuterRef, Q, Subquery, Value from django.db.models.functions import Cast, Concat, Substr from django.test.utils import Approximate from . import PostgreSQLTestCase from .models import AggregateTestModel, StatTestModel try: from django.contrib.postgres.aggreg...
499f25fcdc99d8e982af0e3cade0f458a1f1600b9044a41ae0f2ab5616617ca5
""" Test PostgreSQL full text search. These tests use dialogue from the 1975 film Monty Python and the Holy Grail. All text copyright Python (Monty) Pictures. Thanks to sacred-texts.com for the transcript. """ from django.db import connection from django.db.models import F, Value from django.test import modify_setting...
582aeb7cbb95939167f363a94ae4427ecdbd238985c19aa727fcd5837c6e929a
try: from django.contrib.postgres.fields import JSONField from django.contrib.postgres.fields.jsonb import KeyTransform, KeyTextTransform from django.contrib.postgres import forms except ImportError: pass from django.core.checks import Warning as DjangoWarning from django.utils.deprecation import Remov...
8edbdb50780c19a9d72f73722993be04e77b10e8b45bf8998f79e497802de60a
from django.db import models from .fields import ( ArrayField, BigIntegerRangeField, CICharField, CIEmailField, CITextField, DateRangeField, DateTimeRangeField, DecimalRangeField, EnumField, HStoreField, IntegerRangeField, SearchVectorField, ) class Tag: def __init__(self, tag_id): self.tag_i...
bf662e9b4737dbafbab3dbd1fcdb8e7b84615836b2c139dced3c68bf9c6df42c
import unittest from migrations.test_base import OperationTestBase from django.db import NotSupportedError, connection from django.db.migrations.state import ProjectState from django.db.models import Index from django.test import modify_settings, override_settings from django.test.utils import CaptureQueriesContext ...
b27c02ae916d1234dab343563563d003e6a117ec6d5f55695e0e7550eaa8f56a
""" Indirection layer for PostgreSQL-specific fields, so the tests don't fail when run with a backend other than PostgreSQL. """ import enum from django.db import models try: from django.contrib.postgres.fields import ( ArrayField, BigIntegerRangeField, CICharField, CIEmailField, CITextField, Date...
3de0b2d3b0c581cce795813ba59e43fe1579d63ea71387c7a78f9e804d21e654
from unittest import mock from django.contrib.postgres.indexes import ( BloomIndex, BrinIndex, BTreeIndex, GinIndex, GistIndex, HashIndex, SpGistIndex, ) from django.db import NotSupportedError, connection from django.db.models import CharField, Q from django.db.models.functions import Length from django.test ...
0ced51842cd3e21121c7073b94185355e761423f8f7be50505d46d1950a71538
from io import StringIO from django.core.management import call_command from django.test.utils import modify_settings from . import PostgreSQLTestCase @modify_settings(INSTALLED_APPS={'append': 'django.contrib.postgres'}) class InspectDBTests(PostgreSQLTestCase): def assertFieldsInModel(self, model, field_outpu...
dd887d0c6af3c330990203aaf07838f0b05943314caa48e3cc013be811cdf95f
import json from django.core import checks, exceptions, serializers from django.db import connection from django.db.models import OuterRef, Subquery from django.db.models.expressions import RawSQL from django.forms import Form from django.test.utils import CaptureQueriesContext, isolate_apps from . import PostgreSQLS...
e530139bad11ea1139b227df0aad840641f2a13a2179c4f671d9279e0da1b0d3
from datetime import date from . import PostgreSQLTestCase from .models import ( HStoreModel, IntegerArrayModel, NestedIntegerArrayModel, NullableIntegerArrayModel, OtherTypesArrayModel, RangesModel, ) try: from psycopg2.extras import NumericRange, DateRange except ImportError: pass # psycopg2 isn't ...
789270228a366021da616972db63ee95987a36c1afb75e757fcaf295f985b40f
import datetime from unittest import mock from django.db import IntegrityError, connection, transaction from django.db.models import CheckConstraint, Deferrable, F, Func, Q from django.utils import timezone from . import PostgreSQLTestCase from .models import HotelReservation, RangesModel, Room try: from django....
809552ed00e898b7875627029ba67c09523302b1030cd8b01fecad476061b4e4
from django.db import models class Entry(models.Model): title = models.CharField(max_length=200) updated = models.DateTimeField() published = models.DateTimeField() class Meta: ordering = ('updated',) def __str__(self): return self.title def get_absolute_url(self): r...
dc9efb7118b5b85f7e2d88c71bec67922524c4c5ab73d341f1ac25bef37427a4
from django.db import models class Author(models.Model): name = models.CharField(max_length=100) age = models.IntegerField() friends = models.ManyToManyField('self', blank=True) class Publisher(models.Model): name = models.CharField(max_length=255) num_awards = models.IntegerField() class Book...
30e6e2660bb0623260c2b985810bb83d34bdc3d18930b6800ed1d3f3bd5449d3
from django.db import IntegrityError, transaction from django.test import TestCase, skipIfDBFeature from .models import Bar, Business, Employee, Foo class BasicCustomPKTests(TestCase): @classmethod def setUpTestData(cls): cls.dan = Employee.objects.create( employee_code=123, first_name="D...
049f34558dbaa69025fe9206028f27215ad8e847187d2713b9d0f87327240a12
""" Using a custom primary key By default, Django adds an ``"id"`` field to each model. But you can override this behavior by explicitly adding ``primary_key=True`` to a field. """ from django.db import models from .fields import MyAutoField class Employee(models.Model): employee_code = models.IntegerField(pri...
a87905e53f860d30ac3841d4277cfe2fc6a5af4b6bee0255e8635a0bc2f332b9
from django.db import models class Person(models.Model): first_name = models.CharField(max_length=100, unique=True) last_name = models.CharField(max_length=100) birthday = models.DateField() defaults = models.TextField() class DefaultPerson(models.Model): first_name = models.CharField(max_length...
de98c0da7a0b46bebe30bc1531538feffb941a660fea4fe49c4adc297d34b6e2
import re from io import StringIO from unittest import mock, skipUnless from django.core.management import call_command from django.db import connection from django.db.backends.base.introspection import TableInfo from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature from .models import PeopleMore...
10f245ddf032c28405e4df886b34dc8ceae7766de94a8ecab0c2544397a6bd06
from django.db import models class People(models.Model): name = models.CharField(max_length=255) parent = models.ForeignKey('self', models.CASCADE) class Message(models.Model): from_field = models.ForeignKey(People, models.CASCADE, db_column='from_id') class PeopleData(models.Model): people_pk = m...
77e088d006cd257674c657aefecb1fb59ee86a6768f5e6c902713d94cf962d3b
import sys import traceback from io import BytesIO from unittest import TestCase, mock from wsgiref import simple_server from django.core.servers.basehttp import get_internal_wsgi_application from django.core.signals import request_finished from django.test import RequestFactory, override_settings from .views import ...
93a871b7a35b7e2bc9c37a789ccab188e72b949bf594fefa39e12d1e2c9e6996
from django.urls import path from . import views urlpatterns = [ path('fileresponse/', views.file_response), ]
e91d47cbb0aa7ab3725ac6a92f5f8a8dd41322bde07b6f5fa52b9b21ab797de4
from io import BytesIO from django.http import FileResponse FILE_RESPONSE_HOLDER = {} def file_response(request): f1 = BytesIO(b"test1") f2 = BytesIO(b"test2") response = FileResponse(f1) response._resource_closers.append(f2.close) FILE_RESPONSE_HOLDER['response'] = response FILE_RESPONSE_HO...
137a9a3818e7abbce6ef7f3f75c01bb801cc43d3d0559ddf65ebb30d798819b4
""" One-to-one relationships To define a one-to-one relationship, use ``OneToOneField()``. In this example, a ``Place`` optionally can be a ``Restaurant``. """ from django.db import models class Place(models.Model): name = models.CharField(max_length=50) address = models.CharField(max_length=80) def __...
7bd02228541cbd7eaa1c4c0583b6b53425788dcae590f2b2fb20d376171323d2
import time from django.core.exceptions import ImproperlyConfigured from django.http import HttpResponse from django.test import ( RequestFactory, SimpleTestCase, ignore_warnings, override_settings, ) from django.test.utils import require_jinja2 from django.urls import resolve from django.utils.deprecation import ...
6f46b2e84d80bbef85c63cee4779f19a3c544c60660c2fdb288f9bb852a0ac65
from django.contrib.auth import views as auth_views from django.contrib.auth.decorators import login_required from django.urls import path, re_path from django.views.decorators.cache import cache_page from django.views.generic import TemplateView, dates from . import views from .models import Book urlpatterns = [ ...
5b80667cded0e1ca1ad5d50ad4a4d728440f379166f7c87fd7da0acbbfd6e7e4
import gzip import random import re import struct from io import BytesIO from urllib.parse import quote from django.conf import settings from django.core import mail from django.core.exceptions import PermissionDenied from django.http import ( FileResponse, HttpRequest, HttpResponse, HttpResponseNotFound, Http...
862f51b024c8a622a0ea0dc2407cccc9de9602efa79a89c22ef79ea45ec91c50
from django.http import HttpResponse from django.test import RequestFactory, SimpleTestCase from django.test.utils import override_settings class SecurityMiddlewareTest(SimpleTestCase): def middleware(self, *args, **kwargs): from django.middleware.security import SecurityMiddleware return Security...
944a09094111e6f6f244b1846e3ab715024f75c7cc6e1a9800c0345636f8c3ca
import asyncio import sys import threading from unittest import skipIf from asgiref.sync import SyncToAsync from asgiref.testing import ApplicationCommunicator from django.core.asgi import get_asgi_application from django.core.signals import request_finished, request_started from django.db import close_old_connection...
32b0848820811d39a51fc8f03ec281c633f6e0eda15d244de50cb1a4c6e85856
from django.contrib import admin from django.contrib.admin.sites import AdminSite from django.contrib.auth.models import User from django.contrib.contenttypes.admin import GenericTabularInline from django.contrib.contenttypes.models import ContentType from django.forms.formsets import DEFAULT_MAX_NUM from django.forms....
900d50d9d9c7b74fc347b152aedea971c34debb3c6dda242501c43a37e84f577
import json from django.contrib.messages import constants from django.contrib.messages.storage.base import Message from django.contrib.messages.storage.cookie import ( CookieStorage, MessageDecoder, MessageEncoder, ) from django.test import SimpleTestCase, override_settings from django.utils.safestring import Safe...
6dd0a5a0d7d5e57ed51b58e9325ce72a2617b9c1e5513482d3032a0c3dc94f20
import unittest from django.contrib.messages.middleware import MessageMiddleware from django.http import HttpRequest, HttpResponse class MiddlewareTests(unittest.TestCase): def test_response_without_messages(self): """ MessageMiddleware is tolerant of messages not existing on request. ""...
3ce54a972568f5ec471c3474a75910612ed2a47ed11e32f8dc5c11779b34f94d
""" Reverse lookups This demonstrates the reverse lookup features of the database API. """ from django.db import models class User(models.Model): name = models.CharField(max_length=200) class Poll(models.Model): question = models.CharField(max_length=200) creator = models.ForeignKey(User, models.CASCA...
fb3608002976700af2db6d67306b1ba3a60c43afe50a0d8870ed783aaa99003c
import os import shutil import sys import tempfile import unittest from io import StringIO from unittest import mock from django.conf import settings from django.contrib.staticfiles import finders, storage from django.contrib.staticfiles.management.commands.collectstatic import ( Command as CollectstaticCommand, )...
4e8b54a134440cd873d4a7cbe1d3b2fd3cda7cfd8e17bed6432dea7fb78337c6
import os from datetime import datetime, timedelta from django.conf import settings from django.contrib.staticfiles.storage import ManifestStaticFilesStorage from django.core.files import storage from django.utils import timezone class DummyStorage(storage.Storage): """ A storage class that implements get_mo...
14613afd53a966492124d4438c2378335648259ce1c0063aa509820194d2b1be
import unittest from datetime import date, datetime, time, timedelta from decimal import Decimal from operator import attrgetter, itemgetter from uuid import UUID from django.core.exceptions import FieldError from django.db.models import ( BinaryField, Case, CharField, Count, DurationField, F, GenericIPAddress...
73a694f8dc3c37fea3991e5845a56e50f423eae2074f7f9af669086a5a0d6da7
from django.db import models try: from PIL import Image except ImportError: Image = None class CaseTestModel(models.Model): integer = models.IntegerField() integer2 = models.IntegerField(null=True) string = models.CharField(max_length=100, default='') big_integer = models.BigIntegerField(nul...
6d49172ce6c6e5b708ce6eaa871900465533dade8aedd0863493db4407527a03
import time from datetime import datetime, timedelta from http import cookies from django.http import HttpResponse from django.test import SimpleTestCase from django.test.utils import freeze_time from django.utils.http import http_date from django.utils.timezone import utc class SetCookieTests(SimpleTestCase): ...
ffeb7f68c4aee8a9821319f3340655ad24bcb20d4ed9660bf0a94f5ab46755c8
import io from django.conf import settings from django.core.cache import cache from django.http import HttpResponse from django.http.response import HttpResponseBase from django.test import SimpleTestCase UTF8 = 'utf-8' ISO88591 = 'iso-8859-1' class HttpResponseBaseTests(SimpleTestCase): def test_closed(self): ...
6dd05b80ac5beb8b76cbec15cb87c9aaa54eb9b7022a14e1d8210b7d84dc033e
from django.contrib.auth.models import User from django.db import models # Forward declared intermediate model class Membership(models.Model): person = models.ForeignKey('Person', models.CASCADE) group = models.ForeignKey('Group', models.CASCADE) price = models.IntegerField(default=100) # using custom i...
303617c94b4a88179d7bce3125fe53e82b38c89cdce25a819871241d080e1d4f
from urllib.parse import quote from django.contrib.contenttypes.fields import ( GenericForeignKey, GenericRelation, ) from django.contrib.contenttypes.models import ContentType from django.contrib.sites.models import SiteManager from django.db import models class Site(models.Model): domain = models.CharField...
2690c4d6bbe48a9d731b0d93917e96203cdcd2120ac718685f97e7791687ad45
from unittest import mock from django.apps.registry import Apps, apps from django.contrib.contenttypes import management as contenttypes_management from django.contrib.contenttypes.models import ContentType from django.core.management import call_command from django.test import TestCase, modify_settings from django.te...
ab321eeeeb9ae606dc5be3178475282ddf74abcea1cf875bce7c4a0dce16fba1
from django.db import models class Part(models.Model): name = models.CharField(max_length=20) class Meta: ordering = ('name',) class Car(models.Model): name = models.CharField(max_length=20) default_parts = models.ManyToManyField(Part) optional_parts = models.ManyToManyField(Part, relat...
6feb8b39ea4bf12c38aa53fa10f4dc820d540d886c1a7026295bc7cda51355cd
""" Regression tests for the Test Client, especially the customized assertions. """ import itertools import os from django.contrib.auth.models import User from django.contrib.auth.signals import user_logged_in, user_logged_out from django.http import HttpResponse from django.template import ( Context, RequestConte...
145d357b6b1aa0a2985553431ec14a6f7cf9ba8bc0e83c5d2879747604c9f839
from django.apps import apps from django.db import models from django.test import SimpleTestCase, override_settings from django.test.utils import isolate_lru_cache class FieldDeconstructionTests(SimpleTestCase): """ Tests the deconstruct() method on all core fields. """ def test_name(self): "...
eca9dbe4e77fdffc0e2196c20d8a31037a892caab08d6d382222014a1401cac3
from django.db import models class Article(models.Model): CHOICES = ( (1, 'first'), (2, 'second'), ) headline = models.CharField(max_length=100, default='Default headline') pub_date = models.DateTimeField() status = models.IntegerField(blank=True, null=True, choices=CHOICES) mi...
1a5849282a6c04a775b18d821a5334bbd52a7cea70f4bc6d4f5a7f730cad5b39
""" Tests for the update() queryset method that allows in-place, multi-object updates. """ from django.db import models class DataPoint(models.Model): name = models.CharField(max_length=20) value = models.CharField(max_length=20) another_value = models.CharField(max_length=20, blank=True) class Related...
0311c7e599dc2d1ac0fc76f7c86f02ee58ce7180953f6f42a9ac6874a72832a3
""" Regression tests for Django built-in views. """ from django.db import models class Author(models.Model): name = models.CharField(max_length=100) def get_absolute_url(self): return '/authors/%s/' % self.id class BaseArticle(models.Model): """ An abstract article Model so that we can cre...
33bbbe1d8e84d50204d9621c37995c928f3093fae13cba3ec3fcc4644e6589c0
import os from functools import partial from django.conf.urls.i18n import i18n_patterns from django.urls import include, path, re_path from django.utils.translation import gettext_lazy as _ from django.views import defaults, i18n, static from . import views base_dir = os.path.dirname(os.path.abspath(__file__)) media...
4e373088744f741345122e37884fea511caa6b41246137be5a6cc1724ec1fc01
import datetime import decimal import logging import sys from django.core.exceptions import PermissionDenied, SuspiciousOperation from django.http import Http404, HttpResponse, JsonResponse from django.shortcuts import render from django.template import TemplateDoesNotExist from django.urls import get_resolver from dj...
8ee1de990d95a05c8d262d9ccafc332a56e8f631801a4a44da5bcbd22c25f262
# Unit tests for cache framework # Uses whatever cache backend is set in the test settings file. import copy import io import os import pickle import re import shutil import tempfile import threading import time import unittest from pathlib import Path from unittest import mock from django.conf import settings from dj...
22e0a4f153269cae9535b5986d9d5cf999b87cc257a62399230a972073ea82f7
import unittest from django.utils.termcolors import ( DARK_PALETTE, DEFAULT_PALETTE, LIGHT_PALETTE, NOCOLOR_PALETTE, PALETTES, colorize, parse_color_setting, ) class TermColorTests(unittest.TestCase): def test_empty_string(self): self.assertEqual(parse_color_setting(''), PALETTES[DEFAULT_PALETTE...
9ef2bc9f13bd896d482cdee0860cef6381d73d9203004c8743364a4cbf4a4784
from django.template import Context, Template from django.test import SimpleTestCase from django.utils import html from django.utils.functional import lazy, lazystr from django.utils.safestring import SafeData, mark_safe class customescape(str): def __html__(self): # Implement specific and wrong escaping ...
17a7247d5e16d48abe09000f14784db06045a0f0e32065e457f1c595484990b7
from decimal import Decimal from sys import float_info from django.test import SimpleTestCase from django.utils.numberformat import format as nformat class TestNumberFormat(SimpleTestCase): def test_format_number(self): self.assertEqual(nformat(1234, '.'), '1234') self.assertEqual(nformat(1234.2...
51f71edf788f6f861274641efcd71e5d8cbcded6fd32e30e7b38f85ca7a5fa59
import hashlib import unittest from django.test import SimpleTestCase, ignore_warnings from django.utils.crypto import ( InvalidAlgorithm, constant_time_compare, get_random_string, pbkdf2, salted_hmac, ) from django.utils.deprecation import RemovedInDjango40Warning class TestUtilsCryptoMisc(SimpleTestCase): ...
3450c53544630b6e6bddd86a8fcdf937bad91487bd7cf017364a05b0d49e8c76
""" Tests for stuff in django.utils.datastructures. """ import copy from django.test import SimpleTestCase from django.utils.datastructures import ( CaseInsensitiveMapping, DictWrapper, ImmutableList, MultiValueDict, MultiValueDictKeyError, OrderedSet, ) class OrderedSetTests(SimpleTestCase): def test_...
f356d661608c6198444b6fe437961c22669795e970233476eb1098d8993ed2f3
import platform import unittest from datetime import datetime from unittest import mock from django.test import SimpleTestCase, ignore_warnings from django.utils.datastructures import MultiValueDict from django.utils.deprecation import RemovedInDjango40Warning from django.utils.http import ( base36_to_int, escape_...
d39c448300543d9a01a57715781a178ed93ed76017ad053a7b1e813116c49630
from django.http import HttpResponse from django.template import engines from django.template.response import TemplateResponse from django.test import RequestFactory, SimpleTestCase from django.utils.decorators import decorator_from_middleware class ProcessViewMiddleware: def __init__(self, get_response): ...
9d26cf1b583c63dfeb799e68a264c07dba43450f0a350b3f67d9e82fef74b752
import json import sys from django.test import SimpleTestCase, ignore_warnings from django.utils import text from django.utils.deprecation import RemovedInDjango40Warning from django.utils.functional import lazystr from django.utils.text import format_lazy from django.utils.translation import gettext_lazy, override I...
467dad29ee9b90df8a6f6888eb9cf93df4f7688ee8481d1eb14d4103872dfd8f
from unittest import mock from django.conf import settings from django.db import connection, models from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature from django.test.utils import isolate_apps from .models import Book, ChildModel1, ChildModel2 class SimpleIndexesTests(SimpleTestCase): def t...
ad27a93a3bdb0f845a8f84918a4526b58f7ed7e9c28d23f02975b82be14e55d5
import threading from datetime import datetime, timedelta from unittest import mock from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist from django.db import DEFAULT_DB_ALIAS, DatabaseError, connections, models from django.db.models.manager import BaseManager from django.db.models.query impo...
df2e552b07ab8788f83e658e36af88dcec616efa8c6f025fd775ac5c9c31b6f8
""" Bare-bones model This is a basic model with only two non-primary-key fields. """ import uuid from django.db import models class Article(models.Model): headline = models.CharField(max_length=100, default='Default headline') pub_date = models.DateTimeField() class Meta: ordering = ('pub_date'...
8c516539d62a3607981c19e5f5954baafffd15afdf01f2351d6f104407ba7769
from datetime import datetime from functools import partialmethod from io import StringIO from unittest import mock, skipIf from django.core import serializers from django.core.serializers import SerializerDoesNotExist from django.core.serializers.base import ProgressBar from django.db import connection, transaction f...
b71cea883b56bf81bae9bfa8eb105d94535d66398db442711872dd98059cbcda
from django.contrib import admin from django.contrib.auth.models import Permission, User from django.contrib.contenttypes.models import ContentType from django.test import TestCase from .models import Band class AdminActionsTests(TestCase): @classmethod def setUpTestData(cls): cls.superuser = User.o...
145f6f06b552434ceb8b3aa5f7bfb8517d3c8953508c3c3a43c600d8cf36b417
import os from argparse import ArgumentParser from contextlib import contextmanager from unittest import TestSuite, TextTestRunner, defaultTestLoader, skipUnless from django.db import connections from django.test import SimpleTestCase from django.test.runner import DiscoverRunner from django.test.utils import captured...
97af01923691dd2b85353c8c010029fe2bdaee088f437c5898a242b9c8b80bdf
""" Regression tests for proper working of ForeignKey(null=True). """ from django.db import models class SystemDetails(models.Model): details = models.TextField() class SystemInfo(models.Model): system_details = models.ForeignKey(SystemDetails, models.CASCADE) system_name = models.CharField(max_length=...