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
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)
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 = 'title_ui/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)
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 = 'title_ui/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_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)
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')