def test_file_node(self, fixture_working_dir, snapshot): """Test listing labbook favorites""" lb = LabBook(fixture_working_dir[0]) lb.new(owner={"username": "******"}, name="labbook1", description="my first labbook1") # Setup some favorites in code with open(os.path.join(lb.root_dir, 'code', 'test1.txt'), 'wt') as test_file: test_file.write("blah1") # Create favorites lb.create_favorite("code", "test1.txt", description="My file with stuff 1") query = """ { node(id: "TGFiYm9va0ZpbGU6ZGVmYXVsdCZsYWJib29rMSZjb2RlJnRlc3QxLnR4dA==") { ... on LabbookFile { id key isDir size } } } """ snapshot.assert_match(fixture_working_dir[2].execute(query))
def test_favorites_node(self, fixture_working_dir, snapshot): """Test listing labbook favorites""" lb = LabBook(fixture_working_dir[0]) lb.new(owner={"username": "******"}, name="labbook1", description="my first labbook1") # Setup some favorites in code with open(os.path.join(lb.root_dir, 'code', 'test1.txt'), 'wt') as test_file: test_file.write("blah1") # Create favorites lb.create_favorite("code", "test1.txt", description="My file with stuff 1") # Test bad node that isn't a file query = """ { node(id: "TGFiYm9va0Zhdm9yaXRlOmRlZmF1bHQmbGFiYm9vazEmY29kZSZ0ZXN0MzMzLnR4dA==") { ... on LabbookFavorite { id key description isDir index } } } """ snapshot.assert_match(fixture_working_dir[2].execute(query)) # Get the actual item query = """ { node(id: "TGFiYm9va0Zhdm9yaXRlOmRlZmF1bHQmbGFiYm9vazEmY29kZSZ0ZXN0MS50eHQ=") { ... on LabbookFavorite { id key description isDir index } } } """ snapshot.assert_match(fixture_working_dir[2].execute(query))
def mutate_and_get_payload(cls, root, info, owner, labbook_name, section, key, description=None, is_dir=False, client_mutation_id=None): username = get_logged_in_username() lb = LabBook(author=get_logged_in_author()) lb.from_name(username, owner, labbook_name) # Add Favorite if is_dir: is_dir = is_dir # Make sure trailing slashes are always present when favoriting a dir if key[-1] != "/": key = f"{key}/" new_favorite = lb.create_favorite(section, key, description=description, is_dir=is_dir) # Create data to populate edge create_data = { "id": f"{owner}&{labbook_name}&{section}&{key}", "owner": owner, "section": section, "name": labbook_name, "key": key, "index": new_favorite['index'], "_favorite_data": new_favorite } # Create cursor cursor = base64.b64encode( f"{str(new_favorite['index'])}".encode('utf-8')) return AddLabbookFavorite( new_favorite_edge=LabbookFavoriteConnection.Edge( node=LabbookFavorite(**create_data), cursor=cursor))