本文整理汇总了Python中django.test.SimpleTestCase方法的典型用法代码示例。如果您正苦于以下问题:Python test.SimpleTestCase方法的具体用法?Python test.SimpleTestCase怎么用?Python test.SimpleTestCase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.test
的用法示例。
在下文中一共展示了test.SimpleTestCase方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import SimpleTestCase [as 别名]
def __call__(self, result=None):
"""
Wrapper around default __call__ method to do funky magic
"""
testMethod = getattr(self, self._testMethodName)
skipped = (getattr(self.__class__, "unittest_skip__", False) or
getattr(testMethod, "__unittest_skip__", False))
if not skipped:
try:
self._pre_setup()
except Exception:
result.addError(self, sys.exc_info())
return
with mock.patch('django.db.transaction', fake_transaction):
with mock.patch('django.db.models.base.transaction', fake_transaction):
with mock.patch('django.contrib.sessions.backends.db.transaction', fake_transaction):
super(SimpleTestCase, self).__call__(result)
if not skipped:
try:
self._post_teardown()
except Exception:
result.addError(self, sys.exc_info())
return
示例2: setUpClass
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import SimpleTestCase [as 别名]
def setUpClass(cls):
super(SimpleTestCase, cls).setUpClass()
if cls._overridden_settings:
cls._cls_overridden_context = override_settings(**cls._overridden_settings)
cls._cls_overridden_context.enable()
if cls._modified_settings:
cls._cls_modified_context = modify_settings(cls._modified_settings)
cls._cls_modified_context.enable()
示例3: tearDownClass
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import SimpleTestCase [as 别名]
def tearDownClass(cls):
if hasattr(cls, '_cls_modified_context'):
cls._cls_modified_context.disable()
delattr(cls, '_cls_modified_context')
if hasattr(cls, '_cls_overridden_context'):
cls._cls_overridden_context.disable()
delattr(cls, '_cls_overridden_context')
super(SimpleTestCase, cls).tearDownClass()
示例4: __call__
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import SimpleTestCase [as 别名]
def __call__(self, test_func):
from django.test import SimpleTestCase
if isinstance(test_func, type):
if not issubclass(test_func, SimpleTestCase):
raise Exception(
"Only subclasses of Django SimpleTestCase can be decorated "
"with override_settings")
original_pre_setup = test_func._pre_setup
original_post_teardown = test_func._post_teardown
def _pre_setup(innerself):
self.enable()
original_pre_setup(innerself)
def _post_teardown(innerself):
original_post_teardown(innerself)
self.disable()
test_func._pre_setup = _pre_setup
test_func._post_teardown = _post_teardown
return test_func
else:
@wraps(test_func)
def inner(*args, **kwargs):
with self:
return test_func(*args, **kwargs)
return inner
示例5: test_can_load_import_records_page
# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import SimpleTestCase [as 别名]
def test_can_load_import_records_page(self, fetch_csv):
fetch_csv.return_value = self.csv
to_url = reverse(
'csv_models:refine-and-import', args=[self.dynmodel.id]
)
response = self.client.post(to_url, {
"columns": json.dumps(self.columns),
})
self.assertEqual(response.status_code, 200)
err_found = self.err_string in str(response.content)
self.assertTrue(not err_found, "Import rendered error page")
#class NoTransactionImportDataTestCase(SimpleTestCase):
# databases = "__all__"
#
# def test_can_import_records(self):
# dynmodel = DynamicModel.objects.create(
# name="ImportDataTest",
# csv_url="https://import.test/csv",
# columns=COLUMNS,
# )
# dynmodel.save()
# create_models()
#
# # connection = connections[DEFAULT_DB_ALIAS]
# # connection.disable_constraint_checking()
# create_models()
# make_and_apply_migrations()
#
# # make sure the field was actually updated
# Model = getattr(csv_models, dynmodel.name)
# self.assertEqual(Model.objects.count(), 1)