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


Python Backend.parse_args方法代码示例

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


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

示例1: TestBackend

# 需要导入模块: from backend import Backend [as 别名]
# 或者: from backend.Backend import parse_args [as 别名]
class TestBackend():
    '''A unittest class for nosetests. Tests backend and database functionality.
    '''
    def setUp(self):
        log.basicConfig(level=log.DEBUG)
        self.backend = Backend()

    def tearDown(self):
        self.backend = None

    def test_init(self):
        pass

    def test_get_root(self):
        try:
            self.backend.get_root()
        except:
            assert False

    def test_connection(self):
        try:
            obj = self.backend.db.products.find_one()
            log.info(obj)
            assert type(obj) is DictType
        except:
            assert False

    def test_parse_args(self):
        args = ImmutableMultiDict()
        # No args should return base dictionary
        assert self.backend.parse_args(args) == BASE_ARGS
        # Incorrect args should return base dict
        args = ImmutableMultiDict([('dfdd', 'frefrf'), (342, 4334)])
        assert self.backend.parse_args(args) == BASE_ARGS

    def test_get_categories(self):
        categories = set([
            'electronics',
            'books',
            'movies',
            'comics',
            'games'
        ])

        assert categories == set(self.backend.get_categories())

    def test_parse_args_limit(self):
        # Correct arg should return dict with arg as key
        args = ImmutableMultiDict([
            ('limit', 20),
            ('limit', 15)
        ])
        val = self.backend.parse_args(args)
        assert 'limit' in val
        # value should be the last passed parameter
        assert val['limit'] == 15

    def test_parse_args_field(self):
        # giving a field argument should return dict with fields as key
        args = ImmutableMultiDict([
            ('field', 'price'),
            ('notfield', 'description')
        ])
        val = self.backend.parse_args(args)
        assert 'fields' in val
        # Should be dict
        assert type(val['fields']) is dict
        assert 'price' not in val['fields']
        assert not val['fields']['description']

    def test_parse_args_field_id(self):
        # giving a field argument should return dict with fields as key
        args = ImmutableMultiDict([
            ('field', '_id'),
            ('notfield', 'description')
        ])
        val = self.backend.parse_args(args)
        assert 'fields' in val
        # Should be dict
        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)
#.........这里部分代码省略.........
开发者ID:aisopuro,项目名称:restservice,代码行数:103,代码来源:test_backend.py


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