本文整理汇总了Python中stormpath.resources.base.Resource类的典型用法代码示例。如果您正苦于以下问题:Python Resource类的具体用法?Python Resource怎么用?Python Resource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Resource类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_resource_init_by_properties
def test_resource_init_by_properties(self):
r = Resource(MagicMock(), properties={
'href': 'test/resource',
'createdAt': '2014-07-16T13:48:22.378Z',
'modifiedAt': '2014-07-16T13:48:22.378+01:00',
'name': 'Test Resource',
'someProperty': 'value'
})
# it's not new (has href)
self.assertFalse(r.is_new())
# it knows what it is
self.assertEqual(r.href, 'test/resource')
# we can access the attributes
self.assertEqual(r.name, 'Test Resource')
# there is created_at attribute
self.assertEqual(
r.created_at,
datetime(2014, 7, 16, 13, 48, 22, 378000, tzinfo=tzutc()))
# there is modified_at attribute
self.assertEqual(
r.modified_at,
datetime(
2014, 7, 16, 13, 48, 22, 378000, tzinfo=tzoffset(None, 3600)))
# attribute name was correctly converted
self.assertEqual(r.some_property, 'value')
# there are no writable attributes
with self.assertRaises(AttributeError):
r.name = 5
with self.assertRaises(AttributeError):
r.created_at = 'whatever'
with self.assertRaises(AttributeError):
r.modified_at = 'whatever'
示例2: test_resource_dir_method
def test_resource_dir_method(self):
r = Resource(
MagicMock(),
properties={'href': 'reshref', '_some_property': 'should not show up'})
r._ensure_data = lambda : None
self.assertEqual(['href'], r.__dir__())
示例3: test_resource_str_method
def test_resource_str_method(self):
r = Resource(
MagicMock(),
properties={'href': 'reshref'})
self.assertEqual('<Resource href=reshref>', r.__str__())
r = Resource(
MagicMock(),
properties={'name': 'name'})
self.assertEqual('name', r.__str__())
示例4: test_resource_init_by_href
def test_resource_init_by_href(self):
r = Resource(MagicMock(), href='test/resource')
# it's not new (has href)
self.assertFalse(r.is_new())
# it know what it is
self.assertEqual(r.href, 'test/resource')
# href is not writable
with self.assertRaises(AttributeError):
r.href = 'abc'
# non-existing attribute access is handled correctly
with self.assertRaises(AttributeError):
r.foo
示例5: test_wrapping_resource_attrs
def test_wrapping_resource_attrs(self):
r = Resource(MagicMock(), properties={})
to_wrap = Resource(MagicMock(), properties={})
ret = r._wrap_resource_attr(Application, to_wrap)
self.assertEqual(to_wrap, ret)
ret = r._wrap_resource_attr(Application, {'name': 'some app'})
self.assertEqual('some app', ret.name)
self.assertTrue(isinstance(ret, Application))
ret = r._wrap_resource_attr(Application, None)
self.assertIsNone(ret)
self.assertRaises(TypeError, r._wrap_resource_attr, Application, 'Unsupported Conversion')
示例6: test_resource_init_by_properties
def test_resource_init_by_properties(self):
r = Resource(MagicMock(), properties={
'href': 'test/resource',
'name': 'Test Resource',
'someProperty': 'value'
})
# it's not new (has href)
self.assertFalse(r.is_new())
# it knows what it is
self.assertEqual(r.href, 'test/resource')
# we can access the attributes
self.assertEqual(r.name, 'Test Resource')
# attribute name was correctly converted
self.assertEqual(r.some_property, 'value')
# there are no writable attributes
with self.assertRaises(AttributeError):
r.name = 5
示例7: test_getting_resource_property_names
def test_getting_resource_property_names(self):
r = Resource(
MagicMock(),
properties={'href': 'reshref', '_some_property': 'should not show up'})
self.assertEqual(['href'], r._get_property_names())
示例8: test_sanitize_property
def test_sanitize_property(self):
ret = Resource._sanitize_property({'full_name': 'full name'})
self.assertEqual({'fullName': 'full name'}, ret)