async def update_store(ctx, *, details): store_details = details.split(':') if len(store_details) == 5: # Correct number of arguments provided old_store_name = store_details[0].strip() new_store_name = store_details[1].strip() new_store_location_x = store_details[2].strip() new_store_location_z = store_details[3].strip() new_store_description = store_details[4].strip() catalogue = Catalogue() catalogue.load_stores(PATH_TO_DATA_FILE) # Attempt to remove old store from catalogue. is_removed = catalogue.remove_store(old_store_name) if not is_removed: embed = discord.Embed( title=f'Store: \'{old_store_name}\' cannot be found', color=13424046) await ctx.send(embed=embed) else: # Add updated store updated_store = Store(new_store_name, new_store_location_x, new_store_location_z, new_store_description) catalogue.add_store(updated_store) # Update save file catalogue.save_stores(PATH_TO_DATA_FILE) embed = discord.Embed(title='Store Updated Successfully', color=13424046) await ctx.send(embed=embed) await stores(ctx) else: embed = discord.Embed(title='Error: Please use the following format', color=13424046) await ctx.send(embed=embed) await help(ctx, 'update_store')
def run_tests(): """Test Catalogue class.""" # Test empty Catalogue (defaults) print("Test empty Catalogue:") catalogue = Catalogue() assert not catalogue.stores # an empty list is considered False # Test loading stores print("\nTest loading Stores:") catalogue.load_stores('store_saves.csv') for shop in catalogue.list_stores(): print(f'\n{shop}') print("\nTest listing shop inventory") for item in shop.inventory.list_items(): print(item) assert catalogue.stores # assuming CSV file is non-empty, non-empty list is considered True # Test adding a new Shop with values print("\nTest adding new Shop:") catalogue.add_store(Store("Squelons Wood", 300, 500, "I sell wood!")) for shop in catalogue.list_stores(): print(shop) # Test saving Stores (check CSV file manually to see results) catalogue.save_stores('test.csv')
async def add_store(ctx, *, details): store_details = details.split(':') if len(store_details) != 4: await ctx.send('Error: Incorrect Formatting') await help(ctx, 'add_store') else: store_name = store_details[0].strip() store_location_x = store_details[1].strip() store_location_z = store_details[2].strip() store_description = store_details[3].strip() catalogue = Catalogue() catalogue.load_stores(PATH_TO_DATA_FILE) catalogue.add_store( Store(store_name, store_location_x, store_location_z, store_description)) catalogue.save_stores(PATH_TO_DATA_FILE) await ctx.send('Store added successfully!') await stores(ctx)