• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python query.Query类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中backdrop.core.query.Query的典型用法代码示例。如果您正苦于以下问题:Python Query类的具体用法?Python Query怎么用?Python Query使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Query类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_basic_query_with_time_limits

    def test_basic_query_with_time_limits(self):
        self._save_all('foo_bar',
                       {'_timestamp': d_tz(2012, 12, 12)},
                       {'_timestamp': d_tz(2012, 12, 14)},
                       {'_timestamp': d_tz(2012, 12, 11)})

        # start at
        results = self.engine.execute_query('foo_bar', Query.create(
            start_at=d_tz(2012, 12, 12, 13)))

        assert_that(results,
                    contains(
                        has_entry('_timestamp', d_tz(2012, 12, 14))))

        # end at
        results = self.engine.execute_query('foo_bar', Query.create(
            end_at=d_tz(2012, 12, 11, 13)))

        assert_that(results,
                    contains(
                        has_entry('_timestamp', d_tz(2012, 12, 11))))

        # both
        results = self.engine.execute_query('foo_bar', Query.create(
            start_at=d_tz(2012, 12, 11, 12),
            end_at=d_tz(2012, 12, 12, 12)))

        assert_that(results,
                    contains(
                        has_entry('_timestamp', d_tz(2012, 12, 12))))
开发者ID:alphagov,项目名称:backdrop,代码行数:30,代码来源:test_storage.py


示例2: test_empty_a_data_set

    def test_empty_a_data_set(self):
        self._save_all('foo_bar',
                       {'foo': 'bar'}, {'bar': 'foo'})

        assert_that(len(self.engine.execute_query('foo_bar', Query.create())), is_(2))

        # TODO: fix inconsistency
        self.engine.empty_data_set('foo_bar')

        assert_that(len(self.engine.execute_query('foo_bar', Query.create())), is_(0))
开发者ID:alphagov,项目名称:backdrop,代码行数:10,代码来源:test_storage.py


示例3: step

def step(context, amount, key, time):
    time_query = parser.parse(time)
    if key == '_start_at':
        query = Query.create(start_at=time_query, period=DAY, duration=1)
    elif key == '_end_at':
        query = Query.create(end_at=time_query, period=DAY, duration=-1)
    elif key == '_week_start_at':
        query = Query.create(start_at=time_query, period=WEEK, duration=1)
    else:
        raise NotImplementedError(key)
    result = context.client.storage().execute_query(context.data_set, query)
    assert_that(result, has_length(1))
    assert_that(result[0]['_count'], equal_to(int(amount)))
开发者ID:alphagov,项目名称:backdrop,代码行数:13,代码来源:write_api.py


示例4: test_sort_query_is_executed

    def test_sort_query_is_executed(self, mock_query):
        mock_query.return_value = NoneData()
        self.app.get(
            '/foo?sort_by=value:ascending'
        )
        mock_query.assert_called_with(
            Query.create(sort_by=["value", "ascending"]))

        self.app.get(
            '/foo?sort_by=value:descending'
        )
        mock_query.assert_called_with(
            Query.create(sort_by=["value", "descending"]))
开发者ID:NRCan,项目名称:backdrop,代码行数:13,代码来源:test_read_api_query_endpoint.py


示例5: test_basic_query_with_inclusive_time_limits

    def test_basic_query_with_inclusive_time_limits(self):
        self._save_all('foo_bar',
                       {'_timestamp': d_tz(2014, 12, 01)},
                       {'_timestamp': d_tz(2014, 12, 02)},
                       {'_timestamp': d_tz(2014, 12, 03)})

        # start at
        results = self.engine.execute_query('foo_bar', Query.create(
            start_at=d_tz(2014, 12, 01),
            end_at=d_tz(2014, 12, 03),
            inclusive=True))

        assert_that(len(results), is_(3))
开发者ID:alphagov,项目名称:backdrop,代码行数:13,代码来源:test_storage.py


示例6: test_month_and_group_query_with_start_and_end_at

    def test_month_and_group_query_with_start_and_end_at(self):
        self.mock_storage.execute_query.return_value = [
            {'some_group': 'val1', '_month_start_at': d(2013, 1, 1), '_count': 1},
            {'some_group': 'val1', '_month_start_at': d(2013, 2, 1), '_count': 5},
            {'some_group': 'val2', '_month_start_at': d(2013, 3, 1), '_count': 2},
            {'some_group': 'val2', '_month_start_at': d(2013, 4, 1), '_count': 6},
            {'some_group': 'val2', '_month_start_at': d(2013, 7, 1), '_count': 6},
        ]

        data = self.data_set.execute_query(
            Query.create(period=MONTH,
                         group_by=['some_group'],
                         start_at=d(2013, 1, 1),
                         end_at=d(2013, 4, 2)))
        assert_that(data,
                    has_item(has_entries({"values": has_length(4)})))
        assert_that(data,
                    has_item(has_entries({"values": has_length(4)})))

        first_group = data[0]["values"]
        assert_that(first_group, has_item(has_entries({
            "_start_at": d_tz(2013, 3, 1)})))
        assert_that(first_group, has_item(has_entries({
            "_start_at": d_tz(2013, 4, 1)})))

        first_group = data[1]["values"]
        assert_that(first_group, has_item(has_entries({
            "_start_at": d_tz(2013, 1, 1)})))
        assert_that(first_group, has_item(has_entries({
            "_start_at": d_tz(2013, 2, 1)})))
开发者ID:NRCan,项目名称:backdrop,代码行数:30,代码来源:test_data_set.py


示例7: test_period_group_query_adds_missing_periods_in_correct_order

    def test_period_group_query_adds_missing_periods_in_correct_order(self):
        self.mock_storage.execute_query.return_value = [
            {'some_group': 'val1', '_week_start_at': d(2013, 1, 14), '_count': 23},
            {'some_group': 'val1', '_week_start_at': d(2013, 1, 21), '_count': 41},
            {'some_group': 'val2', '_week_start_at': d(2013, 1, 14), '_count': 31},
            {'some_group': 'val2', '_week_start_at': d(2013, 1, 28), '_count': 12},
        ]

        data = self.data_set.execute_query(
            Query.create(period=WEEK, group_by=['some_group'],
                         start_at=d_tz(2013, 1, 7, 0, 0, 0),
                         end_at=d_tz(2013, 2, 4, 0, 0, 0)))

        assert_that(data, has_item(has_entries({
            "some_group": "val1",
            "values": contains(
                has_entries({"_start_at": d_tz(2013, 1, 7), "_count": 0}),
                has_entries({"_start_at": d_tz(2013, 1, 14), "_count": 23}),
                has_entries({"_start_at": d_tz(2013, 1, 21), "_count": 41}),
                has_entries({"_start_at": d_tz(2013, 1, 28), "_count": 0}),
            ),
        })))

        assert_that(data, has_item(has_entries({
            "some_group": "val2",
            "values": contains(
                has_entries({"_start_at": d_tz(2013, 1, 7), "_count": 0}),
                has_entries({"_start_at": d_tz(2013, 1, 14), "_count": 31}),
                has_entries({"_start_at": d_tz(2013, 1, 21), "_count": 0}),
                has_entries({"_start_at": d_tz(2013, 1, 28), "_count": 12}),
            ),
        })))
开发者ID:NRCan,项目名称:backdrop,代码行数:32,代码来源:test_data_set.py


示例8: test_no_end_at_means_now

    def test_no_end_at_means_now(self):
        query = Query.create(
            period=Day(),
            duration=3,
        )

        assert_that(query.end_at, is_(
            datetime(2014, 1, 9, 0, 0, 0, tzinfo=pytz.UTC)))
开发者ID:NRCan,项目名称:backdrop,代码行数:8,代码来源:test_query.py


示例9: test_period_queries_get_sorted_by__week_start_at

 def test_period_queries_get_sorted_by__week_start_at(self):
     self.setup__timestamp_data()
     query = Query.create(period=WEEK)
     result = self.data_set.execute_query(query)
     assert_that(result, contains(
         has_entry('_start_at', d_tz(2012, 12, 31)),
         has_entry('_start_at', d_tz(2013, 1, 28)),
         has_entry('_start_at', d_tz(2013, 2, 25))
     ))
开发者ID:NRCan,项目名称:backdrop,代码行数:9,代码来源:test_data_set_integration.py


示例10: test_datetimes_are_returned_as_utc

    def test_datetimes_are_returned_as_utc(self):
        self._save_all('foo_bar',
                       {'_timestamp': datetime.datetime(2012, 8, 8)})

        results = self.engine.execute_query('foo_bar', Query.create())

        assert_that(results,
                    contains(
                        has_entries({'_timestamp': d_tz(2012, 8, 8)})))
开发者ID:alphagov,项目名称:backdrop,代码行数:9,代码来源:test_storage.py


示例11: test_capped_data_set_is_capped

    def test_capped_data_set_is_capped(self):
        self.engine.create_data_set('foo_bar', 1)

        for i in range(100):
            self.engine.save_record('foo_bar', {'foo': i})

        assert_that(
            len(self.engine.execute_query('foo_bar', Query.create())),
            less_than(70))
开发者ID:alphagov,项目名称:backdrop,代码行数:9,代码来源:test_storage.py


示例12: test_query_with_filter_prefix

    def test_query_with_filter_prefix(self):
        self._save_all('foo_bar', {'foo': 'bar'}, {'foo': 'foo'})

        results = self.engine.execute_query('foo_bar', Query.create(
            filter_by_prefix=[['foo', 'ba']]))

        assert_that(results,
                    contains(
                        has_entry('foo', 'bar')))
开发者ID:alphagov,项目名称:backdrop,代码行数:9,代码来源:test_storage.py


示例13: test_saving_a_record_with_an_id_updates_it

    def test_saving_a_record_with_an_id_updates_it(self):
        self._save_all('foo_bar',
                       {'_id': 'first', 'foo': 'bar'},
                       {'_id': 'first', 'foo': 'foo'})

        results = self.engine.execute_query('foo_bar', Query.create())

        assert_that(len(results), is_(1))
        assert_that(results, contains(has_entries({'foo': 'foo'})))
开发者ID:alphagov,项目名称:backdrop,代码行数:9,代码来源:test_storage.py


示例14: data_set_contains

def data_set_contains(context, data_set_name, sequence_matcher):
    documents = [json.loads(line) for line in context.text.split("\n")]
    matchers = [has_entries(doc) for doc in documents]

    data_set = context.client.storage().execute_query(data_set_name, Query.create())
    records = [datetimes_to_strings(record) for record in data_set.find()]
    records = [ints_to_floats(record) for record in records]
    records = [nones_to_zeroes(record) for record in records]

    assert_that(records, sequence_matcher(*matchers))
开发者ID:alphagov,项目名称:backdrop,代码行数:10,代码来源:splinter.py


示例15: test_delete_record

    def test_delete_record(self):
        data = [{'_id': '111', 'foo': 'bar'}, {'_id': '222', 'bar': 'foo'}]
        self._save_all('foo_bar', *data)
        assert_that(len(self.engine.execute_query('foo_bar', Query.create())), is_(2))

        self.engine.delete_record('foo_bar', '111')
        assert_that(
            self.engine.execute_query('foo_bar', Query.create()),
            contains(has_entries({'_id': '222', 'bar': 'foo'}))
        )

        self.engine.delete_record('foo_bar', '333')
        assert_that(
            self.engine.execute_query('foo_bar', Query.create()),
            contains(has_entries({'_id': '222', 'bar': 'foo'}))
        )

        self.engine.delete_record('foo_bar', '222')
        assert_that(self.engine.execute_query('foo_bar', Query.create()), is_([]))
开发者ID:alphagov,项目名称:backdrop,代码行数:19,代码来源:test_storage.py


示例16: test_period_query_is_executed

    def test_period_query_is_executed(self, mock_query):
        mock_query.return_value = NoneData()

        self.app.get(
            '/data/some-group/some-type?period=week&' +
            'start_at=' + urllib.quote("2012-11-05T00:00:00Z") + '&' +
            'end_at=' + urllib.quote("2012-12-03T00:00:00Z"))
        mock_query.assert_called_with(
            Query.create(period=WEEK,
                         start_at=d_tz(2012, 11, 5),
                         end_at=d_tz(2012, 12, 3)))
开发者ID:NRCan,项目名称:backdrop,代码行数:11,代码来源:test_read_api_service_data_endpoint.py


示例17: test_period_query_fails_when_weeks_do_not_start_on_monday

    def test_period_query_fails_when_weeks_do_not_start_on_monday(self):
        self.mock_storage.execute_query.return_value = [
            {"_week_start_at": d(2013, 1, 7, 0, 0, 0), "_count": 3},
            {"_week_start_at": d(2013, 1, 8, 0, 0, 0), "_count": 1},
        ]

        assert_raises(
            ValueError,
            self.data_set.execute_query,
            Query.create(period=WEEK)
        )
开发者ID:NRCan,项目名称:backdrop,代码行数:11,代码来源:test_data_set.py


示例18: test_period_query_fails_when_months_do_not_start_on_the_1st

    def test_period_query_fails_when_months_do_not_start_on_the_1st(self):
        self.mock_storage.execute_query.return_value = [
            {"_month_start_at": d(2013, 1, 7, 0, 0, 0), "_count": 3},
            {"_month_start_at": d(2013, 2, 8, 0, 0, 0), "_count": 1},
        ]

        assert_raises(
            ValueError,
            self.data_set.execute_query,
            Query.create(period=MONTH)
        )
开发者ID:NRCan,项目名称:backdrop,代码行数:11,代码来源:test_data_set.py


示例19: test_query_grouped_by_field

    def test_query_grouped_by_field(self):
        self._save_all('foo_bar',
                       {'foo': 'foo'}, {'foo': 'foo'},
                       {'foo': 'bar'})

        results = self.engine.execute_query('foo_bar', Query.create(
            group_by=['foo']))

        assert_that(results,
                    contains_inanyorder(
                        has_entries({'foo': 'bar', '_count': 1}),
                        has_entries({'foo': 'foo', '_count': 2})))
开发者ID:alphagov,项目名称:backdrop,代码行数:12,代码来源:test_storage.py


示例20: test_end_at_and_duration

    def test_end_at_and_duration(self):
        query = Query.create(
            end_at=d_tz(2014, 1, 11, 0, 0, 0),
            period=Day(),
            duration=3,
        )

        assert_that(query.start_at, is_(
            datetime(2014, 1, 8, 0, 0, 0, tzinfo=pytz.UTC)))

        assert_that(query.end_at, is_(
            datetime(2014, 1, 11, 0, 0, 0, tzinfo=pytz.UTC)))
开发者ID:NRCan,项目名称:backdrop,代码行数:12,代码来源:test_query.py



注:本文中的backdrop.core.query.Query类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python query.parse_request_args函数代码示例发布时间:2022-05-24
下一篇:
Python utils.get_subs函数代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap