示例#1
0
    def test_get_query(self):
        query = self.factory.create_query()

        rv = self.make_request('get', '/api/queries/{0}'.format(query.id))

        self.assertEquals(rv.status_code, 200)
        expected = serialize_query(query, with_visualizations=True)
        expected['can_edit'] = True
        expected['is_favorite'] = False
        self.assertResponseEqual(expected, rv.json)
示例#2
0
    def test_get_query(self):
        query = self.factory.create_query()

        rv = self.make_request('get', '/api/queries/{0}'.format(query.id))

        self.assertEquals(rv.status_code, 200)
        expected = serialize_query(query, with_visualizations=True)
        expected['can_edit'] = True
        expected['is_favorite'] = False
        self.assertResponseEqual(expected, rv.json)
示例#3
0
    def get(self):
        """
        Retrieve a list of queries.

        :qparam number page_size: Number of queries to return per page
        :qparam number page: Page number to retrieve
        :qparam number order: Name of column to order by
        :qparam number q: Full text search term

        Responds with an array of :ref:`query <query-response-label>` objects.
        """
        # See if we want to do full-text search or just regular queries
        search_term = request.args.get('q', '')

        results = self.get_queries(search_term)

        # order results according to passed order parameter,
        # special-casing search queries where the database
        # provides an order by search rank
        ordered_results = order_results(results,
                                        fallback=not bool(search_term))

        if request.args.has_key('all'):
            response = [
                serialize_query(result,
                                with_stats=True,
                                with_last_modified_by=False,
                                with_visualizations=True)
                for result in ordered_results
            ]
        else:
            page = request.args.get('page', 1, type=int)
            page_size = request.args.get('page_size', 25, type=int)

            response = paginate(ordered_results,
                                page=page,
                                page_size=page_size,
                                serializer=QuerySerializer,
                                with_stats=True,
                                with_last_modified_by=False,
                                with_visualizations=True)

        if search_term:
            self.record_event({
                'action': 'search',
                'object_type': 'query',
                'term': search_term,
            })
        else:
            self.record_event({
                'action': 'list',
                'object_type': 'query',
            })

        return response