当前位置: 首页>>代码示例>>Python>>正文


Python Backend.get_products方法代码示例

本文整理汇总了Python中backend.Backend.get_products方法的典型用法代码示例。如果您正苦于以下问题:Python Backend.get_products方法的具体用法?Python Backend.get_products怎么用?Python Backend.get_products使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在backend.Backend的用法示例。


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

示例1: TestBackend

# 需要导入模块: from backend import Backend [as 别名]
# 或者: from backend.Backend import get_products [as 别名]

#.........这里部分代码省略.........
        assert type(val['fields']) is dict
        # _id should be false
        assert not val['fields']['_id']
        assert not val['fields']['description']

    def test_parse_args_category(self):
        args = ImmutableMultiDict([
            ('category', 'electronics'),
            ('notcategory', 'Flim flam')
        ])
        val = self.backend.parse_args(args)
        assert 'spec' in val
        assert 'electronics' in val['spec']['category']['$in']
        assert 'flim flam' in val['spec']['category']['$nin']

    def test_parse_args_price(self):
        args = ImmutableMultiDict([
            ('maxprice', 50),
            ('maxprice', 200)
        ])
        val = self.backend.parse_args(args)
        assert 'price' in val['spec']
        assert '$lt' in val['spec']['price']
        assert val['spec']['price']['$lt'] == 200

    def test_parse_args_subcategory(self):
        args = ImmutableMultiDict([
            ('subcategory', 'computers'),
            ('subcategory', 'strips'),
            ('notsubcategory', 'thriller')
        ])
        val = self.backend.parse_args(args)

        assert 'spec' in val
        assert 'computers' in val['spec']['subcategory']['$in']
        assert 'strips' in val['spec']['subcategory']['$in']
        assert 'thriller' in val['spec']['subcategory']['$nin']

    def test_parse_args_sort(self):
        args = ImmutableMultiDict([
            ('sort', 'category'),
            ('sort', 'subcategory'),
            ('dsort', 'price')
        ])
        val = self.backend.parse_args(args)

        assert 'sort' in val
        for field, direction in val['sort']:
            if field in ['category', 'subcategory']:
                assert direction > 0
            elif field == 'price':
                assert direction < 0
            else:
                assert False

    def test_parse_args_amount(self):
        args = ImmutableMultiDict([
            ('minamount', 0),
            ('minamount', 10),
            ('minamount', 5)
        ])
        val = self.backend.parse_args(args)

        assert 'spec' in val
        assert val['spec']['amount']['$gte'] == 5

    def test_search(self):
        args = {
            'limit': 10,
            'spec': {
                'category': {
                    '$in': ['electronics']
                }
            }
        }
        val = self.backend.search(self.backend.db.products, args)
        assert len(val) == 10
        for doc in val:
            #pprint(doc)
            assert doc['category'] == 'electronics'

    def test_get_products(self):
        args = ImmutableMultiDict([
            ('limit', 10),
            ('category', 'electronics'),
            ('category', 'books'),
            ('subcategory', 'romance'),
            ('subcategory', 'tablet'),
            ('maxprice', 500)
        ])
        val = self.backend.get_products(args)
        assert len(val) == 10
        for doc in val:
            assert doc['category'] in [
                'electronics',
                'books'
            ] and doc['subcategory'] in [
                'romance',
                'tablet'
            ] and doc['price'] <= 500
开发者ID:aisopuro,项目名称:restservice,代码行数:104,代码来源:test_backend.py


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