示例#1
0
    def content(self):
        if not json_available or not sqlalchemy_available:
            msg = ['Missing required libraries:', '<ul>']
            if not json_available:
                msg.append('<li>simplejson</li>')
            if not sqlalchemy_available:
                msg.append('<li>Flask-SQLAlchemy</li>')
            msg.append('</ul>')
            return '\n'.join(msg)

        queries = get_debug_queries()
        data = []
        for query in queries:
            is_select = query.statement.strip().lower().startswith('select')
            _params = ''
            try:
                _params = json.dumps(query.parameters)
            except TypeError:
                pass  # object not JSON serializable

            hash = hashlib.sha1(
                current_app.config['SECRET_KEY'] +
                query.statement + _params).hexdigest()

            data.append({
                'duration': query.duration,
                'sql': format_sql(query.statement, query.parameters),
                'raw_sql': query.statement,
                'hash': hash,
                'params': _params,
                'is_select': is_select,
                'context_long': query.context,
                'context': format_fname(query.context)
            })
        return self.render('panels/sqlalchemy.html', {'queries': data})
示例#2
0
    def nav_subtitle(self):
        if not json_available or not sqlalchemy_available:
            return 'Unavailable'

        if get_debug_queries:
            count = len(get_debug_queries())
            return "%d %s" % (count, "query" if count == 1 else "queries")
示例#3
0
    def content(self):
        if not json_available or not sqlalchemy_available:
            msg = ['Missing required libraries:', '<ul>']
            if not json_available:
                msg.append('<li>simplejson</li>')
            if not sqlalchemy_available:
                msg.append('<li>Flask-SQLAlchemy</li>')
            msg.append('</ul>')
            return '\n'.join(msg)

        queries = get_debug_queries()
        data = []
        for query in queries:
            is_select = query.statement.strip().lower().startswith('select')
            _params = ''
            try:
                _params = json.dumps(query.parameters)
            except TypeError:
                pass  # object not JSON serializable

            hash = hashlib.sha1(current_app.config['SECRET_KEY'] +
                                query.statement + _params).hexdigest()

            data.append({
                'duration': query.duration,
                'sql': format_sql(query.statement, query.parameters),
                'raw_sql': query.statement,
                'hash': hash,
                'params': _params,
                'is_select': is_select,
                'context_long': query.context,
                'context': format_fname(query.context)
            })
        return self.render('panels/sqlalchemy.html', {'queries': data})
示例#4
0
    def nav_subtitle(self):
        if not json_available or not sqlalchemy_available:
            return 'Unavailable'

        if get_debug_queries:
            count = len(get_debug_queries())
            return "%d %s" % (count, "query" if count == 1 else "queries")
示例#5
0
    def content(self):
        queries = get_debug_queries()
        data = []
        for query in queries:
            is_select = query.statement.strip().lower().startswith('select')
            _params = ''
            try:
                _params = json.dumps(query.parameters)
            except TypeError:
                pass # object not JSON serializable


            hash = hashlib.sha1(
                current_app.config['SECRET_KEY'] +
                query.statement + _params).hexdigest()

            data.append({
                'duration': query.duration,
                'sql': format_sql(query.statement, query.parameters),
                'raw_sql': query.statement,
                'hash': hash,
                'params': _params,
                'is_select': is_select,
                'context_long': query.context,
                'context': format_fname(query.context)
            })
        return self.render('panels/sqlalchemy.html', { 'queries': data})
示例#6
0
    def content(self):
        queries = get_debug_queries()
        data = []
        for query in queries:
            is_select = query.statement.strip().lower().startswith('select')
            _params = ''
            try:
                _params = json.dumps(query.parameters)
            except TypeError:
                pass  # object not JSON serializable

            hash = hashlib.sha1(current_app.config['SECRET_KEY'] +
                                query.statement + _params).hexdigest()

            data.append({
                'duration': query.duration,
                'sql': format_sql(query.statement, query.parameters),
                'raw_sql': query.statement,
                'hash': hash,
                'params': _params,
                'is_select': is_select,
                'context_long': query.context,
                'context': format_fname(query.context)
            })
        return self.render('panels/sqlalchemy.html', {'queries': data})
示例#7
0
    def test_get_comments(self):

        parent = Comment(comment="parent comment",
                         author=self.user,
                         post=self.post)


        child1 = Comment(parent=parent,
                         post=self.post,
                         author=self.user,
                         comment="child1")

        child2 = Comment(parent=parent,
                         post=self.post,
                         author=self.user,
                         comment="child2")

        child3 = Comment(parent=child1,
                         post=self.post, 
                         author=self.user,
                         comment="child3")

        db.session.add_all([parent, child1, child2, child3])
        db.session.commit()

        num_queries = len(get_debug_queries())

        comments = self.post.comments

        assert len(get_debug_queries()) == num_queries + 1

        assert comments[0].id == parent.id
        assert comments[0].depth == 0
        
        comments = comments[0].comments

        assert comments[0].id == child1.id
        assert comments[1].id == child2.id

        assert comments[0].depth == 1

        comments = comments[0].comments

        assert comments[0].id == child3.id

        assert comments[0].depth == 2
示例#8
0
    def test_get_comments(self):

        parent = Comment(comment="parent comment",
                         author=self.user,
                         post=self.post)

        child1 = Comment(parent=parent,
                         post=self.post,
                         author=self.user,
                         comment="child1")

        child2 = Comment(parent=parent,
                         post=self.post,
                         author=self.user,
                         comment="child2")

        child3 = Comment(parent=child1,
                         post=self.post,
                         author=self.user,
                         comment="child3")

        db.session.add_all([parent, child1, child2, child3])
        db.session.commit()

        num_queries = len(get_debug_queries())

        comments = self.post.comments

        assert len(get_debug_queries()) == num_queries + 1

        assert comments[0].id == parent.id
        assert comments[0].depth == 0

        comments = comments[0].comments

        assert comments[0].id == child1.id
        assert comments[1].id == child2.id

        assert comments[0].depth == 1

        comments = comments[0].comments

        assert comments[0].id == child3.id

        assert comments[0].depth == 2
    def test_query_recording(self):
        with self.app.test_request_context():
            todo = self.Todo('Test 1', 'test')
            self.db.session.add(todo)
            self.db.session.commit()

            queries = sqlalchemy.get_debug_queries()
            self.assertEqual(len(queries), 1)
            query = queries[0]
            self.assert_('insert into' in query.statement.lower())
            self.assertEqual(query.parameters[0], 'Test 1')
            self.assertEqual(query.parameters[1], 'test')
            self.assert_('test_sqlalchemy.py' in query.context)
            self.assert_('test_query_recording' in query.context)
    def test_query_recording(self):
        with self.app.test_request_context():
            todo = self.Todo('Test 1', 'test')
            self.db.session.add(todo)
            self.db.session.commit()

            queries = sqlalchemy.get_debug_queries()
            self.assertEqual(len(queries), 1)
            query = queries[0]
            self.assert_('insert into' in query.statement.lower())
            self.assertEqual(query.parameters[0], 'Test 1')
            self.assertEqual(query.parameters[1], 'test')
            self.assert_('test_sqlalchemy.py' in query.context)
            self.assert_('test_query_recording' in query.context)
示例#11
0
 def has_content(self):
     if not json_available or not sqlalchemy_available:
         return True  # will display an error message
     return bool(get_debug_queries())
示例#12
0
 def has_content(self):
     if not json_available or not sqlalchemy_available:
         return True  # will display an error message
     return bool(get_debug_queries())
示例#13
0
 def nav_subtitle(self):
     if get_debug_queries:
         count = len(get_debug_queries())
         return "%d %s" % (count, "query" if count == 1 else "queries")
示例#14
0
 def has_content(self):
     return True if get_debug_queries and get_debug_queries() else False
示例#15
0
 def has_content(self):
     return True if get_debug_queries and get_debug_queries() else False
示例#16
0
 def nav_subtitle(self):
     if get_debug_queries:
         count = len(get_debug_queries())
         return "%d %s" % (count, "query" if count == 1 else "queries")
示例#17
0
    def content(self):
        queries = get_debug_queries()
        for query in queries:
            query.sql = self._format_sql(query.statement, query.parameters)

        return self.render('panels/sqlalchemy.html', { 'queries': queries})