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


Python base.CollectionResource类代码示例

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


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

示例1: test_get_single_app_by_indexing_and_get

    def test_get_single_app_by_indexing_and_get(self):
        ds = MagicMock()
        ds.get_resource.return_value = {
            'href': '/',
            'offset': 2,
            'limit': 25,
            'items': [
                {'href': 'test/resource'},
                {'href': 'another/resource'}
            ]
        }
        rl = CollectionResource(client=MagicMock(data_store=ds), properties={
            'href': '/',
            'offset': 0,
            'limit': 25,
            'items': [
                {'href': 'test/resource'},
                {'href': 'another/resource'}
            ]
        })

        a = rl[0]
        b = rl['test/resource']
        c = rl.get('another/resource')

        self.assertEqual(a.href, 'test/resource')
        self.assertEqual(b.href, 'test/resource')
        self.assertEqual(c.href, 'another/resource')
开发者ID:nkwood,项目名称:stormpath-sdk-python,代码行数:28,代码来源:test_resource.py

示例2: test_search_method_on_collection

    def test_search_method_on_collection(self):
        c = CollectionResource(MagicMock(), properties={'href': 'href'})
        ret = c.search({'q': 'some_query'})
        self.assertEqual({'q': 'some_query'}, ret._query)

        ret = c.search('some_query')
        self.assertEqual({'q': 'some_query'}, ret._query)
开发者ID:nkwood,项目名称:stormpath-sdk-python,代码行数:7,代码来源:test_resource.py

示例3: test_resource_refresh

    def test_resource_refresh(self):
        ds = MagicMock()
        ds.get_resource.return_value = {
            'offset': 2,
            'limit': 8,
            'items': []
        }

        rl = CollectionResource(client=MagicMock(data_store=ds), href='/test_resources')

        rl.refresh()

        ds.uncache_resource.assert_called_once_with('/test_resources')
开发者ID:nkwood,项目名称:stormpath-sdk-python,代码行数:13,代码来源:test_resource.py

示例4: test_collection_resource_to_json

    def test_collection_resource_to_json(self):
        ds = MagicMock()
        ds.get_resource.return_value = {
            'href': '/',
            'offset': 0,
            'limit': 25,
            'size': 2,
            'items': [
                {'href': 'test/resource'},
                {'href': 'another/resource'}
            ]
        }

        props = {
            'href': '/',
            'offset': 0,
            'limit': 25,
            'size': 2,
            'items': [
                {'href': 'test/resource'},
                {'href': 'another/resource'}
            ]
        }

        rl = CollectionResource(client=MagicMock(data_store=ds), properties=props)

        self.assertEqual(props, json.loads(rl.to_json()))

        # collection resource as attribute
        rds = MagicMock()

        class Res(Resource, SaveMixin, DictMixin):
            writable_attrs = ('foo_val', 'bar', 'rl')

        res = Res(MagicMock(data_store=rds), href='test/resource1')
        res.rl = rl

        data = {
            'foo_val': True,
            'bar': False
        }

        res.update(data)
        data.update({'href': 'test/resource1'})
        data.update({'rl': props})
        res._expand = Expansion(*['rl'])
        self.assertEqual(data, json.loads(res.to_json()))
开发者ID:stormpath,项目名称:stormpath-sdk-python,代码行数:47,代码来源:test_resource.py

示例5: test_limit_offset_query

    def test_limit_offset_query(self):
        ds = MagicMock()
        ds.get_resource.return_value = {
            'offset': 5,
            'limit': 5,
            'items': []
        }

        rl = CollectionResource(client=MagicMock(data_store=ds), href='/')

        rl2 = rl.query(offset=5, limit=5)
        self.assertEqual(ds.get_resource.call_count, 0)

        list(rl2)
        ds.get_resource.assert_called_once_with('/', params={
            'offset': 5,
            'limit': 5})

        self.assertEqual(rl2.offset, 5)
        self.assertEqual(rl2.limit, 5)
开发者ID:senko,项目名称:stormpath-sdk-python,代码行数:20,代码来源:test_resource.py

示例6: test_creation_with_expansion

    def test_creation_with_expansion(self):
        ds = MagicMock()
        ds.create_resource.return_value = {
            'href': 'test/resource',
            'name': 'Test Resource',
        }

        rl = CollectionResource(
            client=MagicMock(data_store=ds,
                BASE_URL='http://www.example.com'),
            properties={
                'href': '/',
            })

        e = Expansion()
        e.add_property('bar', limit=5)

        rl.create({}, expand=e, some_param=True)

        ds.create_resource.assert_called_once_with('http://www.example.com/',
            {}, params={'someParam': True, 'expand': 'bar(limit:5)'})
开发者ID:senko,项目名称:stormpath-sdk-python,代码行数:21,代码来源:test_resource.py

示例7: test_creation_with_workflow_param_passing

    def test_creation_with_workflow_param_passing(self):
        ds = MagicMock()
        ds.create_resource.return_value = {
            'href': 'test/resource',
            'name': 'Test Resource',
        }

        rl = CollectionResource(
            client=MagicMock(data_store=ds,
                BASE_URL='http://www.example.com'),
            properties={
                'href': '/',
            })

        r = rl.create({}, some_param=True)

        ds.create_resource.assert_called_once_with('http://www.example.com/',
            {}, params={'someParam': True})

        self.assertTrue(r.href, 'test/resource')
        self.assertTrue(r.name, 'Test Resource')
开发者ID:senko,项目名称:stormpath-sdk-python,代码行数:21,代码来源:test_resource.py

示例8: test_init_by_properties

    def test_init_by_properties(self):
        rl = CollectionResource(client=MagicMock(), properties={
            'href': '/',
            'offset': 0,
            'limit': 25,
            'items': [
                {'href': 'test/resource'},
                {'href': 'another/resource'}
            ]
        })

        self.assertTrue(rl.is_materialized())

        # test length computation
        self.assertEqual(len(rl), 2)
        # test indexing
        self.assertEqual(rl[0].href, 'test/resource')
        self.assertEqual(rl[1].href, 'another/resource')
        # test iteration
        hrefs = [r.href for r in rl]
        self.assertTrue(hrefs, ['test/resource', 'another/resource'])
开发者ID:senko,项目名称:stormpath-sdk-python,代码行数:21,代码来源:test_resource.py


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