本文整理汇总了Python中normalize.FieldSelector.post方法的典型用法代码示例。如果您正苦于以下问题:Python FieldSelector.post方法的具体用法?Python FieldSelector.post怎么用?Python FieldSelector.post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类normalize.FieldSelector
的用法示例。
在下文中一共展示了FieldSelector.post方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dict
# 需要导入模块: from normalize import FieldSelector [as 别名]
# 或者: from normalize.FieldSelector import post [as 别名]
def test_dict(self):
from normalize.coll import dict_of
from testclasses import Person
Rolodeck = dict_of(Person)
deck = Rolodeck({
"bob": Person(id=123, name="Bob"),
"peter": Person(id=124, name="Peter"),
"eve": Person(id=125, name="Steve"),
})
fs1 = FieldSelector(["bob", "id"])
self.assertEqual(fs1.get(deck), 123)
self.assertRaisesRegexp(
ValueError, r'id is required', fs1.delete, deck,
)
fs2 = FieldSelector(["cuthbert", "id"])
fs2.post(deck, 923)
self.assertEqual(deck['cuthbert'].id, 923)
FieldSelector(["ruth"]).post(deck, {"id": 523, "name": "Ruth"})
self.assertEqual(deck['ruth'].name, "Ruth")
FieldSelector(["bob"]).delete(deck)
self.assertNotIn("bob", deck)
FieldSelector([None]).delete(deck)
self.assertEqual(deck, {})
示例2: test_post
# 需要导入模块: from normalize import FieldSelector [as 别名]
# 或者: from normalize.FieldSelector import post [as 别名]
def test_post(self):
record = MockComplexJsonRecord()
fs = FieldSelector(["name"])
fs.post(record, "Bobby")
self.assertEqual(record.name, "Bobby")
fs = FieldSelector(["children", 0, "name"])
fs.post(record, "Johnny")
self.assertEqual(record.children[0].name, "Johnny")
# Test addition to collection
fs = FieldSelector(["children", 1, "name"])
fs.post(record, "Susan")
self.assertEqual(record.children[1].name, "Susan")
# Test invalid addition to collection
fs = FieldSelector(["children", 9999, "name"])
with self.assertRaisesRegexp(
ValueError, "FieldSelector set out of order"
):
fs.post(record, "Joker")
# Test create of sub-Record
fs = FieldSelector(["nested", "name"])
fs.put(record, "Nested")
self.assertEqual(record.nested.name, "Nested")
示例3: test_post_required
# 需要导入模块: from normalize import FieldSelector [as 别名]
# 或者: from normalize.FieldSelector import post [as 别名]
def test_post_required(self):
class FussyRecord(Record):
id = Property(required=True)
class FussPot(Record):
fuss_list = ListProperty(of=FussyRecord)
fuss_map = DictProperty(of=FussyRecord)
top_fuss = Property(isa=FussyRecord)
fp = FussPot()
fs1 = FieldSelector(("top_fuss", "id"))
fs2 = FieldSelector(("fuss_map", "phew", "id"))
fs3 = FieldSelector(("fuss_list", 0, "id"))
fs1.post(fp, 1)
fs2.post(fp, 2)
fs3.post(fp, 3)
expected = FussPot(
top_fuss={"id": 1},
fuss_map={"phew": {"id": 2}},
fuss_list=[{"id":3}],
)