hash stringlengths 64 64 | content stringlengths 0 1.51M |
|---|---|
35643fc6c81817d56e131a71719b9d29161d394c9a31875137691323b1d23876 | import unittest
from datetime import date, datetime, time, timedelta
from django.utils.dateparse import (
parse_date, parse_datetime, parse_duration, parse_time,
)
from django.utils.timezone import get_fixed_timezone
class DateParseTests(unittest.TestCase):
def test_parse_date(self):
# Valid inputs
... |
40dfdd6694373dece89c35680f306e35554a3d27daedd6f4d1fa74a4daaab7cc | import os
from datetime import datetime
from django.test import SimpleTestCase
from django.utils.functional import lazystr
from django.utils.html import (
conditional_escape, escape, escapejs, format_html, html_safe, json_script,
linebreaks, smart_urlquote, strip_spaces_between_tags, strip_tags, urlize,
)
from... |
e9cb432b28b4e3073c958639ea4ed3aaf8d641e11e9634bc44eb7e00c548e167 | import copy
import unittest
from django.utils.tree import Node
class NodeTests(unittest.TestCase):
def setUp(self):
self.node1_children = [('a', 1), ('b', 2)]
self.node1 = Node(self.node1_children)
self.node2 = Node()
def test_str(self):
self.assertEqual(str(self.node1), "(DE... |
5a65377b365401438e90c3a21d85c4dd79202d36452f8080a2f1ecc6c9f806d9 | # Used to test for modules which don't have submodules.
|
1b3673246186e13645e90e345aec1b01ade72d8c606ec30617b2f77ede23ceb0 | from django.template import Context, Template
from django.test import SimpleTestCase
from django.utils import html, text
from django.utils.functional import lazy, lazystr
from django.utils.safestring import SafeData, mark_safe
class customescape(str):
def __html__(self):
# implement specific and obviously... |
dc28870f4404cd63554b8658ddbf314f970f9bb014ec368894231136630bd929 | from decimal import Decimal
from sys import float_info
from unittest import TestCase
from django.utils.numberformat import format as nformat
class TestNumberFormat(TestCase):
def test_format_number(self):
self.assertEqual(nformat(1234, '.'), '1234')
self.assertEqual(nformat(1234.2, '.'), '1234.2... |
2965342d6f9425b841f75269410f433cc5af30b012bb0184979cefaf2b8aadeb | import unittest
from django.utils.functional import cached_property, lazy
class FunctionalTestCase(unittest.TestCase):
def test_lazy(self):
t = lazy(lambda: tuple(range(3)), list, tuple)
for a, b in zip(t(), range(3)):
self.assertEqual(a, b)
def test_lazy_base_class(self):
... |
2bb116ecd5cf8efc50a73c00903329874f42938a5f6270e2a3b6a45ce2cce1c1 | import hashlib
import unittest
from django.utils.crypto import constant_time_compare, pbkdf2
class TestUtilsCryptoMisc(unittest.TestCase):
def test_constant_time_compare(self):
# It's hard to test for constant time, just test the result.
self.assertTrue(constant_time_compare(b'spam', b'spam'))
... |
29e5712c02b23d78b0c0e1631b5405c8be4cf3a167f574db854d2f546c3cf201 | import gettext
import os
import shutil
import tempfile
from importlib import import_module
from unittest import mock
import _thread
from django import conf
from django.contrib import admin
from django.test import SimpleTestCase, override_settings
from django.test.utils import extend_sys_path
from django.utils import ... |
f5b74cfbd0d4cf126156eeba2c462ec07af9e9b9ea345327d960ce8858a2d374 | import unittest
from datetime import (
date as original_date, datetime as original_datetime,
time as original_time,
)
from django.utils.datetime_safe import date, datetime, time
class DatetimeTests(unittest.TestCase):
def setUp(self):
self.just_safe = (1900, 1, 1)
self.just_unsafe = (189... |
103bc559a647c80afa0801efa656beef5fb38f401c708ffd71eb62c2a8ef29de | import unittest
from django.utils.ipv6 import clean_ipv6_address, is_valid_ipv6_address
class TestUtilsIPv6(unittest.TestCase):
def test_validates_correct_plain_address(self):
self.assertTrue(is_valid_ipv6_address('fe80::223:6cff:fe8a:2e8a'))
self.assertTrue(is_valid_ipv6_address('2a02::223:6cff... |
ddbfb0d074036b1766bf147a3a3c56075ac4cc163c37b37ef6c96ca39bc56ffd | """
Tests for stuff in django.utils.datastructures.
"""
import copy
from django.test import SimpleTestCase
from django.utils.datastructures import (
DictWrapper, ImmutableList, MultiValueDict, MultiValueDictKeyError,
OrderedSet,
)
class OrderedSetTests(SimpleTestCase):
def test_bool(self):
# Re... |
0e7b81f10c683efca6bd8e82b08826f104afa58689bd2df1c2b6d6f4451bf49f | import unittest
from datetime import datetime
from django.test import SimpleTestCase, ignore_warnings
from django.utils.datastructures import MultiValueDict
from django.utils.deprecation import RemovedInDjango30Warning
from django.utils.http import (
base36_to_int, cookie_date, http_date, int_to_base36, is_safe_ur... |
b39d97377c37b06bd9226aec6a79599d0391ad7ab9fe0b915edb042d402a0d90 | import os
import shutil
import stat
import sys
import tempfile
import unittest
from django.utils.archive import Archive, extract
TEST_DIR = os.path.join(os.path.dirname(__file__), 'archives')
class ArchiveTester:
archive = None
def setUp(self):
"""
Create temporary directory for testing ext... |
9f0de37f4526b064ff478be5e2fb99e7c5b21e46924d408bcff7ca7cc3a22fcc | import unittest
from unittest import mock
from django.utils.lorem_ipsum import paragraph, paragraphs, sentence, words
class LoremIpsumTests(unittest.TestCase):
def test_negative_words(self):
"""words(n) returns n + 19 words, even if n is negative."""
self.assertEqual(
words(-5),
... |
1158ae4a89b8c57b820f8e7ab4c6e787fb3a18c46b9eace3ed0569b3e5ace1a2 | import copy
import pickle
import sys
import warnings
from unittest import TestCase
from django.utils.functional import LazyObject, SimpleLazyObject, empty
from .models import Category, CategoryInfo
class Foo:
"""
A simple class with just one attribute.
"""
foo = 'bar'
def __eq__(self, other):
... |
28d9d1b51928a65831b6fa6e53cafcd25ebd8b9541d566029a1c5204f1469501 | """Tests for jslex."""
# originally from https://bitbucket.org/ned/jslex
from django.test import SimpleTestCase
from django.utils.jslex import JsLexer, prepare_js_for_gettext
class JsTokensTest(SimpleTestCase):
LEX_CASES = [
# ids
("a ABC $ _ a123", ["id a", "id ABC", "id $", "id _", "id a123"]),... |
2ad3c60ffbc2e8273bfa3ef17e4e022248d1a5addf5f2e3da5ed4181a0d1fd6b | 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 classproperty, decorator_from_middleware
class ProcessViewMiddleware:
def process_view(self, req... |
9792398388c4d45f980914c449ab019007b89fc5bca603f77344bd361437dc70 | import datetime
import unittest
from django.test import TestCase
from django.utils import feedgenerator
from django.utils.timezone import get_fixed_timezone, utc
class FeedgeneratorTest(unittest.TestCase):
"""
Tests for the low-level syndication feed framework.
"""
def test_get_tag_uri(self):
... |
36d2a2958599d4eff728b4d82f69abf37930c3e534ed5e0fd375c501a5df2877 | from unittest import TestCase
from django.utils.baseconv import (
BaseConverter, base2, base16, base36, base56, base62, base64,
)
class TestBaseConv(TestCase):
def test_baseconv(self):
nums = [-10 ** 10, 10 ** 10] + list(range(-100, 100))
for converter in [base2, base16, base36, base56, base... |
7811eef5d1b539035b4384c6bb24f0f56e747920042757d121617901f48c19af | import json
from django.test import SimpleTestCase
from django.utils import text
from django.utils.functional import lazystr
from django.utils.text import format_lazy
from django.utils.translation import gettext_lazy, override
IS_WIDE_BUILD = (len('\U0001F4A9') == 1)
class TestUtilsText(SimpleTestCase):
def te... |
96f083034d0513c7d83581dd2e985ee873873990093f921d3d8ef5077c40f55c | from django.conf import settings
from django.db import connection, models
from django.test import SimpleTestCase, skipUnlessDBFeature
from django.test.utils import isolate_apps
from .models import Book, ChildModel1, ChildModel2
class IndexesTests(SimpleTestCase):
def test_suffix(self):
self.assertEqual(... |
1736fa96e7eefcf11dd7221e7d44af8416f9aaa53ee05a161da9c27c1240996c | from django.db import models
class Book(models.Model):
title = models.CharField(max_length=50)
author = models.CharField(max_length=50)
pages = models.IntegerField(db_column='page_count')
shortcut = models.CharField(max_length=50, db_tablespace='idx_tbls')
isbn = models.CharField(max_length=50, db... |
884a73b8565733cca19788ac28e85c00915ea2b4c481e27f935c91d3e8e327fb | import threading
from datetime import datetime, timedelta
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
from django.db import DEFAULT_DB_ALIAS, DatabaseError, connections
from django.db.models.manager import BaseManager
from django.db.models.query import EmptyQuerySet, QuerySet
from dj... |
6214e57a15cf6d7973a9ed3bdc2d4843dd0d38ebbb9d173b602c26d1c65f1a2b | """
Bare-bones model
This is a basic model with only two non-primary-key fields.
"""
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', 'headline')... |
df0ac71fde4247e8d4e8f60d9c6363fdb184af84328314b7a54c6e581b0953d0 | from xml.dom import minidom
from django.core import serializers
from django.core.serializers.xml_serializer import DTDForbidden
from django.test import TestCase, TransactionTestCase
from .tests import SerializersTestBase, SerializersTransactionTestBase
class XmlSerializerTestCase(SerializersTestBase, TestCase):
... |
460469a6bb450c2b05a50f1a2c05f1fded0794180eefcd74de3e3a5c4392db83 | import importlib
import unittest
from io import StringIO
from django.core import management, serializers
from django.core.serializers.base import DeserializationError
from django.test import SimpleTestCase, TestCase, TransactionTestCase
from .models import Author
from .tests import SerializersTestBase, SerializersTra... |
5ff540b0efce8e4c740bd08064c57b7e681e50d5bacb776f84fb4965926384d2 | 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... |
2ddfb829a0ac5959c2ea4f4f492052db5593746eada61806195ed90b0f89dccb | from django.core import serializers
from django.db import connection
from django.test import TestCase
from .models import Child, FKDataNaturalKey, NaturalKeyAnchor
from .tests import register_tests
class NaturalKeySerializerTests(TestCase):
pass
def natural_key_serializer_test(self, format):
# Create all t... |
c7b2f8dcbd4b752e764cc2ed971a88d683494f7ece2ce1ab76dfa19f832f8d60 | """
A test spanning all the capabilities of all the serializers.
This class defines sample data and a dynamically generated
test case that is capable of testing the capabilities of
the serializers. This includes all valid data values, plus
forward, backwards and self references.
"""
import datetime
import decimal
impo... |
1222f8ee3238f060d3608a676064417a6a805ffb40042ef185a45c26a6c36467 | import datetime
import decimal
import json
import re
from django.core import serializers
from django.core.serializers.base import DeserializationError
from django.core.serializers.json import DjangoJSONEncoder
from django.db import models
from django.test import SimpleTestCase, TestCase, TransactionTestCase
from djang... |
e9ccf72da8c839c6c4a0e0ecf4514fef5bcb10453d8a7c03b20da5495b5aecb0 | from django.core.serializers.base import DeserializedObject
from django.test import SimpleTestCase
from .models import Author
class TestDeserializedObjectTests(SimpleTestCase):
def test_repr(self):
author = Author(name='John', pk=1)
deserial_obj = DeserializedObject(obj=author)
self.asse... |
7da4423c790bd501fcb79debd7dd7bd30c75d0b2469e350a932541ed65fd96c8 | # Required for migration detection (#22645)
|
fe5cc8affb6aca4982d0c82fbbb768bc384588ade44ffa0626ed64dcab475ec7 | from datetime import date
from django import forms
from django.contrib.admin.models import ADDITION, CHANGE, DELETION, LogEntry
from django.contrib.admin.options import (
HORIZONTAL, VERTICAL, ModelAdmin, TabularInline,
get_content_type_for_model,
)
from django.contrib.admin.sites import AdminSite
from django.... |
8e60973f18eed3c240acd359a5dcceb57b2e5ac39fb0331adbc2d4a9eb9a7eb1 | from django.contrib.auth.models import User
from django.db import models
class Band(models.Model):
name = models.CharField(max_length=100)
bio = models.TextField()
sign_date = models.DateField()
class Meta:
ordering = ('name',)
def __str__(self):
return self.name
class Song(mod... |
f08d96f0f6dabb61419fceb2fbe894f73d600aa17f2d9e35a8ae8ef48d375bc1 | 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... |
59afd5ad17b1e7bbd6f1762d2bb68d9351126fab2724dec531edac62db5ac694 | from django.contrib.admin.options import ModelAdmin, TabularInline
from django.utils.deprecation import RemovedInDjango30Warning
from .models import Band, Song
from .test_checks import CheckTestCase
class HasAddPermissionObjTests(CheckTestCase):
def test_model_admin_inherited_valid(self):
class BandAdmin... |
7f6fb9ee7ec5ac461340550c4339f21c6b877c275ec6846710c8cb4450575267 | from django import forms
from django.contrib.admin import BooleanFieldListFilter, SimpleListFilter
from django.contrib.admin.options import VERTICAL, ModelAdmin, TabularInline
from django.contrib.admin.sites import AdminSite
from django.core.checks import Error
from django.db.models import F
from django.db.models.funct... |
46e28818ab3fc16f560399ff01036b57ac1a20e989a61c15c0d8a9a750f1ba51 | """
Tests for django test runner
"""
import unittest
from unittest import mock
from admin_scripts.tests import AdminScriptTestCase
from django import db
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.core.management import call_command
from django.test import (
... |
9174192862967a59bb7da27cbf1c2452de18c5fab994f0296f017e123692450f | from django.db import models
class Person(models.Model):
first_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=20)
|
3a23cd3fd5c790b0446a7d11c90e2e17239dfe1dbe30447c8b65993473774cbc | 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... |
5e698f1b940e913cef02b0f624a07a49ee6e688d5cd9537188c1637eb9616bd1 | import unittest
from io import StringIO
from django.db import connection
from django.test import TestCase
from django.test.runner import DiscoverRunner
from .models import Person
@unittest.skipUnless(connection.vendor == 'sqlite', 'Only run on sqlite so we can check output SQL.')
class TestDebugSQL(unittest.TestCas... |
1275cff1264f729ecda63db2285b6d275515508d5e951cb30aad846fd63b3c24 | import os
from argparse import ArgumentParser
from contextlib import contextmanager
from unittest import TestSuite, TextTestRunner, defaultTestLoader
from django.test import TestCase
from django.test.runner import DiscoverRunner
from django.test.utils import captured_stdout
@contextmanager
def change_cwd(directory):... |
d6051e7229a189fbd9a1ecc11a4bb0cc203ca9d45ee82bd1d20c356fa255ea5b | import unittest
from django.test import SimpleTestCase
from django.test.runner import RemoteTestResult
from django.utils.version import PY37
try:
import tblib
except ImportError:
tblib = None
class ExceptionThatFailsUnpickling(Exception):
"""
After pickling, this class fails unpickling with an error... |
3499c51692dee813ff1b5a1db989df010166b935bfdf42f3dd8ce38c14191239 | from django.db.models import Q
from django.test import TestCase
from .models import (
Comment, Forum, Item, Post, PropertyValue, SystemDetails, SystemInfo,
)
class NullFkTests(TestCase):
def test_null_fk(self):
d = SystemDetails.objects.create(details='First details')
s = SystemInfo.objects.... |
81f1fbef82ecc8c00f831670fe00a0525bff31325994cd7131512247ad0c6bb9 | """
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=... |
a0f71d1af94ead4199f678416acd9dd46c8f47f8159012a72a37f66ed5de0696 | 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... |
7a025fe4bbeb3ec75a0f059ab064fd606dc637c6be456003b80e9501554014b9 | from django.db import models
from django.utils.translation import gettext_lazy as _
class Site(models.Model):
domain = models.CharField(max_length=100)
def __str__(self):
return self.domain
class Article(models.Model):
"""
A simple Article model for testing
"""
site = models.Foreign... |
eb82bb9fd654ba3540a8d73d4b3b46f31e943241a649775c5c1e0348d9a532a0 | from django.contrib import admin
from .models import Article, ArticleProxy, Site
class ArticleInline(admin.TabularInline):
model = Article
fields = ['title']
class SiteAdmin(admin.ModelAdmin):
inlines = [ArticleInline]
site = admin.AdminSite(name='admin')
site.register(Article)
site.register(ArticleP... |
5f45dd424099f2457b504131a0d071e45a0a3f51b8e692a8292db87cc2973ce8 | 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
... |
b049728e158723aeea68a9e1e91e587886b380c232555d52cb926afd0d612c8b | from django.conf.urls import url
from .admin import site
urlpatterns = [
url(r'^test_admin/admin/', site.urls),
]
|
3420fb3ab84e9e0166756e32986df1ec3de29bca8edd94fe6091762630f9292b | from django.db import transaction
from django.test import TestCase
from .models import Article, InheritedArticleA, InheritedArticleB, Publication
class ManyToManyTests(TestCase):
def setUp(self):
# Create a couple of Publications.
self.p1 = Publication.objects.create(title='The Python Journal')
... |
3eaecccd21bf9feb4b3c5ac6dbd540d5ccf6659fb79e312ddaab6827df2dc54c | """
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 =... |
1cd51ee55be043aa38cafbfd9ecc13f888d84cbe5ac288f82edf0d49d75639d1 | from io import BytesIO
from django.core.exceptions import RequestDataTooBig, TooManyFieldsSent
from django.core.handlers.wsgi import WSGIRequest
from django.test import SimpleTestCase
from django.test.client import FakePayload
TOO_MANY_FIELDS_MSG = 'The number of GET/POST parameters exceeded settings.DATA_UPLOAD_MAX_... |
2e4b2221423b6628ddfd1602ed4b3e351c20998d8522a52fbd139892deeb3c74 | 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.request import split_d... |
6a4ee35c2405441325f50c2714bd7b8e965ad3bef1c5adbfcad93c4eb0afd436 | import datetime
from unittest import mock
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):
Article.objects.create(name='A... |
88b01a20cab6e12a091235fa1ceb872d001c6dcbcdd5dfe5347e0d45bc45dde7 | from django.db.models import F, Q
from django.test import SimpleTestCase
class QTests(SimpleTestCase):
def test_combine_and_empty(self):
q = Q(x=1)
self.assertEqual(q & Q(), q)
self.assertEqual(Q() & q, q)
def test_combine_and_both_empty(self):
self.assertEqual(Q() & Q(), Q())... |
d4bea741701fa0771a4fc7850378032713532b0903463eb9321c6bbed0cf5290 | import datetime
import pickle
import unittest
from collections import OrderedDict
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
f... |
f1f22ac914881805a5d3b9d49d055df0c205418e38ea5875c84bf6d7e8695f84 | """
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)
... |
e2c1f20631d2c4439ab1c0c70dce17ec447d6704ab923aeef14536d929822bac | 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... |
4c476e24be6eef81defbc7e5af751fc1e866b21a472ec3f0179dda3e8635bff7 | import unittest
from django.db import NotSupportedError, connection, transaction
from django.db.models import Count
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
from django.test.utils import CaptureQueriesContext
from .models import Tag
@skipUnlessDBFeature('supports_explaining_query_execu... |
fe59f38380f4bcf6249ed6c438c4f1cc1f334964c2780749cbb61d46f3b9a30f | """
Testing some internals of the template processing. These are *not* examples to be copied in user code.
"""
from django.template import Library, TemplateSyntaxError
from django.template.base import (
FilterExpression, Parser, Token, TokenType, Variable,
)
from django.template.defaultfilters import register as fi... |
5fb98c2e6f4fa23df85823701f34cea0dbac7a47ae66fb00d3fa26f6bb081f47 | 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):
... |
e1b8c9197a50fd1de4a92613304a653cc411ab172a2d8a27e55bf8fd4353fb32 | from django import Xtemplate # NOQA
|
1af284532e01a141a5f7e40ab602df832dc1d0c7f4f3d72542bf043acbb10cb2 | import sys
from django.contrib.auth.models import Group
from django.template import Context, Engine, TemplateSyntaxError
from django.template.base import UNKNOWN_SOURCE
from django.test import SimpleTestCase, override_settings
from django.urls import NoReverseMatch
from django.utils import translation
class Template... |
a8c9e834ab328567e2565b178f0414f8c0f48640cd8b7bf9dca5f0034963edcd | 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... |
3178e27b8edb49b23b2bb75103da6258861ca4c5e1773bec2217f762db2309cd | from django.template import Library
from django.template.base import Node
from django.test import TestCase
class FilterRegistrationTests(TestCase):
def setUp(self):
self.library = Library()
def test_filter(self):
@self.library.filter
def func():
return ''
self.ass... |
c237be58f464fc4146676ea78ad19a24681902f11400c34fa9b21b1d3bc974c4 | 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... |
73236f3db8522efba849f066dd437aecd3b9483df466846ffe25938c55a5eeed | from django.template.base import Variable, VariableDoesNotExist
from django.test import SimpleTestCase
class VariableDoesNotExistTests(SimpleTestCase):
def test_str(self):
exc = VariableDoesNotExist(msg='Failed lookup in %r', params=({'foo': 'bar'},))
self.assertEqual(str(exc), "Failed lookup in {... |
7ea17e03e14697506771cb5b1d929a0bbdb0875ee372f827cfb4482f9e35e26c | from unittest import TestCase
from django.template import Context, Engine
class CallableVariablesTests(TestCase):
@classmethod
def setUpClass(cls):
cls.engine = Engine()
super().setUpClass()
def test_callable(self):
class Doodad:
def __init__(self, value):
... |
df6a229348bbaaa1d51ae217ead8b9998d877a7b13a04a5b7db768ec9fc91725 | 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... |
d21c8a7f75369afc02a11571f6bbd64cfc17a8b254c9c86fd9fbbc499d7ed2f6 | import functools
import os
from django.template.engine import Engine
from django.test.utils import override_settings
from django.utils.safestring import mark_safe
ROOT = os.path.dirname(os.path.abspath(__file__))
TEMPLATE_DIR = os.path.join(ROOT, 'templates')
def setup(templates, *args, **kwargs):
"""
Runs ... |
5676e9deaecc42758dbca6e8c42f41da351fdf810ea751284f0703b2f0052453 | from unittest import TestCase
from django.template import Engine
from .utils import TEMPLATE_DIR
class OriginTestCase(TestCase):
def setUp(self):
self.engine = Engine(dirs=[TEMPLATE_DIR])
def test_origin_compares_equal(self):
a = self.engine.get_template('index.html')
b = self.engin... |
d500634d6ec1a70b3255b67bcedf47e77f691b90d90c705a3f710990cb8b2730 | from django.conf.urls import url
from . import views
urlpatterns = [
# View returning a template response
url(r'^template_response_view/$', views.template_response_view),
# A view that can be hard to find...
url(r'^snark/', views.snark, name='snark'),
]
|
c816d0e01065ae83dd14b865b3b0d04e7743c51c6c46fbb9b2490db256111202 | from django.conf.urls import include, url
from . import views
ns_patterns = [
# Test urls for testing reverse lookups
url(r'^$', views.index, name='index'),
url(r'^client/([0-9,]+)/$', views.client, name='client'),
url(r'^client/(?P<id>[0-9]+)/(?P<action>[^/]+)/$', views.client_action, name='client_ac... |
92b40f0d6a1e77b2c4def204855d1f51dc7b996fb517be50b8a0401f0b207c12 | from django import template
register = template.Library()
@register.simple_tag()
def annotated_tag_function(val: int):
return val
|
3a7b3d1792543353ef523044e1748fc9ce3c069873d91388f4907e7aac066317 | import unittest
from django.template.smartif import IfParser
class SmartIfTests(unittest.TestCase):
def assertCalcEqual(self, expected, tokens):
self.assertEqual(expected, IfParser(tokens).parse().eval({}))
# We only test things here that are difficult to test elsewhere
# Many other tests are f... |
6e0cb3b592a24dcb7ef5f85d9350ffc0192638489ef827f208f30c4934b443cf | # Fake views for testing url reverse lookup
from django.http import HttpResponse
from django.template.response import TemplateResponse
def index(request):
pass
def client(request, id):
pass
def client_action(request, id, action):
pass
def client2(request, tag):
pass
def template_response_view(... |
3cc32a1b58437aea7127d747edbd0efb5a7c73dec28f99c8a010de96fab87aeb | 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(... |
12bb8a43f867e42cde8a1d0d9ff8c223596c23299f6fe5190b76d4aabeed1a0a | from unittest import TestCase
from django.template import Context, Engine
from django.template.base import TextNode, VariableNode
class NodelistTest(TestCase):
@classmethod
def setUpClass(cls):
cls.engine = Engine()
super().setUpClass()
def test_for(self):
template = self.engine... |
c6576a6f33549122966a81daf34991a12101ca60a4de9a538f89826de4c4051c | import os
from django.template import Context, Engine, TemplateDoesNotExist
from django.test import SimpleTestCase
from .utils import ROOT
RECURSIVE = os.path.join(ROOT, 'recursive_templates')
class ExtendsBehaviorTests(SimpleTestCase):
def test_normal_extend(self):
engine = Engine(dirs=[os.path.join(... |
787095e1b0c5ef3af146f6c8850a946de13bf23edde13effc4fde0758cdc0a91 | import os
from django.template import Context, Engine, TemplateSyntaxError
from django.test import SimpleTestCase
from .utils import ROOT
RELATIVE = os.path.join(ROOT, 'relative_templates')
class ExtendsRelativeBehaviorTests(SimpleTestCase):
def test_normal_extend(self):
engine = Engine(dirs=[RELATIVE... |
a6cd668b93f65e0174d8fd5a8081b75e727ebb62a25a10c8e19cafc4bd5fd750 | import os
from django.template import Context, Engine, TemplateSyntaxError
from django.template.base import Node
from django.template.library import InvalidTemplateLibrary
from django.test import SimpleTestCase
from django.test.utils import extend_sys_path
from .templatetags import custom, inclusion
from .utils impor... |
09e15cc8edb9f5ceb07cb5c054eaaad462f576b62b92dbc56db785ddb3aee5ac | from unittest import skipUnless
from django.db import connection
from django.db.models.deletion import CASCADE
from django.db.models.fields.related import ForeignKey
from django.test import TestCase, TransactionTestCase
from .models import Article, ArticleTranslation, IndexTogetherSingleList
class SchemaIndexesTest... |
1c4e72f982b282d518a41714f90bbdc7606c9e35c9db5fbf5a3f5496b2e98380 | 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):
... |
3a60519acfbbaeab863d19b7d3bad5a85b58e8e986cec88d678894d110349a5e | """
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':... |
a6b506158e7ac1c4b50737058d8385be2546318909b993caf3871709cb4ec14d | from django.db import models
class DebugObject(models.Model):
pass
|
47a8987ee40e17b4adc22cb9e1918092d772a7433b5c7d40239cd20477ace8cd | from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^request_attrs/$', views.request_processor),
url(r'^debug/$', views.debug_processor),
]
|
031d6e85f12cd9e405c810f097586caadcaa81463527a822693beff5523fe3df | from django.shortcuts import render
from .models import DebugObject
def request_processor(request):
return render(request, 'context_processors/request_attrs.html')
def debug_processor(request):
context = {
'debug_objects': DebugObject.objects,
'other_debug_objects': DebugObject.objects.usin... |
0767fff1fcf184a7618d18d426da0cf6aecece4ada642cd96532d40c612c6a57 | from datetime import datetime
from operator import attrgetter
from django.test import TestCase
from .models import (
CustomMembership, Employee, Event, Friendship, Group, Ingredient,
Invitation, Membership, Person, PersonSelfRefM2M, Recipe, RecipeIngredient,
Relationship,
)
class M2mThroughTests(TestCas... |
0c6ddbe3da0c48c45f5ea72ddd0f9b1984769fd14d64d19d73c7c50c68dec94a | 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... |
b9371557e767182a66eb1fc9f61bfafbda89c8237f6d97c1a4a0765c4c56b40e | import datetime
import re
from datetime import date
from decimal import Decimal
from django import forms
from django.core.exceptions import ImproperlyConfigured
from django.db import models
from django.forms.models import (
BaseModelFormSet, _get_foreign_key, inlineformset_factory,
modelformset_factory,
)
from... |
63afdf2fc6dc50a0b8b02aa0521f2b61da6eb103b00d168505e3a113cd93f1b5 | 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... |
9f011188d6470fec200c814fee851b9ebac100cd2f4551adf762eec578fe00ca | from django.forms.models import inlineformset_factory
from django.test import TestCase
from .models import (
AutoPKChildOfUUIDPKParent, AutoPKParent, ChildRelatedViaAK,
ChildWithEditablePK, ParentWithUUIDAlternateKey, UUIDPKChild,
UUIDPKChildOfAutoPKParent, UUIDPKParent,
)
class InlineFormsetTests(TestCa... |
2258cc2cd5b22d8bb4d024abea401a0b22a72a3188e81a8b2a627397572ec0ee | from django.test import TestCase
from .models import Parent
class MutuallyReferentialTests(TestCase):
def test_mutually_referential(self):
# Create a Parent
q = Parent(name='Elizabeth')
q.save()
# Create some children
c = q.child_set.create(name='Charles')
q.chil... |
0ddc8cf6c5abd69711fa69841fd66a0a40b51f3e8f3d86a3e266cc89a5932dab | """
Mutually referential many-to-one relationships
Strings can be used instead of model literals to set up "lazy" relations.
"""
from django.db import models
class Parent(models.Model):
name = models.CharField(max_length=100)
# Use a simple string for forward declarations.
bestchild = models.ForeignKey... |
eb46a0e93f911fd017d1d79ba9560f7907d2fe83235cd7ace9af6fc71bc3a244 | 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... |
52fb6ccaff218ae4cacc8348e3cdca3d2df9d74710a0b5342e4887906a9c7882 | """
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... |
d482b8f123b8899ff557c4be9c302ff4756bb702df26fd77fcce8664e4caa681 | 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... |
9552df03b67e0337b06ac226fd4795cab502ac0692993c1068e16ec14b0602dc | """
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 ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.