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

Python custom_data.CustomData类代码示例

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

本文整理汇总了Python中stormpath.resources.custom_data.CustomData的典型用法代码示例。如果您正苦于以下问题:Python CustomData类的具体用法?Python CustomData怎么用?Python CustomData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: test_saving_does_not_mangle_property_names

    def test_saving_does_not_mangle_property_names(self):
        props = {
            "href": "test/resource",
            "foo_with_underscores": 1,
            "camelCaseBar": 2,
            "baz": {
                "baz_value": True,
                "bazCamelCase": False,
                "quux": ["one", "two", {"value_three": 3, "valueThreeCamel": 3}],
            },
        }
        ds = MagicMock()
        client = MagicMock(data_store=ds)
        d = CustomData(client, properties=props)

        d["another_underscores"] = 3
        d["anotherCamelCase"] = 4

        d.save()
        ds.update_resource.assert_called_once_with(
            "test/resource",
            {
                "foo_with_underscores": 1,
                "camelCaseBar": 2,
                "another_underscores": 3,
                "anotherCamelCase": 4,
                "baz": {
                    "baz_value": True,
                    "bazCamelCase": False,
                    "quux": ["one", "two", {"value_three": 3, "valueThreeCamel": 3}],
                },
            },
        )
开发者ID:lusis,项目名称:stormpath-sdk-python,代码行数:33,代码来源:test_custom_data.py


示例2: test_serializing_props_only_serializes_custom_data

    def test_serializing_props_only_serializes_custom_data(self):
        d = CustomData(MagicMock(), properties=self.props)

        del self.props['href']
        del self.props['createdAt']

        self.assertEqual(d._get_properties(), self.props)
开发者ID:ecrisostomo,项目名称:stormpath-sdk-python,代码行数:7,代码来源:test_custom_data.py


示例3: test_serializing_props_only_serializes_custom_data

    def test_serializing_props_only_serializes_custom_data(self):
        d = CustomData(MagicMock(), properties=self.props)

        del self.props['href']
        del self.props['createdAt']
        del self.props['sp_http_status']

        props = {k: self.props[k] for k in set(self.props) - {'modifiedAt'}}
        self.assertEqual(d._get_properties(), props)
开发者ID:stormpath,项目名称:stormpath-sdk-python,代码行数:9,代码来源:test_custom_data.py


示例4: test_custom_data_deletion

    def test_custom_data_deletion(self):
        ds = MagicMock()
        client = MagicMock(data_store=ds)

        d = CustomData(client, properties=self.props)
        d.delete()

        ds.delete_resource.assert_called_once_with(self.props['href'])
        assert {} == dict(d)
开发者ID:stormpath,项目名称:stormpath-sdk-python,代码行数:9,代码来源:test_custom_data.py


示例5: test_doesnt_schedule_del_if_new_property

    def test_doesnt_schedule_del_if_new_property(self):
        ds = MagicMock()
        ds.get_resource.return_value = self.props
        client = MagicMock(data_store=ds)

        d = CustomData(client, properties=self.props)
        with self.assertRaises(KeyError):
            del d['corge']
        d.save()
        self.assertFalse(ds.delete_resource.called)
开发者ID:ecrisostomo,项目名称:stormpath-sdk-python,代码行数:10,代码来源:test_custom_data.py


示例6: test_save_empties_delete_list

    def test_save_empties_delete_list(self):
        ds = MagicMock()
        client = MagicMock(data_store=ds)

        d = CustomData(client, properties=self.props)
        del d['foo']
        d.save()
        ds.delete_resource.reset_mock()
        d.save()
        self.assertFalse(ds.delete_resource.called)
开发者ID:ecrisostomo,项目名称:stormpath-sdk-python,代码行数:10,代码来源:test_custom_data.py


示例7: test_del_doesnt_delete_if_new_resource

    def test_del_doesnt_delete_if_new_resource(self, is_new):
        is_new.return_value = True
        ds = MagicMock()
        client = MagicMock(data_store=ds)

        d = CustomData(client, properties=self.props)
        del d['foo']
        is_new.return_value = False
        d.save()
        self.assertFalse(ds.delete_resource.called)
开发者ID:ecrisostomo,项目名称:stormpath-sdk-python,代码行数:10,代码来源:test_custom_data.py


示例8: test_custom_data_implements_dict_protocol

    def test_custom_data_implements_dict_protocol(self):
        d = CustomData(MagicMock(), properties=self.props)

        self.assertTrue('created_at' in d)
        self.assertTrue('modified_at' in d)
        self.assertTrue('foo' in d)
        self.assertEqual(d['foo'], 1)
        self.assertEqual(d['created_at'], self.created_at)
        self.assertEqual(d['modified_at'], self.modified_at)
        self.assertEqual(d.get('foo'), 1)
        self.assertEqual(d.get('created_at'), self.created_at)
        self.assertEqual(d.get('modified_at'), self.modified_at)
        self.assertEqual(d.get('nonexistent'), None)
        self.assertEqual(d.get('nonexistent', 42), 42)

        with self.assertRaises(KeyError):
            d['nonexistent']

        keys = set(sorted(d.keys(), key=str))
        self.assertEqual(keys, set(d))
        self.assertEqual(keys, {'created_at', 'modified_at', 'bar', 'baz', 'foo', 'quux'})
        values = sorted(list(d.values()), key=str)

        keys_from_items = {k for k, v in d.items()}
        values_from_items = sorted([v for k, v in d.items()], key=str)

        self.assertEqual(keys, keys_from_items)
        self.assertEqual(values, values_from_items)
开发者ID:stormpath,项目名称:stormpath-sdk-python,代码行数:28,代码来源:test_custom_data.py


示例9: test_del_then_read_doesnt_set_deleted

    def test_del_then_read_doesnt_set_deleted(self):
        props = {"href": "test/resource", "bar": "2", "baz": ["one", "two", "three"], "quux": {"key": "value"}}
        ds = MagicMock()
        ds.get_resource.return_value = self.props
        client = MagicMock(data_store=ds)

        d = CustomData(client, properties=props)
        del d["foo"]
        with self.assertRaises(KeyError):
            d["foo"]
        d.save()
        ds.delete_resource.assert_called_once_with("test/resource/foo")
开发者ID:lusis,项目名称:stormpath-sdk-python,代码行数:12,代码来源:test_custom_data.py


示例10: test_del_delays_deletion_until_save

    def test_del_delays_deletion_until_save(self):
        ds = MagicMock()
        client = MagicMock(data_store=ds)

        d = CustomData(client, properties=self.props)
        del d['foo']
        del d['bar']

        self.assertFalse(ds.delete_resource.called)
        d.save()
        ds.delete_resource.assert_any_call('test/resource/foo')
        ds.delete_resource.assert_any_call('test/resource/bar')
        self.assertEqual(ds.delete_resource.call_count, 2)
开发者ID:ecrisostomo,项目名称:stormpath-sdk-python,代码行数:13,代码来源:test_custom_data.py


示例11: test_manually_set_property_has_precedence

    def test_manually_set_property_has_precedence(self):
        props = {"href": "test/resource", "bar": "2", "baz": ["one", "two", "three"], "quux": {"key": "value"}}

        d = CustomData(MagicMock(), properties=props)

        d["quux"] = "a-little-corgi"
        d._set_properties(props)

        quux = d.data.pop("quux")
        props.pop("quux")
        props.pop("href")

        # quux property is as set
        self.assertEqual(quux, "a-little-corgi")
        self.assertEqual(d.data, props)
开发者ID:lusis,项目名称:stormpath-sdk-python,代码行数:15,代码来源:test_custom_data.py


示例12: test_del_then_read_doesnt_set_deleted

    def test_del_then_read_doesnt_set_deleted(self):
        props = {
            'href': 'test/resource',
            'bar': '2',
            'baz': ['one', 'two', 'three'],
            'quux': {'key': 'value'}
        }
        ds = MagicMock()
        ds.get_resource.return_value = self.props
        client = MagicMock(data_store=ds)

        d = CustomData(client, properties=props)
        del d['foo']
        with self.assertRaises(KeyError):
            d['foo']
        d.save()
        ds.delete_resource.assert_called_once_with('test/resource/foo')
开发者ID:ecrisostomo,项目名称:stormpath-sdk-python,代码行数:17,代码来源:test_custom_data.py


示例13: test_manually_set_property_has_precedence

    def test_manually_set_property_has_precedence(self):
        props = {
            'href': 'test/resource',
            'bar': '2',
            'baz': ['one', 'two', 'three'],
            'quux': {'key': 'value'}
        }

        d = CustomData(MagicMock(), properties=props)

        d['quux'] = 'a-little-corgi'
        d._set_properties(props)

        quux = d._data.pop('quux')
        props.pop('quux')
        props.pop('href')

        # quux property is as set
        self.assertEqual(quux, 'a-little-corgi')
        self.assertEqual(d._data, props)
开发者ID:stormpath,项目名称:stormpath-sdk-python,代码行数:20,代码来源:test_custom_data.py


示例14: test_saving_does_not_mangle_property_names

    def test_saving_does_not_mangle_property_names(self):
        props = {
            'href': 'test/resource',
            'foo_with_underscores': 1,
            'camelCaseBar': 2,
            'baz': {
                'baz_value': True,
                'bazCamelCase': False,
                'quux': [
                    'one',
                    'two',
                    {'value_three': 3, 'valueThreeCamel': 3}
                ]
            }
        }
        ds = MagicMock()
        client = MagicMock(data_store=ds)

        d = CustomData(client, properties=props)
        d['another_underscores'] = 3
        d['anotherCamelCase'] = 4
        d.save()

        ds.update_resource.assert_called_once_with('test/resource', {
            'foo_with_underscores': 1,
            'camelCaseBar': 2,
            'another_underscores': 3,
            'anotherCamelCase': 4,
            'baz': {
                'baz_value': True,
                'bazCamelCase': False,
                'quux': [
                    'one',
                    'two',
                    {'value_three': 3, 'valueThreeCamel': 3}
                ]
            }
        })
开发者ID:stormpath,项目名称:stormpath-sdk-python,代码行数:38,代码来源:test_custom_data.py


示例15: test_non_materialized_property_is_ensured

    def test_non_materialized_property_is_ensured(self, _ensure_data):
        d = CustomData(MagicMock(), href='test/resource')

        self.assertFalse(d.is_materialized())
        d.get('corge')
        self.assertTrue(_ensure_data.called)
开发者ID:ecrisostomo,项目名称:stormpath-sdk-python,代码行数:6,代码来源:test_custom_data.py


示例16: test_custom_data_created_with_properties

    def test_custom_data_created_with_properties(self):
        d = CustomData(MagicMock(), properties=self.props)

        self.assertTrue(d.is_materialized())
        self.assertEqual(d['foo'], 1)
开发者ID:ecrisostomo,项目名称:stormpath-sdk-python,代码行数:5,代码来源:test_custom_data.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python common.text_var函数代码示例发布时间:2022-05-27
下一篇:
Python base.Resource类代码示例发布时间: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