django.test.ignore_warnings

Here are the examples of the python api django.test.ignore_warnings taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

7 Examples 7

3 Source : test_include.py
with Apache License 2.0
from gethue

    def test_include_error07(self):
        template = self.engine.get_template('include-error07')

        if self.engine.debug:
            with self.assertRaises(RuntimeError):
                template.render(Context())
        else:
            with ignore_warnings(category=RemovedInDjango21Warning):
                self.assertEqual(template.render(Context()), '')

    @setup({'include-error08': '{% include "include-fail2" %}'}, include_fail_templates)

3 Source : test_include.py
with Apache License 2.0
from gethue

    def test_include_error08(self):
        template = self.engine.get_template('include-error08')

        if self.engine.debug:
            with self.assertRaises(TemplateSyntaxError):
                template.render(Context())
        else:
            with ignore_warnings(category=RemovedInDjango21Warning):
                self.assertEqual(template.render(Context()), '')

    @setup({'include-error09': '{% include failed_include %}'}, include_fail_templates)

3 Source : test_include.py
with Apache License 2.0
from gethue

    def test_include_error09(self):
        context = Context({'failed_include': 'include-fail1'})
        template = self.engine.get_template('include-error09')

        if self.engine.debug:
            with self.assertRaises(RuntimeError):
                template.render(context)
        else:
            with ignore_warnings(category=RemovedInDjango21Warning):
                self.assertEqual(template.render(context), '')

    @setup({'include-error10': '{% include failed_include %}'}, include_fail_templates)

3 Source : test_include.py
with Apache License 2.0
from gethue

    def test_include_error10(self):
        context = Context({'failed_include': 'include-fail2'})
        template = self.engine.get_template('include-error10')

        if self.engine.debug:
            with self.assertRaises(TemplateSyntaxError):
                template.render(context)
        else:
            with ignore_warnings(category=RemovedInDjango21Warning):
                self.assertEqual(template.render(context), '')


class IncludeTests(SimpleTestCase):

3 Source : test_logging.py
with Apache License 2.0
from gethue

    def test_logs_exceptions_during_rendering_with_debug_disabled(self):
        template = self.engine.from_string('{% include "child" %}')
        template.name = 'template_name'
        with ignore_warnings(category=RemovedInDjango21Warning):
            self.assertEqual(template.render(self.ctx), '')
        self.assertEqual(
            self.test_handler.log_record.getMessage(),
            "Exception raised while rendering {% include %} for template "
            "'template_name'. Empty string rendered instead."
        )
        self.assertIsNotNone(self.test_handler.log_record.exc_info)
        self.assertEqual(self.test_handler.log_record.levelno, logging.WARN)

    def test_logs_exceptions_during_rendering_with_no_template_name(self):

3 Source : test_logging.py
with Apache License 2.0
from gethue

    def test_logs_exceptions_during_rendering_with_no_template_name(self):
        template = self.engine.from_string('{% include "child" %}')
        with ignore_warnings(category=RemovedInDjango21Warning):
            self.assertEqual(template.render(self.ctx), '')
        self.assertEqual(
            self.test_handler.log_record.getMessage(),
            "Exception raised while rendering {% include %} for template "
            "'unknown'. Empty string rendered instead."
        )
        self.assertIsNotNone(self.test_handler.log_record.exc_info)
        self.assertEqual(self.test_handler.log_record.levelno, logging.WARN)

0 Source : test_http.py
with Apache License 2.0
from gethue

    def test_is_safe_url(self):
        bad_urls = (
            'http://example.com',
            'http:///example.com',
            'https://example.com',
            'ftp://example.com',
            r'\\example.com',
            r'\\\example.com',
            r'/\\/example.com',
            r'\\\example.com',
            r'\\example.com',
            r'\\//example.com',
            r'/\/example.com',
            r'\/example.com',
            r'/\example.com',
            'http:///example.com',
            r'http:/\//example.com',
            r'http:\/example.com',
            r'http:/\example.com',
            'javascript:alert("XSS")',
            '\njavascript:alert(x)',
            '\x08//example.com',
            r'http://otherserver\@example.com',
            r'http:\\testserver\@example.com',
            r'http://testserver\me:[email protected]',
            r'http://testserver\@example.com',
            r'http:\\testserver\confirm\[email protected]',
            'http:999999999',
            'ftp:9999999999',
            '\n',
            'http://[2001:cdba:0000:0000:0000:0000:3257:9652/',
            'http://2001:cdba:0000:0000:0000:0000:3257:9652]/',
        )
        for bad_url in bad_urls:
            with ignore_warnings(category=RemovedInDjango21Warning):
                self.assertFalse(http.is_safe_url(bad_url, host='testserver'), "%s should be blocked" % bad_url)
            self.assertFalse(
                http.is_safe_url(bad_url, allowed_hosts={'testserver', 'testserver2'}),
                "%s should be blocked" % bad_url,
            )

        good_urls = (
            '/view/?param=http://example.com',
            '/view/?param=https://example.com',
            '/view?param=ftp://example.com',
            'view/?param=//example.com',
            'https://testserver/',
            'HTTPS://testserver/',
            '//testserver/',
            'http://testserver/[email protected]',
            '/url%20with%20spaces/',
            'path/http:2222222222',
        )
        for good_url in good_urls:
            with ignore_warnings(category=RemovedInDjango21Warning):
                self.assertTrue(http.is_safe_url(good_url, host='testserver'), "%s should be allowed" % good_url)
            self.assertTrue(
                http.is_safe_url(good_url, allowed_hosts={'otherserver', 'testserver'}),
                "%s should be allowed" % good_url,
            )

        if six.PY2:
            # Check binary URLs, regression tests for #26308
            self.assertTrue(
                http.is_safe_url(b'https://testserver/', allowed_hosts={'testserver'}),
                "binary URLs should be allowed on Python 2"
            )
            self.assertFalse(http.is_safe_url(b'\x08//example.com', allowed_hosts={'testserver'}))
            self.assertTrue(http.is_safe_url('àview/'.encode('utf-8'), allowed_hosts={'testserver'}))
            self.assertFalse(http.is_safe_url('àview'.encode('latin-1'), allowed_hosts={'testserver'}))

        # Valid basic auth credentials are allowed.
        self.assertTrue(http.is_safe_url(r'http://user:pass@testserver/', allowed_hosts={'user:pass@testserver'}))
        # A path without host is allowed.
        self.assertTrue(http.is_safe_url('/confirm/[email protected]'))
        # Basic auth without host is not allowed.
        self.assertFalse(http.is_safe_url(r'http://testserver\@example.com'))

    def test_is_safe_url_secure_param_https_urls(self):