Ejemplo n.º 1
0
 def test_check_wattage(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
     item_dict["brand"] = "b"
     item_dict["voltage"] = 10
     e = ElectricAppliances(**item_dict)
     wattage = e.check_wattage(10)
     self.assertEqual(wattage, 250)
Ejemplo n.º 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
     item_dict["brand"] = "b"
     item_dict["voltage"] = 2
     e = ElectricAppliances(**item_dict)
     new_dict = e.return_as_dictionary()
     self.assertEqual(e.product_code, new_dict["product_code"])
     self.assertEqual(e.description, new_dict["description"])
     self.assertEqual(e.brand, new_dict["brand"])
     self.assertEqual(e.voltage, new_dict["voltage"])
Ejemplo n.º 3
0
def add_new_item():
    '''
    Add new item to the 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")
class ElectricAppliancesTests(TestCase):
    """
    Tests for the ElectricAppliances class
    """
    def setUp(self):
        """
        Sets up tests for ElectricAppliances
        """
        self.item = ElectricAppliances('10', 'test', '4', '5', 'GE', '110')

    def test_init(self):
        """
        Test ElectricAppliances.__init__()
        """
        self.assertEqual(self.item.voltage, '110')
        self.assertEqual(self.item.brand, 'GE')
        self.assertEqual(self.item.description, 'test')

    def test_dict(self):
        """
        Test ElectricAppliances.return_as_dictionary()
        """
        self.assertEqual(
            self.item.return_as_dictionary(), {
                'product_code': '10',
                'description': 'test',
                'market_price': '4',
                'rental_price': '5',
                'brand': 'GE',
                'voltage': '110'
            })
Ejemplo n.º 5
0
 def test_add_new_item_electrical(self):
     text_trap = io.StringIO()
     sys.stdout = text_trap
     user_input = ["2", "b", "2.0", "n", "y", "b", "2.0"]
     f_inventory = {}
     with patch('builtins.input', side_effect=user_input):
         f_inventory = add_new_item(f_inventory)
     new_dict = f_inventory["2"]
     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"
     item_dict["brand"] = "b"
     item_dict["voltage"] = "2.0"
     e = ElectricAppliances(**item_dict)
     new_dict1 = e.return_as_dictionary()
     self.assertEqual(new_dict["product_code"], new_dict1["product_code"])
     self.assertEqual(new_dict["description"], new_dict1["description"])
     self.assertEqual(new_dict["brand"], new_dict1["brand"])
     self.assertEqual(new_dict["voltage"], new_dict1["voltage"])
     sys.stdout = sys.__stdout__
    def test_dict(self):
        """
        Test that a proper ElectricAppliances dict is returned
        """
        item = ElectricAppliances(
            1,
            "EA1",
            "1000",
            "2000",
            brand="GE",
            voltage="220")

        output_dict = item.return_as_dictionary()
        self.assertEqual(
            {
                'product_code': 1,
                'description': 'EA1',
                'market_price': '1000',
                'rental_price': '2000',
                'brand': 'GE',
                'voltage': '220'
            },
            output_dict)
 def test_init(self):
     """
     Test that a proper ElectricAppliances object is returned
     """
     item = ElectricAppliances(
         1,
         "EA1",
         "1000",
         "2000",
         brand="GE",
         voltage="220")
     self.assertEqual("220", item.voltage)
     self.assertEqual("GE", item.brand)
     self.assertEqual("EA1", item.description)
Ejemplo n.º 8
0
    def test_return_as_dictionary(self):
        """
        Tests the return as dictionary method of
        the electric appliance class. Ensures the length
        of returned dictionary matches desired
        length.

        :return: None

        """
        # Create an instance of the Electric Appliances Class
        electric_appliance = ElectricAppliances("1", "2", "3", "4", "5", "6")
        test_dic = electric_appliance.return_as_dictionary()

        # Verify return_as_dictionary function populates
        # Each item, and are properly instantiated
        self.assertEqual(6, len(test_dic))
        self.assertEqual('1', test_dic['product_code'])
        self.assertEqual('2', test_dic['description'])
        self.assertEqual('3', test_dic['market_price'])
        self.assertEqual('4', test_dic['rental_price'])
        self.assertEqual('5', test_dic['brand'])
        self.assertEqual('6', test_dic['voltage'])
Ejemplo n.º 9
0
 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
     item_dict["brand"] = "b"
     item_dict["voltage"] = 2
     e = ElectricAppliances(**item_dict)
     self.assertEqual(e.product_code, 2)
     self.assertEqual(e.description, "b")
     self.assertEqual(e.rental_price, 2.0)
     self.assertEqual(e.market_price, 2.0)
     self.assertEqual(e.brand, "b")
     self.assertEqual(e.voltage, 2)
Ejemplo n.º 10
0
    def test_electric_appliances(self):

        elect_app1 = {
            'productCode': '001',
            'description': 'elect_1',
            'marketPrice': '$25',
            'rentalPrice': '$15',
            'brand': 'brand1',
            'voltage': '220v'
        }

        self.assertEqual(
            elect_app1,
            ElectricAppliances('brand1', '220v', '001', 'elect_1', '$25',
                               '$15').return_as_dictionary())
 def setUp(self):
     self.electric_appliance = ElectricAppliances(product_code=1,
                                                  description='test',
                                                  market_price=99.99,
                                                  rental_price=9.99,
                                                  brand='Dewalt',
                                                  voltage=20)
     self.expected_electric_appliance_dict = {
         'product_code': 1,
         'description': 'test',
         'market_price': 99.99,
         'rental_price': 9.99,
         'brand': 'Dewalt',
         'voltage': 20
     }
Ejemplo n.º 12
0
def add_new_item(f_inventory):
    """
    Function to add an additional item to Inventory
    """
    # Get price from the market prices module
    item_price = get_price()
    item_dict = input_item_info()
    item_dict["item_price"] = item_price
    if item_dict.get("style") == "furniture":
        new_item = Furniture(**item_dict)
    elif item_dict.get("style") == "electric":
        new_item = ElectricAppliances(**item_dict)
    else:
        new_item = Inventory(**item_dict)
    f_inventory[item_dict["item_code"]] = new_item.return_as_dictionary()
    print("New inventory item added")
    return f_inventory
Ejemplo n.º 13
0
    def test_initializer(self):
        """
        Tests the initializer of the Inventory class.
        Verifies classes attributes are filled when
        class is instantiated.
        :return: None

        """
        # Create an instance of the Electric Appliances
        electric_appliance = ElectricAppliances("1", "2", "3", "4", "5", "6")

        # Test to verify data has been passed through the
        # initializer
        self.assertIsNotNone(electric_appliance.product_code)
        self.assertIsNotNone(electric_appliance.description)
        self.assertIsNotNone(electric_appliance.market_price)
        self.assertIsNotNone(electric_appliance.rental_price)
        self.assertIsNotNone(electric_appliance.brand)
        self.assertIsNotNone(electric_appliance.voltage)
 def setUp(self):
     """
     Sets up tests for ElectricAppliances
     """
     self.item = ElectricAppliances('10', 'test', '4', '5', 'GE', '110')