Beispiel #1
0
    def test_middleware_app_profiler(self):
        temp_filename = get_temporary_filename()
        profiler_path = "/__profiler__"
        try:
            pm = linesman.middleware.ProfilingMiddleware(
                Mock(), profiler_path=profiler_path)
            session = linesman.ProfilingSession(generate_profiler_entry())
            pm._backend.add(session)

            app = TestApp(pm)

            # Test that invalid URLs fail
            app.get('/__profiler__/notaurl', status=404)
            app.get('/__profiler__/graph/notavalidgraph', status=404)
            app.get('/__profiler__/media/js/notafile', status=404)
            app.get('/__profiler__/profiles/notavaliduuids', status=404)

            app.get('/__profiler__/media/js/accordian.js')
            app.get('/__profiler__/profiles/%s' % session.uuid)
            resp = app.get('/__profiler__')
            assert (session.uuid in resp.body)
        finally:
            # Clean up after ourselves
            try:
                os.remove(temp_filename)
            except:
                pass
 def test_init_default_args(self, mock_create_graph):
     """ Test ProfilingSession initialization with default args """
     session = linesman.ProfilingSession(self.stats)
     mock_create_graph.assert_called_with(self.stats)
     assert_equals(session.path, None)
     assert_equals(session.timestamp, None)
     assert_equals(str(session._uuid), session.uuid)
 def test_init_environ(self, mock_create_graph):
     """ Test ProfilingSession initialization with an environ args """
     environ = {'PATH_INFO': '/some/path'}
     session = linesman.ProfilingSession(self.stats, environ)
     mock_create_graph.assert_called_with(self.stats)
     assert_equals(session.path, environ.get('PATH_INFO'))
     assert_equals(session.timestamp, None)
     assert_equals(str(session._uuid), session.uuid)
Beispiel #4
0
def create_mock_session(timestamp=SPECIFIC_DATE_DATETIME):
    class Stat(object):
        totaltime = 0

    return linesman.ProfilingSession([Stat()], timestamp=timestamp)