def test_electric_appliances_class(self):
        """Test the ElectricAppliances instantiation and return_as_directory() method"""
        expected = {
            'item_code': 'SECTIONAL',
            'description': 'A pleather sectional sofa',
            'market_price': '1045.87',
            'rental_price': '102.77',
            'material': 'Pleather',
            'size': 'XL'
        }

        item_attributes = {
            'item_code': 'SECTIONAL',
            'description': 'A pleather sectional sofa',
            'market_price': '1045.87',
            'rental_price': '102.77',
            'material': 'Pleather',
            'size': 'XL'
        }

        self.item = Furniture(**item_attributes)

        self.assertIsInstance(self.item, Inventory, Furniture)

        self.assertEqual(expected, self.item.return_as_dictionary())
Beispiel #2
0
def add_new_item():
    """
    add a new item
    :return:
    """
    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")
Beispiel #3
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

        input1 = ['1', 'shoe', '1', 'n', 'n']
        item1 = Inventory('1', 'shoe', price, '1')
        with patch('builtins.input', side_effect=input1):
            add_new_item()            
        #Adding furniture item with main
        input2 = ['2', 'chair', '2', 'y', 'wood', 'S']        
        item2 = Furniture('2', 'chair', price, '2', 'wood', 'S')
        with patch('builtins.input', side_effect=input2):
            add_new_item()
        #Adding electric appliance with main
        input3 = ['3', 'stove', '3', 'n', 'y', 'LG', '100']
        item3 = ElectricAppliances('3', 'stove', price, '3', 'LG', '100')
        with patch('builtins.input', side_effect=input3):
            add_new_item()
        actual_inventory = return_inventory()
        expected_inventory = {
            '1': item1.return_as_dictionary(),
            '2': item2.return_as_dictionary(),
            '3': item3.return_as_dictionary()}
        self.assertEqual(actual_inventory, expected_inventory)
Beispiel #4
0
    def test_furniture(self):
        furniture = Furniture(10, "thing", 24, 1000, "feathers", 100)

        out_dict = {"product_code": 10, "description": "thing",
        "market_price": 24, "rental_price": 1000, "material": "feathers",
        "size": 100}

        self.assertEqual(out_dict, furniture.return_as_dictionary())
 def test_furniture(self):
     """Tests the creation of an instance for furniture object"""
     test_dict = {
         'product_code': 6789,
         'description': 'Horse',
         'market_price': 50,
         'rental_price': 10,
         'material': 'Leather',
         'size': 'Large'
     }
     test_furn = Furniture(6789, 'Horse', 50, 10, 'Leather', 'Large')
     self.assertEqual(test_dict, test_furn.return_as_dictionary())
Beispiel #6
0
    def test_furniture_initalization(self):
        """ Test for succesful, accurate initialization of Furniture. """

        new_product = Furniture(2, 'Sofa', 600, 175, 'leather', 'l')
        new_product_dict = new_product.return_as_dictionary()

        self.assertEqual(2, new_product_dict['product_code'])
        self.assertEqual('Sofa', new_product_dict['description'])
        self.assertEqual(600, new_product_dict['market_price'])
        self.assertEqual(175, new_product_dict['rental_price'])
        self.assertEqual('leather', new_product_dict['material'])
        self.assertEqual('l', new_product_dict['size'])
 def test_furniture(self):
     """Test that the furniture class returns the correct dict."""
     fur = Furniture(FUR_CDE, FUR_DSC, FUR_MKT_PRC, FUR_RNT_PRC, FUR_MAT,
                     FUR_SZ)
     self.assertEqual(
         {
             'product_code': FUR_CDE,
             'description': FUR_DSC,
             'market_price': FUR_MKT_PRC,
             'rental_price': FUR_RNT_PRC,
             'material': FUR_MAT,
             'size': FUR_SZ
         }, fur.return_as_data_struct())
Beispiel #8
0
    def test_integration(self):
        """Tests the integration of main with other modules"""
        new_item = Inventory(1, 'horse', 50, 10)
        new_electric = ElectricAppliances(2, 'horse', 50, 10, 'Sony', 5)
        new_furniture = Furniture(3, 'horse', 50, 10, 'leather', 'huge')

        new_item_specs = new_item.return_as_dictionary()
        new_electric_specs = new_electric.return_as_dictionary()
        new_furniture_specs = new_furniture.return_as_dictionary()

        self.assertEqual(1, new_item_specs['product_code'])
        self.assertEqual(2, new_electric_specs['product_code'])
        self.assertEqual(3, new_furniture_specs['product_code'])
 def test_furniture_class(self):
     self.test_item = Furniture("123", "Table", "329.99", "59.99", "Wood",
                                "50")
     self.test_dict = self.test_item.return_as_dictionary()
     self.assertDictEqual(
         self.test_dict, {
             "product_code": "123",
             "description": "Table",
             "market_price": "329.99",
             "rental_price": "59.99",
             "material": "Wood",
             "size": "50"
         })
Beispiel #10
0
 def test_furniture(self):
     """ tests furniture class to return information about
         furniture items in the inventory class as a dict"""
     testdict = {
         'productcode': '340',
         'description': 'chair',
         'marketprice': '50',
         'rentalprice': '60',
         'material': 'wood',
         'size': 'M'
     }
     furniture_test = Furniture(*testdict.values())
     furniture_dict_test = furniture_test.return_as_dictionary()
     self.assertDictEqual(testdict, furniture_dict_test)
Beispiel #11
0
    def test_furniture_class(self):
        """Test for the Furniture class."""
        furniture_test = Furniture("Wood", "L", "F-12", "Table", 500, 60)

        furniture_test_dict = {
            "material": "Wood",
            "size": "L",
            "product_code": "F-12",
            "description": "Table",
            "market_price": 500,
            "rental_price": 60
        }

        self.assertDictEqual(vars(furniture_test), furniture_test_dict)
        self.assertDictEqual(furniture_test.return_as_dictionary(), furniture_test_dict)
    def setUp(self):
        """Sets up the initial paramaeters"""
        self.product_code = '26'
        self.description = 'Oven'
        self.market_price = '$50'
        self.rental_price = '$20'
        self.material = 'Leather'
        self.size = 'M'

        self.test_furniture = Furniture(self.product_code, self.description,
                                        self.market_price, self.rental_price,
                                        self.material, self.size)
        self.expected_furniture_dict = {
            'product_code': self.product_code,
            'description': self.description,
            'market_price': self.market_price,
            'rental_price': self.rental_price,
            'material': self.material,
            'size': self.size
        }
    def test_furniture_class(self):
        '''This method will initialize the __init__ in the Furniture class,
        and then test all items'''
        Furniture.product_code = 12
        Furniture.description = "test_description"
        Furniture.market_price = 24
        Furniture.rental_price = 15
        Furniture.material = 'test_material'
        Furniture.size = '50x10x2'

        true_dict = {
            'product_code': 12,
            'description': 'test_description',
            'market_price': 24,
            'rental_price': 15,
            'material': 'test_material',
            'size': '50x10x2'
        }

        # Test all initializers into the Furniture class, and use
        # 'return_as_dictionary' to produce results. if the functions do
        # not work, the ValueError exception will be raised.
        try:
            test_items = Furniture(Furniture.product_code,
                                   Furniture.description,
                                   Furniture.market_price,
                                   Furniture.rental_price, Furniture.material,
                                   Furniture.size)
            dict_obj = test_items.return_as_dictionary()
        except:
            raise ValueError

        # test return value, return_as_dictionary
        self.assertEqual(dict_obj, true_dict)

        # verify the number of initializers
        real_count = 6
        key_count = 0
        for furn in dict_obj:
            key_count += 1
        self.assertEqual(real_count, key_count)
    def setUp(self):
        """ Create a furniture object """
        self.product_code = '12'
        self.description = 'Mattress'
        self.market_price = '$300'
        self.rental_price = '$150'
        self.material = 'MemoryFoam'
        self.size = 'L'

        self.example_furniture = Furniture(self.product_code, self.description,
                                           self.market_price,
                                           self.rental_price, self.material,
                                           self.size)
        self.correct_dict = {
            'product_code': self.product_code,
            'description': self.description,
            'market_price': self.market_price,
            'rental_price': self.rental_price,
            'material': self.material,
            'size': self.size
        }
 def test_add_new_item(self):
     """Test that new items are properly categorized and constructed, ...
     ...with market prices and FULL_INVENTORY mocked."""
     mkt_prc.get_latest_price = Mock(return_value=543)
     FULL_INVENTORY = Mock(return_value='dummy')
     with patch('builtins.input',
                side_effect=[
                    FUR_CDE, FUR_DSC, FUR_RNT_PRC, 'Y', FUR_MAT, FUR_SZ
                ]):
         self.assertEqual(
             Furniture(FUR_CDE, FUR_DSC, 543, FUR_RNT_PRC, FUR_MAT, FUR_SZ),
             add_new_item())
     with patch('builtins.input',
                side_effect=[
                    EA_CDE, EA_DSC, EA_RNT_PRC, 'N', 'Y', EA_BRD, EA_VLT
                ]):
         self.assertEqual(
             ElectricAppliances(EA_CDE, EA_DSC, 543, EA_RNT_PRC, EA_BRD,
                                EA_VLT), add_new_item())
     with patch('builtins.input',
                side_effect=[INV_CDE, INV_DSC, INV_RNT_PRC, 'N', 'N']):
         self.assertEqual(Inventory(INV_CDE, INV_DSC, 543, INV_RNT_PRC),
                          add_new_item())
class FurnitureTest(TestCase):
    """ Test the furniture class """
    def setUp(self):
        """ Create a furniture object """
        self.product_code = '12'
        self.description = 'Mattress'
        self.market_price = '$300'
        self.rental_price = '$150'
        self.material = 'MemoryFoam'
        self.size = 'L'

        self.example_furniture = Furniture(self.product_code, self.description,
                                           self.market_price,
                                           self.rental_price, self.material,
                                           self.size)
        self.correct_dict = {
            'product_code': self.product_code,
            'description': self.description,
            'market_price': self.market_price,
            'rental_price': self.rental_price,
            'material': self.material,
            'size': self.size
        }

    def test_inventory(self):
        """ Verify that the attributes have been appropriately assigned """
        assert self.example_furniture.product_code == self.product_code
        assert self.example_furniture.description == self.description
        assert self.example_furniture.market_price == self.market_price
        assert self.example_furniture.rental_price == self.rental_price
        assert self.example_furniture.material == self.material
        assert self.example_furniture.size == self.size

    def test_return_as_dictionary(self):
        """ Verify that the object is correctly defined in a dictionary """
        dict_return = self.example_furniture.return_as_dictionary()
        assert dict_return == self.correct_dict
class FurnitureTests(TestCase):
    """Tests creation of furniture subclass"""
    def setUp(self):
        """Sets up the initial paramaeters"""
        self.product_code = '26'
        self.description = 'Oven'
        self.market_price = '$50'
        self.rental_price = '$20'
        self.material = 'Leather'
        self.size = 'M'

        self.test_furniture = Furniture(self.product_code, self.description,
                                        self.market_price, self.rental_price,
                                        self.material, self.size)
        self.expected_furniture_dict = {
            'product_code': self.product_code,
            'description': self.description,
            'market_price': self.market_price,
            'rental_price': self.rental_price,
            'material': self.material,
            'size': self.size
        }

    def test_furniture_creation(self):
        """Tests creation of furniture subclass"""
        assert self.test_furniture.product_code == self.product_code
        assert self.test_furniture.description == self.description
        assert self.test_furniture.market_price == self.market_price
        assert self.test_furniture.rental_price == self.rental_price
        assert self.test_furniture.material == self.material
        assert self.test_furniture.size == self.size

    def test_appliance_dict(self):
        """Tests successful creation of the dictionary"""
        test_app_dict = self.test_furniture.return_as_dictionary()
        assert test_app_dict == self.expected_furniture_dict