def test_encode(): # type: () -> None Foo = Object.extend("Foo") obj = Foo() assert utils.encode(obj) == { "className": "Foo", "__type": "Pointer", "objectId": None, } acl = ACL() assert utils.encode(acl) == {} acl.set_read_access("xxx", True) assert utils.encode(acl) == {"xxx": {"read": True}} point = GeoPoint() assert utils.encode(point) == { "__type": "GeoPoint", "longitude": 0, "latitude": 0, } assert utils.encode([obj, acl, point]) == [ {"className": "Foo", "__type": "Pointer", "objectId": None}, {"xxx": {"read": True}}, {"__type": "GeoPoint", "longitude": 0, "latitude": 0}, ] assert utils.encode({"a": obj, "b": acl}) == { "a": {"className": "Foo", "__type": "Pointer", "objectId": None}, "b": {"xxx": {"read": True}}, }
def before_todo_save(todo): content = todo.get('content') if not content: raise LeanEngineError('内容不能为空') if len(content) >= 240: todo.set('content', content[:240] + ' ...') author = todo.get('author') if author: acl = ACL() acl.set_public_read_access(True) acl.set_read_access(author.id, True) acl.set_write_access(author.id, True) todo.set_acl(acl)
def test_encode(): Foo = Object.extend('Foo') obj = Foo() assert utils.encode(obj) == { 'className': 'Foo', '__type': 'Pointer', 'objectId': None, } acl = ACL() assert utils.encode(acl) == {} acl.set_read_access('xxx', True) assert utils.encode(acl) == {'xxx': {'read': True}} point = GeoPoint() assert utils.encode(point) == { '__type': 'GeoPoint', 'longitude': 0, 'latitude': 0, } assert utils.encode([obj, acl, point]) == [ { 'className': 'Foo', '__type': 'Pointer', 'objectId': None, }, { 'xxx': {'read': True} }, { '__type': 'GeoPoint', 'longitude': 0, 'latitude': 0, } ] assert utils.encode({'a': obj, 'b': acl}) == { 'a': { 'className': 'Foo', '__type': 'Pointer', 'objectId': None, }, 'b': { 'xxx': {'read': True} }, }