from djangocg.test import TestCase from djangocg.test.utils import override_settings from djangocg.utils import timezone from djangocg.utils.unittest import skipUnless from .models import Book, BookSigning TZ_SUPPORT = hasattr(time, 'tzset') # On OSes that don't provide tzset (Windows), we can't set the timezone # in which the program runs. As a consequence, we must skip tests that # don't enforce a specific timezone (with timezone.override or equivalent), # or attempt to interpret naive datetimes in the default timezone. requires_tz_support = skipUnless(TZ_SUPPORT, "This test relies on the ability to run a program in an arbitrary " "time zone, but your operating system isn't able to do that.") class ArchiveIndexViewTests(TestCase): fixtures = ['generic-views-test-data.json'] urls = 'regressiontests.generic_views.urls' def _make_books(self, n, base_date): for i in range(n): b = Book.objects.create( name='Book %d' % i, slug='book-%d' % i, pages=100+i, pubdate=base_date - datetime.timedelta(days=1))
from djangocg.conf import settings from djangocg.db import transaction, connection from djangocg.db.utils import ConnectionHandler, DEFAULT_DB_ALIAS, DatabaseError from djangocg.test import (TransactionTestCase, skipIfDBFeature, skipUnlessDBFeature) from djangocg.utils import unittest from .models import Person # Some tests require threading, which might not be available. So create a # skip-test decorator for those test functions. try: import threading except ImportError: threading = None requires_threading = unittest.skipUnless(threading, 'requires threading') class SelectForUpdateTests(TransactionTestCase): def setUp(self): transaction.enter_transaction_management(True) transaction.managed(True) self.person = Person.objects.create(name='Reinhardt') # We have to commit here so that code in run_select_for_update can # see this data. transaction.commit() # We need another database connection to test that one connection # issuing a SELECT ... FOR UPDATE will block.