def check_rendering(self, markdown_to_html):
     for markdown in markdown_to_html:
         with app.test_request_context('/'):
             assert render_template_string(
                 '{{contents|markdown}}',
                 contents=markdown).strip() == markdown_to_html.get(
                     markdown)
Exemplo n.º 2
0
def test_unique_trace_id_when_servicing_an_http_request(pytestconfig):
    capmanager = pytestconfig.pluginmanager.getplugin('capturemanager')

    with app.test_request_context('/'):
        app.preprocess_request()
        client.application.logger.info('Foo')
        record = parse_log_output(capmanager)
        uuid_one = record['traceid']

    with app.test_request_context('/'):
        app.preprocess_request()
        client.application.logger.info('Foo')
        record = parse_log_output(capmanager)
        uuid_two = record['traceid']

    assert uuid_one != uuid_two
Exemplo n.º 3
0
    def test_exemptions(self):
        with app.test_request_context('/'):
            app.preprocess_request()

            response = ResponseWithoutCSP(response='Foo')
            response = app.process_response(response)

            self.assertNotIn('Content-Security-Policy', response.headers)
Exemplo n.º 4
0
def test_trace_id_propagated_when_receiving_one_in_header(pytestconfig):
    capmanager = pytestconfig.pluginmanager.getplugin('capturemanager')

    with app.test_request_context('/',
                                  headers=Headers([('X-Trace-ID',
                                                    'upstream-trace-id')])):
        app.preprocess_request()
        client.application.logger.info('Foo')
        record = parse_log_output(capmanager)

    assert record['traceid'] == 'upstream-trace-id'
    def test_url_for_adds_cache_query_string(self):
        filename = 'hmlr_design_system/assets/dist/test.txt'
        with open(filename, 'w+') as file:
            file.write('Hello')

        with app.test_request_context('/'):
            output = render_template_string(
                "{{ url_for('static', filename='test.txt') }}")

        md5_value = md5_for_file(filename, hexdigest=True)

        self.assertIn('?cache={}'.format(md5_value), output)

        os.remove(filename)
Exemplo n.º 6
0
def test_exc_info_in_log_entries_when_passed(pytestconfig):
    capmanager = pytestconfig.pluginmanager.getplugin('capturemanager')

    with app.test_request_context('/',
                                  headers=Headers([('X-Trace-ID',
                                                    'upstream-trace-id')])):
        app.preprocess_request()

        try:
            raise Exception('Hello')
        except Exception as e:
            client.application.logger.info('Foo', exc_info=e)

        record = parse_log_output(capmanager)

    assert 'Traceback (most recent call last)' in ' '.join(record['exception'])
    assert 'Exception: Hello' in ' '.join(record['exception'])
    def test_repeated_url_for_calls_hits_cache_not_disk(
            self, mock_md5_for_file):
        filename = 'hmlr_design_system/assets/dist/test.txt'
        with open(filename, 'w+') as file:
            file.write('Hello')

        with app.test_request_context('/'):
            hash_one = render_template_string(
                "{{ url_for('static', filename='test.txt') }}")
            hash_two = render_template_string(
                "{{ url_for('static', filename='test.txt') }}")
            hash_three = render_template_string(
                "{{ url_for('static', filename='test.txt') }}")

            self.assertEqual(mock_md5_for_file.call_count, 1)

        self.assertEqual(hash_one, hash_two)
        self.assertEqual(hash_two, hash_three)

        os.remove(filename)
    def test_gzip_cache_key_format(self):
        with app.test_request_context('/foo?cachebuster=123'):
            response = mock.MagicMock(headers=Headers([('ETag', 'bar')]))
            key = gzip_cache_key(response)

        self.assertEqual(key, '/foobar')
Exemplo n.º 9
0
    def request(self, **kwargs):
        self.ctx = app.test_request_context('/', **kwargs)
        self.ctx.push()

        self.form = ExampleForm()
        self.form.validate_on_submit()
    def test_hashed_url_for_only_runs_for_static_asset_routes(self):
        with app.test_request_context('/'):
            output = render_template_string(
                "{{ url_for('index.index_page') }}")

        self.assertNotIn('?cache', output)