hash
stringlengths
64
64
content
stringlengths
0
1.51M
6cfd3faf688f8267f81baa8a39932051f21cd9024d22b6cbae881de2a19a05a0
from django.db import models class Person(models.Model): first_name = models.CharField(max_length=20) last_name = models.CharField(max_length=20) friends = models.ManyToManyField('self') # A set of models that use a non-abstract inherited 'through' model. class ThroughBase(models.Model): person = mo...
f492faaccab2b33eee838f278c8d5beed793554c0e508f4985a59484298196cf
from django.test.runner import DiscoverRunner class CustomOptionsTestRunner(DiscoverRunner): def __init__(self, verbosity=1, interactive=True, failfast=True, option_a=None, option_b=None, option_c=None, **kwargs): super().__init__(verbosity=verbosity, interactive=interactive, failfast=fa...
401502fa2a3d7d8a0c270e3a6b823df0d9d83afdba00081f3128da358aaca362
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...
e5a27c447edc06f82e7fad260b7c2004b22dc5e37a90349339cf50cde4cfcb3d
from datetime import datetime from decimal import Decimal from django import forms from django.conf import settings from django.contrib.admin import helpers from django.contrib.admin.utils import ( NestedObjects, display_for_field, display_for_value, flatten, flatten_fieldsets, label_for_field, lookup_field, q...
33261b022af44aa18973a659a51b3588e208b423900beb8354f8496825e11291
from django import forms from django.contrib import admin from .models import Article, ArticleProxy, Site class ArticleAdminForm(forms.ModelForm): nolabel_form_field = forms.BooleanField(required=False) class Meta: model = Article fields = ['title'] @property def changed_data(self):...
6ef19febb5307f8f7b285da58ecf2d675cdee1821e1f0dfa534211c97c86f2d7
import json from datetime import datetime from django.contrib.admin.models import ADDITION, CHANGE, DELETION, LogEntry from django.contrib.admin.utils import quote from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType from django.test import TestCase, override_settings ...
de7437ae798513a5a0c73bfee4fff342488efda3817b4abd07ed854c365feed5
from django.urls import path from .admin import site urlpatterns = [ path('test_admin/admin/', site.urls), ]
795351c23eb535384a6f8f7fc1be49f27f20e2a25e94ff7c9ab54398e406a31d
from unittest import mock from django.db import transaction from django.test import TestCase, skipUnlessDBFeature from .models import ( Article, InheritedArticleA, InheritedArticleB, Publication, User, ) class ManyToManyTests(TestCase): def setUp(self): # Create a couple of Publications. se...
a50b6f678dc4fb87df0c96d8ad5998d8797fb396df32535399a4bd8e9cedbebd
""" Many-to-many relationships To define a many-to-many relationship, use ``ManyToManyField()``. In this example, an ``Article`` can be published in multiple ``Publication`` objects, and a ``Publication`` has multiple ``Article`` objects. """ from django.db import models class Publication(models.Model): title =...
a3e8cd7e322a39b94e7375c5931f1199b78cf63e7a69a94d702f534a17e3a404
from io import BytesIO from itertools import chain from urllib.parse import urlencode from django.core.exceptions import DisallowedHost from django.core.handlers.wsgi import LimitedStream, WSGIRequest from django.http import HttpRequest, RawPostDataException, UnreadablePostError from django.http.multipartparser import...
e4438dcea6410f4c0b1b86a0c19d3417af74971785ca2111424cda4a9fe9606c
import datetime from unittest import mock from django.db import connections from django.db.models.sql.compiler import cursor_iter from django.test import TestCase from .models import Article class QuerySetIteratorTests(TestCase): itersize_index_in_mock_args = 3 @classmethod def setUpTestData(cls): ...
b3f2f69b4ee3e5e0a1a4935be85b7d22bec86af66baec76ce1654b5d66a8f7fd
import datetime import pickle import sys import unittest from operator import attrgetter from django.core.exceptions import EmptyResultSet, FieldError from django.db import DEFAULT_DB_ALIAS, connection from django.db.models import Count, F, Q from django.db.models.sql.constants import LOUTER from django.db.models.sql....
aa71a082500b75926030d66b67e08c5ddcb8e70cc6273956be022b6de7d01159
""" Various complex queries that have been problematic in the past. """ import threading from django.db import models class DumbCategory(models.Model): pass class ProxyCategory(DumbCategory): class Meta: proxy = True class NamedCategory(DumbCategory): name = models.CharField(max_length=10) ...
6e44b22be1263f3711fd190714c967bfe811d1cdeb8c7da89cee33ff69e8a565
from django.db.models import Exists, F, IntegerField, OuterRef, Value from django.db.utils import DatabaseError, NotSupportedError from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature from .models import Number, ReservedName @skipUnlessDBFeature('supports_select_union') class QuerySetSetOperationTe...
3e1e31b163d1e6071d7abb225a6c2f085f0c4a299c8c2152f83e30a8c715fa01
import unittest from django.db import NotSupportedError, connection, transaction from django.db.models import Count from django.test import ( TestCase, ignore_warnings, skipIfDBFeature, skipUnlessDBFeature, ) from django.test.utils import CaptureQueriesContext from django.utils.deprecation import RemovedInDjango31...
de3dc7a10dc33b8a0348a850cb0c4a4dfa2f1c6e3a2647a3a67981eb98f65cc0
from datetime import datetime from django.core.exceptions import FieldError from django.db.models import CharField, F, Q from django.db.models.expressions import SimpleCol from django.db.models.fields.related_lookups import RelatedIsNull from django.db.models.functions import Lower from django.db.models.lookups import...
e17e11c7b853d41bea3b53211e164da4883559231dd7b4b1ac45912a3a6633d0
import datetime from django.core.exceptions import FieldDoesNotExist from django.db.models import F from django.db.models.functions import Lower from django.test import TestCase from .models import ( Article, CustomDbColumn, CustomPk, Detail, Individual, Member, Note, Number, Order, Paragraph, SpecialCategory...
1600c01c2446f5fc5b9d07ff9fa734a878b3ac87aa3fb9c03449968d33486d8b
from django.http import HttpRequest from django.template import ( Context, Engine, RequestContext, Template, Variable, VariableDoesNotExist, ) from django.template.context import RenderContext from django.test import RequestFactory, SimpleTestCase class ContextTests(SimpleTestCase): def test_context(self): ...
691a0e2363bca930f6edbe7303ff48de3ebc721272e6b08d209b8fd929990819
import logging from django.template import Engine, Variable, VariableDoesNotExist from django.test import SimpleTestCase class VariableResolveLoggingTests(SimpleTestCase): loglevel = logging.DEBUG def test_log_on_variable_does_not_exist_silent(self): class TestObject: class SilentDoesNot...
555f5565add571006cd9106dbabca5344e9552879df5912e07b1067afe6cde42
import functools from django.template import Library from django.template.base import Node from django.test import SimpleTestCase class FilterRegistrationTests(SimpleTestCase): def setUp(self): self.library = Library() def test_filter(self): @self.library.filter def func(): ...
c516a83c7f3bd84322f6d84e10012ae83636f1ced9afcc4a0fc9dc584037ac58
import os.path import sys import tempfile import unittest from contextlib import contextmanager from django.template import TemplateDoesNotExist from django.template.engine import Engine from django.test import SimpleTestCase, override_settings from django.utils.functional import lazystr from .utils import TEMPLATE_D...
da37c24e16cdd8b6a5b8f6bfa8928723b2f997ce6461b5183a88fd7705eacb0e
from django.template import Context, Template, Variable, VariableDoesNotExist from django.test import SimpleTestCase from django.utils.translation import gettext_lazy class TemplateTests(SimpleTestCase): def test_lazy_template_string(self): template_string = gettext_lazy('lazy string') self.assert...
ba6e6cb28d0e1655d9104dfa42140247df9a86905f245433e9cb96f35ca2e132
import pickle import time from datetime import datetime from django.template import engines from django.template.response import ( ContentNotRenderedError, SimpleTemplateResponse, TemplateResponse, ) from django.test import ( RequestFactory, SimpleTestCase, modify_settings, override_settings, ) from django.tes...
5ddaf8c90857262c0946e7166a654808c0df4ea6ceca027db31d477915f68d5b
from django.urls import path from . import views urlpatterns = [ # View returning a template response path('template_response_view/', views.template_response_view), # A view that can be hard to find... path('snark/', views.snark, name='snark'), ]
7f6439a48f8c7961012d279fd4e6f72041ae8c0b90b04114a321d4f7d6ecfba9
from django.urls import include, path, re_path from . import views ns_patterns = [ # Test urls for testing reverse lookups path('', views.index, name='index'), re_path(r'^client/([0-9,]+)/$', views.client, name='client'), re_path(r'^client/(?P<id>[0-9]+)/(?P<action>[^/]+)/$', views.client_action, name...
5f2c400493bdeeaf6a316066038f082199f0b3a6fa8f481edb154edafe8e923a
import os from django.core.exceptions import ImproperlyConfigured from django.template import Context from django.template.engine import Engine from django.test import SimpleTestCase, override_settings from .utils import ROOT, TEMPLATE_DIR OTHER_DIR = os.path.join(ROOT, 'other_templates') class RenderToStringTest(...
d9cdbfa0720f8445e76867d775f3d458f36e1949267b80c78cfeffd033728b0e
import datetime from unittest import skipIf, skipUnless from django.db import connection from django.db.models import Index from django.db.models.deletion import CASCADE from django.db.models.fields.related import ForeignKey from django.db.models.query_utils import Q from django.test import ( TestCase, Transaction...
b5733c4381fcdc7402fa454de8a47f946dc411efe124158ce2a5a7c816a1a80e
from django.db import connection, models class CurrentTranslation(models.ForeignObject): """ Creates virtual relation to the translation with model cache enabled. """ # Avoid validation requires_unique_target = False def __init__(self, to, on_delete, from_fields, to_fields, **kwargs): ...
000a050cd41cc25ba44e956b999ad5b7ba5bd69003f6c0ab3864a9404c9aa029
""" Tests for Django's bundled context processors. """ from django.test import SimpleTestCase, TestCase, override_settings @override_settings( ROOT_URLCONF='context_processors.urls', TEMPLATES=[{ 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'APP_DIRS': True, 'OPTIONS':...
6aff79751ec14568fb80ef7ae9fa97ed3ab48c2f67dc95ac5830cca1ba85077a
from django.urls import path from . import views urlpatterns = [ path('request_attrs/', views.request_processor), path('debug/', views.debug_processor), ]
9e2b897cdb502f1281db3ecb375cf7ad4b68a07367c84125f40b7b355b0d6ada
from datetime import datetime from operator import attrgetter from django.db import IntegrityError from django.test import TestCase from .models import ( CustomMembership, Employee, Event, Friendship, Group, Ingredient, Invitation, Membership, Person, PersonSelfRefM2M, Recipe, RecipeIngredient, Relationsh...
98024282de79fd4196d41b730907be0554f8c0e64bdb1d533fa237e6e0c79451
from datetime import datetime from django.db import models # M2M described on one of the models class Person(models.Model): name = models.CharField(max_length=128) class Meta: ordering = ('name',) def __str__(self): return self.name class Group(models.Model): name = models.CharFie...
36f2ed193102cee7b0ad08859e2eec15fc9d071f00f3ceec2388be0c73e70403
import datetime import re from datetime import date from decimal import Decimal from django import forms from django.core.exceptions import ImproperlyConfigured, ValidationError from django.db import models from django.forms.models import ( BaseModelFormSet, _get_foreign_key, inlineformset_factory, modelformse...
4993387302756672ea4c5bde6e20491e1c6a4ab24a74987ed7b42c8e4d3b1b23
import datetime import uuid from django.db import models class Author(models.Model): name = models.CharField(max_length=100) class Meta: ordering = ('name',) def __str__(self): return self.name class BetterAuthor(Author): write_speed = models.IntegerField() class Book(models.Mod...
f9be2f5d24f52091b3ea63d4e9c9393a0edd26622830b7b38fc5723bf11cc771
import datetime from copy import deepcopy from django.core.exceptions import FieldError, MultipleObjectsReturned from django.db import models, transaction from django.db.utils import IntegrityError from django.test import TestCase from django.utils.translation import gettext_lazy from .models import ( Article, Ca...
7467524389d57be996fc1c2c6c4c307e1ae7082909c1b06f5bebb41b7ea410ea
""" Many-to-one relationships To define a many-to-one relationship, use ``ForeignKey()``. """ from django.db import models class Reporter(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) email = models.EmailField() def __str__(self): ret...
2dafa66d96ce6dc8dacd0ff45a553e55c9c70efcc1e848803fb2c4685df48cbe
import base64 import os import shutil import string import tempfile import unittest from datetime import timedelta from http import cookies from django.conf import settings from django.contrib.sessions.backends.base import UpdateError from django.contrib.sessions.backends.cache import SessionStore as CacheSession from...
8b2a10b2520c0312a186428b4ba127e224b6133f2c782f656ef5b6cec215fe72
""" This custom Session model adds an extra column to store an account ID. In real-world applications, it gives you the option of querying the database for all active sessions for a particular account. """ from django.contrib.sessions.backends.db import SessionStore as DBStore from django.contrib.sessions.base_session ...
bf9941616c822e8f8f333fb6408de27ea83d6a2c90ef2f4e453509072f5aa5fd
from unittest import mock from urllib.parse import urlencode from django.contrib.sitemaps import ( SitemapNotFound, _get_sitemap_full_url, ping_google, ) from django.core.exceptions import ImproperlyConfigured from django.test import modify_settings, override_settings from .base import SitemapTestsBase class Pi...
3b061518785df35f9efbefec83801f55b993b625b660e5c671fe1a649167c577
from unittest import mock from django.core.management import call_command from .base import SitemapTestsBase @mock.patch('django.contrib.sitemaps.management.commands.ping_google.ping_google') class PingGoogleTests(SitemapTestsBase): def test_default(self, ping_google_func): call_command('ping_google') ...
2d1739dbe26d36b35f30a9727c71973f5aac8676b38852f046c2928a729ea2b0
from django.apps import apps from django.contrib.sites.models import Site from django.core.cache import cache from django.test import TestCase, modify_settings, override_settings from .models import I18nTestModel, TestModel @modify_settings(INSTALLED_APPS={'append': 'django.contrib.sitemaps'}) @override_settings(ROO...
244dac3a31be6fcb5b373f18d8a27fb55fd6fefa55457ec537cf879d9bf3cb4d
import os from datetime import date from unittest import skipUnless from django.conf import settings from django.contrib.sitemaps import Sitemap from django.contrib.sites.models import Site from django.core.exceptions import ImproperlyConfigured from django.test import modify_settings, override_settings from django.ut...
a1993eedf601443c14d9bf1ce162b79db282b8fe8afa9005e5a22ad4ca58c009
"""Tests for django.db.utils.""" import unittest from django.core.exceptions import ImproperlyConfigured from django.db import DEFAULT_DB_ALIAS, connection from django.db.utils import ConnectionHandler, ProgrammingError, load_backend from django.test import SimpleTestCase, TestCase class ConnectionHandlerTests(Simpl...
859bcf6f5d93db6cc405b624518bc0d697d8fc78405266023a3b7901c1e675c4
import datetime from django.db import connection, models, transaction from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature from .models import ( Award, AwardNote, Book, Child, Contact, Eaten, Email, File, Food, FooFile, FooFileProxy, FooImage, FooPhoto, House, Image, Item, Location, Logi...
6fb0c32189694ccb88b25501eada380326d63ce66ac08533331cf2a7ddaee5a3
""" Testing using the Test Client The test client is a class that can act like a simple browser for testing purposes. It allows the user to compose GET and POST requests, and obtain the response that the server gave to those requests. The server Response objects are annotated with the details of the contexts and temp...
2db50f839bf7962019b93abcd9db0572b0f8eb3fc06b38408573a9136fe78fdc
from django.test import SimpleTestCase from django.test.client import FakePayload class FakePayloadTests(SimpleTestCase): def test_write_after_read(self): payload = FakePayload() payload.read() msg = "Unable to write a payload after it's been read" with self.assertRaisesMessage(Val...
6f25522ec5c8e15232290b0657d7cb08708d9f1e8b0f99a2f6e6164f16e52947
from django.contrib.auth import views as auth_views from django.urls import path from django.views.generic import RedirectView from . import views urlpatterns = [ path('upload_view/', views.upload_view, name='upload_view'), path('get_view/', views.get_view, name='get_view'), path('post_view/', views.post_...
c2d78324e7e47b6c12b9684835fa1e8feb3ce80cdee5f56bf02c36a95b91e7f7
import json from urllib.parse import urlencode from xml.dom.minidom import parseString from django.contrib.auth.decorators import login_required, permission_required from django.core import mail from django.forms import fields from django.forms.forms import Form, ValidationError from django.forms.formsets import BaseF...
0a5e89848f45e4050bd3082ae8c89334fb0ecbd05ca57c2be17cccf9aff1af29
from django.core.exceptions import PermissionDenied from django.template.response import TemplateResponse from django.test import SimpleTestCase, modify_settings, override_settings from django.urls import path class MiddlewareAccessingContent: def __init__(self, get_response): self.get_response = get_resp...
94d6fa09ba8562e979eead76d3f79dd8e1c9813fd5f6e20755ff6eb9694f3a69
from django.core.exceptions import ImproperlyConfigured from django.core.handlers.wsgi import WSGIHandler, WSGIRequest, get_script_name from django.core.signals import request_finished, request_started from django.db import close_old_connections, connection from django.test import ( RequestFactory, SimpleTestCase, ...
4703d953445f1a03a7da51f0d7fb8b51b63dbc5f60a8643d183a8660917c7962
from django.urls import path from . import views urlpatterns = [ path('regular/', views.regular), path('no_response_fbv/', views.no_response), path('no_response_cbv/', views.NoResponse()), path('streaming/', views.streaming), path('in_transaction/', views.in_transaction), path('not_in_transact...
6313b461527e994d506e8d702a0c0fca26ca33e206bb5576f7574bbbbcdf9fb0
from http import HTTPStatus from django.core.exceptions import SuspiciousOperation from django.db import connection, transaction from django.http import HttpResponse, StreamingHttpResponse from django.views.decorators.csrf import csrf_exempt def regular(request): return HttpResponse(b"regular content") def no_...
67a2aaf983cf6994823e31b233096644eb27466678c3b9f8cedef8e562f31602
from django.core.exceptions import ImproperlyConfigured from django.core.servers.basehttp import get_internal_wsgi_application from django.core.signals import request_started from django.core.wsgi import get_wsgi_application from django.db import close_old_connections from django.test import SimpleTestCase, override_se...
cd9b4bcec982e93a3d5a827d655f37d6dd40a736eba95bcd4a83fa2918f6eec6
from django.http import FileResponse, HttpResponse from django.urls import path def helloworld(request): return HttpResponse("Hello World!") urlpatterns = [ path('', helloworld), path('file/', lambda x: FileResponse(open(__file__, 'rb'))), ]
58421e049c4055e57b16b0e67173608c21c83a0f7bf92e21c46b265a556ec912
"""Tests related to django.db.backends that haven't been organized.""" import datetime import threading import unittest import warnings from django.core.management.color import no_style from django.db import ( DEFAULT_DB_ALIAS, DatabaseError, IntegrityError, connection, connections, reset_queries, transaction,...
e7e405af5907acc3e814f1de2b007a0f17e5308ff07b1c3a8f593d83b7c01bdd
from django.db import models from django.template import Context, Template from django.test import SimpleTestCase, TestCase, override_settings from django.test.utils import isolate_apps from .models import ( AbstractBase1, AbstractBase2, AbstractBase3, Child1, Child2, Child3, Child4, Child5, Child6, Child7, Re...
91994522daa20642d5f33984b212aa75ce5b523e15817499cd9e5c97c69d153c
import datetime import itertools import unittest from copy import copy from unittest import mock from django.core.management.color import no_style from django.db import ( DatabaseError, IntegrityError, OperationalError, connection, ) from django.db.models import Model, Q from django.db.models.constraints import Ch...
364a8cbd6c1f6a97845782ad0c1ad24c347489db1dfe4f5e483f97248d26c7f3
from django.apps.registry import Apps from django.db import models # Because we want to test creation and deletion of these as separate things, # these models are all inserted into a separate Apps so the main test # runner doesn't migrate them. new_apps = Apps() class Author(models.Model): name = models.CharFie...
61b54736ca1bbc3c775db559f9cdbee393b2a9f876357f8d8ae1b8eedaf3a70b
from django.contrib.admin import ModelAdmin, TabularInline from django.contrib.admin.helpers import InlineAdminForm from django.contrib.admin.tests import AdminSeleniumTestCase from django.contrib.auth.models import Permission, User from django.contrib.contenttypes.models import ContentType from django.test import Requ...
03a804b340a8c37ce056b018faad8825bea51b16312a8e3b12f2d4267677097c
""" Testing of admin inline formsets. """ import random from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType from django.db import models class Parent(models.Model): name = models.CharField(max_length=50) def __str__(self): retur...
11702e38be38b9ebbbbe80e819484234d2e6e2cec1d6633ab04d3b639bdad041
from django import forms from django.contrib import admin from django.db import models from .models import ( Author, BinaryTree, CapoFamiglia, Chapter, Child, ChildModel1, ChildModel2, Consigliere, EditablePKBook, ExtraTerrestrial, Fashionista, FootNote, Holder, Holder2, Holder3, Holder4, Inner, Inner2, In...
5a3f53bebbf2ccf0813ea214d1a0e06871b7313abfb33ffd03db92013432642d
from django.urls import path from . import admin urlpatterns = [ path('admin/', admin.site.urls), ]
ca98df78a1cdf473b39195f030711009901326b98a26197e16759968141828e5
from django.db import connection from django.db.models import Max from django.test import TestCase from .models import Cash, CashModel class FromDBValueTest(TestCase): @classmethod def setUpTestData(cls): CashModel.objects.create(cash='12.50') def test_simple_load(self): instance = CashM...
29ed9c398331612b83692211d421c0df3412d17281b171e2f5018b6f7fa0e022
import decimal from django.db import models class Cash(decimal.Decimal): currency = 'USD' def __str__(self): s = super().__str__(self) return '%s %s' % (s, self.currency) class CashField(models.DecimalField): def __init__(self, **kwargs): kwargs['max_digits'] = 20 kwarg...
63708f94dd0ba1463f320a388606b43aabb6dd7060a796bd48a0f092591866c2
from django.core import checks from django.core.checks import Error from django.db import models from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature from django.test.utils import ( isolate_apps, modify_settings, override_system_checks, ) @isolate_apps('check_framework', attr_name='apps') @overri...
9458c9a67a055589d2fbf7f3fc738f9dd68834d0354dca72100c20122e4eff18
from unittest import mock from django.db import connections, models from django.test import SimpleTestCase from django.test.utils import isolate_apps, override_settings class TestRouter: """ Routes to the 'other' database if the model name starts with 'Other'. """ def allow_migrate(self, db, app_labe...
372bf8c47e7e74ca69a8a9340abbb17c5c20d18347b4aac7b8f717aafd190bb6
from django.core.checks import Error from django.core.checks.translation import ( check_language_settings_consistent, check_setting_language_code, check_setting_languages, check_setting_languages_bidi, ) from django.test import SimpleTestCase class TranslationCheckTests(SimpleTestCase): def setUp(self): ...
f02ac64d927cbcbe8f8cec40e1c109d9f72ab90c5e93218ec016ae927915d113
from django.conf import settings from django.core.checks.messages import Error, Warning from django.core.checks.urls import ( E006, check_url_config, check_url_namespaces_unique, check_url_settings, get_warning_for_invalid_pattern, ) from django.test import SimpleTestCase from django.test.utils import override_...
b0c4e821f7c9640f0c4399a26d409738fb165adcd34c121f97d051b0ff2451f5
import unittest from unittest import mock from django.core.checks import Tags, run_checks from django.core.checks.registry import CheckRegistry from django.db import connection from django.test import TestCase class DatabaseCheckTests(TestCase): databases = {'default', 'other'} @property def func(self):...
fea378d0da0342d9cc3680f80f9ba1138ccfee61577a8cec511f5ff72bbfc633
import datetime from decimal import Decimal from django.contrib.humanize.templatetags import humanize from django.template import Context, Template, defaultfilters from django.test import SimpleTestCase, modify_settings, override_settings from django.utils import translation from django.utils.html import escape from d...
d34c49274d640f2eae1757325f9e2c9ad562ee9472a00bd002fbde0c920b5f1e
from functools import update_wrapper, wraps from unittest import TestCase 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 HttpRequest, HttpResponse, HttpResponseNotA...
ca808f9570f718fc2a01b59c4680152aed489bd7cddb7343c51c415ec3367202
import datetime from django.contrib.auth.models import User from django.test import TestCase from .models import Order, RevisionableModel, TestObject class ExtraRegressTests(TestCase): @classmethod def setUpTestData(cls): cls.u = User.objects.create_user( username="fred", pa...
fa9d7f447873a561a352484e4e32aec81944ff0039435c69f57d3b10680bad56
from functools import update_wrapper from django.contrib import admin from django.db import models from django.http import HttpResponseRedirect from django.urls import reverse class Action(models.Model): name = models.CharField(max_length=50, primary_key=True) description = models.CharField(max_length=70) ...
e23ed2a101a660daba64e60ab1da38ceb0f63a7e301e671478087b65198927af
from django.urls import path from .models import site urlpatterns = [ path('admin/', site.urls), ]
cd977c0d71497a6d7d82e8d07970c9321b59679482f68ad0be0b6af8d74411f3
import os import shutil import tempfile from django import conf from django.test import SimpleTestCase from django.test.utils import extend_sys_path class TestStartProjectSettings(SimpleTestCase): def setUp(self): self.temp_dir = tempfile.TemporaryDirectory() self.addCleanup(self.temp_dir.cleanup...
de3adf972889b06a974ca5d0f559e71121ebc01a2e9981fa51d9693cfd16f75f
from django.urls import path from . import views urlpatterns = [ path('empty/', views.empty_view), ]
7ec60849512b8fd3b1ca519b9f2e725482a8cb94fe219c39187c4829d2a78505
from django.urls import path from . import views urlpatterns = [ path('condition/', views.index), path('condition/last_modified/', views.last_modified_view1), path('condition/last_modified2/', views.last_modified_view2), path('condition/etag/', views.etag_view1), path('condition/etag2/', views.eta...
1dbb951c18955dc7dd30efc5b201f822ff8678e665eff4146b831b6fececbf33
""" A series of tests to establish that the command-line management tools work as advertised - especially with regards to the handling of the DJANGO_SETTINGS_MODULE and default settings.py files. """ import os import re import shutil import socket import subprocess import sys import tempfile import unittest from io imp...
ecf695ac54255693a5f0e0f88603a1aa82e9f8cfb507c7cc1a1e550602a4515b
#!/usr/bin/env python import sys from django.conf import settings from django.core.management import execute_from_command_line if __name__ == '__main__': settings.configure(DEBUG=True, CUSTOM=1) execute_from_command_line(sys.argv)
98c9e04667f47210cfff4800175bf7e3084fa5ceb043496888180f93f25c735f
import os from django.urls import path from django.views.static import serve here = os.path.dirname(__file__) urlpatterns = [ path('custom_templates/<path:path>', serve, { 'document_root': os.path.join(here, 'custom_templates')}), ]
c0741a5917d319f845dd9af4b6582592d16fcb7c105420acf310c34410fbe326
#!/usr/bin/env python import sys from django.conf import global_settings, settings from django.core.management import execute_from_command_line class Settings: def __getattr__(self, name): if name == 'FOO': return 'bar' return getattr(global_settings, name) def __dir__(self): ...
c86f082bf6f08b249752a0964c7b0702e395aec2c478d708260663696928da57
from django.conf import settings from django.contrib.redirects.middleware import RedirectFallbackMiddleware from django.contrib.redirects.models import Redirect from django.contrib.sites.models import Site from django.core.exceptions import ImproperlyConfigured from django.http import HttpResponseForbidden, HttpRespons...
e2b25f2854bba4c55d5d3d7421fe632e35a03b9500c5cb579a8886c6d94c90cc
from django.http import HttpResponse from django.urls import path urlpatterns = [ path('', lambda req: HttpResponse('OK')), ]
0df1c5a5758041588ca179cd1d5c13abe65700afd0107f765a6dd427c11c4765
from operator import attrgetter from django.db import IntegrityError, NotSupportedError, connection from django.db.models import FileField, Value from django.db.models.functions import Lower from django.test import ( TestCase, override_settings, skipIfDBFeature, skipUnlessDBFeature, ) from .models import ( Co...
9e111f01d9e0ef8fe15e2ed50a4c82be83f5ee28ca99db05d3cdf747a7cbec47
import datetime from unittest import mock, skipIf, skipUnless from django.core.exceptions import FieldError from django.db import NotSupportedError, connection from django.db.models import ( F, OuterRef, RowRange, Subquery, Value, ValueRange, Window, WindowFrame, ) from django.db.models.aggregates import Avg, Max,...
de07deec62917a6721fda6034d2e3b994d740abd257a1eda843de268d465e3c3
from django.db import models class Employee(models.Model): name = models.CharField(max_length=40, blank=False, null=False) salary = models.PositiveIntegerField() department = models.CharField(max_length=40, blank=False, null=False) hire_date = models.DateField(blank=False, null=False) age = models...
2a31d25ee24154cb2faebf7ce0af7cbd403613959e7b8fb453ecedac7a50560a
from datetime import datetime from operator import attrgetter from django.core.exceptions import FieldError from django.db.models import ( CharField, Count, DateTimeField, F, Max, OuterRef, Subquery, Value, ) from django.db.models.functions import Upper from django.test import TestCase from django.utils.deprecatio...
85623074ea8b56666ce40afc8c98f2caafdcfcd76729a94f495fb49ea3b77bbd
""" Specifying ordering Specify default ordering for a model using the ``ordering`` attribute, which should be a list or tuple of field names. This tells Django how to order ``QuerySet`` results. If a field name in ``ordering`` starts with a hyphen, that field will be ordered in descending order. Otherwise, it'll be ...
8569312386a91c12111c45420747f596060a61324ed95e2a84ae4b668ecc9e16
import warnings from django.test import SimpleTestCase from django.utils.deprecation import ( DeprecationInstanceCheck, RemovedInNextVersionWarning, RenameMethodsBase, ) class RenameManagerMethods(RenameMethodsBase): renamed_methods = ( ('old', 'new', DeprecationWarning), ) class RenameMethodsT...
f480d6e2e3db6d6c1b43dd917dd712866a1433d9347e83905534ad6eafbbb4a4
import base64 import hashlib import os import shutil import sys import tempfile as sys_tempfile import unittest from io import BytesIO, StringIO from urllib.parse import quote from django.core.files import temp as tempfile from django.core.files.uploadedfile import SimpleUploadedFile from django.http.multipartparser i...
8d285a42a9acc55cbccae06b9c2287b60b41d07e7e71b3d143e87f8fccbc44ff
from django.urls import path, re_path from . import views urlpatterns = [ path('upload/', views.file_upload_view), path('verify/', views.file_upload_view_verify), path('unicode_name/', views.file_upload_unicode_name), path('echo/', views.file_upload_echo), path('echo_content_type_extra/', views.fi...
709738464b09354b42c52ee800e6d7417b69574ed74d22a0f52876eb5590275a
import hashlib import os from django.core.files.uploadedfile import UploadedFile from django.http import HttpResponse, HttpResponseServerError, JsonResponse from .models import FileModel from .tests import UNICODE_FILENAME, UPLOAD_TO from .uploadhandler import ErroringUploadHandler, QuotaUploadHandler def file_uplo...
7fc2e55e18f8924906dfa90138c4922b5afc5eeeffe169c31549604881b6a035
from django.contrib.flatpages.sitemaps import FlatPageSitemap from django.contrib.sitemaps import views from django.urls import include, path urlpatterns = [ path( 'flatpages/sitemap.xml', views.sitemap, {'sitemaps': {'flatpages': FlatPageSitemap}}, name='django.contrib.sitemaps.views.sitem...
ca95efe9c3ab847af6248f01a8ee47c61c28f9bf4be788c67c882e740b981679
from django.conf import settings from django.contrib.flatpages.forms import FlatpageForm from django.contrib.flatpages.models import FlatPage from django.contrib.sites.models import Site from django.test import TestCase, modify_settings, override_settings from django.utils import translation @modify_settings(INSTALLE...
4469abc0b70df6db40d3f8dbc5fc1cdf7e938973f6d7bd592ea3d37d4d56251d
import datetime import os from decimal import Decimal from unittest import mock, skipUnless from django import forms from django.core.exceptions import ( NON_FIELD_ERRORS, FieldError, ImproperlyConfigured, ) from django.core.files.uploadedfile import SimpleUploadedFile from django.core.validators import Validation...
072c0b9961cabba9792837e076666e5c085950249ff72f8518152c3ecb930aee
import datetime import os import tempfile import uuid from django.core import validators from django.core.exceptions import ValidationError from django.core.files.storage import FileSystemStorage from django.db import models temp_storage_dir = tempfile.mkdtemp() temp_storage = FileSystemStorage(temp_storage_dir) cl...
b07e1fdaefc2fee16ed0feac2b8210836cb279be5267ad8d3e90c154e5853462
from django.db.models import CharField, Max from django.db.models.functions import Lower from django.test import TestCase, skipUnlessDBFeature from django.test.utils import register_lookup from .models import Celebrity, Fan, Staff, StaffTag, Tag @skipUnlessDBFeature('can_distinct_on_fields') @skipUnlessDBFeature('su...
04a657a19f23defdbc236cc9f50045fef8b02d5c7364bc1aec39bffe0b154e96
""" Distance and Area objects to allow for sensible and convenient calculation and conversions. Here are some tests. """ import unittest from django.contrib.gis.measure import A, Area, D, Distance class DistanceTest(unittest.TestCase): "Testing the Distance object" def test_init(self): "Testing ini...
0e8a81474927aa17f17ff7bb86de99550ab82322ffa0dd40e30dbc1adba32fd2
import unittest from django.core.exceptions import ImproperlyConfigured from django.db import ProgrammingError try: from django.contrib.gis.db.backends.postgis.operations import PostGISOperations HAS_POSTGRES = True except ImportError: HAS_POSTGRES = False if HAS_POSTGRES: class FakeConnection: ...
a93fa152d76cd5bc52d9794d070a2574d70558cf51d76edfe3e46d28b72d5075
import os from unittest import mock, skipUnless from django.conf import settings from django.contrib.gis.geoip2 import HAS_GEOIP2 from django.contrib.gis.geos import GEOSGeometry from django.test import SimpleTestCase if HAS_GEOIP2: from django.contrib.gis.geoip2 import GeoIP2, GeoIP2Exception # Note: Requires ...