def test_query_owner_fail(self, mock_config_file): inv_manager = InventoryManager(mock_config_file[0]) lb = inv_manager.create_labbook("test", "test", "labbook1", description="my first labbook") new_location = shutil.move(lb.root_dir, '/tmp') try: lb = inv_manager.load_labbook_from_directory(new_location) with pytest.raises(InventoryException): inv_manager.query_owner(lb) finally: shutil.rmtree(new_location)
def test_query_owner(self, mock_config_file): inv_manager = InventoryManager(mock_config_file[0]) lb = inv_manager.create_labbook("test", "test", "labbook1", description="my first labbook") assert "test" == inv_manager.query_owner(lb)
def resolve_local_labbooks(self, info, order_by: str, sort: str, **kwargs): """Method to return all graphene Labbook instances for the logged in user available locally Uses the "currently logged in" user Args: order_by(str): String specifying how labbooks should be sorted sort(str): 'desc' for descending (default) 'asc' for ascending Returns: list(Labbook) """ username = get_logged_in_username() if sort == "desc": reverse = True elif sort == "asc": reverse = False else: raise ValueError(f"Unsupported sort_str: {sort}. Use `desc`, `asc`") # Collect all labbooks for all owners inv_manager = InventoryManager() local_lbs = inv_manager.list_labbooks(username=username, sort_mode=order_by) if reverse: local_lbs.reverse() edges = [(inv_manager.query_owner(lb), lb.name) for lb in local_lbs] cursors = [base64.b64encode("{}".format(cnt).encode("UTF-8")).decode("UTF-8") for cnt, x in enumerate(edges)] # Process slicing and cursor args lbc = ListBasedConnection(edges, cursors, kwargs) lbc.apply() # Get Labbook instances edge_objs = [] for edge, cursor in zip(lbc.edges, lbc.cursors): create_data = {"id": "{}&{}".format(edge[0], edge[1]), "name": edge[1], "owner": edge[0]} edge_objs.append(LabbookConnection.Edge(node=Labbook(**create_data), cursor=cursor)) return LabbookConnection(edges=edge_objs, page_info=lbc.page_info)