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)
コード例 #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
    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)
コード例 #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"
コード例 #5
0
    def test_url_for_adds_cache_query_string(self):
        filename = "demo/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)
コード例 #6
0
    def test_repeated_url_for_calls_hits_cache_not_disk(self, mock_md5_for_file):
        filename = "demo/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)
コード例 #7
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"])
コード例 #8
0
    def test_hashed_url_for_only_runs_for_static_asset_routes(self):
        with app.test_request_context("/"):
            output = render_template_string("{{ url_for('components.index') }}")

        self.assertNotIn("?cache", output)
コード例 #9
0
    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")