本文整理汇总了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')
示例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)
示例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')
示例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()))
示例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)
示例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)'})
示例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')
示例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'])