当前位置: 首页>>代码示例>>Python>>正文


Python test.SimpleTestCase方法代码示例

本文整理汇总了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 
开发者ID:sfu-fas,项目名称:coursys,代码行数:26,代码来源:testcase.py

示例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() 
开发者ID:hspandher,项目名称:django-test-addons,代码行数:11,代码来源:test_cases.py

示例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() 
开发者ID:hspandher,项目名称:django-test-addons,代码行数:11,代码来源:test_cases.py

示例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 
开发者ID:blackye,项目名称:luscan-devel,代码行数:28,代码来源:utils.py

示例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) 
开发者ID:propublica,项目名称:django-collaborative,代码行数:35,代码来源:test_views.py


注:本文中的django.test.SimpleTestCase方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。