本文整理匯總了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}],
)