Python django.test.SimpleTestCase() Examples

The following are 5 code examples of django.test.SimpleTestCase(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.test , or try the search function .
Example #1
Source File: testcase.py    From coursys with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #2
Source File: test_cases.py    From django-test-addons with MIT License 5 votes vote down vote up
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() 
Example #3
Source File: test_cases.py    From django-test-addons with MIT License 5 votes vote down vote up
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() 
Example #4
Source File: utils.py    From luscan-devel with GNU General Public License v2.0 5 votes vote down vote up
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 
Example #5
Source File: test_views.py    From django-collaborative with MIT License 5 votes vote down vote up
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)