hash stringlengths 64 64 | content stringlengths 0 1.51M |
|---|---|
b6c7b36bbcae00b0100ddd89052930d9c14a3d757fdb6f6426869e3a5f2bc767 | 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... |
84283903fe0ba760b19de0398de47f5476d2a0e3238be881c0ad97f5c4f8b4b3 | from django.db import models
class FileModel(models.Model):
testfile = models.FileField(upload_to='test_upload')
|
707e8597a86b14636a5632953f4ce21f1ccd51424ca41196ee8f80b5fcfe3ec2 | """
Upload handlers to test the upload API.
"""
from django.core.files.uploadhandler import FileUploadHandler, StopUpload
class QuotaUploadHandler(FileUploadHandler):
"""
This test upload handler terminates the connection if more than a quota
(5MB) is uploaded.
"""
QUOTA = 5 * 2 ** 20 # 5 MB
... |
e35d11a2ca264c775ce9af2039dd1d574c7a736204fee591b80942bd2cee158f | from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^upload/$', views.file_upload_view),
url(r'^verify/$', views.file_upload_view_verify),
url(r'^unicode_name/$', views.file_upload_unicode_name),
url(r'^echo/$', views.file_upload_echo),
url(r'^echo_content_type_extra/$', vie... |
fda1194c14d5495c8f1c319c3d037fd1712016e5e21daad0264b42e8c78857af | 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... |
2151a50ff625b42559745fe0e7cded84bae2aab3391236fdf706b6102ac2a76a | from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.flatpages.models import FlatPage
from django.contrib.sites.models import Site
from django.test import TestCase, modify_settings, override_settings
from .settings import FLATPAGES_TEMPLATES
class TestDataMixin:
@clas... |
9639d700ca2bf9b4a09eb4eb9bcd22747c4c1221a9c1fdd361c4d9324dc34bcd | from django.contrib.flatpages.models import FlatPage
from django.test import SimpleTestCase
from django.test.utils import override_script_prefix
class FlatpageModelTests(SimpleTestCase):
def setUp(self):
self.page = FlatPage(title='Café!', url='/café/')
def test_get_absolute_url_urlencodes(self):
... |
b665b7e045fe737001ad8be210b8bc319c941c95c5e08c6daf00eaf0a583e4b5 | from django.contrib.auth.models import User
from django.contrib.flatpages.models import FlatPage
from django.contrib.sites.models import Site
from django.test import Client, TestCase, modify_settings, override_settings
from .settings import FLATPAGES_TEMPLATES
@modify_settings(INSTALLED_APPS={'append': 'django.contr... |
17b4c0c185cff512d902c5db21c081b047f12a874224d0ebcd4a3f8f292c97c7 | from django.conf.urls import include, url
from django.contrib.flatpages.sitemaps import FlatPageSitemap
from django.contrib.sitemaps import views
# special urls for flatpage test cases
urlpatterns = [
url(r'^flatpages/sitemap\.xml$', views.sitemap,
{'sitemaps': {'flatpages': FlatPageSitemap}},
name... |
c3d01ac9fdf29e92a9aac86a6f648718cdc366a3f2655533514fbf5638497547 | import os
FLATPAGES_TEMPLATES = [{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(os.path.dirname(__file__), 'templates')],
'OPTIONS': {
'context_processors': (
'django.contrib.auth.context_processors.auth',
),
},
}]
|
2237edfae84590de662979325d7970541a185c752084154eb7a5baed9342a570 | 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... |
b93aa61d3369cad2f4fa0e30a250fa811bac464a4603f97b5fdc75704e545aba | from django.apps import apps
from django.contrib.sites.models import Site
from django.test import TestCase
from django.test.utils import modify_settings, override_settings
@override_settings(
ROOT_URLCONF='flatpages_tests.urls',
SITE_ID=1,
)
@modify_settings(
INSTALLED_APPS={
'append': ['django.co... |
00055887a70713fb61fcab727064bf3eb500ba406df00e1f4a79431dd2d6ce26 | from django.contrib.auth.models import AnonymousUser, User
from django.contrib.flatpages.models import FlatPage
from django.contrib.sites.models import Site
from django.template import Context, Template, TemplateSyntaxError
from django.test import TestCase
class FlatpageTemplateTagTests(TestCase):
@classmethod
... |
b74029c4cc92a95aac4551fdfd19584606906636eb4b91aca712828f7d5f18b5 | from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.flatpages.models import FlatPage
from django.contrib.sites.models import Site
from django.test import TestCase, modify_settings, override_settings
from .settings import FLATPAGES_TEMPLATES
class TestDataMixin:
@clas... |
fe2a0fd6cab92f6c056ea2a0196e50d05940299b931360ba9289b837ed9dc901 | from datetime import datetime
from django.test import TestCase
from .models import Article, Reporter, Writer
class M2MIntermediaryTests(TestCase):
def test_intermeiary(self):
r1 = Reporter.objects.create(first_name="John", last_name="Smith")
r2 = Reporter.objects.create(first_name="Jane", last_n... |
e3ae68653c486057b550d6fcbc7876a2a8b912492e941b738822ff5330afc087 | """
Many-to-many relationships via an intermediary table
For many-to-many relationships that need extra fields on the intermediary
table, use an intermediary model.
In this example, an ``Article`` can have multiple ``Reporter`` objects, and
each ``Article``-``Reporter`` combination (a ``Writer``) has a ``position``
f... |
6726dc1fb74e31cf414c8a95c66c21121a083f862a531c7eb31892b72382e59f | import os
from django.apps import apps
from django.test import SimpleTestCase
from django.test.utils import extend_sys_path
class EggLoadingTest(SimpleTestCase):
def setUp(self):
self.egg_dir = '%s/eggs' % os.path.dirname(__file__)
def tearDown(self):
apps.clear_cache()
def test_egg1(s... |
e90427b179931455c6319075b308379663c86b01092f0f25452f2761a588c879 | import datetime
from django import forms
from django.core.validators import ValidationError
from django.forms.models import ModelChoiceIterator
from django.forms.widgets import CheckboxSelectMultiple
from django.template import Context, Template
from django.test import TestCase
from .models import Article, Author, Bo... |
80127fb9bb5cff2dbfe38418eb07685a5a23947200be4a8e71e2545df0c56465 | 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... |
7ae2776e5f1fe52a713ac8d9dc43c8a60c741b5fcfce78789a22327f12281b6c | 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)
ART... |
bd2d74c317b9fd341727f037f4f6c2f075c889057769c9afb0e4d1c43786fcb5 | from django import forms
from django.core.exceptions import ValidationError
from django.test import TestCase
from .models import UUIDPK
class UUIDPKForm(forms.ModelForm):
class Meta:
model = UUIDPK
fields = '__all__'
class ModelFormBaseTest(TestCase):
def test_create_save_error(self):
... |
df5ac6fddb979f0299e3514ec2c40e5f5f9b2921788c2618238521e08a86a706 | import datetime
from django.test import TestCase, skipIfDBFeature
from django.utils.timezone import utc
from .models import Donut, RumBaba
class DataTypesTestCase(TestCase):
def test_boolean_type(self):
d = Donut(name='Apple Fritter')
self.assertFalse(d.is_frosted)
self.assertIsNone(d.h... |
0c6a0fe7bc129b90b296a6b555d5183b76d2276f0080ef60352d9ea412ce4102 | """
This is a basic model to test saving and loading boolean and date-related
types, which in the past were problematic for some database backends.
"""
from django.db import models
class Donut(models.Model):
name = models.CharField(max_length=100)
is_frosted = models.BooleanField(default=False)
has_sprin... |
9b7dc1f9a2e1568763c1da73d148fd56d690d43ffed91b64bdec9b9c72ed59e0 | from django.db.models import CharField, Max
from django.db.models.functions import Lower
from django.test import TestCase, skipUnlessDBFeature
from .models import Celebrity, Fan, Staff, StaffTag, Tag
@skipUnlessDBFeature('can_distinct_on_fields')
@skipUnlessDBFeature('supports_nullable_unique_constraints')
class Dis... |
ad1898643fd40dce75f4d356d23db7ae331fbdcdaf6b4d0020bf3538ed9d0a87 | from django.db import models
class Tag(models.Model):
name = models.CharField(max_length=10)
parent = models.ForeignKey(
'self',
models.SET_NULL,
blank=True,
null=True,
related_name='children',
)
class Meta:
ordering = ['name']
def __str__(self):
... |
b9808adf23c1a3ebdb131c5ad1202f8b04fbaa3cc6bf07782527966610e151a4 | import re
from django.test import TestCase, skipUnlessDBFeature
from .utils import SpatialRefSys, oracle, postgis, spatialite
test_srs = ({
'srid': 4326,
'auth_name': ('EPSG', True),
'auth_srid': 4326,
# Only the beginning, because there are differences depending on installed libs
'srtext': 'GEOG... |
80cc62177aa9d47b2fbbaeee385a8cb342ee1bbd927328fa63eacf3cfe087b08 | """
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 testInit(self):
"Testing init... |
0a122b57d67e9ddf237f27fed5131b7f89ad1fd0ad92fa1f9c24a871ca2de5f4 | 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:
... |
ce76f25779310f42e16a33c5d2480afcafa1c0f66c6b25489152034efbcbce85 | 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 ... |
bf8eb80e5cb25f66a85545f6589ea95d81eabeb365a84c7317cf753ac4b3c6f4 | try:
from django.contrib.gis import admin
except ImportError:
from django.contrib import admin
admin.OSMGeoAdmin = admin.ModelAdmin
|
924583180f873ec09da7c353942aa21a3038cae89883679615e524c39bb4d3c0 | import copy
from django.contrib.gis.db.models.sql import AreaField, DistanceField
from django.test import SimpleTestCase
class FieldsTests(SimpleTestCase):
def test_area_field_deepcopy(self):
field = AreaField(None)
self.assertEqual(copy.deepcopy(field), field)
def test_distance_field_deepc... |
a92d302137636117f957b9bff173f2f45b796bc974436fa4d62249074620aed3 | from django.db import connection, models
from django.db.models.expressions import Func
from django.test import SimpleTestCase
from .utils import FuncTestMixin
def test_mutation(raises=True):
def wrapper(mutation_func):
def test(test_case_instance, *args, **kwargs):
class TestFunc(Func):
... |
b0d59bf3d014154eb61115f5a5912788233d9393b3a6b41710f2fc8ee422bb04 | import ctypes
from unittest import mock
from django.contrib.gis.ptr import CPointerBase
from django.test import SimpleTestCase
class CPointerBaseTests(SimpleTestCase):
def test(self):
destructor_mock = mock.Mock()
class NullPointerException(Exception):
pass
class FakeGeom1(... |
9c37158f1a065148d74cb27ddb97448c0c8b51cf16c231b31b1ed80285203b14 | import copy
import unittest
from functools import wraps
from unittest import mock
from django.conf import settings
from django.db import DEFAULT_DB_ALIAS, connection
from django.db.models.expressions import Func
def skipUnlessGISLookup(*gis_lookups):
"""
Skip a test unless a database supports all of gis_look... |
24fb222a74574b8e82a87a41bf1c1e69933b796e973bbe22f2b85f20fc6c3b54 | """
This module has the mock object definitions used to hold reference geometry
for the GEOS and GDAL tests.
"""
import json
import os
from django.utils.functional import cached_property
# Path where reference test data is located.
TEST_DATA = os.path.join(os.path.dirname(__file__), 'data')
def tuplize(seq):
"T... |
a3d23efa8766d71892d967af7c1ad03d56027a0b1714d045c144403b5b7d3d92 | import re
from django.contrib.gis import forms
from django.contrib.gis.forms import BaseGeometryWidget, OpenLayersWidget
from django.contrib.gis.geos import GEOSGeometry
from django.forms import ValidationError
from django.test import SimpleTestCase, override_settings
from django.utils.html import escape
class Geome... |
75a66754e3f76376cf75f5d4dae788facb30762134c223d4cd0fcba3047706d3 | import datetime
from django.test import TestCase, override_settings
from django.utils import timezone
from .models import Article, Category, Comment
class DateTimesTests(TestCase):
def test_related_model_traverse(self):
a1 = Article.objects.create(
title="First one",
pub_date=dat... |
aa97c3f6859041e9bde6813115a2890547f46c45edf739fbce7b1cc55b8fcf76 | from django.db import models
class Article(models.Model):
title = models.CharField(max_length=100)
pub_date = models.DateTimeField()
published_on = models.DateField(null=True)
categories = models.ManyToManyField("Category", related_name="articles")
def __str__(self):
return self.title
... |
eb4ee2a539c04140cc7a63e239fa231787e9590d78d99540e80f3c521681228f | from django.db import DatabaseError, IntegrityError, transaction
from django.test import TestCase
from .models import (
Counter, InheritedCounter, ProxyCounter, SubCounter, WithCustomPK,
)
class ForceTests(TestCase):
def test_force_update(self):
c = Counter.objects.create(name="one", value=1)
... |
0859c2f26369fd34bab9b772cb6a429589c2d520009bd18ba484c663534d40b7 | """
Tests for forcing insert and update queries (instead of Django's normal
automatic behavior).
"""
from django.db import models
class Counter(models.Model):
name = models.CharField(max_length=10)
value = models.IntegerField()
class InheritedCounter(Counter):
tag = models.CharField(max_length=10)
cla... |
ba2fae41f6df6fdd92b24c48208f8a55473b852cc17321b978be4278cf99e838 | from math import ceil
from django.db import IntegrityError, connection, models
from django.db.models.sql.constants import GET_ITERATOR_CHUNK_SIZE
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
from .models import (
MR, A, Avatar, Base, Child, HiddenUser, HiddenUserProfile, M, M2MFrom,
... |
3ffdf48e0c61f271457fea5fb64f8ec463c2a749bf32fa762c54ad8aa75260bb | from django.db import models
class R(models.Model):
is_default = models.BooleanField(default=False)
def __str__(self):
return "%s" % self.pk
def get_default_r():
return R.objects.get_or_create(is_default=True)[0].pk
class S(models.Model):
r = models.ForeignKey(R, models.CASCADE)
class T... |
e076a5b61b99c3b275154a9c286e288f744d675148b6d3ff03a25a7bd6c78faa | from django.contrib import admin
from django.contrib.auth.models import User as AuthUser
from django.contrib.contenttypes.models import ContentType
from django.core import checks, management
from django.db import DEFAULT_DB_ALIAS, models
from django.db.models import signals
from django.test import TestCase, override_se... |
6b85d0fcf34a520688c0ecf3d52fc2f899aecf579d635f3fa9d4675c949e820d | """
By specifying the 'proxy' Meta attribute, model subclasses can specify that
they will take data directly from the table of their base class table rather
than using a new table of their own. This allows them to act as simple proxies,
providing a modified interface to the data from the base class.
"""
from django.db ... |
d958b08a98bfe90cff086fd6619267d2117159a8abdac87bb67e540b813c7eee | from django.contrib import admin
from .models import ProxyTrackerUser, TrackerUser
site = admin.AdminSite(name='admin_proxy')
site.register(TrackerUser)
site.register(ProxyTrackerUser)
|
1fb37a9860cd6d541872df03d200169166b1647fdd1842ea3d529761e78bf9ec | from django.conf.urls import url
from .admin import site
urlpatterns = [
url(r'^admin/', site.urls),
]
|
60c333737f2b225db667468d123f80ea5ed96f16445fda04c37426bdf7c4c05f | from django.core.checks import Error, Warning as DjangoWarning
from django.db import models
from django.db.models.fields.related import ForeignObject
from django.test.testcases import SimpleTestCase, skipIfDBFeature
from django.test.utils import isolate_apps, override_settings
@isolate_apps('invalid_models_tests')
cl... |
72bd992ae853178b6d0fd20b695bfe2307e08f67161b1f405880f6404a9d863c | from unittest import mock
from django.core.checks import Error
from django.db import connections, models
from django.test import SimpleTestCase
from django.test.utils import isolate_apps
def dummy_allow_migrate(db, app_label, **hints):
# Prevent checks from being run on the 'other' database, which doesn't have
... |
37ca28bdd21bc6c718c316aa9dc25cc34124283687dbcb1f12c578ce148261c4 | import unittest
from django.conf import settings
from django.core.checks import Error
from django.core.checks.model_checks import _check_lazy_references
from django.core.exceptions import ImproperlyConfigured
from django.db import connections, models
from django.db.models.signals import post_init
from django.test impo... |
d62fe891926fff67051d3c6c28ab81336b78c5989d187668d7a71e267bcba6a8 | from django.db import models
from django.test import SimpleTestCase
from django.test.utils import isolate_apps
@isolate_apps('invalid_models_tests')
class CustomFieldTest(SimpleTestCase):
def test_none_column(self):
class NoColumnField(models.AutoField):
def db_type(self, connection):
... |
e7b0c5bbd78568c226ae3972059601e0000d5ef92f92c25f2a73407f2f07b44a | from django.core import checks
from django.db import models
from django.test import SimpleTestCase
from django.test.utils import isolate_apps
@isolate_apps('invalid_models_tests')
class DeprecatedFieldsTests(SimpleTestCase):
def test_IPAddressField_deprecated(self):
class IPAddressModel(models.Model):
... |
bb5e99588a931305b4ce0dbbb0c98703b1b9bb1b35d4baa0cff014404b55458a | import unittest
from django.core.checks import Error, Warning as DjangoWarning
from django.db import connection, models
from django.test import SimpleTestCase, TestCase, skipIfDBFeature
from django.test.utils import isolate_apps, override_settings
from django.utils.functional import lazy
from django.utils.timezone imp... |
e675e4a8e60e0acc7ad3ef4ce3192608a291378a55861a44a2c1d9b9a8056cce | from datetime import datetime
from operator import attrgetter
from django.db.models import Q
from django.test import TestCase
from .models import Article
class OrLookupsTests(TestCase):
def setUp(self):
self.a1 = Article.objects.create(
headline='Hello', pub_date=datetime(2005, 11, 27)
... |
5cb36693f40ffdc4f5c21ac235255c929b7db25f6732b54e54a3a04148d8478e | """
OR lookups
To perform an OR lookup, or a lookup that combines ANDs and ORs, combine
``QuerySet`` objects using ``&`` and ``|`` operators.
Alternatively, use positional arguments, and pass one or more expressions of
clauses using the variable ``django.db.models.Q``.
"""
from django.db import models
class Articl... |
35ef6ab037c65d6abae635463bf1703f9d6ef027da83afa89d0691d28af899bf | import asyncore
import base64
import mimetypes
import os
import shutil
import smtpd
import socket
import sys
import tempfile
import threading
from email import message_from_binary_file, message_from_bytes
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr
from io impo... |
7448a0a170bfaca02f8215a335538fa288220d5823ad3f827143946f7db8c9f5 | from django.core import mail
from django.core.management import call_command
from django.test import SimpleTestCase, override_settings
@override_settings(
ADMINS=(('Admin', 'admin@example.com'), ('Admin and Manager', 'admin_and_manager@example.com')),
MANAGERS=(('Manager', 'manager@example.com'), ('Admin and ... |
189d85aa70283c86f7083ae14b82e70e978df31460c2843c652c7f7e5ec3d8d9 | """A custom backend for testing."""
from django.core.mail.backends.base import BaseEmailBackend
class EmailBackend(BaseEmailBackend):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.test_outbox = []
def send_messages(self, email_messages):
# Messages are ... |
166f94877f0fa081118e87ee2a0545adfa96ddcb8e270505755dc0a9577b50b3 | from django.test import TestCase
from .models import Category, Person
class ManyToOneRecursiveTests(TestCase):
def setUp(self):
self.r = Category(id=None, name='Root category', parent=None)
self.r.save()
self.c = Category(id=None, name='Child category', parent=self.r)
self.c.save... |
2a2bd5fc004eef9fd665b7cc324a71f103731cb57be57a4497a8ef9d1c3cc13d | """
Relating an object to itself, many-to-one
To define a many-to-one relationship between a model and itself, use
``ForeignKey('self', ...)``.
In this example, a ``Category`` is related to itself. That is, each
``Category`` has a parent ``Category``.
Set ``related_name`` to designate what the reverse relationship i... |
01bc93ab3d402fd28f392a6a4108791f51b551acf7ebf16cec8a405ca1c3c318 | from datetime import date
from decimal import Decimal
from django.db.models.query import RawQuerySet
from django.db.models.query_utils import InvalidQuery
from django.test import TestCase, skipUnlessDBFeature
from .models import (
Author, Book, BookFkAsPk, Coffee, FriendlyAuthor, MixedCaseIDColumn,
Reviewer,
... |
8876f617778729f42397af640e323ffef966c5276a21e37e9ebc41858f2471bd | from django.db import models
class Author(models.Model):
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
dob = models.DateField()
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Protect against annotations being passe... |
523fb16ea653a7f4e95f59452ef66c0a3b80dbc132332fafbc849978a2e156e6 | import unittest
from django.core import validators
from django.core.exceptions import ValidationError
from django.db import IntegrityError, connection, models
from django.test import SimpleTestCase, TestCase
from .models import (
BigIntegerModel, IntegerModel, PositiveIntegerModel,
PositiveSmallIntegerModel, ... |
249cb0db8d3bcff9f3639009fbc2e9fca6647d53513835bb9c3df19b9acdb280 | import datetime
from decimal import Decimal
from django.db.models.fields import (
AutoField, BinaryField, BooleanField, CharField, DateField, DateTimeField,
DecimalField, EmailField, FilePathField, FloatField, GenericIPAddressField,
IntegerField, IPAddressField, NullBooleanField, PositiveIntegerField,
... |
b36795921b1a191190bd79008dbf07b5569c9c1711fc987439c6b704acc783e1 | import datetime
import json
from django import forms
from django.core import exceptions, serializers
from django.db import models
from django.test import SimpleTestCase, TestCase
from .models import DurationModel, NullDurationModel
class TestSaveLoad(TestCase):
def test_simple_roundtrip(self):
duration... |
3deac348360e9e9a2edd1bfce5f4f4d2b42e26570910046fbaa1ad568e79eb10 | from decimal import Decimal
from django.apps import apps
from django.core import checks
from django.db import models
from django.test import TestCase, skipIfDBFeature
from django.test.utils import isolate_apps
from .models import Bar, FkToChar, Foo, PrimaryKeyCharModel
class ForeignKeyTests(TestCase):
def test... |
8dd418f15ae690a0e368a9c539903acfc29db68924aca99f68d504c3aa52cfa1 | from unittest import skipIf
from django import forms
from django.db import connection, models
from django.test import TestCase
from .models import Post
class TextFieldTests(TestCase):
def test_max_length_passed_to_formfield(self):
"""
TextField passes its max_length attribute to form fields cre... |
b54081a766beabc16153b2c00530616c64570d4e7c73f09a037a166129af0864 | import pickle
from django import forms
from django.db import models
from django.test import SimpleTestCase, TestCase
from django.utils.functional import lazy
from .models import (
Foo, RenamedField, VerboseNameField, Whiz, WhizIter, WhizIterEmpty,
)
class Nested:
class Field(models.Field):
pass
cl... |
340fe3214821adfc837ae10c541349c57b76a0bc42514638f8fe580eef99b949 | import os
import tempfile
import uuid
from django.contrib.contenttypes.fields import (
GenericForeignKey, GenericRelation,
)
from django.contrib.contenttypes.models import ContentType
from django.core.files.storage import FileSystemStorage
from django.db import models
from django.db.models.fields.files import Imag... |
b9fb44391667602b12862439a4bedbac209cb7c3df0f753190f514b1b443814d | from django import test
from django.contrib.contenttypes.fields import (
GenericForeignKey, GenericRelation,
)
from django.db import models
from django.db.models.fields.related import (
ForeignKey, ForeignObject, ForeignObjectRel, ManyToManyField, ManyToOneRel,
OneToOneField,
)
from .models import AllField... |
e1fea125026388b7c30b4c7f4dce582dbf6ebfecb09790a1fb7631fae829e7d9 | import json
import uuid
from django.core import exceptions, serializers
from django.db import IntegrityError, models
from django.test import (
SimpleTestCase, TestCase, TransactionTestCase, skipUnlessDBFeature,
)
from .models import (
NullableUUIDModel, PrimaryKeyUUIDModel, RelatedToUUIDModel, UUIDGrandchild,... |
1b240d4a691ee500f0b4d50aa52416843b2551921bc36811f304874b0fcfd7b8 | import os
import sys
import unittest
from django.core.files import temp
from django.core.files.base import ContentFile
from django.core.files.uploadedfile import TemporaryUploadedFile
from django.db.utils import IntegrityError
from django.test import TestCase, override_settings
from .models import Document
class Fi... |
d3a0e7568fd451219f1165bf25bf95210dc9a4a1858c4390caff0dfe8fcabe1d | import datetime
from django.db import models
from django.test import (
SimpleTestCase, TestCase, override_settings, skipUnlessDBFeature,
)
from django.test.utils import requires_tz_support
from django.utils import timezone
from .models import DateTimeModel
class DateTimeFieldTests(TestCase):
def test_datet... |
5a29b70ffa37e8332f364eea02e17c9ce833afe45ddda6b4353148b428740f9b | from django.test import TestCase
from .models import BigS, UnicodeSlugField
class SlugFieldTests(TestCase):
def test_slugfield_max_length(self):
"""
SlugField honors max_length.
"""
bs = BigS.objects.create(s='slug' * 50)
bs = BigS.objects.get(pk=bs.pk)
self.asser... |
9a1deb197dcba8467ba88c1047b24f26b4d7b17617e1adc9f014548f46a88c03 | import unittest
from decimal import Decimal
from django.core import validators
from django.core.exceptions import ValidationError
from django.db import connection, models
from django.test import TestCase
from .models import BigD, Foo
class DecimalFieldTests(TestCase):
def test_to_python(self):
f = mode... |
11eef29c48a7a9da23c073b3be764206e7527461ba2cc8f39280ba0abe8e4f22 | import os
import shutil
from unittest import skipIf
from django.core.exceptions import ImproperlyConfigured
from django.core.files import File
from django.core.files.images import ImageFile
from django.test import TestCase
from django.test.testcases import SerializeMixin
try:
from .models import Image
except Impr... |
4c825f83ece7cfa040d602a099c7022506cf55822a97953a2d361343b544c3a3 | from django.apps import apps
from django.db import models
from django.test import SimpleTestCase, TestCase
from django.test.utils import isolate_apps
from .models import ManyToMany
class ManyToManyFieldTests(SimpleTestCase):
def test_abstract_model_pending_operations(self):
"""
Many-to-many fiel... |
738be6d87014f062d01966674b09de50248619bdb344c96c8eb09faecbc8c88e | from django import forms
from django.core.exceptions import ValidationError
from django.db import IntegrityError, models, transaction
from django.test import SimpleTestCase, TestCase
from .models import BooleanModel, FksToBooleans, NullBooleanModel
class BooleanFieldTests(TestCase):
def _test_get_prep_value(self... |
2e4d36939cf1cc7f9bbc7dcdb10841f51ba674b94cb1a4aa2f53104f01d1e7d8 | from unittest import skipIf
from django.core.exceptions import ValidationError
from django.db import connection, models
from django.test import SimpleTestCase, TestCase
from .models import Post
class TestCharField(TestCase):
def test_max_length_passed_to_formfield(self):
"""
CharField passes it... |
fa80a184e55520ed64557da3b52789ced87501732a3b6675f7cd3637f96e434a | from django.core.exceptions import ValidationError
from django.db import models
from django.test import TestCase
from .models import GenericIPAddress
class GenericIPAddressFieldTests(TestCase):
def test_genericipaddressfield_formfield_protocol(self):
"""
GenericIPAddressField with a specified pr... |
6df519725d7ec4e0825c3cd7ab651c113ac841c9211caa9469e3b30f2f375e8d | from django.core.exceptions import ValidationError
from django.db import models
from django.test import TestCase
from .models import DataModel
class BinaryFieldTests(TestCase):
binary_data = b'\x00\x46\xFE'
def test_set_and_retrieve(self):
data_set = (self.binary_data, memoryview(self.binary_data))
... |
44491f476b80936925ca6d404f5e257b4f2a185af8b754596768642e9516f150 | from django.db import transaction
from django.test import TestCase
from .models import FloatModel
class TestFloatField(TestCase):
def test_float_validates_object(self):
instance = FloatModel(size=2.5)
# Try setting float field to unsaved object
instance.size = instance
with trans... |
42343787441e06c545c4e5dece4b975de6a5bc0cc83f377203697ecbe8d7199b | from django.db import models
from django.test import SimpleTestCase
from django.test.utils import isolate_apps
@isolate_apps('absolute_url_overrides')
class AbsoluteUrlOverrideTests(SimpleTestCase):
def test_get_absolute_url(self):
"""
get_absolute_url() functions as a normal method.
"""
... |
82d29b1cf1e9d6b4b87172f1c276f6bde70c1bad5e0905dbe04ab7c4fe66cd9c | import unittest
from datetime import datetime
from django.core.paginator import (
EmptyPage, InvalidPage, PageNotAnInteger, Paginator,
UnorderedObjectListWarning,
)
from django.test import TestCase
from .custom import ValidAdjacentNumsPaginator
from .models import Article
class PaginationTests(unittest.Test... |
d299c349e97823e3094d22925f4839254fca3577446baa3ea5bc3a4a9149f5fa | from django.db import models
class Article(models.Model):
headline = models.CharField(max_length=100, default='Default headline')
pub_date = models.DateTimeField()
def __str__(self):
return self.headline
|
0a47eb2daf3d6eb525eff6d7acc9489c653c0c3bfa480b124964ada6d6504457 | from django.core.paginator import Page, Paginator
class ValidAdjacentNumsPage(Page):
def next_page_number(self):
if not self.has_next():
return None
return super().next_page_number()
def previous_page_number(self):
if not self.has_previous():
return None
... |
df811d65b7607863e61ab8072326e9711cbf2bd184980e1318417b0cb994bbcc | """
A series of tests to establish that the command-line bash completion works.
"""
import os
import sys
import unittest
from django.apps import apps
from django.core.management import ManagementUtility
from django.test.utils import captured_stdout
class BashCompletionTests(unittest.TestCase):
"""
Testing th... |
dfdd8cb9f55d7fea46dbf73567b73e159b1364fbb2442e2bce1b5c2c134b66df | from django.test import TestCase
from .models import Person
class SaveDeleteHookTests(TestCase):
def test_basic(self):
p = Person(first_name="John", last_name="Smith")
self.assertEqual(p.data, [])
p.save()
self.assertEqual(p.data, [
"Before save",
"After sa... |
c7f3612ae0faabaa6dc2bf245be4f82e363c634e49e0538c98641143218a29fe | """
Adding hooks before/after saving and deleting
To execute arbitrary code around ``save()`` and ``delete()``, just subclass
the methods.
"""
from django.db import models
class Person(models.Model):
first_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=20)
def __init__(se... |
89aa74582eaf5daf6d80276645855c23e695b05085624d88f526d8c3b50ea4be | from django import forms
from django.contrib import admin
from django.contrib.admin import AdminSite
from django.contrib.contenttypes.admin import GenericStackedInline
from django.core import checks
from django.test import SimpleTestCase, override_settings
from .models import (
Album, Author, Book, City, Influence... |
328e03a837da26630d97ede05f207cebf9c578ea42e3645babb0c0b6dfff17aa | """
Tests of ModelAdmin system checks logic.
"""
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
class Album(models.Model):
title = models.CharField(max_length=150)
class Song(models.Model):
title = mod... |
2f4e343581ac2376a7f840e35d9f410180edb84053043d0be694825b81c257b6 | from django.core import management
from django.core.management import CommandError
from django.test import TestCase
from .models import Article
class SampleTestCase(TestCase):
fixtures = ['fixture1.json', 'fixture2.json']
def testClassFixtures(self):
"Test cases can load fixture objects into models ... |
9097ad305753f3d8b3112c2bc20c5980303b2020bd804bb58c00fffe67d3cf30 | import datetime
import pickle
import unittest
import uuid
from copy import deepcopy
from django.core.exceptions import FieldError
from django.db import DatabaseError, connection, models, transaction
from django.db.models import CharField, Q, TimeField, UUIDField
from django.db.models.aggregates import (
Avg, Count... |
b1ab4556a736f0e9b2250d8052beb82bda33875e5ea879422959455f0d3a9265 | """
Tests for F() query expression syntax.
"""
import uuid
from django.db import models
class Employee(models.Model):
firstname = models.CharField(max_length=50)
lastname = models.CharField(max_length=50)
salary = models.IntegerField(blank=True, null=True)
def __str__(self):
return '%s %s' %... |
3fe3dbed098845e6c9a5971f20efee205d490505b7372725b31727d272236d3b | from django.db.models.aggregates import Sum
from django.db.models.expressions import F
from django.test import TestCase
from .models import Company, Employee
class ValuesExpressionsTests(TestCase):
@classmethod
def setUpTestData(cls):
Company.objects.create(
name='Example Inc.', num_emplo... |
ed7f3c864b818702e9326dd54bdb677066684244401a47245230eb1463a4a938 | import datetime
from operator import attrgetter
from django.core.exceptions import FieldError
from django.db import models
from django.db.models.fields.related import ForeignObject
from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature
from django.test.utils import isolate_apps
from django.utils import ... |
be976eacf3bce18e4ac0d99b463e15b11f2bb6d3aec0793e0d365e61acb924d1 | from operator import attrgetter
from django.test.testcases import TestCase
from .models import Address, Contact, Customer
class TestLookupQuery(TestCase):
@classmethod
def setUpTestData(cls):
cls.address = Address.objects.create(company=1, customer_id=20)
cls.customer1 = Customer.objects.cr... |
33054b1aec0fbc9dab1ef2751b841172a4256a0172cf56426f6f28387731c803 | import datetime
from django import forms
from django.test import TestCase
from .models import Article
class FormsTests(TestCase):
# ForeignObjects should not have any form fields, currently the user needs
# to manually deal with the foreignobject relation.
class ArticleForm(forms.ModelForm):
cla... |
5f5dfe5ecd11ee91f45d4b46487282a215b94b537b91ba7b3fc0561f5ac0d79f | from django.test import TestCase
from .models import SlugPage
class RestrictedConditionsTests(TestCase):
def setUp(self):
slugs = [
'a',
'a/a',
'a/b',
'a/b/a',
'x',
'x/y/z',
]
SlugPage.objects.bulk_create([SlugPage(sl... |
abb6408818780e94172427748963641a68b97523245189a97e7fb74c705fb551 | import datetime
import re
import sys
from contextlib import contextmanager
from unittest import SkipTest, skipIf
from xml.dom.minidom import parseString
import pytz
from django.contrib.auth.models import User
from django.core import serializers
from django.core.exceptions import ImproperlyConfigured
from django.db im... |
237fc2f03c24cd527e69274a7b523d30076a0989d65eef0bae93503215008eed | from django.db import models
class Event(models.Model):
dt = models.DateTimeField()
class MaybeEvent(models.Model):
dt = models.DateTimeField(blank=True, null=True)
class Session(models.Model):
name = models.CharField(max_length=20)
class SessionEvent(models.Model):
dt = models.DateTimeField()
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.