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


Python utils.override_settings方法代码示例

本文整理汇总了Python中django.test.utils.override_settings方法的典型用法代码示例。如果您正苦于以下问题:Python utils.override_settings方法的具体用法?Python utils.override_settings怎么用?Python utils.override_settings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.test.utils的用法示例。


在下文中一共展示了utils.override_settings方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_post_valid_jwt_with_auth

# 需要导入模块: from django.test import utils [as 别名]
# 或者: from django.test.utils import override_settings [as 别名]
def test_post_valid_jwt_with_auth(self):
        now = datetime.utcnow()
        payload = {
            'iss': 'issuer',
            'exp': now + timedelta(seconds=100),
            'iat': now,
            'username': 'temporary',
        }
        jwt_value = utils.encode_jwt(payload)

        with override_settings(JWT_AUTH_DISABLED=False):
            response = self.client.post(
                '/jwt_auth/', {'example': 'example'},
                HTTP_AUTHORIZATION='JWT {}'.format(jwt_value),
                content_type='application/json')
            self.assertEqual(response.status_code, 200)
            self.assertEqual(
                json.loads(response.content), {'username': 'temporary'})

        with override_settings(JWT_AUTH_DISABLED=True):
            response = self.client.post(
                '/jwt_auth/', {'example': 'example'},
                HTTP_AUTHORIZATION='JWT {}'.format(jwt_value),
                content_type='application/json')
            self.assertEqual(response.status_code, 403) 
开发者ID:Humanitec,项目名称:django-oauth-toolkit-jwt,代码行数:27,代码来源:test_authentication.py

示例2: test_signer_with_different_secret_keys

# 需要导入模块: from django.test import utils [as 别名]
# 或者: from django.test.utils import override_settings [as 别名]
def test_signer_with_different_secret_keys(self):
        user = self.create_test_user(is_active=False)
        data_to_sign = {'user_id': user.pk}
        secrets = [
            '#0ka!t#6%28imjz+2t%l(()yu)tg93-1w%$du0*po)*@l+@+4h',
            'feb7tjud7m=91$^mrk8dq&nz(0^!6+1xk)%gum#oe%(n)8jic7',
        ]
        signatures = []
        for secret in secrets:
            with override_settings(
                    SECRET_KEY=secret):
                signer = RegisterSigner(data_to_sign)
                data = signer.get_signed_data()
                signatures.append(data[signer.SIGNATURE_FIELD])

        assert signatures[0] != signatures[1] 
开发者ID:apragacz,项目名称:django-rest-registration,代码行数:18,代码来源:test_register.py

示例3: test_signer_with_different_secret_keys

# 需要导入模块: from django.test import utils [as 别名]
# 或者: from django.test.utils import override_settings [as 别名]
def test_signer_with_different_secret_keys(self):
        email = 'testuser1@example.com'
        user = self.create_test_user(is_active=False)
        data_to_sign = {
            'user_id': user.pk,
            'email': email,
        }
        secrets = [
            '#0ka!t#6%28imjz+2t%l(()yu)tg93-1w%$du0*po)*@l+@+4h',
            'feb7tjud7m=91$^mrk8dq&nz(0^!6+1xk)%gum#oe%(n)8jic7',
        ]
        signatures = []
        for secret in secrets:
            with override_settings(
                    SECRET_KEY=secret):
                signer = RegisterEmailSigner(data_to_sign)
                data = signer.get_signed_data()
                signatures.append(data[signer.SIGNATURE_FIELD])

        assert signatures[0] != signatures[1] 
开发者ID:apragacz,项目名称:django-rest-registration,代码行数:22,代码来源:test_register_email.py

示例4: test_signer_with_different_secret_keys

# 需要导入模块: from django.test import utils [as 别名]
# 或者: from django.test.utils import override_settings [as 别名]
def test_signer_with_different_secret_keys(self):
        user = self.create_test_user(is_active=False)
        data_to_sign = {'user_id': user.pk}
        secrets = [
            '#0ka!t#6%28imjz+2t%l(()yu)tg93-1w%$du0*po)*@l+@+4h',
            'feb7tjud7m=91$^mrk8dq&nz(0^!6+1xk)%gum#oe%(n)8jic7',
        ]
        signatures = []
        for secret in secrets:
            with override_settings(
                    SECRET_KEY=secret):
                signer = ResetPasswordSigner(data_to_sign)
                data = signer.get_signed_data()
                signatures.append(data[signer.SIGNATURE_FIELD])

        assert signatures[0] != signatures[1] 
开发者ID:apragacz,项目名称:django-rest-registration,代码行数:18,代码来源:test_reset_password.py

示例5: test_get_all_running_tasks

# 需要导入模块: from django.test import utils [as 别名]
# 或者: from django.test.utils import override_settings [as 别名]
def test_get_all_running_tasks(self):
        """Test that multiple hosts' task lists are combined."""
        second_host = "test"
        first_host_list = [1, 2, 3]
        second_host_list = [4, 5, 6]
        expected = first_host_list + second_host_list

        _cache = WorkerCache()
        for task in first_host_list:
            _cache.add_task_to_cache(task)

        with override_settings(HOSTNAME=second_host):
            _cache = WorkerCache()
            for task in second_host_list:
                _cache.add_task_to_cache(task)

        self.assertEqual(sorted(_cache.get_all_running_tasks()), sorted(expected)) 
开发者ID:project-koku,项目名称:koku,代码行数:19,代码来源:test_worker_cache.py

示例6: benchmark

# 需要导入模块: from django.test import utils [as 别名]
# 或者: from django.test.utils import override_settings [as 别名]
def benchmark(self, query_str, to_list=True, num_queries=1):
        # Clears the cache before a single benchmark to ensure the same
        # conditions across single benchmarks.
        caches[settings.CACHALOT_CACHE].clear()

        self.query_name = query_str
        query_str = 'Test.objects.using(using)' + query_str
        if to_list:
            query_str = 'list(%s)' % query_str
        self.query_function = eval('lambda using: ' + query_str)

        with override_settings(CACHALOT_ENABLED=False):
            self.bench_once(CONTEXTS[0], num_queries)

        self.bench_once(CONTEXTS[1], num_queries, invalidate_before=True)

        self.bench_once(CONTEXTS[2], 0) 
开发者ID:noripyt,项目名称:django-cachalot,代码行数:19,代码来源:benchmark.py

示例7: run

# 需要导入模块: from django.test import utils [as 别名]
# 或者: from django.test.utils import override_settings [as 别名]
def run(self):
        for db_alias in settings.DATABASES:
            self.db_alias = db_alias
            self.db_vendor = connections[self.db_alias].vendor
            print('Benchmarking %s…' % self.db_vendor)
            for cache_alias in settings.CACHES:
                cache = caches[cache_alias]
                self.cache_name = cache.__class__.__name__[:-5].lower()
                with override_settings(CACHALOT_CACHE=cache_alias):
                    self.execute_benchmark()

        self.df = pd.DataFrame.from_records(self.data)
        if not os.path.exists(RESULTS_PATH):
            os.mkdir(RESULTS_PATH)
        self.df.to_csv(os.path.join(RESULTS_PATH, 'data.csv'))

        self.xlim = (0, self.df['time'].max() * 1.01)
        self.output('db')
        self.output('cache') 
开发者ID:noripyt,项目名称:django-cachalot,代码行数:21,代码来源:benchmark.py

示例8: test_get_expire_at_browser_close

# 需要导入模块: from django.test import utils [as 别名]
# 或者: from django.test.utils import override_settings [as 别名]
def test_get_expire_at_browser_close(self):
        # Tests get_expire_at_browser_close with different settings and different
        # set_expiry calls
        with override_settings(SESSION_EXPIRE_AT_BROWSER_CLOSE=False):
            self.session.set_expiry(10)
            self.assertFalse(self.session.get_expire_at_browser_close())

            self.session.set_expiry(0)
            self.assertTrue(self.session.get_expire_at_browser_close())

            self.session.set_expiry(None)
            self.assertFalse(self.session.get_expire_at_browser_close())

        with override_settings(SESSION_EXPIRE_AT_BROWSER_CLOSE=True):
            self.session.set_expiry(10)
            self.assertFalse(self.session.get_expire_at_browser_close())

            self.session.set_expiry(0)
            self.assertTrue(self.session.get_expire_at_browser_close())

            self.session.set_expiry(None)
            self.assertTrue(self.session.get_expire_at_browser_close()) 
开发者ID:r4fek,项目名称:django-cassandra-engine,代码行数:24,代码来源:test_sessions.py

示例9: test_actual_expiry

# 需要导入模块: from django.test import utils [as 别名]
# 或者: from django.test.utils import override_settings [as 别名]
def test_actual_expiry(self):
        # this doesn't work with JSONSerializer (serializing timedelta)
        with override_settings(
            SESSION_SERIALIZER='django.contrib.sessions.serializers.PickleSerializer'
        ):
            self.session = (
                self.backend()
            )  # reinitialize after overriding settings

            # Regression test for #19200
            old_session_key = None
            new_session_key = None
            try:
                self.session['foo'] = 'bar'
                self.session.set_expiry(-timedelta(seconds=10))
                self.session.save()
                old_session_key = self.session.session_key
                # With an expiry date in the past, the session expires instantly.
                new_session = self.backend(self.session.session_key)
                new_session_key = new_session.session_key
                self.assertNotIn('foo', new_session)
            finally:
                self.session.delete(old_session_key)
                self.session.delete(new_session_key) 
开发者ID:r4fek,项目名称:django-cassandra-engine,代码行数:26,代码来源:test_sessions.py

示例10: test_mismatch_warning

# 需要导入模块: from django.test import utils [as 别名]
# 或者: from django.test.utils import override_settings [as 别名]
def test_mismatch_warning(self, mock_logger, mock_consul):
        """
        Test that a warning is logged when trying to spawn the default, but a default already
        and contains mismatching parameters with the given settings.
        """
        urls = ['http://user:pass@doesnotexist.example.com:12345', 'http://user2:pass2@doesnotexist.example.com:12345']
        for url in urls:
            with override_settings(DEFAULT_RABBITMQ_API_URL=url):
                RabbitMQServer.objects._create_default()
        mock_logger.warning.assert_called_with(
            'RabbitMQServer for %s already exists, and its settings do not match the Django '
            'settings: %s vs %s, %s vs %s, %s vs %s, %s vs %s, %s vs %s, %s vs %s',
            'accepts_new_clients', True,
            'admin_password', 'pass2',
            'admin_username', 'user2',
            'api_url', 'http://doesnotexist.example.com:12345',
            'instance_host', 'rabbitmq.example.com',
            'instance_port', 5671,
        ) 
开发者ID:open-craft,项目名称:opencraft,代码行数:21,代码来源:test_openedx_database_mixins.py

示例11: test_request_subject_does_need_to_match_issuer_override_settings

# 需要导入模块: from django.test import utils [as 别名]
# 或者: from django.test.utils import override_settings [as 别名]
def test_request_subject_does_need_to_match_issuer_override_settings(self):
        """ tests that the with_asap decorator can override the
            ASAP_SUBJECT_SHOULD_MATCH_ISSUER setting.
        """
        token = create_token(
            issuer='client-app', audience='server-app',
            key_id='client-app/key01', private_key=self._private_key_pem,
            subject='not-client-app',
        )
        with override_settings(**dict(
                self.test_settings, ASAP_SUBJECT_SHOULD_MATCH_ISSUER=False)):
            response = self.client.get(
                reverse('subject_does_need_to_match_issuer'),
                HTTP_AUTHORIZATION=b'Bearer ' + token)
            self.assertContains(
                response,
                'Unauthorized: Subject and Issuer do not match',
                status_code=401
            ) 
开发者ID:atlassian,项目名称:asap-authentication-python,代码行数:21,代码来源:test_django.py

示例12: test_dummy_cache

# 需要导入模块: from django.test import utils [as 别名]
# 或者: from django.test.utils import override_settings [as 别名]
def test_dummy_cache(self):
        """
        There should not be any query caching when cache backend is dummy.
        """
        CACHES = {
            'default': {
                'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
            },
            'django_cache_manager.cache_backend': {
                'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
            }
        }
        with override_settings(DEBUG=True, CACHES=CACHES):
            for i in range(5):
                len(Manufacturer.objects.all())
            self.assertEqual(len(connection.queries), 5) 
开发者ID:vijaykatam,项目名称:django-cache-manager,代码行数:18,代码来源:model_integration_tests.py

示例13: test_migration_11

# 需要导入模块: from django.test import utils [as 别名]
# 或者: from django.test.utils import override_settings [as 别名]
def test_migration_11(self):
        # create users with the CI feature off
        # to replicate pre feature database state
        with override_settings(ST_CASE_INSENSITIVE_USERNAMES=False):
            utils.create_user(username='FOO')
            utils.create_user(username='BaR')
            utils.create_user(username='baz')
        # default all nicknames to empty
        self.assertEqual(
            UserProfile.objects.all().update(nickname=''), 3)
        data_migration_11.populate_nickname(apps, None)
        self.assertEqual(
            [u.nickname for u in UserProfile.objects.all()],
            ['FOO', 'BaR', 'baz'])

        self.assertEqual(
            [u.username for u in User.objects.all()],
            ['FOO', 'BaR', 'baz'])
        data_migration_11.make_usernames_lower(apps, None)
        self.assertEqual(
            [u.username for u in User.objects.all()],
            ['foo', 'bar', 'baz'])
        self.assertEqual(
            [u.nickname for u in UserProfile.objects.all()],
            ['FOO', 'BaR', 'baz']) 
开发者ID:nitely,项目名称:Spirit,代码行数:27,代码来源:tests.py

示例14: test_migration_11_make_usernames_lower_integrity_err

# 需要导入模块: from django.test import utils [as 别名]
# 或者: from django.test.utils import override_settings [as 别名]
def test_migration_11_make_usernames_lower_integrity_err(self):
        with override_settings(ST_CASE_INSENSITIVE_USERNAMES=False):
            utils.create_user(username='FOO')
            utils.create_user(username='fOo')
            utils.create_user(username='Foo')
            utils.create_user(username='bar')
            utils.create_user(username='bAr')
            utils.create_user(username='baz')

        self.assertEqual(
            [u.username for u in User.objects.all()],
            ['FOO', 'fOo', 'Foo', 'bar', 'bAr', 'baz'])

        # transaction is already handled
        with self.assertRaises(IntegrityError) as cm:
            data_migration_11.make_usernames_lower(apps, None)
            self.maxDiff = None
            self.assertEqual(
                str(cm.exception),
                "There are two or more users with similar name but "
                "different casing, for example: someUser and SomeUser, "
                "either remove one of them or set the "
                "`ST_CASE_INSENSITIVE_USERNAMES` setting to False. "
                "Then run the upgrade/migration again. Any change was reverted. "
                "Duplicate users are ['FOO', 'fOo', 'Foo', 'bar', 'bAr']") 
开发者ID:nitely,项目名称:Spirit,代码行数:27,代码来源:tests.py

示例15: test_migration_11_idempotency

# 需要导入模块: from django.test import utils [as 别名]
# 或者: from django.test.utils import override_settings [as 别名]
def test_migration_11_idempotency(self):
        """Should be idempotent"""
        with override_settings(ST_CASE_INSENSITIVE_USERNAMES=False):
            utils.create_user(username='FOO')
        self.assertEqual(
            UserProfile.objects.all().update(nickname=''), 1)
        data_migration_11.populate_nickname(apps, None)
        data_migration_11.make_usernames_lower(apps, None)
        self.assertEqual(
            [u.username for u in User.objects.all()],
            ['foo'])
        self.assertEqual(
            [u.nickname for u in UserProfile.objects.all()],
            ['FOO'])
        data_migration_11.populate_nickname(apps, None)
        data_migration_11.make_usernames_lower(apps, None)
        self.assertEqual(
            [u.username for u in User.objects.all()],
            ['foo'])
        self.assertEqual(
            [u.nickname for u in UserProfile.objects.all()],
            ['FOO']) 
开发者ID:nitely,项目名称:Spirit,代码行数:24,代码来源:tests.py


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