本文整理汇总了Python中stormpath.resources.custom_data.CustomData.get方法的典型用法代码示例。如果您正苦于以下问题:Python CustomData.get方法的具体用法?Python CustomData.get怎么用?Python CustomData.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stormpath.resources.custom_data.CustomData
的用法示例。
在下文中一共展示了CustomData.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_custom_data_implements_dict_protocol
# 需要导入模块: from stormpath.resources.custom_data import CustomData [as 别名]
# 或者: from stormpath.resources.custom_data.CustomData import get [as 别名]
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)
示例2: test_non_materialized_property_is_ensured
# 需要导入模块: from stormpath.resources.custom_data import CustomData [as 别名]
# 或者: from stormpath.resources.custom_data.CustomData import get [as 别名]
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)