本文整理汇总了Python中tastypie.bundle.Bundle.data["api"]方法的典型用法代码示例。如果您正苦于以下问题:Python Bundle.data["api"]方法的具体用法?Python Bundle.data["api"]怎么用?Python Bundle.data["api"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tastypie.bundle.Bundle
的用法示例。
在下文中一共展示了Bundle.data["api"]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_hydrate
# 需要导入模块: from tastypie.bundle import Bundle [as 别名]
# 或者: from tastypie.bundle.Bundle import data["api"] [as 别名]
def test_hydrate(self):
note = Note.objects.get(pk=1)
bundle = Bundle(obj=note)
# With no value, default or nullable, we should get an ``ApiFieldError``.
field_1 = ApiField()
field_1.instance_name = "api"
self.assertRaises(ApiFieldError, field_1.hydrate, bundle)
# The default.
field_2 = ApiField(default="foo")
field_2.instance_name = "api"
self.assertEqual(field_2.hydrate(bundle), "foo")
# The callable default.
def foo():
return "bar"
field_3 = ApiField(default=foo)
field_3.instance_name = "api"
self.assertEqual(field_3.hydrate(bundle), "bar")
# The nullable case.
field_4 = ApiField(null=True)
field_4.instance_name = "api"
self.assertEqual(field_4.hydrate(bundle), None)
# The readonly case.
field_5 = ApiField(readonly=True)
field_5.instance_name = "api"
bundle.data["api"] = "abcdef"
self.assertEqual(field_5.hydrate(bundle), None)
# A real, live attribute!
field_6 = ApiField(attribute="title")
field_6.instance_name = "api"
bundle.data["api"] = note.title
self.assertEqual(field_6.hydrate(bundle), u"First Post!")