def test_get_latest_price_mock(self):
     """a mock test"""
     market_prices.get_latest_price = MagicMock(return_value=3)
     market_prices.get_latest_price()
     market_prices.get_latest_price.assert_called()
     market_prices.get_latest_price.assert_called_once()
     self.assertEqual(3, market_prices.get_latest_price())
    def test_get_latest_price(self):
        # Given
        item_code = 1234

        # When
        result = get_latest_price(item_code)

        # Then
        self.assertEqual(24, get_latest_price(item_code))
    def test_get_latest_price(self):
        """Tests that get latest price returns the expected value.
        In this case, the expected value is what we pass in.
        The function is very broken.

        """
        self.assertEqual(get_latest_price(100), 100)
        self.assertEqual(get_latest_price(1000), 1000)
        self.assertEqual(get_latest_price(-100), -100)
        self.assertEqual(get_latest_price(-1000), -1000)
Example #4
0
def test_get_latest_price_market():
    """Tests that get latest price returns the expected value.

    In this case, the expected value is what we pass in.
    We're testing a broken output yielding incorrect results.

    """
    assert get_latest_price(100) == 100
    assert get_latest_price(1000) == 1000
    assert get_latest_price(-100) == -100
    assert get_latest_price(-1000) == -1000
Example #5
0
def add_new_item():
    # global FULL_INVENTORY
    item_code = input("Enter item code: ")
    item_description = input("Enter item description: ")
    item_rental_price = input("Enter item rental price: ")

    # Get price from the market prices module
    item_price = get_latest_price(item_code)
    new_item_dict = {
        'product_code': item_code,
        'description': item_description,
        'market_price': item_price,
        'rental_price': item_rental_price
    }

    is_furniture = input("Is this item a piece of Furniture? (Y/N): ")
    if is_furniture.lower() == "y":
        item_material = input("Enter item material: ")
        item_size = input("Enter item size (S,M,L,XL): ")
        new_item = Furniture(material=item_material,
                             size=item_size,
                             **new_item_dict)
    else:
        is_electric_appliance = input("Is this item an electric appliance? \
(Y/N): ")
        if is_electric_appliance.lower() == "y":
            item_brand = input("Enter item brand: ")
            item_voltage = input("Enter item voltage: ")
            new_item = ElectricAppliances(brand=item_brand,
                                          voltage=item_voltage,
                                          **new_item_dict)
        else:
            new_item = Inventory(**new_item_dict)
    FULL_INVENTORY.append(new_item)
    print("New inventory item added")
Example #6
0
    def test_main(self):
        add_inv_item = ("1234", "inventory item", "2", "n", "n")
        add_furn_item = ("5678", "furniture item", "4", "y", "furniture material", "M")
        add_elect_item = ("9012", "electric appliance item", "6", "n",
                          "y", "appliance brand", "120")
        test_inventory = {"9012": {"product_code": "9012", "description": "electric appliance item",
                                   "market_price": 24, "rental_price": "6",
                                   "brand": "appliance brand", "voltage": "120"},
                          "5678": {"product_code": "5678", "description": "furniture item",
                                   "market_price": 24, "rental_price": "4",
                                   "material": "furniture material", "size": "M"},
                          "1234": {"product_code": "1234", "description": "inventory item",
                                   "market_price": 24, "rental_price": "2"}}
        test_item = ["1234"]
        test_item_expected = {"description": "inventory item", "market_price": 24,
                              "product_code": "1234", "rental_price": "2"}

        with patch("builtins.input", side_effect=add_inv_item):
            main.add_new_item()

        with patch("builtins.input", side_effect=add_furn_item):
            main.add_new_item()

        with patch("builtins.input", side_effect=add_elect_item):
            main.add_new_item()

        with patch("builtins.input", side_effect=test_item):
            self.assertEqual(main.item_info(), test_item_expected)

        self.assertEqual(test_inventory, main.FULL_INVENTORY)

        self.assertEqual(24, market_prices.get_latest_price(1234))

        with self.assertRaises(SystemExit):
            main.exit_program()
Example #7
0
def add_new_item():
    """
    docstring
    """

    global fullInventory
    item_code = input("Enter item code: ")
    item_description = input("Enter item description: ")
    item_rental_price = input("Enter item rental price: ")

    # Get price from the market prices module
    item_price = market_prices.get_latest_price(item_code)

    is_furniture = input("Is this item a piece of furniture? (Y/N): ")
    if is_furniture.lower() == "y":
        item_material = input("Enter item material: ")
        item_size = input("Enter item size (S,M,L,XL): ")
        new_item = furnitureClass.furniture(item_code, item_description,
                                            item_price, item_rental_price,
                                            item_material, item_size)
    else:
        is_electric_appliance = input(
            "Is this item an electric appliance? (Y/N): ")
        if is_electric_appliance.lower() == "y":
            item_brand = input("Enter item brand: ")
            item_voltage = input("Enter item voltage: ")
            new_item = electricAppliancesClass.electricAppliances(
                item_code, item_description, item_price, item_rental_price,
                item_brand, item_voltage)
        else:
            new_item = inventoryClass.inventory(item_code, item_description,
                                                item_price, item_rental_price)
    fullInventory[item_code] = new_item.returnAsDictionary()
    print("New inventory item added")
Example #8
0
def add_new_item():
    """
    This is a method to add new items to the inventory
    """

    product_info = {}
    product_info['product_code'] = input("Enter item code: ")
    product_info['description'] = input("Enter item description: ")
    product_info['rental_price'] = input("Enter item rental price: ")

    # Get price from the market prices module
    product_info['market_price'] = market_prices.get_latest_price(
        product_info['product_code'])

    is_furniture = input("Is this item a piece of furniture? (Y/N): ")
    if is_furniture.lower() == "y":
        product_info['material'] = input("Enter item material: ")
        product_info['size'] = input("Enter item size (S,M,L,XL): ")
        new_item = furniture_class.Furniture(product_info)
    else:
        is_electric_appliance = input(
            "Is this item an electric appliance? (Y/N): ")
        if is_electric_appliance.lower() == "y":
            product_info['brand'] = input("Enter item brand: ")
            product_info['voltage'] = input("Enter item voltage: ")
            new_item = electric_appliances_class.ElectricAppliances(
                product_info)
        else:
            new_item = inventory_class.Inventory(product_info)
    FULL_INVENTORY[
        product_info['product_code']] = new_item.return_as_dictionary()
    print("New inventory item added")
Example #9
0
    def test_main_integration(self):
        """Test all functions with main as a starting point"""

        price = market_prices.get_latest_price(0)

        #Adding non categorized inventory item with main
        item1 = ['1', 'shoe', '1', 'n', 'n']
        with patch('builtins.input', side_effect=item1):
            main.add_new_item()

        unintegrated_item1 = Inventory(['1', 'shoe', price, '1'])

        #Adding furniture item with main
        item2 = ['2', 'chair', '2', 'y', 'wood', 'S']
        with patch('builtins.input', side_effect=item2):
            main.add_new_item()

        unintegrated_item2 = Furniture(['2', 'chair', price, '2'], 'wood', 'S')

        #Adding electric appliance with main
        item3 = ['3', 'stove', '3', 'n', 'y', 'LG', '100']
        with patch('builtins.input', side_effect=item3):
            main.add_new_item()

        unintegrated_item3 = ElectricAppliances(['3', 'stove', price, '3'],
                                                'LG', '100')

        actual_inventory = main.return_full_inventory()
        expected_inventory = {
            '1': unintegrated_item1.return_as_dictionary(),
            '2': unintegrated_item2.return_as_dictionary(),
            '3': unintegrated_item3.return_as_dictionary()
        }

        self.assertEqual(actual_inventory, expected_inventory)
def get_price(item_code):
    """
    Get price data
    :param item_code: integer
    :return: floating point
    """
    return get_latest_price(item_code)
Example #11
0
class Test_InventoryClass(TestCase):
    def test_init(self):
        item_dict = {}
        item_dict["item_code"] = 2
        item_dict["item_description"] = "b"
        item_dict["item_rental_price"] = 2.0
        item_dict["item_price"] = 2.0
        i = Inventory(**item_dict)
        self.assertEqual(i.product_code, 2)
        self.assertEqual(i.description, "b")
        self.assertEqual(i.rental_price, 2.0)
        self.assertEqual(i.market_price, 2.0)

    def test_return_as_dictionary(self):
        item_dict = {}
        item_dict["item_code"] = 2
        item_dict["item_description"] = "b"
        item_dict["item_rental_price"] = 2.0
        item_dict["item_price"] = 2.0
        i = Inventory(**item_dict)
        new_dict = i.return_as_dictionary()
        self.assertEqual(i.product_code, new_dict["product_code"])
        self.assertEqual(i.description, new_dict["description"])
        self.assertEqual(i.rental_price, new_dict["rental_price"])

    def test_check_market_price(self):
        item_dict = {}
          item_dict["item_code"] = 2
        item_dict["item_description"] = "b"
        item_dict["item_rental_price"] = 2.0
        item_dict["item_price"] = 2.0
        i = Inventory(**item_dict)
        self.assertEqual(i.check_market_price(), False)
        i.market_price = get_latest_price()
        self.assertEqual(i.check_market_price(), True)
Example #12
0
def add_new_item():
    """add a new item into full inventory"""
    item_code = input("Enter item code: ")
    item_description = input("Enter item description: ")
    item_rental_price = input("Enter item rental price: ")

    # Get price from the market prices module
    item_price = get_latest_price(item_code)

    is_furniture = input("Is this item a piece of furniture? (Y/N): ")
    if is_furniture.lower() == "y":
        item_material = input("Enter item material: ")
        item_size = input("Enter item size (S,M,L,XL): ")
        new_item = Furniture(item_code, item_description,\
         item_price, item_rental_price,\
         item_material, item_size)
    else:
        is_electric_appliance = input("Is this item an electric appliance? (Y/N): ")
        if is_electric_appliance.lower() == "y":
            item_brand = input("Enter item brand: ")
            item_voltage = input("Enter item voltage: ")
            new_item = ElectricAppliances(item_code, item_description,\
             item_price, item_rental_price, item_brand, item_voltage)
        else:
            new_item = Inventory(item_code, item_description, item_price, item_rental_price)

    FULL_INVENTORY[item_code] = new_item.return_as_dictionary()
    print("New inventory item added")
 def test_get_latest_price(self):
     """Test the user can retrieve the latest market price"""
     market_prices.get_latest_price = MagicMock(return_value=24)
     actual_price = market_prices.get_latest_price(1)
     expected_price = 24
     market_prices.get_latest_price.assert_called_with(1)
     self.assertEqual(actual_price, expected_price)
Example #14
0
def add_new_item():
    """gets information about a new item from user,
    then enters item into inventory"""
    code = input("Enter item code: ")
    description = input("Enter item description: ")
    rental_price = input("Enter item rental price: ")

    # Get price from the market prices module
    price = market_prices.get_latest_price(code)

    is_furniture = input("Is this item a piece of furniture? (Y/N): ")
    if is_furniture.lower() == "y":
        material = input("Enter item material: ")
        size = input("Enter item size (S,M,L,XL): ")
        new_item = furniture_class.Furniture(code, description, price,
         rental_price, material, size)
    else:
        is_electric_appliance = input("Is this item an electric appliance? (Y/N): ")
        if is_electric_appliance.lower() == "y":
            brand = input("Enter item brand: ")
            voltage = input("Enter item voltage: ")
            new_item = electric_appliances_class.ElectricAppliances(code, description, price,
                                                                    rental_price, brand, voltage)
        else:
            new_item = inventory_class.Inventory(code, description, price,
             rental_price)
    FULL_INVENTORY[code] = new_item.return_as_dictionary()
    print("New inventory item added")
Example #15
0
    def test_market_prices(self):
        "Mock test market_prices"

        self.assertEqual(get_latest_price(624), 24)

        self.get_latest_price = MagicMock(return_value=38)
        assert self.get_latest_price(624) == 38
 def test_get_market_price(self):
     """
     MarketPrices.get_latest_price will always return 24 for now.
     TODO: Fix this test upon build out of MarketPrices.get_latest_price
     """
     for i in range(10):
         self.assertEqual(24, MarketPrices.get_latest_price(i))
Example #17
0
def addnewitem():
    '''
    method docstring
    '''

    itemcode = input("Enter item code: ")
    itemdescription = input("Enter item description: ")
    itemrentalprice = input("Enter item rental price: ")

    # Get price from the market prices module
    itemprice = market_prices.get_latest_price(itemcode)

    isfurniture = input("Is this item a piece of furniture? (Y/N): ")
    if isfurniture.lower() == "y":
        itemmaterial = input("Enter item material: ")
        itemsize = input("Enter item size (S,M,L,XL): ")
        newitem = furnitureclass.Furniture(itemcode, itemdescription,
                                           itemprice, itemrentalprice,
                                           itemmaterial, itemsize)
    else:
        iselectricappliance = input(
            "Is this item an electric appliance? (Y/N): ")
        if iselectricappliance.lower() == "y":
            itembrand = input("Enter item brand: ")
            itemvoltage = input("Enter item voltage: ")
            newitem = electricappliancesclass.Electricappliances(
                itemcode, itemdescription, itemprice, itemrentalprice,
                itembrand, itemvoltage)
        else:
            newitem = inventoryclass.Inventory(itemcode, itemdescription,
                                               itemprice, itemrentalprice)
    FULL_INVENTORY[itemcode] = newitem.returnasdictionary()
    print("New inventory item added")
Example #18
0
def add_new_item():
    """
    add a new item to the inventory based on user inputs
    """
    #global FULL_INVENTORY
    item_code = get_input("Enter item code: ")
    item_desc = get_input("Enter item description: ")
    item_rental_price = get_input("Enter item rental price: ")

    # Get price from the market prices module
    item_price = market_prices.get_latest_price(item_code)
    new_inventory_item = inventory_class.Inventory(item_code, item_desc,
                                                   item_price,
                                                   item_rental_price)
    is_furniture = get_input("Is this item a piece of furniture? (Y/N): ")
    if is_furniture.lower() == "y":
        item_material = get_input("Enter item material: ")
        item_size = get_input("Enter item size (S,M,L,XL): ")
        new_item = furniture_class.Furniture(new_inventory_item, item_material,
                                             item_size)
    else:
        is_electrical_appliance = get_input(
            "Is this item an electric appliance? (Y/N): ")
        if is_electrical_appliance.lower() == "y":
            item_brand = get_input("Enter item brand: ")
            item_voltage = get_input("Enter item voltage: ")
            new_item = elec_appliances_class.ElecAppliances(
                new_inventory_item, item_brand, item_voltage)
        else:
            new_item = new_inventory_item
    FULL_INVENTORY[item_code] = new_item.return_as_dictionary()
    print("New inventory item added")
    return new_item.return_as_dictionary
Example #19
0
def addnew_item():
    '''Add new item to inventory.'''
    item_code = input("Enter item code: ")
    item_description = input("Enter item description: ")
    item_rental_price = input("Enter item rental price: ")

    # Get price from the market prices module
    item_price = market_prices.get_latest_price(item_code)

    is_furniture = input("Is this item a piece of furniture? (Y/N): ")
    if is_furniture.lower() == "y":
        item_material = input("Enter item material: ")
        item_size = input("Enter item size (S,M,L,XL): ")
        new_item = furniture_class.Furniture(item_code, item_description,
                                             item_price, item_rental_price,
                                             item_material, item_size)
    else:
        is_electric_appliance = input("Is this item" +
                                      "an electric appliance? (Y/N): ")
        if is_electric_appliance.lower() == "y":
            item_brand = input("Enter item brand: ")
            item_voltage = input("Enter item voltage: ")
            new_item = (electric_appliances_class.ElectricAppliance(
                item_code, item_description, item_price, item_rental_price,
                item_brand, item_voltage))
        else:
            new_item = inventory_class.Inventory(item_code, item_description,
                                                 item_price, item_rental_price)
    FULL_INVENTORY[item_code] = new_item.return_as_dictionary()
    print("New inventory item added")
Example #20
0
    def test_integration(self):
        '''testing integration'''
        # integrate market price
        market_price = market_prices.get_latest_price(1)

        #create a dict mocking items
        item_one = ['1', 'Painting', '50', 'n', 'n']
        item_two = ['2', 'Desk', '100', 'y', 'wood', 'L']
        item_three = ['3', 'Washer', '200', 'n', 'y', 'Kenmore', '120']

        with patch('builtins.input', side_effect=item_one):
            main.add_new_item()

        with patch('builtins.input', side_effect=item_two):
            main.add_new_item()

        with patch('builtins.input', side_effect=item_three):
            main.add_new_item()

        test_dict = {
            '1': {
                'product_code': '1',
                'description': 'Painting',
                'market_price': 24,
                'rental_price': '50'
            },
            '2': {
                'product_code': '2',
                'description': 'Desk',
                'market_price': 24,
                'rental_price': '100',
                'material': 'wood',
                'size': 'L'
            },
            '3': {
                'product_code': '3',
                'description': 'Washer',
                'market_price': 24,
                'rental_price': '200',
                'brand': 'Kenmore',
                'voltage': '120'
            }
        }

        # create items using the class modules
        class_item_one = Inventory('1', 'Painting', market_price, '50')
        class_item_two = Furniture('2', 'Desk', market_price, '100', 'wood',
                                   'L')
        class_item_three = ElectricAppliances('3', 'Washer', market_price,
                                              '200', 'Kenmore', '120')

        class_dict = {
            '1': class_item_one.return_as_dictionary(),
            '2': class_item_two.return_as_dictionary(),
            '3': class_item_three.return_as_dictionary()
        }

        # compare the items built with the class modules with the mock test items
        self.assertEqual(class_dict, test_dict)
Example #21
0
    def setUp(self):
        # Intercept the standard out to validate certain outputs are written
        # to the console.
        self.hold_stdout = sys.stdout
        self.stdout_intercept = io.StringIO()
        sys.stdout = self.stdout_intercept

        self.inventory = Inventory("Bird House", "Its a bird home",
                                   Prices.get_latest_price("Bird House"), 2000)

        self.furniture = Furniture("Therapist Couch",
                                   "Tell me about your mother",
                                   Prices.get_latest_price("Therapist Couch"),
                                   3000, "existential crises", "L")

        self.appliance = ElectricAppliances("edp_001", "Electric Dog Polisher",
                                            Prices.get_latest_price("edp_001"),
                                            4000, "Purina", 5)
 def test_get_price(self):
     ''' Test the get price method '''
     self.assertEqual(main.getprice(), print('Get price'))
     main.getprice = MagicMock(return_value=24)
     self.assertEqual(mp.get_latest_price("abc"), 24)
     self.assertEqual(main.getprice('777'), 24)
     main.getprice.assert_called()
     main.getprice.assert_called_with('777')
     main.getprice.assert_called_once_with('777')
Example #23
0
def get_price(item_code):
    """
    :param item_code:
    :type item_code:
    :return:
    :rtype:
    """
    price = market_prices.get_latest_price(item_code)
    return price
    def test_module(self):
        full_inventory = {}
        # full_inventory = {
        #     'e': electricAppliances('e', 'this is a test inventory', 1000, 1200, 'python', 110),
        #     'f': furniture('f', 'this is a test inventory', 1000, 1200, 'plastic', '12x12'),
        # }

        # Get price
        self.assertEqual(24, market_prices.get_latest_price('e'))
        self.assertEqual(24, market_prices.get_latest_price('f'))

        # Add new electric appliance and new furniture
        full_inventory['e'] = electricAppliances('e',
                                                 'this is a test inventory',
                                                 1000, 1200, 'python',
                                                 110).returnAsDictionary()
        full_inventory['f'] = furniture('f', 'this is a test inventory', 1000,
                                        1200, 'plastic',
                                        '12x12').returnAsDictionary()
 def test_check_market_price(self):
     item_dict = {}
     item_dict["item_code"] = 1
     item_dict["item_description"] = "a"
     item_dict["item_rental_price"] = 1.0
     item_dict["item_price"] = 1.0
     i = Inventory(**item_dict)
     self.assertEqual(i.check_market_price(), False)
     i.market_price = get_latest_price()
     self.assertEqual(i.check_market_price(), True)
Example #26
0
    def setUp(self):
        self.product_code = 24
        self.description = "Junk"
        self.market_price = get_latest_price(self.product_code)
        self.rental_price = 30

        self.inventory = inventory_class.Inventory(self.product_code,
                                                   self.description,
                                                   self.market_price,
                                                   self.rental_price)
Example #27
0
    def setUp(self):
        self.product_code = 23
        self.description = "Table"
        self.market_price = get_latest_price(self.product_code)
        self.rental_price = 23
        self.material = "Wood"
        self.size = "L"

        self.furniture = Furniture(self.product_code, self.description,
                                   self.market_price, self.rental_price,
                                   self.material, self.size)
Example #28
0
def collect_product_info():
    """ Collect common info for Inventory items.
    """
    item_code = get_item_code()
    item_description = get_item_description()
    item_rental_price = get_item_rental_price()

    # Get price from the market prices module
    item_price = mp.get_latest_price(item_code)

    return item_code, item_description, item_rental_price, item_price
Example #29
0
def get_price(item_code):
    """Calls market_price.get_latest_price and returns value

    Args:
        item_code (str) : Code of the item to fetch price for.

    Returns:
        int value returned from market_prices.get_latest_price

    """
    return market_prices.get_latest_price(item_code)
Example #30
0
def get_price(item_code):
    """
    Get the price of an item

    Args:
        item_code: Item code number

    Returns:
        price: Item price
    """
    print("Get price on " + str(item_code))
    return market_prices.get_latest_price(item_code)