Пример #1
0
    def test_index_clear(self):
        import os
        import tempfile
        fields = [
            ('fulldirs', '1'),
            ('sort', 'cumulative'),
            ('limit', '500'),
            ('mode', 'callers'),
            ('clear', 'submit'),
        ]
        content_type, body = encode_multipart_formdata(fields)
        environ = {
            'wsgi.input': BytesIO(body),
            'CONTENT_TYPE': content_type,
            'CONTENT_LENGTH': len(body),
            'REQUEST_METHOD': 'POST',
        }

        middleware = self._makeOne(None)
        f = tempfile.mktemp()
        f = open(f, 'w')
        f.write('x')
        f.close()
        middleware.log_filename = f.name
        request = self._makeRequest(environ)
        html = middleware.index(request)
        self.assertFalse(
            html.find('There is not yet any profiling data') == -1)
        self.assertFalse(os.path.exists(f.name))
Пример #2
0
    def test_call_keep_first_request(self):
        import os
        import tempfile
        fields = [
            ('fulldirs', '1'),
            ('sort', 'cumulative'),
            ('limit', '500'),
            ('mode', 'callers'),
        ]
        content_type, body = encode_multipart_formdata(fields)
        environ = self._makeEnviron({
            'wsgi.input': BytesIO(body),
            'CONTENT_TYPE': content_type,
            'CONTENT_LENGTH': len(body),
        })
        log_filename = tempfile.mktemp()
        middleware = self._makeOne(app,
                                   discard_first_request=False,
                                   log_filename=log_filename)
        self.assertFalse(middleware.first_request)
        statuses = []
        headerses = []

        def start_response(status, headers, exc_info=None):
            statuses.append(status)
            headerses.append(headers)

        middleware(environ, start_response)
        self.assertEqual(statuses[0], '200 OK')
        self.assertFalse(middleware.first_request)
        self.assertTrue(os.path.exists(log_filename))
        os.remove(log_filename)
Пример #3
0
    def test_call_withpath(self):
        fields = [
            ('fulldirs', '1'),
            ('sort', 'cumulative'),
            ('limit', '500'),
            ('mode', 'callers'),
        ]
        content_type, body = encode_multipart_formdata(fields)
        environ = self._makeEnviron({
            'wsgi.input': BytesIO(body),
            'CONTENT_TYPE': content_type,
            'CONTENT_LENGTH': len(body),
        })

        middleware = self._makeOne(None)
        environ['PATH_INFO'] = middleware.path
        statuses = []
        headerses = []

        def start_response(status, headers):
            statuses.append(status)
            headerses.append(headers)

        iterable = middleware(environ, start_response)
        html = text_(iterable[0])
        self.assertFalse(
            html.find('There is not yet any profiling data') == -1)
        self.assertEqual(statuses[0], '200 OK')
        self.assertEqual(headerses[0][0],
                         ('content-type', 'text/html; charset="UTF-8"'))
        self.assertEqual(headerses[0][1], ('content-length', str(len(html))))
Пример #4
0
    def test_index_withstats_and_filename(self):
        import os
        import tempfile
        fields = [
            ('sort', 'stats'),
            ('limit', '500'),
            ('mode', 'fake'),
            ('filename', 'fred'),
        ]
        content_type, body = encode_multipart_formdata(fields)
        request = self._makeRequest({
            'wsgi.input': BytesIO(body),
            'CONTENT_TYPE': content_type,
            'CONTENT_LENGTH': len(body),
        })

        middleware = self._makeOne(None)
        stats = DummyStats()
        middleware.Stats = stats
        f = tempfile.mktemp()
        f = open(f, 'w')
        f.write('x')
        f.close()
        middleware.log_filename = f.name
        request.environ['PATH_INFO'] = middleware.path
        middleware.index(request)
        self.assertEqual(stats.stripped, True)
        self.assertNotEqual(stats.stream, True)
        self.assertEqual(stats.printlimit, 500)
        self.assertEqual(stats.filename, 'fred')
        self.assertEqual(stats.sortspec, 'stats')
        os.remove(f.name)
Пример #5
0
 def test_index_get_withdata(self):
     request = self._makeRequest({
         'REQUEST_METHOD': 'GET',
         'wsgi.input': '',
     })
     middleware = self._makeOne(None)
     output = BytesIO(bytes_('hello!'))
     html = middleware.index(request, output)
     self.assertTrue('Profiling information is generated' in html)
Пример #6
0
    def test_index_post_withdata_fulldirs(self):
        fields = [
            ('fulldirs', '1'),
            ('sort', 'cumulative'),
            ('limit', '500'),
            ('mode', 'callers'),
        ]
        content_type, body = encode_multipart_formdata(fields)
        request = self._makeRequest({
            'wsgi.input': BytesIO(body),
            'CONTENT_TYPE': content_type,
            'CONTENT_LENGTH': len(body),
        })

        middleware = self._makeOne(None)
        request.environ['PATH_INFO'] = middleware.path
        output = BytesIO(bytes_('hello!'))
        html = middleware.index(request, output)
        self.assertTrue('Profiling information is generated' in html)
Пример #7
0
 def test_index_post(self):
     fields = [
         ('fulldirs', '1'),
         ('sort', 'cumulative'),
         ('limit', '500'),
         ('mode', 'callers'),
     ]
     content_type, body = encode_multipart_formdata(fields)
     environ = {
         'wsgi.input': BytesIO(body),
         'CONTENT_TYPE': content_type,
         'CONTENT_LENGTH': len(body),
         'REQUEST_METHOD': 'POST',
     }
     middleware = self._makeOne(None)
     request = self._makeRequest(environ)
     html = middleware.index(request)
     self.assertFalse(
         html.find('There is not yet any profiling data') == -1)