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


Python test.override_settings方法代码示例

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


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

示例1: test_check_custom_user_model_default_admin

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import override_settings [as 别名]
def test_check_custom_user_model_default_admin(self):
            # Django doesn't re-register admins when using `override_settings`,
            # so we have to do it manually in this test case.
            admin.site.register(get_user_model(), UserAdmin)

            warnings = checks.check_custom_user_model(HijackAdminConfig)
            expected_warnings = [
                Warning(
                    'django-hijack-admin does not work out the box with a custom user model.',
                    hint='Please mix HijackUserAdminMixin into your custom UserAdmin.',
                    obj=settings.AUTH_USER_MODEL,
                    id='hijack_admin.W001',
                )
            ]
            self.assertEqual(warnings, expected_warnings)

            admin.site.unregister(get_user_model()) 
开发者ID:arteria,项目名称:django-hijack-admin,代码行数:19,代码来源:test_checks.py

示例2: test_security_code_session_token_verification_api

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import override_settings [as 别名]
def test_security_code_session_token_verification_api(client, backend):
    with override_settings(PHONE_VERIFICATION=backend):
        f.create_verification(
            security_code=SECURITY_CODE,
            phone_number=PHONE_NUMBER,
            session_token=SESSION_TOKEN,
        )
        url = reverse("phone-verify")
        data = {
            "phone_number": PHONE_NUMBER,
            "security_code": SECURITY_CODE,
            "session_token": SESSION_TOKEN,
        }
        response = client.json.post(url, data=data)
        assert response.status_code == 200
        assert response.data["message"] == "Security code is valid." 
开发者ID:CuriousLearner,项目名称:django-phone-verify,代码行数:18,代码来源:test_api.py

示例3: test_phone_verification_with_incomplete_payload

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import override_settings [as 别名]
def test_phone_verification_with_incomplete_payload(client, backend):
    with override_settings(PHONE_VERIFICATION=backend):
        f.create_verification(
            security_code=SECURITY_CODE,
            phone_number=PHONE_NUMBER,
            session_token=SESSION_TOKEN,
        )
        url = reverse("phone-verify")
        data = {"phone_number": PHONE_NUMBER}
        response = client.json.post(url, data=data)
        assert response.status_code == 400
        response_data = json.loads(json.dumps(response.data))
        assert response_data["session_token"][0] == "This field is required."
        assert response_data["security_code"][0] == "This field is required."

        data = {"security_code": SECURITY_CODE}
        response = client.json.post(url, data=data)
        assert response.status_code == 400
        response_data = json.loads(json.dumps(response.data))
        assert response_data["phone_number"][0] == "This field is required." 
开发者ID:CuriousLearner,项目名称:django-phone-verify,代码行数:22,代码来源:test_api.py

示例4: test_check_security_code_expiry

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import override_settings [as 别名]
def test_check_security_code_expiry(client, backend):
    with override_settings(PHONE_VERIFICATION=backend):
        f.create_verification(
            security_code=SECURITY_CODE,
            phone_number=PHONE_NUMBER,
            session_token=SESSION_TOKEN,
        )
        time.sleep(2)
        url = reverse("phone-verify")
        data = {
            "phone_number": PHONE_NUMBER,
            "security_code": SECURITY_CODE,
            "session_token": SESSION_TOKEN,
        }
        response = client.json.post(url, data=data)
        response_data = json.loads(json.dumps(response.data))

        backend_cls = _get_backend_cls(backend)

        if backend_cls in backends:
            assert response.status_code == 400
            assert response_data["non_field_errors"][0] == "Security code has expired"
        elif backend_cls in sandbox_backends:
            # Sandbox Backend returns a 200 status code when verifying security code expiry
            assert response.status_code == 200 
开发者ID:CuriousLearner,项目名称:django-phone-verify,代码行数:27,代码来源:test_api.py

示例5: test_exception_is_logged_when_raised

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import override_settings [as 别名]
def test_exception_is_logged_when_raised(client, mocker, backend):
    with override_settings(PHONE_VERIFICATION=backend):
        mock_send_verification = mocker.patch(
            "phone_verify.services.PhoneVerificationService.send_verification"
        )
        mock_logger = mocker.patch("phone_verify.services.logger")
        backend_cls = _get_backend_cls(backend)
        if (
            backend_cls == "nexmo.NexmoBackend"
            or backend_cls == "nexmo.NexmoSandboxBackend"
        ):
            exc = ClientError()
            mock_send_verification.side_effect = exc
        elif (
            backend_cls == "twilio.TwilioBackend"
            or backend_cls == "twilio.TwilioSandboxBackend"
        ):
            exc = TwilioRestException(status=mocker.Mock(), uri=mocker.Mock())
            mock_send_verification.side_effect = exc
        send_security_code_and_generate_session_token(phone_number="+13478379634")
        mock_logger.error.assert_called_once_with(
            f"Error in sending verification code to +13478379634: {exc}"
        ) 
开发者ID:CuriousLearner,项目名称:django-phone-verify,代码行数:25,代码来源:test_services.py

示例6: test_send_bulk_sms

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import override_settings [as 别名]
def test_send_bulk_sms(client, mocker, backend):
    with override_settings(PHONE_VERIFICATION=backend):
        backend_import = settings.PHONE_VERIFICATION["BACKEND"]
        backend_cls = import_string(backend_import)
        cls_obj = backend_cls(**settings.PHONE_VERIFICATION["OPTIONS"])

        mock_send_sms = mocker.patch(f"{backend_import}.send_sms")
        numbers = ["+13478379634", "+13478379633", "+13478379632"]
        message = "Fake message"

        cls_obj.send_bulk_sms(numbers, message)
        assert mock_send_sms.called
        assert mock_send_sms.call_count == 3
        mock_send_sms.assert_has_calls(
            [
                mocker.call(number=numbers[0], message=message),
                mocker.call(number=numbers[1], message=message),
                mocker.call(number=numbers[2], message=message),
            ]
        ) 
开发者ID:CuriousLearner,项目名称:django-phone-verify,代码行数:22,代码来源:test_backends.py

示例7: _prepare_settings

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import override_settings [as 别名]
def _prepare_settings():
    """Prepare and apply settings overrides needed for testing."""
    # Override container name prefix setting.
    resolwe_settings.FLOW_EXECUTOR_SETTINGS[
        "CONTAINER_NAME_PREFIX"
    ] = "{}_{}_{}".format(
        resolwe_settings.FLOW_EXECUTOR_SETTINGS.get("CONTAINER_NAME_PREFIX", "resolwe"),
        # NOTE: This is necessary to avoid container name clashes when tests are run from
        # different Resolwe code bases on the same system (e.g. on a CI server).
        get_random_string(length=6),
        os.path.basename(resolwe_settings.FLOW_EXECUTOR_SETTINGS["DATA_DIR"]),
    )
    return override_settings(
        CELERY_ALWAYS_EAGER=True,
        FLOW_EXECUTOR=resolwe_settings.FLOW_EXECUTOR_SETTINGS,
        FLOW_MANAGER=resolwe_settings.FLOW_MANAGER_SETTINGS,
    ) 
开发者ID:genialis,项目名称:resolwe,代码行数:19,代码来源:test_runner.py

示例8: run_suite

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import override_settings [as 别名]
def run_suite(self, suite, **kwargs):
        """Run the test suite with manager workers in the background."""
        # Due to the way the app modules are imported, there's no way to
        # statically override settings with TEST overrides before e.g.
        # resolwe.flow.managers.manager is loaded somewhere in the code
        # (the most problematic files are signals.py and
        # resolwe.test.testcases.process); the only realistic mechanism
        # is to override later and call some sort of commit method in
        # the manager.

        keep_data_override = override_settings(FLOW_MANAGER_KEEP_DATA=self.keep_data)
        keep_data_override.__enter__()

        if self.parallel > 1:
            return super().run_suite(suite, **kwargs)

        return _run_manager(super().run_suite, suite, **kwargs) 
开发者ID:genialis,项目名称:resolwe,代码行数:19,代码来源:test_runner.py

示例9: test_transfer_view

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import override_settings [as 别名]
def test_transfer_view(self):
        self.login("julia")
        org = Organization.objects.get(name="Les Amis de la Terre")
        user = PytitionUser.objects.get(user__username="julia")
        user_petition = Petition.objects.create(title="Petition 1", user=user)
        url = reverse("transfer_petition", args=[user_petition.id])

        response = self.client.post(url, data={"new_owner_type": "org", "new_owner_name": org.slugname}, follow=True)
        self.assertEqual(response.status_code, 200)
        user_petition = Petition.objects.get(id=user_petition.id)
        self.assertEqual(user_petition.org, org)

        response = self.client.post(url, data={"new_owner_type": "user", "new_owner_name": user.user.username}, follow=True)
        self.assertEqual(response.status_code, 200)
        user_petition = Petition.objects.get(id=user_petition.id)
        self.assertEqual(user_petition.user, user)

        with override_settings(DISABLE_USER_PETITION=True):
            user_petition = Petition.objects.create(title="Petition 1", org=org)
            response = self.client.post(url, data={"new_owner_type": "user", "new_owner_name": user.user.username}, follow=True)
            self.assertContains(response, "Users are not allowed to transfer petitions to organizations on this instance.")
            user_petition = Petition.objects.get(id=user_petition.id)
            self.assertIsNone(user_petition.user) 
开发者ID:pytition,项目名称:Pytition,代码行数:25,代码来源:tests_PetitionTransfer.py

示例10: test_data_file_is_unknown_format___response_is_200

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import override_settings [as 别名]
def test_data_file_is_unknown_format___response_is_200(self):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                user = fake_user()
                cmf = fake_data_file()

                response = self.app.post(
                    cmf.get_absolute_data_file_url(),
                    headers={
                        'Authorization': 'Bearer {}'.format(AccessToken.for_user(user))
                    },
                    upload_files=(
                        ('file', 'file.tar', b'an-unknown-mime-format'),
                    ),
                )

                self.assertEqual(200, response.status_code) 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:19,代码来源:test_data_files.py

示例11: test_data_file_is_uploaded___file_can_be_retrieved

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import override_settings [as 别名]
def test_data_file_is_uploaded___file_can_be_retrieved(self, file_content, content_type):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                user = fake_user()
                cmf = fake_data_file()

                self.app.post(
                    cmf.get_absolute_data_file_url(),
                    headers={
                        'Authorization': 'Bearer {}'.format(AccessToken.for_user(user))
                    },
                    upload_files=(
                        ('file', 'file{}'.format(mimetypes.guess_extension(content_type)), file_content),
                    ),
                )

                response = self.app.get(
                    cmf.get_absolute_data_file_url(),
                    headers={
                        'Authorization': 'Bearer {}'.format(AccessToken.for_user(user))
                    },
                )

                self.assertEqual(response.body, file_content)
                self.assertEqual(response.content_type, content_type) 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:27,代码来源:test_data_files.py

示例12: test_state_is_ready___run_is_started

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import override_settings [as 别名]
def test_state_is_ready___run_is_started(self, status, task_id):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                res_factory = FakeAsyncResultFactory(target_task_id=task_id)
                analysis = fake_analysis(status=status, run_task_id=task_id, input_file=fake_related_file(), settings_file=fake_related_file())
                initiator = fake_user()

                sig_res = Mock()
                sig_res.delay.return_value = res_factory(task_id)

                with patch('src.server.oasisapi.analyses.models.Analysis.run_analysis_signature', PropertyMock(return_value=sig_res)):
                    analysis.run(initiator)

                    sig_res.link.assert_called_once_with(record_run_analysis_result.s(analysis.pk, initiator.pk))
                    sig_res.link_error.assert_called_once_with(
                        signature('on_error', args=('record_run_analysis_failure', analysis.pk, initiator.pk), queue=analysis.model.queue_name)
                    )
                    sig_res.delay.assert_called_once_with() 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:20,代码来源:test_analysis_model.py

示例13: test_state_is_running_or_generating_inputs___validation_error_is_raised_revoke_is_not_called

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import override_settings [as 别名]
def test_state_is_running_or_generating_inputs___validation_error_is_raised_revoke_is_not_called(self, status, task_id):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                res_factory = FakeAsyncResultFactory(target_task_id=task_id)
                initiator = fake_user()

                sig_res = Mock()
                with patch('src.server.oasisapi.analyses.models.Analysis.generate_input_signature', PropertyMock(return_value=sig_res)):
                    analysis = fake_analysis(status=status, run_task_id=task_id, portfolio=fake_portfolio(location_file=fake_related_file()))

                    with self.assertRaises(ValidationError) as ex:
                        analysis.generate_inputs(initiator)

                    self.assertEqual({'status': [
                        'Analysis status must be one of [NEW, INPUTS_GENERATION_ERROR, INPUTS_GENERATION_CANCELLED, READY, RUN_COMPLETED, RUN_CANCELLED, RUN_ERROR]'
                    ]}, ex.exception.detail)
                    self.assertEqual(status, analysis.status)
                    self.assertFalse(res_factory.revoke_called) 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:20,代码来源:test_analysis_model.py

示例14: test_portfolio_has_no_location_file___validation_error_is_raised_revoke_is_not_called

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import override_settings [as 别名]
def test_portfolio_has_no_location_file___validation_error_is_raised_revoke_is_not_called(self, task_id):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                res_factory = FakeAsyncResultFactory(target_task_id=task_id)
                initiator = fake_user()

                sig_res = Mock()
                with patch('src.server.oasisapi.analyses.models.Analysis.generate_input_signature', PropertyMock(return_value=sig_res)):
                    analysis = fake_analysis(status=Analysis.status_choices.NEW, run_task_id=task_id)

                    with self.assertRaises(ValidationError) as ex:
                        analysis.generate_inputs(initiator)

                    self.assertEqual({'portfolio': ['"location_file" must not be null']}, ex.exception.detail)

                    self.assertEqual(Analysis.status_choices.NEW, analysis.status)
                    self.assertFalse(res_factory.revoke_called) 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:19,代码来源:test_analysis_model.py

示例15: test_settings_file_is_not_a_valid_format___response_is_400

# 需要导入模块: from django import test [as 别名]
# 或者: from django.test import override_settings [as 别名]
def test_settings_file_is_not_a_valid_format___response_is_400(self):
        with TemporaryDirectory() as d:
            with override_settings(MEDIA_ROOT=d):
                user = fake_user()
                analysis = fake_analysis()

                response = self.app.post(
                    analysis.get_absolute_settings_file_url(),
                    headers={
                        'Authorization': 'Bearer {}'.format(AccessToken.for_user(user))
                    },
                    upload_files=(
                        ('file', 'file.tar', b'content'),
                    ),
                    expect_errors=True,
                )

                self.assertEqual(400, response.status_code) 
开发者ID:OasisLMF,项目名称:OasisPlatform,代码行数:20,代码来源:test_analysis_api.py


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