def test_serialize_children(self): model = Element(name='parent') model.children.append(Element(name='child0', slot='slot0')) model.children.append(Element(name='child1', slot='slot1')) model.save() json = { "id": unicode(model.key()), "name":"parent", "type":"Element", "children": [ { "slot":"slot0", "child": { "id": unicode(model.children[0].key()), "type":"Element", "name": "child0" } }, { "slot":"slot1", "child": { "id": unicode(model.children[1].key()), "type":"Element", "name": "child1" } } ] } actual = serializer.serialize(model) assert_equal(json, actual)
def test_save_children(self): '''children の保存(parent 未保存時)''' element = Element(name='parent') children = [Element(name='child0'), Element(name='child1')] element.children.append(children[0]) element.children.append(children[1]) element.save() element = Element.get(element.key()) assert_equal(2, len(element.children)) assert_equal('child0', element.children[0].name) assert_equal('child1', element.children[1].name)
def test_serialize_element(self): '''Element のシリアライズ''' model = Element(name='name0', effects=[ Effect(op='+', param='str', min=1), Effect(op='=', param='dex', min=3, max=5) ]) model.save() actual = serializer.serialize(model) json = { 'id': unicode(model.key()), 'name': 'name0', 'type': 'Element', 'effects': [ {'op': '+', 'param': 'str', 'min': 1, 'max': 1}, {'op': '=', 'param': 'dex', 'min': 3, 'max': 5} ] } assert_equal(actual, json)
def test_save(self): element = Element(name='parent') element.save() assert_true(element.is_saved())