Esempio n. 1
0
    def test_get_products_by_name_part_case_sensitive(self):
        p1 = Product(id_="X1", name="TOY uppercase", price=10)
        p2 = Product(id_="X2", name="toy lowercase", price=10)
        c = Catalogue({p1.id: p1, p2.id: p2})
        filtered_products = c.get_products_by_name_part("toy")

        self.assertDictEqual({p2.id: p2}, filtered_products)
Esempio n. 2
0
def main():
    """
    Creates a library with dummy data and prompts the user for input.
    """
    lib_catalogue = Catalogue()
    my_epic_library = Library(lib_catalogue)
    my_epic_library.display_library_menu()
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')
Esempio n. 4
0
    def test_get_products_with_appropriate_price(self):
        p1 = Product(id_="X1", name="Toy X1", price=10.3)
        p2 = Product(id_="X2", name="Toy X2", price=8.3)
        c = Catalogue({p1.id: p1, p2.id: p2})
        filtered_products = c.get_products_with_appropriate_price(lambda price: price < 10.0)

        self.assertDictEqual({p2.id: p2}, filtered_products)
def test_update_price_on_id_not_found_gives_error():
    cat = Catalogue("2021 catalogue")
    candle1 = Candle("Beach", 54, "lavender", "square", "4 hours", "10cm by 10cm", "£100")
    cat.add_candle(candle1)
    with pytest.raises(ValueError) as e:
        cat.update_candle_price(2, "£80")
    assert str(e.value) == "Item not found"
Esempio n. 6
0
    def test_add_product(self):
        p = Product(id_="P", name="X", price=0)
        c = Catalogue()
        c.add_product(p)
        p.name = "Y"

        self.assertEqual("X", c.inventory["P"].name)
Esempio n. 7
0
    def test_init(self):
        p = Product(id_="P", name="", price=0)
        inventory = {p.id: p}
        c = Catalogue(inventory)
        del inventory[p.id]

        self.assertEqual(1, len(c.inventory))
def test_add_candle_puts_two_candles_in_list():
    cat = Catalogue("2021 catalogue")
    candle1 = Candle("Beach", 54, "lavender", "square", "4 hours", "10cm by 10cm", "£100")
    candle2 = Candle("Beach", 2, "lavender", "square", "4 hours", "10cm by 10cm", "£100")
    cat.add_candle(candle1)
    cat.add_candle(candle2) 
    assert cat.candles_list == [candle1, candle2]
Esempio n. 9
0
 def __init__(self, catalogue_json_file: str, offer_types_json_file: str,
              product_offers_json_file: str):
     self.catalogue = Catalogue(catalogue_json_file)
     self.product_offers = ProductOffers(offer_types_json_file,
                                         product_offers_json_file)
     self.products = {}
     self.sub_total, self.discount, self.total = 0.0, 0.0, 0.0
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')
Esempio n. 11
0
 def test_inventory_overflow_init(self):
     p1 = Product(id_="P1", name="", price=0)
     p2 = Product(id_="P2", name="", price=0)
     p3 = Product(id_="P3", name="", price=0)
     big_inventory = {"1": p1, "2": p2, "3": p3}
     with self.assertRaises(InventoryOverflowException):
         c = Catalogue(big_inventory)
Esempio n. 12
0
def main():
    """
    Creates a library with dummy data and prompts the user for input.
    """
    item_list = generate_test_items()
    catalogue = Catalogue(item_list)
    my_epic_library = Library(catalogue)
    my_epic_library.display_library_menu()
def test_delete_candle_removes_the_candle_from_list():
    cat = Catalogue("2021 catalogue")
    candle1 = Candle("Beach", 54, "lavender", "square", "4 hours", "10cm by 10cm", "£100")
    candle2 = Candle("Beach", 2, "lavender", "square", "4 hours", "10cm by 10cm", "£100")
    cat.add_candle(candle1)
    cat.add_candle(candle2) 
    cat.delete_candle(54)
    assert cat.candles_list == [candle2]
 def test_adding_products_to_catalogue(self):
     self.test_catalogue = Catalogue(self.test_products)
     self.test_catalogue.add_products([
         Product('Additional Product 1', 1.00),
         Product('Additional Product 2', 1.00)
     ])
     self.assertEqual(len(self.test_catalogue.products),
                      len(self.test_products) + 2)
Esempio n. 15
0
    def __init__(self,
                 prix_file="test_data/prix.csv",
                 remises_file="test_data/remises.csv"):

        self.catalog_manager = Catalogue(prix_file, remises_file)
        self.catalog_prix, self.catalog_remises = self.catalog_manager.get_dicts(
        )
        self.tickets = []
Esempio n. 16
0
def main():
    """
    Creates a library with dummy data and prompts the user for input.
    """
    book_list = generate_test_books()
    my_epic_catalogue = Catalogue(book_list)
    my_epic_library = Library(my_epic_catalogue)
    my_epic_library.display_library_menu()
Esempio n. 17
0
    def test_add_too_many_products_in_a_batch(self):
        p1 = Product(id_="P1", name="", price=0)
        p2 = Product(id_="P2", name="", price=0)
        p3 = Product(id_="P3", name="", price=0)
        c = Catalogue()
        self.assertEqual(2, c.add_products([p1, p2, p3]))

        self.assertDictEqual({p1.id: p1, p2.id: p2}, c.inventory)
Esempio n. 18
0
 def test_inventory_overflow_add_product(self):
     p1 = Product(id_="P1", name="", price=0)
     p2 = Product(id_="P2", name="", price=0)
     p3 = Product(id_="P3", name="", price=0)
     c = Catalogue()
     c.add_product(p1)
     c.add_product(p2)
     with self.assertRaises(InventoryOverflowException):
         c.add_product(p3)
Esempio n. 19
0
def main():
    # def __init__(self, title, call_no, author, num_copies):
    # issue, publisher):
    # def __init__(self, title, call_no, author, num_copies, name,
    #              issue, publisher):
    b1 = Book("Provenance", "342.2", "Anne Leckie", 20)
    b2 = Book("Ancillary Justice", "342.2A", "Anne Leckie", 1)
    j1 = Journal("Individual Psychology", "123.4", "Gabriela Pap", 1,
                 "Journal of Psychology", 23, "SAGE Publications")
    d1 = Dvd("Mad Max: Fury Road", "789.0", "George Miller", 8, "May 15, 2015",
             "1")
    cat = Catalogue({
        "342.2":
        Book("Provenance", "342.2", "Anne Leckie", 20),
        "342.2A":
        Book("Ancillary Justice", "342.2A", "Anne Leckie", 1),
        "123.4":
        Journal("Individual Psychology", "123.4", "Gabriela Pap", 1,
                "Journal of Psychology", 23, "SAGE Publications"),
        "789.0":
        Dvd("Mad Max: Fury Road", "789.0", "George Miller", 8, "May 15, 2015",
            "1")
    })
    vpl = Library(cat)

    display_menu = True

    while display_menu:
        print("What would you like to do?")
        print("1. Find item by title (String)")
        print("2. Add item to catalogue")
        print("3. Remove item from catalogue (call no)")
        print("4. Check out a copy (call no)")
        print("5. Return your copy (call no)")
        print("6. Display library catalogue")
        print("7. Quit menu")

        choice = int(input("Select action: "))

        if choice == 2:
            vpl.get_cat().add_item()
        elif choice == 6:
            vpl.display_available_books()
        elif choice == 7:
            display_menu = False
        elif choice not in range(1, 6):
            print("\nInvalid input.  Try again.\n")
        else:
            par = input("Enter parameter: ")
            input_dict = {
                1: vpl.search,
                3: cat.remove_item,
                4: vpl.check_out,
                5: vpl.return_item
            }

            print(input_dict.get(choice)(par))
def test_delete_both_candles_gives_empty_list():
    cat = Catalogue("2021 catalogue")
    candle1 = Candle("Beach", 54, "lavender", "square", "4 hours", "10cm by 10cm", "£100")
    candle2 = Candle("Beach", 2, "lavender", "square", "4 hours", "10cm by 10cm", "£100")
    cat.add_candle(candle1)
    cat.add_candle(candle2) 
    cat.delete_candle(54)
    cat.delete_candle(2)
    assert cat.candles_list == []
 def setUp(self):
     self.test_products = [
         Product('Baked Beans', 0.99),
         Product('Biscuits', 1.20),
         Product('Sardines', 1.89),
         Product('Shampoo (Small)', 2.00),
         Product('Shampoo (Medium)', 2.50),
         Product('Shampoo (Large)', 3.50),
     ]
     self.test_catalouge = Catalogue(self.test_products)
async def stores(ctx):
    catalogue = Catalogue()
    catalogue.load_stores(PATH_TO_DATA_FILE)
    embed = discord.Embed(title='MelonCraft Stores', color=13424046)
    for store in catalogue.list_stores():
        embed.add_field(
            name=store.name,
            value=
            f'{store.description} ({store.location_x}, {store.location_z})',
            inline=False)
    await ctx.send(embed=embed)
Esempio n. 23
0
def main():
    """
    Creates a library and prompts the user with options.
    """

    # Create a new library with a new catalogue
    library = Library(Catalogue())

    # User Prompt
    while True:
        library.give_options()
async def update_item(ctx, *, details):
    item_details = details.split(':')
    embed = discord.Embed()
    if len(item_details) == 5:  # Correct number of arguments provided
        store_name = item_details[0].strip()
        old_item_name = item_details[1].strip()
        new_item_name = item_details[2].strip()
        new_item_quantity = item_details[3].strip()
        new_item_cost = int(item_details[4].strip())

        catalogue = Catalogue()
        catalogue.load_stores(PATH_TO_DATA_FILE)
        is_valid_store_name = False
        for store in catalogue.list_stores():
            if store.name.lower() == store_name.lower():
                is_valid_store_name = True
                # Attempt to remove old Item from inventory
                is_removed = store.inventory.remove_item(old_item_name)
                if not is_removed:
                    embed = discord.Embed(
                        title=f'Item: \'{old_item_name}\' cannot be found',
                        color=13424046)
                else:
                    # Add updated Item
                    updated_item = Item(new_item_name, new_item_quantity,
                                        new_item_cost)
                    store.inventory.add_item(updated_item)

                    # Update save file
                    catalogue.save_stores(PATH_TO_DATA_FILE)
                    embed = discord.Embed(title='Item Updated Successfully',
                                          color=13424046)
                    embed.add_field(
                        name=f'{new_item_name}',
                        value=f'{new_item_quantity} / {new_item_cost}D')

        if not is_valid_store_name:
            embed = discord.Embed(
                title=f'Store: \'{store_name}\' cannot be found',
                color=13424046)
    else:
        embed = discord.Embed(title='Error: Please use the following format',
                              color=13424046)
        embed.add_field(
            name=
            '.update_item <Store_Name> : <Old_Item_Name> : <New_Item_Name> : <New_Item_Quantity> : '
            '<New_Item_Cost>',
            value=
            '\t.update_item All Australian Wool : Red Wool : Blue Wool : 2 Stacks : 1',
            inline=False)
        embed.add_field(name='Blue Wool', value='2 Stacks / 1D')
    await ctx.send(embed=embed)
def test_delete_candle_gives_error_if_candle_not_in_list():
    cat = Catalogue("2021 catalogue")
    candle1 = Candle("Beach", 54, "lavender", "square", "4 hours", "10cm by 10cm", "£100")
    candle2 = Candle("Beach", 2, "lavender", "square", "4 hours", "10cm by 10cm", "£100")
    candle3 = Candle("Beach", 3, "lavender", "square", "4 hours", "10cm by 10cm", "£100")
    cat.add_candle(candle1)
    cat.add_candle(candle2) 
    with pytest.raises(ValueError):
        cat.delete_candle(candle3)
    assert cat.candles_list == [candle1, candle2]
    with pytest.raises(ValueError) as error:
        cat.delete_candle(candle3)
    assert str(error.value) == "Item not found"
Esempio n. 26
0
def main():
    """
    Creates a library with dummy data and prompts the user for input.
    """

    b1 = Book("100.200.300", "Harry Potter 1", 2, "J K Rowling")
    b2 = Book("999.224.854", "Harry Potter 2", 5, "J K Rowling")
    b3 = Book("631.495.302", "Harry Potter 3", 4, "J K Rowling")
    b4 = Book("123.02.204", "The Cat in the Hat", 1, "Dr. Seuss")
    cat = Catalogue([b1, b2, b3, b4])
    lib = Library(cat)

    lib.display_library_menu()
async def remove_store(ctx, *, store_name):
    catalogue = Catalogue()
    catalogue.load_stores(PATH_TO_DATA_FILE)
    # Attempt to remove store from catalogue.
    is_removed = catalogue.remove_store(store_name)
    if not is_removed:
        embed = discord.Embed(title=f'Store: \'{store_name}\' cannot be found',
                              color=13424046)
        await ctx.send(embed=embed)
    else:
        # Update save file
        catalogue.save_stores(PATH_TO_DATA_FILE)
        await ctx.send('Store removed successfully!')
        await stores(ctx)
Esempio n. 28
0
def test_catalogue():
    catalog = Catalogue(prix_file="test_data/prix.csv",
                        remises_file="test_data/remises.csv")
    catalog_prix, catalog_remises = catalog.get_dicts()

    print("- Liste des prix:")
    print(catalog_prix)
    print("- Liste des promo:")
    print(catalog_remises)

    print("--- MAJ catalogue ---")
    catalog_prix, catalog_remises = catalog.maj(
        prix_file='test_data/prix2.csv', remises_file='test_data/remises2.csv')

    print("- Liste des prix:")
    print(catalog_prix)
    print("- Liste des promo:")
    print(catalog_remises)
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)
async def add_item(ctx, *, details):
    item_details = details.split(':')
    embed = discord.Embed()
    if len(item_details) == 4:  # Correct number of arguments given
        store_name = item_details[0].strip()
        item_name = item_details[1].strip()
        item_quantity = item_details[2].strip()
        item_cost = item_details[3].strip()

        catalogue = Catalogue()
        catalogue.load_stores(PATH_TO_DATA_FILE)
        is_valid_store_name = False
        for store in catalogue.list_stores():
            if store.name.lower() == store_name.lower():
                is_valid_store_name = True

                # Add new Item to store inventory
                new_item = Item(item_name, item_quantity, int(item_cost))
                store.inventory.add_item(new_item)

                # Update save file
                catalogue.save_stores(PATH_TO_DATA_FILE)
                embed = discord.Embed(title='Item Added Successfully',
                                      color=13424046)
                embed.add_field(name=f'{item_name}',
                                value=f'{item_quantity} / {item_cost}D')

        if not is_valid_store_name:
            embed = discord.Embed(
                title=f'Store: \'{store_name}\' cannot be found',
                color=13424046)
    else:
        embed = discord.Embed(title='Error: Please use the following format',
                              color=13424046)
        embed.add_field(
            name=
            '.sell <Store_Name> : <Item_Name> : <Quantity> : <Cost_in_Diamonds>',
            value='e.g. .sell All Australian Wool : Red Wool : 2 Stacks : 1',
            inline=False)
        embed.add_field(name='Red Wool', value='2 Stacks / 1D')
    await ctx.send(embed=embed)