import requests
import urllib.parse

class TestMetrics:

    def test_metrics_html(self, master_ar_process_pertest, valid_user_header):
        """
        /nginx/status returns metrics in HTML format
        """
        url = master_ar_process_pertest.make_url_from_path('/nginx/status')

        resp = requests.get(
            url,
            allow_redirects=False,
            headers=valid_user_header)

        assert resp.status_code == 200
        assert resp.headers['Content-Type'] == 'text/html'

    def test_metrics_prometheus(self, master_ar_process_pertest, valid_user_header):
        """
        /nginx/metrics returns metrics in Prometheus format
        """
        url = master_ar_process_pertest.make_url_from_path('/nginx/metrics')

        resp = requests.get(
            url,
            allow_redirects=False,
            headers=valid_user_header)

        assert resp.status_code == 200
        assert resp.headers['Content-Type'] == 'text/plain'
        assert resp.text.startswith('# HELP nginx_vts_info Nginx info')

    def test_metrics_prometheus_escape(self, master_ar_process_pertest, valid_user_header):
        """
        /nginx/metrics escapes Prometheus format correctly.
        """

        # https://github.com/prometheus/docs/blob/master/content/docs/instrumenting/exposition_formats.md#text-format-details
        # "label_value can be any sequence of UTF-8 characters, but the backslash
        # (\, double-quote ("}, and line feed (\n) characters have to be escaped
        # as \\, \", and \n, respectively."

        # Add \t for tab as well, to show that is passes through unescaped

        url_path = urllib.parse.quote('/service/monitoring/gra"f\\a\nn\ta')
        url = master_ar_process_pertest.make_url_from_path(url_path)

        resp = requests.get(
            url,
            allow_redirects=False,
            headers=valid_user_header)

        assert resp.status_code == 404

        url = master_ar_process_pertest.make_url_from_path('/nginx/metrics')

        resp = requests.get(
            url,
            allow_redirects=False,
            headers=valid_user_header)

        assert resp.status_code == 200
        assert resp.headers['Content-Type'] == 'text/plain'
        # DCOS-50265 swaps the truth of the following two asserts:
        # not escaped:
        assert '/service/monitoring/gra"f\\a\nn\ta' not in resp.text
        # correctly escaped:
        assert '/service/monitoring/gra\\"f\\\\a\\nn\ta' in resp.text

@@ -1,19 +1,4 @@
-import requests
 %0Aimp
@@ -15,16 +15,34 @@
 .parse%0A%0A
+import requests%0A%0A%0A
 class Te

Fix lint