class FurnitureClassTests(TestCase):
    '''tests for the furniture class module'''
    def setUp(self):
        '''creates a furniture object, a sofa'''
        self.sofa = Furniture(321, 'brown sofa', 300, 100, 'Faux Leather',
                              'Large')

    def test_init(self):
        '''tests init values for the sofa'''
        assert self.sofa.product_code == 321
        assert self.sofa.description == 'brown sofa'
        assert self.sofa.market_price == 300
        assert self.sofa.rental_price == 100
        assert self.sofa.material == 'Faux Leather'
        assert self.sofa.size == 'Large'

    def test_return_as_dict(self):
        '''tests the return as dict method in class inventory'''
        sofa_dict = self.sofa.return_as_dictionary()
        assert sofa_dict == {
            'product_code': 321,
            'description': 'brown sofa',
            'market_price': 300,
            'rental_price': 100,
            'material': 'Faux Leather',
            'size': 'Large'
        }
class FurnitureTests(TestCase):
    """Test cases for Furniture class"""
    def setUp(self):
        self.product_dict = {}
        self.product_dict['product_code'] = 100
        self.product_dict['description'] = 'Chair'
        self.product_dict['market_price'] = 200
        self.product_dict['rental_price'] = 50
        self.product_dict['material'] = 'Leather'
        self.product_dict['size'] = 'L'
        self.chair = Furniture(**self.product_dict)

    def test_init(self):
        """Tests that furniture class initializes correctly"""
        self.assertEqual(self.chair.product_code,
                         self.product_dict['product_code'])
        self.assertEqual(self.chair.description,
                         self.product_dict['description'])
        self.assertEqual(self.chair.market_price,
                         self.product_dict['market_price'])
        self.assertEqual(self.chair.rental_price,
                         self.product_dict['rental_price'])
        self.assertEqual(self.chair.material, self.product_dict['material'])
        self.assertEqual(self.chair.size, self.product_dict['size'])

    def test_return_as_dictionary(self):
        """Tests that furniture class returns the expected dictionary"""
        self.assertEqual(self.product_dict, self.chair.return_as_dictionary())
class inventory_test(TestCase):
    """unit test for inventory and its sub classes"""
    def setUp(self):
        """set up instance of each sub class"""
        self.furniture = Furniture(100, "test chair", 20, (1.5, "day"), "wood",
                                   "Large")

        self.appliance = ElectricAppliances(200, "test lamp", 30, (2.5, "day"),
                                            "basic", "110V")
        self.appliance_expected_output = {
            "product_code": 200,
            "description": "test lamp",
            "market_price": 30,
            "rental_price": (2.5, "day"),
            "brand": "basic",
            "voltage": "110V",
        }
        self.furniture_expected_output = {
            "product_code": 100,
            "description": "test chair",
            "market_price": 20,
            "rental_price": (1.5, "day"),
            "material": "wood",
            "size": "Large",
        }

    def test_electric_appliances(self):

        self.assertDictEqual(self.appliance.return_as_dictionary(),
                             self.appliance_expected_output)

    def test_furniture(self):

        self.assertDictEqual(self.furniture.return_as_dictionary(),
                             self.furniture_expected_output)
class furnitureClassTests(TestCase):
    """
    Tests furniture class
    """
    def setUp(self):
        """
        Set up
        """
        self.item = Furniture('100', 'couch', '500', '250', material='wool', size='10')

    def test_init(self):
        """
        Tests initialization
        """
        self.assertIsInstance(self.item, (Inventory, Furniture))
        self.assertEqual(self.item.material, 'wool')
        self.assertEqual(self.item.size, '10')

    def test_returnAsDictionary(self):
        """
        Tests returning as dictionary
        """
        item_dict = self.item.return_as_dictionary()
        self.assertIsInstance(item_dict, dict)
        self.assertEqual(item_dict['product_code'], '100')
        self.assertEqual(item_dict['description'], 'couch')
        self.assertEqual(item_dict['market_price'], '500')
        self.assertEqual(item_dict['rental_price'], '250')
        self.assertEqual(item_dict['material'], 'wool')
        self.assertEqual(item_dict['size'], '10')
class FurnitureTests(TestCase):
    """ Unit Tests for Furniture Module. """
    def setUp(self):
        self.furniture = Furniture("sophie", "loaphie", -34, 2000, "stuff", 2)

    def test_furniture_variables(self):
        """
        Validates setting the variables of a Furniture object.
        """
        self.assertEqual("sophie", self.furniture.product_code)
        self.assertEqual("loaphie", self.furniture.description)
        self.assertEqual(-34, self.furniture.market_price)
        self.assertEqual(2000, self.furniture.rental_price)
        self.assertEqual("stuff", self.furniture.material)
        self.assertEqual(2, self.furniture.size)

    def test_furniture_as_dictionary(self):
        """
        Validates Return As Dictionary method of an Furniture object.
        """
        furniture_dict = self.furniture.return_as_dictionary()
        self.assertEqual("sophie", furniture_dict.get("product_code"))
        self.assertEqual("loaphie", furniture_dict.get("description"))
        self.assertEqual(-34, furniture_dict.get("market_price"))
        self.assertEqual(2000, furniture_dict.get("rental_price"))
        self.assertEqual("stuff", furniture_dict.get("material"))
        self.assertEqual(2, furniture_dict.get("size"))
Exemple #6
0
class FurnitureTests(TestCase):
    """
    To test Furniture class and method.
    """
    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)

    def test_return_as_dictionary_call2(self):
        """
        This
        """
        dict_result = self.furniture.return_as_dictionary()

        expected_dict = {}
        expected_dict['product_code'] = 23
        expected_dict['description'] = "Table"
        expected_dict['market_price'] = 24
        expected_dict['rental_price'] = 23
        expected_dict['material'] = "Wood"
        expected_dict['size'] = "L"

        self.assertEqual(expected_dict, dict_result)
Exemple #7
0
 def test_furniture_todict(self):
     """Test that Furniture returns as dictionary"""
     fields = ("productCode", "description", "marketPrice", "rentalPrice",
               "material", "size")
     app = Furniture(*fields)
     expected = {f: f for f in fields}
     self.assertEqual(app.return_as_dictionary(), expected)
Exemple #8
0
def test_return_as_dict_furniture():
    """Tests that furniture class returns the expected dictionary"""
    product_dict = {}
    product_dict['product_code'] = 100
    product_dict['description'] = 'Chair'
    product_dict['market_price'] = 200
    product_dict['rental_price'] = 50
    product_dict['material'] = 'Leather'
    product_dict['size'] = 'L'

    chair = Furniture(**product_dict)

    print(chair.return_as_dictionary())
    print(product_dict)

    assert product_dict == chair.return_as_dictionary()
Exemple #9
0
def add_furniture(item_code, item_description, item_price, item_rental_price,
                  item_material, item_size):
    """ add furniture method to decouple UI/bus logic for unit test """
    new_item = Furniture(item_code, item_description, item_price,
                         item_rental_price, item_material, item_size)
    FULL_INVENTORY[item_code] = new_item.return_as_dictionary()
    print("New inventory item added")
Exemple #10
0
class FurnitureTests(unittest.TestCase):
    """Contains all the tests for the Furniture Class."""
    def setUp(self):
        self.chair = Furniture('100', "this is a chair", '150.00', '5.00')
        self.chair2 = Furniture('120',
                                "this is chair #2",
                                '180.00',
                                '0.00',
                                material="Leather",
                                size="small")

    def test_init(self):
        """Test we can initialize a piece of Furniture properly."""
        # test chair with no material or size
        self.assertEqual(self.chair.size, "N/A")
        self.assertEqual(self.chair.material, "N/A")

        # test chair with material and size defined
        self.assertEqual(self.chair2.size, "small")
        self.assertEqual(self.chair2.material, "Leather")

    def test_return_as_dict(self):
        """Test dictionary function for extended furniture needs."""
        chair2_dict = self.chair2.return_as_dictionary()

        self.assertIsInstance(chair2_dict, dict)
        self.assertEqual(chair2_dict["size"], "small")
        self.assertEqual(chair2_dict["material"], "Leather")
class FurnitureTest(TestCase):
    '''unittest the Furniture class under the furniture_class module'''
    def setUp(self):
        '''
        create an instance from the Furniture class,
        from furniture_class module
        '''
        self.furniture = Furniture('product03', 'description03', 555, 111,
                                   'material01', 'M')

    def test_furniture(self):
        self.assertEqual('product03', self.furniture.product_code)
        self.assertEqual('description03', self.furniture.description)
        self.assertEqual(555, self.furniture.market_price)
        self.assertEqual(111, self.furniture.rental_price)
        self.assertEqual('material01', self.furniture.material)
        self.assertEqual('M', self.furniture.size)

    def test_furniture_dict(self):
        self.assertEqual(
            {
                'product_code': 'product03',
                'description': 'description03',
                'market_price': 555,
                'rental_price': 111,
                'material': 'material01',
                'size': 'M'
            }, self.furniture.return_as_dictionary())
Exemple #12
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)
Exemple #13
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")
Exemple #14
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)
    def test_return_dict(self):
        """calls the return_as_dictionary function on the Furniture class"""
        furniture = Furniture("2222", "Chair", "$200", "$150", "Wood", "Small")

        furniture_info = furniture.return_as_dictionary()
        self.assertEqual(furniture_info, {'product_code': '2222', 'description': 'Chair',
                                          'market_price': '$200', 'rental_price': '$150',
                                          'material' : 'Wood', 'size' : 'Small'})
Exemple #16
0
    def test_return_as_dictionary(self):

        couch = Furniture(3, 'comfy', 500, 600, 'leather', 'M')

        test_dictionary = {
            'product_code': 3,
            'description': 'comfy',
            'market_price': 500,
            'rental_price': 600,
            'material': 'leather',
            'size': 'M'
        }

        for key, value in test_dictionary.items():
            self.assertEqual(value, couch.return_as_dictionary()[f'{key}'])

        self.assertEqual(dict, type(couch.return_as_dictionary()))
 def test_furniture_dict(self):
     """Test to confirm proper info translation to a dict."""
     trial_instance = Furniture('1111', 'product description', 200.00, 50.00,
                                'leather', 'queen')
     trial_instance_dict = trial_instance.return_as_dictionary()
     self.assertEqual(trial_instance_dict, {'product_code': '1111',
                                            'description': 'product description',
                                            'market_price': 200.00, 'rental_price': 50.00,
                                            'material': 'leather', 'size': 'queen'})
 def test_return_dict(self):
     furn = Furniture(54, 'Test Elec', 200, 300, 'leather', 10)
     furn_dict = furn.return_as_dictionary()
     test_dict = {'product_code': 54,
                 'description': 'Test Elec',
                 'market_price': 200,
                 'rental_price': 300,
                 'material': 'leather',
                 'size': 10}
     self.assertEqual(furn_dict, test_dict)
 def test_furniture(self):
     """test out the furniture class"""
     test = Furniture(17, 'desc', 354, 144, 'bronze', 'yuge')
     self.assertEqual(test.return_as_dictionary(),
                      {'product_code': 17,
                       'description': 'desc',
                       'market_price': 354,
                       'rental_price': 144,
                       'material': 'bronze',
                       'size': 'yuge'})
Exemple #20
0
 def test_return_as_dict_fur(self):
     input_dict = Furniture('a', 'b', 100, 150, 'm', 'z')
     dict_output = dict()
     dict_output['productCode'] = 'a'
     dict_output['description'] = 'b'
     dict_output['marketPrice'] = 100
     dict_output['rentalPrice'] = 150
     dict_output['material'] = 'm'
     dict_output['size'] = 'z'
     self.assertDictEqual(input_dict.return_as_dictionary(),dict_output)
    def test_furniture(self):
        furn = {'product_code': '0455',
                'description': 'couch',
                'market_price': 280.0,
                'rental_price': 30.0,
                'material': 'leather',
                'size': 'L'}
        details = ('0455', 'couch', 280.0, 30.0, 'leather', 'L')
        furn_test = Furniture(*details)

        self.assertEqual(furn, furn_test.return_as_dictionary())
 def test_furniture(self):
     """tests the furniture item functionality"""
     couch = Furniture('C74', 'IKEA Malmer Couch', 24, 125,
                       'Leather', 'L')
     compare = {'productCode':'C74',
                'description':'IKEA Malmer Couch',
                'marketPrice':24,
                'rentalPrice':125,
                'material':'Leather',
                'size':'L'}
     self.assertDictEqual(couch.return_as_dictionary(), compare)
Exemple #23
0
 def test_furniture(self):
     furn_dict_test = {
         'product_code': '555',
         'description': 'black',
         'market_price': 250,
         'rental_price': 30,
         'material': 'wood',
         'size': 's'
     }
     furn_dict = Furniture('555', 'black', 250, 30, 'wood', 's')
     self.assertEqual(furn_dict_test, furn_dict.return_as_dictionary())
Exemple #24
0
 def test_furniture(self):
     f = Furniture('X55', 'Red couch', 120, 20, 'Cloth', 'XL')
     f_dict = f.return_as_dictionary()
     assert f_dict == {
         'product_code': 'X55',
         'description': 'Red couch',
         'market_price': 120,
         'rental_price': 20,
         'material': 'Cloth',
         'size': 'XL'
     }
 def test_furniture(self):
     f = {
         'product_code': '200',
         'description': 'beanbag',
         'market_price': 600.0,
         'rental_price': 100.0,
         'material': 'faux fur',
         'size': 'L'
     }
     d = ('200', 'beanbag', 600.0, 100.0, 'faux fur', 'L')
     test = Furniture(*d)
     self.assertEqual(f, test.return_as_dictionary())
 def test_furniture(self):
     furniture = Furniture(2, 'Chair', 25, 10, 'Leather', 'S')
     furniture_dict_test = furniture.return_as_dictionary()
     self.assertEqual(
         furniture_dict_test, {
             'product_code': 2,
             'description': 'Chair',
             'market_price': 25,
             'rental_price': 10,
             'material': 'Leather',
             'size': 'S'
         })
 def test_furniture(self):
     test_furn = Furniture(1234, "test product", 567, 246, "wood", "L")
     self.assertIsInstance(test_furn, Furniture)
     test_furn_dict = {
         "product_code": 1234,
         "description": "test product",
         "market_price": 567,
         "rental_price": 246,
         "material": "wood",
         "size": "L"
     }
     self.assertDictEqual(test_furn_dict, test_furn.return_as_dictionary())
Exemple #28
0
 def test_furniture(self):
     ''' furniture test'''
     furniture = Furniture('Code3', 'Item3 Test', 30, 3, 'Leather', 'small')
     self.assertAlmostEqual(
         furniture.return_as_dictionary(), {
             'product_code': 'Code3',
             'description': 'Item3 Test',
             'market_price': 30,
             'rental_price': 3,
             'material': 'Leather',
             'size': 'small'
         })
Exemple #29
0
    def test_return_as_dict(self):
        furniture = Furniture(1, "item", 5, 5, "material", "XL")
        test_dict = {
            'product_code': 1,
            'description': "item",
            'market_price': 5,
            'rental_price': 5,
            'material': "material",
            'size': "XL"
        }

        self.assertEqual(test_dict, furniture.return_as_dictionary())
 def test_furniture(self):
     """Tests the creation of an instance for furniture object"""
     test_dict = {
         'product_code': 1011,
         'description': 'SuperToy',
         'market_price': 50,
         'rental_price': 10,
         'material': 'Leather',
         'size': 'Large'
     }
     test_furn = Furniture(1011, 'SuperToy', 50, 10, 'Leather', 'Large')
     self.assertEqual(test_dict, test_furn.return_as_dictionary())