當前位置: 首頁>>代碼示例>>Python>>正文


Python django.test方法代碼示例

本文整理匯總了Python中django.test方法的典型用法代碼示例。如果您正苦於以下問題:Python django.test方法的具體用法?Python django.test怎麽用?Python django.test使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django的用法示例。


在下文中一共展示了django.test方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_check_custom_user_model_default_admin

# 需要導入模塊: import django [as 別名]
# 或者: from django import test [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: client

# 需要導入模塊: import django [as 別名]
# 或者: from django import test [as 別名]
def client():
    """Django Test Client, with some convenient overriden methods.
    """
    from django.test import Client

    class _Client(Client):
        @property
        def json(self):
            """Add json method on the client for sending json type request.

            Usages:
            >>> import json
            >>> url = reverse("phone-verify")
            >>> client.json.get(url)
            >>> client.json.post(url, data=json.dumps(payload))
            """
            return PartialMethodCaller(
                obj=self, content_type='application/json;charset="utf-8"'
            )

    return _Client() 
開發者ID:CuriousLearner,項目名稱:django-phone-verify,代碼行數:23,代碼來源:conftest.py

示例3: test_cookie_samesite_none_force_all

# 需要導入模塊: import django [as 別名]
# 或者: from django import test [as 別名]
def test_cookie_samesite_none_force_all(self):
        with self.settings(SESSION_COOKIE_SAMESITE='None', SESSION_COOKIE_SAMESITE_FORCE_ALL=True):
            response = self.client.get('/cookies-test/')
            self.assertEqual(response.cookies['sessionid']['samesite'], 'None')
            self.assertEqual(response.cookies['csrftoken']['samesite'], 'None')
            self.assertEqual(response.cookies['custom_cookie']['samesite'], 'None')
            self.assertEqual(response.cookies['zcustom_cookie']['samesite'], 'None')

            cookies_string = sorted(response.cookies.output().split('\r\n'))
            self.assertTrue('custom_cookie=' in cookies_string[1])
            self.assertTrue('; SameSite=None' in cookies_string[1])
            self.assertTrue('csrftoken=' in cookies_string[0])
            self.assertTrue('; SameSite=None' in cookies_string[0])
            self.assertTrue('sessionid=' in cookies_string[2])
            self.assertTrue('; SameSite=None' in cookies_string[2])
            self.assertTrue('zcustom_cookie=' in cookies_string[3])
            self.assertTrue('; SameSite=None' in cookies_string[3]) 
開發者ID:jotes,項目名稱:django-cookies-samesite,代碼行數:19,代碼來源:test_middleware.py

示例4: test_cookie_samesite_django30

# 需要導入模塊: import django [as 別名]
# 或者: from django import test [as 別名]
def test_cookie_samesite_django30(self):
        # Raise DeprecationWarning for newer versions of Django
        with patch('django.get_version', return_value=DJANGO_SUPPORTED_VERSION):
            with self.assertRaises(DeprecationWarning) as exc:
                self.client.get('/cookies-test/')

            self.assertEqual(exc.exception.args[0], (
                'Your version of Django supports SameSite flag in the cookies mechanism. '
                'You should remove django-cookies-samesite from your project.'
            ))

        with patch('django_cookies_samesite.middleware.django.get_version', return_value=DJANGO_SUPPORTED_VERSION):
            with self.assertRaises(DeprecationWarning) as exc:
                self.client.get('/cookies-test/')

            self.assertEqual(exc.exception.args[0], (
                'Your version of Django supports SameSite flag in the cookies mechanism. '
                'You should remove django-cookies-samesite from your project.'
            )) 
開發者ID:jotes,項目名稱:django-cookies-samesite,代碼行數:21,代碼來源:test_middleware.py

示例5: test_cookie_names_changed

# 需要導入模塊: import django [as 別名]
# 或者: from django import test [as 別名]
def test_cookie_names_changed(self):
        session_name = 'sessionid-test'
        csrf_name = 'csrftoken-test'
        with self.settings(
            SESSION_COOKIE_NAME=session_name,
            CSRF_COOKIE_NAME=csrf_name,
            SESSION_COOKIE_SAMESITE='Lax'
        ):
            response = self.client.get('/cookies-test/')

            self.assertEqual(response.cookies[session_name]['samesite'], 'Lax')
            self.assertEqual(response.cookies[csrf_name]['samesite'], 'Lax')
            cookies_string = sorted(response.cookies.output().split('\r\n'))

            self.assertTrue(csrf_name + '=' in cookies_string[0])
            self.assertTrue('; SameSite=Lax' in cookies_string[0])
            self.assertTrue(session_name + '=' in cookies_string[2])
            self.assertTrue('; SameSite=Lax' in cookies_string[2]) 
開發者ID:jotes,項目名稱:django-cookies-samesite,代碼行數:20,代碼來源:test_middleware.py

示例6: test_unsupported_browsers

# 需要導入模塊: import django [as 別名]
# 或者: from django import test [as 別名]
def test_unsupported_browsers(self, ua_string):
        session_name = 'sessionid-test'
        csrf_name = 'csrftoken-test'

        with self.settings(
            SESSION_COOKIE_NAME=session_name,
            CSRF_COOKIE_NAME=csrf_name,
            SESSION_COOKIE_SAMESITE='Lax'
        ):
            response = self.client.get(
                '/cookies-test/',
                HTTP_USER_AGENT=ua_string,
            )
            self.assertEqual(response.cookies[session_name]['samesite'], '')
            self.assertEqual(response.cookies[csrf_name]['samesite'], '')

            cookies_string = sorted(response.cookies.output().split('\r\n'))
            self.assertTrue('; SameSite=Lax' not in cookies_string[0])
            self.assertTrue('; SameSite=Lax' not in cookies_string[1]) 
開發者ID:jotes,項目名稱:django-cookies-samesite,代碼行數:21,代碼來源:test_middleware.py

示例7: test_supported_browsers

# 需要導入模塊: import django [as 別名]
# 或者: from django import test [as 別名]
def test_supported_browsers(self, ua_string):
        session_name = 'sessionid-test'
        csrf_name = 'csrftoken-test'

        with self.settings(
            SESSION_COOKIE_NAME=session_name,
            CSRF_COOKIE_NAME=csrf_name,
            SESSION_COOKIE_SAMESITE='Lax'
        ):
            response = self.client.get(
                '/cookies-test/',
                HTTP_USER_AGENT=ua_string,
            )
            self.assertEqual(response.cookies[session_name]['samesite'], 'Lax')
            self.assertEqual(response.cookies[csrf_name]['samesite'], 'Lax')

            cookies_string = sorted(response.cookies.output().split('\r\n'))
            self.assertTrue('; SameSite=Lax' in cookies_string[0])
            self.assertTrue('; SameSite=Lax' in cookies_string[2]) 
開發者ID:jotes,項目名稱:django-cookies-samesite,代碼行數:21,代碼來源:test_middleware.py

示例8: test_path_conflict

# 需要導入模塊: import django [as 別名]
# 或者: from django import test [as 別名]
def test_path_conflict(self):
        """ Check the crazy scenario where an existing metadata object has the same path. """
        old_path = self.product_metadata._path
        self.product_metadata._path = '/products/2/'
        self.product_metadata.save()
        self.assertEqual(self.product_metadata._object_id, self.product.pk)

        # Create a new product that will take the same path
        new_product = Product.objects.create()
        Coverage._meta.get_model('modelinstance').objects.filter(_content_type=self.product_content_type,
                                                                 _object_id=new_product.id).update(title="New Title")

        # This test will not work if we have the id wrong
        if new_product.id != 2:
            raise Exception("Test Error: the product ID is not as expected, this test cannot work.")

        # Check that the existing path was corrected
        product_metadata = Coverage._meta.get_model('modelinstance').objects.get(id=self.product_metadata.id)
        self.assertEqual(old_path, product_metadata._path)

        # Check the new data is available under the correct path
        metadata = get_metadata(path="/products/2/")
        self.assertEqual(metadata.title.value, u"New Title") 
開發者ID:whyflyru,項目名稱:django-seo,代碼行數:25,代碼來源:tests.py

示例9: test_create_error_model

# 需要導入模塊: import django [as 別名]
# 或者: from django import test [as 別名]
def test_create_error_model(self):
        """Validate that a complete Error model is created using JobError
        """

        job_type_name = 'test-job'
        name = 'bad-data'
        title = 'Bad Data'
        description = 'Error received when bad data is detected'
        category = 'DATA'

        error = JobError(job_type_name, name, title, description, category)
        model = error.create_model()
        self.assertEqual(model.name, name)
        self.assertEqual(model.title, title)
        self.assertEqual(model.description, description)
        self.assertEqual(model.category, category)
        self.assertEqual(model.job_type_name, job_type_name) 
開發者ID:ngageoint,項目名稱:scale,代碼行數:19,代碼來源:test_error.py

示例10: test_save_models

# 需要導入模塊: import django [as 別名]
# 或者: from django import test [as 別名]
def test_save_models(self):
        """Tests calling JobErrorMapping.save_models() successfully"""

        job_type_name = 'test-job'
        mapping = JobErrorMapping(job_type_name)

        error_1 = JobError(job_type_name, 'mapped_error_1', title='Title', description='Description',
                           category='ALGORITHM')
        error_2 = JobError(job_type_name, 'mapped_error_2', category='DATA')
        mapping.add_mapping(1, error_1)
        mapping.add_mapping(2, error_2)

        # Make sure error models are created successfully
        mapping.save_models()
        self.assertEqual(Error.objects.filter(job_type_name=job_type_name).count(), 2)

        # Make some changes
        error_1.description = 'New description'
        error_2.category = 'ALGORITHM'

        # Make sure error models are updated successfully
        mapping.save_models()
        self.assertEqual(Error.objects.get(name='mapped_error_1').description, 'New description')
        self.assertEqual(Error.objects.get(name='mapped_error_2').category, 'ALGORITHM') 
開發者ID:ngageoint,項目名稱:scale,代碼行數:26,代碼來源:test_mapping.py

示例11: test_scale_post_steps_successful

# 需要導入模塊: import django [as 別名]
# 或者: from django import test [as 別名]
def test_scale_post_steps_successful(self, mock_env_vars, mock_job_exe_manager):
        """Tests successfully executing scale_post_steps."""

        # Set up mocks
        def get_env_vars(name, *args, **kwargs):
            return str(self.job.id) if name == 'SCALE_JOB_ID' else str(self.job_exe.exe_num)
        mock_env_vars.side_effect = get_env_vars
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.job_type.get_job_interface.return_value.perform_post_steps.return_value = RESULTS
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.id = self.job_exe.id
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.job_id = self.job_exe.job_id
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.job_type_id = self.job_exe.job_type_id
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.exe_num = self.job_exe.exe_num

        # Call method to test
        cmd = PostCommand()
        cmd.run_from_argv(['manage.py', 'scale_post_steps'])

        # Check results
        job_exe_output = JobExecutionOutput.objects.get(job_exe_id=self.job_exe.id)
        self.assertDictEqual(job_exe_output.get_output().get_dict(), JOB_RESULTS.get_dict()) 
開發者ID:ngageoint,項目名稱:scale,代碼行數:22,代碼來源:test_scale_post_steps.py

示例12: test_scale_post_steps_no_stderr

# 需要導入模塊: import django [as 別名]
# 或者: from django import test [as 別名]
def test_scale_post_steps_no_stderr(self, mock_env_vars, mock_job_exe_manager):
        """Tests successfully executing scale_post_steps."""

        # Set up mocks
        def get_env_vars(name, *args, **kwargs):
            return str(self.job.id) if name == 'SCALE_JOB_ID' else str(self.job_exe.exe_num)
        mock_env_vars.side_effect = get_env_vars
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.stdout = 'something'
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.stderr = None
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.job_type.get_job_interface.return_value.perform_post_steps.return_value = RESULTS
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.id = self.job_exe.id
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.job_id = self.job_exe.job_id
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.job_type_id = self.job_exe.job_type_id
        mock_job_exe_manager.get_job_exe_with_job_and_job_type.return_value.exe_num = self.job_exe.exe_num

        # Call method to test
        cmd = PostCommand()
        cmd.run_from_argv(['manage.py', 'scale_post_steps'])

        # Check results
        job_exe_output = JobExecutionOutput.objects.get(job_exe_id= self.job_exe.id)
        self.assertDictEqual(job_exe_output.get_output().get_dict(), JOB_RESULTS.get_dict()) 
開發者ID:ngageoint,項目名稱:scale,代碼行數:24,代碼來源:test_scale_post_steps.py

示例13: test_input_data_names_must_be_unique

# 需要導入模塊: import django [as 別名]
# 或者: from django import test [as 別名]
def test_input_data_names_must_be_unique(self):
        definition = {
            'command': 'test-command',
            'command_arguments': '${param-1}',
            'version': '1.0',
            'input_data': [{
                'name': 'param-1',
                'type': 'file',
            }, {
                'name': 'param-1',
                'type': 'property',
            }]
        }
        try:
            JobInterface(definition)
            self.fail('Expected invalid job definition to throw an exception')
        except InvalidInterfaceDefinition:
            pass 
開發者ID:ngageoint,項目名稱:scale,代碼行數:20,代碼來源:test_job_interface.py

示例14: setUp

# 需要導入模塊: import django [as 別名]
# 或者: from django import test [as 別名]
def setUp(self):
        """
            Remove migration file generated by test if there is any missing.
        """
        clean_migrations() 
開發者ID:javrasya,項目名稱:django-river,代碼行數:7,代碼來源:test__migrations.py

示例15: tearDown

# 需要導入模塊: import django [as 別名]
# 或者: from django import test [as 別名]
def tearDown(self):
        """
            Remove migration file generated by test if there is any missing.
        """
        clean_migrations() 
開發者ID:javrasya,項目名稱:django-river,代碼行數:7,代碼來源:test__migrations.py


注:本文中的django.test方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。