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


Python Resource.is_new方法代码示例

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


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

示例1: test_resource_init_by_properties

# 需要导入模块: from stormpath.resources.base import Resource [as 别名]
# 或者: from stormpath.resources.base.Resource import is_new [as 别名]
    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'
开发者ID:nkwood,项目名称:stormpath-sdk-python,代码行数:35,代码来源:test_resource.py

示例2: test_resource_init_by_href

# 需要导入模块: from stormpath.resources.base import Resource [as 别名]
# 或者: from stormpath.resources.base.Resource import is_new [as 别名]
    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
开发者ID:nkwood,项目名称:stormpath-sdk-python,代码行数:15,代码来源:test_resource.py

示例3: test_resource_init_by_properties

# 需要导入模块: from stormpath.resources.base import Resource [as 别名]
# 或者: from stormpath.resources.base.Resource import is_new [as 别名]
    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
开发者ID:denibertovic,项目名称:stormpath-sdk-python,代码行数:20,代码来源:test_resource.py


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