Exemple #1
0
    def test_generate_query_string_for_data_with_start_index_filter(self):
        start_index = 2
        expected_sql = "SELECT json FROM logger_instance WHERE"\
                       " xform_id = %s  AND CAST(json->>%s AS INT) > %s AND"\
                       " CAST(json->>%s AS INT) < %s AND deleted_at IS NULL "\
                       "ORDER BY id OFFSET %s"

        (sql, columns, params) = DataView.generate_query_string(
            self.data_view,
            start_index,
            self.limit,
            self.last_submission_time,
            self.all_data,
            self.sort)

        self.assertEquals(sql, expected_sql)

        records = [record for record in DataView.query_iterator(sql,
                                                                columns,
                                                                params,
                                                                self.count)]
        self.assertEquals(len(records), 1)
        self.assertIn('name', records[0])
        self.assertIn('age', records[0])
        self.assertIn('gender', records[0])
        self.assertNotIn('pizza_type', records[0])
Exemple #2
0
    def test_generate_query_string_for_data_with_start_index_filter(self):
        start_index = 2
        expected_sql = "SELECT json FROM logger_instance WHERE"\
                       " xform_id = %s  AND CAST(json->>%s AS INT) > %s AND"\
                       " CAST(json->>%s AS INT) < %s AND deleted_at IS NULL "\
                       "ORDER BY id OFFSET %s"

        (sql, columns, params) = DataView.generate_query_string(
            self.data_view,
            start_index,
            self.limit,
            self.last_submission_time,
            self.all_data,
            self.sort)

        self.assertEquals(sql, expected_sql)

        records = [record for record in DataView.query_iterator(sql,
                                                                columns,
                                                                params,
                                                                self.count)]
        self.assertEquals(len(records), 1)
        self.assertIn('name', records[0])
        self.assertIn('age', records[0])
        self.assertIn('gender', records[0])
        self.assertNotIn('pizza_type', records[0])
Exemple #3
0
    def test_generate_query_string_for_data_with_sort_column_desc(self):
        sort = '{"age": -1}'
        expected_sql = "SELECT json FROM logger_instance WHERE"\
                       " xform_id = %s  AND CAST(json->>%s AS INT) > %s AND"\
                       " CAST(json->>%s AS INT) < %s AND deleted_at IS NULL"\
                       " ORDER BY  json->>%s DESC"

        (sql, columns, params) = DataView.generate_query_string(
            self.data_view,
            self.start_index,
            self.limit,
            self.last_submission_time,
            self.all_data,
            sort)

        self.assertEquals(sql, expected_sql)

        records = [record for record in DataView.query_iterator(sql,
                                                                columns,
                                                                params,
                                                                self.count)]

        self.assertTrue(self.is_sorted_desc([r.get("age") for r in records]))
Exemple #4
0
    def test_generate_query_string_for_data_with_limit_filter(self):
        limit_filter = 1
        expected_sql = "SELECT json FROM logger_instance"\
                       " WHERE xform_id = %s  AND CAST(json->>%s AS INT) > %s"\
                       " AND CAST(json->>%s AS INT) < %s AND deleted_at "\
                       "IS NULL ORDER BY id LIMIT %s"

        (sql, columns, params) = DataView.generate_query_string(
            self.data_view,
            self.start_index,
            limit_filter,
            self.last_submission_time,
            self.all_data,
            self.sort)

        self.assertEquals(sql, expected_sql)

        records = [record for record in DataView.query_iterator(sql,
                                                                columns,
                                                                params,
                                                                self.count)]

        self.assertEquals(len(records), limit_filter)
Exemple #5
0
    def test_generate_query_string_for_data_with_sort_column_desc(self):
        sort = '{"age": -1}'
        expected_sql = "SELECT json FROM logger_instance WHERE"\
                       " xform_id = %s  AND CAST(json->>%s AS INT) > %s AND"\
                       " CAST(json->>%s AS INT) < %s AND deleted_at IS NULL"\
                       " ORDER BY  json->>%s DESC"

        (sql, columns, params) = DataView.generate_query_string(
            self.data_view,
            self.start_index,
            self.limit,
            self.last_submission_time,
            self.all_data,
            sort)

        self.assertEquals(sql, expected_sql)

        records = [record for record in DataView.query_iterator(sql,
                                                                columns,
                                                                params,
                                                                self.count)]

        self.assertTrue(self.is_sorted_desc([r.get("age") for r in records]))
Exemple #6
0
    def test_generate_query_string_for_data_with_limit_filter(self):
        limit_filter = 1
        expected_sql = "SELECT json FROM logger_instance"\
                       " WHERE xform_id = %s  AND CAST(json->>%s AS INT) > %s"\
                       " AND CAST(json->>%s AS INT) < %s AND deleted_at "\
                       "IS NULL ORDER BY id LIMIT %s"

        (sql, columns, params) = DataView.generate_query_string(
            self.data_view,
            self.start_index,
            limit_filter,
            self.last_submission_time,
            self.all_data,
            self.sort)

        self.assertEquals(sql, expected_sql)

        records = [record for record in DataView.query_iterator(sql,
                                                                columns,
                                                                params,
                                                                self.count)]

        self.assertEquals(len(records), limit_filter)