def test_nosql_attribute_inspector_embedded_attribute(self): infos = NoSqlAttributeInspector.inspect(MyEntity, 'children.id.foo') assert len(infos) == 2 assert infos[1][0] == RESOURCE_ATTRIBUTE_KINDS.TERMINAL assert infos[1][1] == None assert infos[1][2] == 'id.foo'
def __build(self, op, attr_name, attr_value): infos = NoSqlAttributeInspector.inspect(self._entity_class, attr_name) is_nested = len(infos) > 1 parent_type = self._entity_class exprs = [] for info in infos[:-1]: nested_attr_kind, nested_attr_type, nested_attr_name = info root_coll = get_root_collection(parent_type) templ_map = dict(root_collection_name=root_coll.__name__, nested_attr_name=nested_attr_name, ) if nested_attr_kind == RESOURCE_ATTRIBUTE_KINDS.MEMBER: expr = self.__nested_member_query_template % templ_map else: # RESOURCE_ATTRIBUTE_KINDS.COLLECTION # FIXME: Test this. # expr = self.__nested_collection_query_template % templ_map raise NotImplementedError('Not implemented.') # pragma: no cover exprs.insert(0, expr) parent_type = nested_attr_type terminal_attr_name = infos[-1][-1] expr = self.__prepare_criterion(terminal_attr_name, op, attr_value) if is_nested: # FIXME: Need to handle value -> string conversion here. root_coll = get_root_collection(parent_type) templ_map = dict(root_collection_name=root_coll.__name__, terminal_expression=str(expr)) terminal_expr = self.__nested_terminal_query_template % templ_map expr = func_reduce(lambda g, h: h % dict(nested_expression=g), exprs, terminal_expr) return expr
def test_nosql_attribute_inspector(self): infos = NoSqlAttributeInspector.inspect(MyEntity, 'children.children.id') assert len(infos) == 3 assert infos[0][0] == RESOURCE_ATTRIBUTE_KINDS.COLLECTION assert infos[0][1] == MyEntityChild assert infos[0][2] == 'children' assert infos[1][0] == RESOURCE_ATTRIBUTE_KINDS.COLLECTION assert infos[1][1] == MyEntityGrandchild assert infos[1][2] == 'children' assert infos[2][0] == RESOURCE_ATTRIBUTE_KINDS.TERMINAL assert infos[2][1] == int assert infos[2][2] == 'id'