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


Python base.Resource类代码示例

本文整理汇总了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;未经允许,请勿转载。