• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python base.Resource类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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'
开发者ID:nkwood,项目名称:stormpath-sdk-python,代码行数:33,代码来源:test_resource.py


示例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__())
开发者ID:nkwood,项目名称:stormpath-sdk-python,代码行数:7,代码来源:test_resource.py


示例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__())
开发者ID:nkwood,项目名称:stormpath-sdk-python,代码行数:9,代码来源:test_resource.py


示例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
开发者ID:nkwood,项目名称:stormpath-sdk-python,代码行数:13,代码来源:test_resource.py


示例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')
开发者ID:nkwood,项目名称:stormpath-sdk-python,代码行数:14,代码来源:test_resource.py


示例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
开发者ID:denibertovic,项目名称:stormpath-sdk-python,代码行数:18,代码来源:test_resource.py


示例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())
开发者ID:nkwood,项目名称:stormpath-sdk-python,代码行数:5,代码来源:test_resource.py


示例8: test_sanitize_property

 def test_sanitize_property(self):
     ret = Resource._sanitize_property({'full_name': 'full name'})
     self.assertEqual({'fullName': 'full name'}, ret)
开发者ID:nkwood,项目名称:stormpath-sdk-python,代码行数:3,代码来源:test_resource.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python custom_data.CustomData类代码示例发布时间:2022-05-27
下一篇:
Python base.CollectionResource类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap