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


Python custom_data.CustomData类代码示例

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


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


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