def test_electric_appliances(self): """Test that an electric appliance object is created""" elec_app = { 'product_code': '002', 'description': 'Microwave', 'market_price': 130.0, 'rental_price': 10.0, 'brand': 'GE', 'voltage': 3.2 } item_details = ('002', 'Microwave', 130.0, 10.0, 'GE', 3.2) item_test = ElectricAppliances(*item_details) self.assertEqual(elec_app, item_test.return_as_dictionary())
def test_electric_appliance(self): test_electric_appliance = ElectricAppliances(self.product_code, self.description, self.market_price, self.rental_price, self.brand, self.voltage) self.assertDictEqual( { "product_code": self.product_code, "description": self.description, "market_price": self.market_price, "rental_price": self.rental_price, "brand": self.brand, "voltage": self.voltage }, test_electric_appliance.return_as_dictionary())
def test_electric_appliances(self): expected = { 'product_code': '4508', 'description': 'Drill', 'market_price': 340, 'rental_price': 10.00, 'brand': 'LG', 'voltage': 50000 } ea_details = ElectricAppliances('4508', 'Drill', 340, 10.00, 'LG', 50000) self.assertEqual(ea_details.return_as_dictionary(), expected) self.assertEqual(ea_details.brand, 'LG') self.assertEqual(ea_details.voltage, 50000)
def test_return_dictionary(self): """ Dictionary output """ appliance = ElectricAppliances("A", "B", "C", "D", "E", "F") self.assertDictEqual( { "product_code": "A", "description": "B", "market_price": "C", "rental_price": "D", "brand": "E", "voltage": "F", }, appliance.return_as_dictionary())
class ElectricAppliancesTests(TestCase): '''tests for the electric appliance module''' def setUp(self): '''creates a washing machine object''' self.washer = ElectricAppliances(2, 'Washing Machine', 500, 200, 'Kenmore', 120) def test_init(self): '''tests the init for the washer''' assert self.washer.product_code == 2 assert self.washer.description == 'Washing Machine' assert self.washer.market_price == 500 assert self.washer.rental_price == 200 assert self.washer.brand == 'Kenmore' assert self.washer.voltage == 120 def test_return_as_dict(self): '''tests the return as dictionary method''' washer_dict = self.washer.return_as_dictionary() assert washer_dict == { 'product_code': 2, 'description': 'Washing Machine', 'market_price': 500, 'rental_price': 200, 'brand': 'Kenmore', 'voltage': 120 }
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")
class ApplianceTest(TestCase): """Test cases for Electric Appliance class""" def setUp(self): self.product_dict = {} self.product_dict['product_code'] = 8942 self.product_dict['description'] = 'Oven' self.product_dict['market_price'] = 600 self.product_dict['rental_price'] = 200 self.product_dict['brand'] = 'Samsung' self.product_dict['voltage'] = 230 self.oven = ElectricAppliances(**self.product_dict) def test_init(self): """Tests that electric appliance class initializes correctly""" self.assertEqual(self.oven.product_code, self.product_dict['product_code']) self.assertEqual(self.oven.description, self.product_dict['description']) self.assertEqual(self.oven.market_price, self.product_dict['market_price']) self.assertEqual(self.oven.rental_price, self.product_dict['rental_price']) self.assertEqual(self.oven.brand, self.product_dict['brand']) self.assertEqual(self.oven.voltage, self.product_dict['voltage']) def test_return_as_dictionary(self): """Tests that electric appliance returns the expected dictionary""" self.assertEqual(self.product_dict, self.oven.return_as_dictionary())
def test_electric_apps_props(self): """Test to confirm proper storage of all usual product info, and additional furniture info.""" trial_instance = ElectricAppliances('1111', 'product description', 200.00, 50.00, 'Dell', '120 Volts') self.assertEqual(trial_instance.brand, 'Dell') self.assertEqual(trial_instance.voltage, '120 Volts')
class electricAppliancesTests(TestCase): """ Tests for electric appliances class """ def setUp(self): """ Set up """ self.item = ElectricAppliances('100', 'couch', '500', '250', brand='Ace', voltage='300') def test_init(self): """ Initialization tests """ self.assertIsInstance(self.item, (Inventory, ElectricAppliances)) self.assertEqual(self.item.brand, 'Ace') self.assertEqual(self.item.voltage, '300') def test_returnAsDictionary(self): """ Dictionary test """ 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['brand'], 'Ace') self.assertEqual(item_dict['voltage'], '300')
def test_return_as_dict_appliance(): """Tests that electric appliance class returns the expected dictionary""" product_dict = {} product_dict['product_code'] = 8942 product_dict['description'] = 'Oven' product_dict['market_price'] = 600 product_dict['rental_price'] = 200 product_dict['brand'] = 'Samsung' product_dict['voltage'] = 230 oven = ElectricAppliances(**product_dict) print(oven.return_as_dictionary()) print(product_dict) assert product_dict == oven.return_as_dictionary()
class ElectricAppliancesTest(TestCase): '''unittest the ElectricAppliances class under the electric_appliances_class module''' def setUp(self): '''create an instance from the ElectricAppliances class, from electric_appliances_class module''' self.electric_appliances = ElectricAppliances('product02', 'description02', 444, 222, 'brand01', 220) def test_electric_appliances(self): self.assertEqual('product02', self.electric_appliances.product_code) self.assertEqual('description02', self.electric_appliances.description) self.assertEqual(444, self.electric_appliances.market_price) self.assertEqual(222, self.electric_appliances.rental_price) self.assertEqual('brand01', self.electric_appliances.brand) self.assertEqual(220, self.electric_appliances.voltage) def test_electric_appliances_dict(self): self.assertEqual( { 'product_code': 'product02', 'description': 'description02', 'market_price': 444, 'rental_price': 222, 'brand': 'brand01', 'voltage': 220 }, self.electric_appliances.return_as_dictionary())
class ElectricAppliancesTests(TestCase): """ To test ElectricAppliances class and method. """ def setUp(self): self.product_code = 22 self.description = "Lamb" self.market_price = get_latest_price(self.product_code) self.rental_price = 22 self.brand = "GE" self.voltage = "210" self.electrical = ElectricAppliances(self.product_code, self.description, self.market_price, self.rental_price, self.brand, self.voltage) def test_return_as_dictionary_call3(self): """ This """ dict_result = self.electrical.return_as_dictionary() expected_dict = {} expected_dict['product_code'] = 22 expected_dict['description'] = "Lamb" expected_dict['market_price'] = 24 expected_dict['rental_price'] = 22 expected_dict['brand'] = "GE" expected_dict['voltage'] = "210" self.assertEqual(expected_dict, dict_result)
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")
class TestElectricAppliances(TestCase): """ tests modules in electric_appliances_class.py """ def setUp(self): self.product_code = 199021 self.description = 'na' self.market_price = 100 self.rental_price = 500 self.brand = 'ge' self.voltage = 120 self.check_electric = ElectricAppliances(self.product_code, self.description, self.market_price, self.rental_price, self.brand, self.voltage) def test_init(self): """ check initialization of variables """ self.assertEqual(self.check_electric.product_code, self.product_code) self.assertEqual(self.check_electric.description, self.description) self.assertEqual(self.check_electric.market_price, self.market_price) self.assertEqual(self.check_electric.rental_price, self.rental_price) self.assertEqual(self.check_electric.brand, self.brand) self.assertEqual(self.check_electric.voltage, self.voltage) def test_return_as_dict(self): """ check dictionary output """ dict_output = self.check_electric.return_as_dict() self.assertEqual(dict_output['product_code'], self.product_code) self.assertEqual(dict_output['description'], self.description) self.assertEqual(dict_output['market_price'], self.market_price) self.assertEqual(dict_output['rental_price'], self.rental_price) self.assertEqual(dict_output['brand'], self.brand) self.assertEqual(dict_output['voltage'], self.voltage)
def setUp(self): self.item_chair = {} self.item_microwave = {} self.item_sofa = {} self.full_inventory = {} self.inventory_string = '' self.item_chair['product_code'] = 100 self.item_chair['description'] = 'Chair' self.item_chair['market_price'] = 111 self.item_chair['rental_price'] = 11 self.full_inventory[self.item_chair['product_code']] = \ Inventory(**self.item_chair).return_as_dictionary() self.item_microwave['product_code'] = 200 self.item_microwave['description'] = 'Microwave' self.item_microwave['market_price'] = 222 self.item_microwave['rental_price'] = 22 self.item_microwave['brand'] = 'Samsung' self.item_microwave['voltage'] = 230 self.full_inventory[self.item_microwave['product_code']] = \ ElectricAppliances(**self.item_microwave).return_as_dictionary() self.item_sofa['product_code'] = 300 self.item_sofa['description'] = 'Sofa' self.item_sofa['market_price'] = 333 self.item_sofa['rental_price'] = 33 self.item_sofa['material'] = 'Leather' self.item_sofa['size'] = 'XL' self.full_inventory[self.item_sofa['product_code']] = \ Furniture(**self.item_sofa).return_as_dictionary() for item_code in self.full_inventory: for value in self.full_inventory[item_code].values(): self.inventory_string += f'{value}'
def test_electric_appliances(self): elec_app = ElectricAppliances(elec_code, elec_description, elec_price, elec_rental_price, elec_brand, elec_voltage) full_inventory[elec_code] = elec_app.return_as_dictionary() self.assertTrue(elec_code in full_inventory) this_item = full_inventory[elec_code] self.assertTrue(this_item['product_code'] == elec_code) self.assertTrue(this_item['description'] == elec_description) self.assertTrue(this_item['market_price'] == elec_price) self.assertTrue(this_item['rental_price'] == elec_rental_price) self.assertTrue(this_item['brand'] == elec_brand) self.assertTrue(this_item['voltage'] == elec_voltage)
class ElectricAppliancesTests(TestCase): """ Unit Tests for ElectricAppliances Module """ def setUp(self): self.appliance = ElectricAppliances("fc_001", "Flux Capacitor", 20000, 2000, "Doc Brown Labs", "2.21 Jiggawatts") def test_electric_appliance_variables(self): """ Validates setting the variables of a ElectricAppliances object. """ self.assertEqual("fc_001", self.appliance.product_code) self.assertEqual("Flux Capacitor", self.appliance.description) self.assertEqual(20000, self.appliance.market_price) self.assertEqual(2000, self.appliance.rental_price) self.assertEqual("Doc Brown Labs", self.appliance.brand) self.assertEqual("2.21 Jiggawatts", self.appliance.voltage) def test_electric_appliance_as_dictionary(self): """ Validates Return As Dictionary method of an ElectricAppliances object. """ appliance_dict = self.appliance.return_as_dictionary() self.assertEqual("fc_001", appliance_dict.get("product_code")) self.assertEqual("Flux Capacitor", appliance_dict.get("description")) self.assertEqual(20000, appliance_dict.get("market_price")) self.assertEqual(2000, appliance_dict.get("rental_price")) self.assertEqual("Doc Brown Labs", appliance_dict.get("brand")) self.assertEqual("2.21 Jiggawatts", appliance_dict.get("voltage"))
def test_return_as_dictionary(self): product = ElectricAppliances(product_code="ABC", description="Meh", market_price=9.99, rental_price=0.99, brand="VGood", voltage="220") output_dict = dict() output_dict["productCode"] = "ABC" output_dict["description"] = "Meh" output_dict["marketPrice"] = 9.99 output_dict["rentalPrice"] = 0.99 output_dict["brand"] = "VGood" output_dict["voltage"] = "220" self.assertDictEqual(output_dict, product.return_as_dictionary())
class ElectricApplianceTests(TestCase): """Tests for the ElectricAppliances class.""" def setUp(self): self.appl = ElectricAppliances("A1", "Test", 2, 3, "Brand", 4) def test_init(self): """Test object instantiation.""" self.assertEqual(self.appl.product_code, "A1") self.assertEqual(self.appl.description, "Test") self.assertEqual(self.appl.market_price, 2) self.assertEqual(self.appl.rental_price, 3) self.assertEqual(self.appl.brand, "Brand") self.assertEqual(self.appl.voltage, 4) def test_return_dict(self): """Test return_as_dict method.""" # expected dict to return appl_dict = { 'product_code': "A1", 'description': "Test", 'market_price': 2, 'rental_price': 3, 'brand': "Brand", 'voltage': 4 } self.assertEqual(appl_dict, self.appl.return_as_dict())
def setUp(self): self.item_table = dict() self.item_vacuum = dict() self.item_bed = dict() self.full_inventory = dict() self.item_table['product_code'] = 1 self.item_table['description'] = 'Table' self.item_table['market_price'] = 24 self.item_table['rental_price'] = 100 self.full_inventory[self.item_table['product_code']] = \ Inventory(**self.item_table).return_as_dictionary() self.item_vacuum['product_code'] = 2 self.item_vacuum['description'] = 'Vacuum' self.item_vacuum['market_price'] = 24 self.item_vacuum['rental_price'] = 200 self.item_vacuum['brand'] = 'Samsung' self.item_vacuum['voltage'] = 110 self.full_inventory[self.item_vacuum['product_code']] = \ ElectricAppliances(**self.item_vacuum).return_as_dictionary() self.item_bed['product_code'] = 300 self.item_bed['description'] = 'Bed' self.item_bed['market_price'] = 24 self.item_bed['rental_price'] = 300 self.item_bed['material'] = 'Wood' self.item_bed['size'] = 'L' self.full_inventory[self.item_bed['product_code']] = \ Furniture(**self.item_bed).return_as_dictionary()
def test_return_as_dictionary(self): stove = ElectricAppliances(2, 'black', 200, 100, 'Steve Stoves', 55) test_dictionary = { 'product_code': 2, 'description': 'black', 'market_price': 200, 'rental_price': 100, 'brand': 'Steve Stoves', 'voltage': 55 } for key, value in test_dictionary.items(): self.assertEqual(test_dictionary[f'{key}'], stove.return_as_dictionary()[f'{key}']) self.assertEqual(dict, type(stove.return_as_dictionary()))
def test_electric_appliances(self): electric_app_sample = ElectricAppliances(12, "sample description", "sample market price", "sample rental price", "sample brand", "sample voltage") self.assertEqual( electric_app_sample.return_as_dictionary(), { 'product_code': 12, 'description': "sample description", 'market_price': "sample market price", 'rental_price': "sample rental price", 'brand': "sample brand", 'voltage': "sample voltage" })
def test_add_new_item_electrical(self): """Test can add new ElectricalAppliances""" menu = MainMenu() capture_output(menu.add_new_item) expected = ElectricAppliances("item-code", "item-desc", MainTests.MOCK_PRICE, "rental-price", "brand", "volt").return_as_dictionary() self.assertEqual(menu.inventory, {"item-code": expected})
def test_output(self): info = {} info['product_code'] = '1002' info['description'] = 'heater' info['market_price'] = '500' info['rental_price'] = '100' info['brand'] = 'GE' info['voltage'] = '110v' heater = ElectricAppliances(info) result = heater.return_as_dictionary() self.assertEqual(result['product_code'], "1002") self.assertEqual(result['description'], 'heater') self.assertEqual(result['market_price'], '500') self.assertEqual(result['rental_price'], '100') self.assertEqual(result['brand'], 'GE') self.assertEqual(result['voltage'], '110v')
def new_electric_appliance_item(item_code, item_description, item_price, item_rental_price, item_brand, item_voltage): """ Function to add a new electric appliance item to dictionary """ new_item = ElectricAppliances(item_code, item_description, item_price, item_rental_price, item_brand, item_voltage) return new_item
def test_init(self): item = ElectricAppliances("GE", "120", **item_info) self.assertEqual('12345', item.product_code) self.assertEqual('refrigerator', item.description) self.assertEqual('2100.00', item.market_price) self.assertEqual('140.00', item.rental_price) self.assertEqual('GE', item.brand) self.assertEqual('120', item.voltage)
def test_init(self): oven = ElectricAppliances(60, "oven", 1800, 60, "ShittyOven", 66) self.assertEqual(oven.product_code, 60) self.assertEqual(oven.description, "oven") self.assertEqual(oven.market_price, 1800) self.assertEqual(oven.rental_price, 60) self.assertEqual(oven.brand, "ShittyOven") self.assertEqual(oven.voltage, 66)
def test_init(self): """Test __init__()""" test_obj = ElectricAppliances(1, 2, 3, 4, 5, 6) self.assertEqual(test_obj.product_code, 1) self.assertEqual(test_obj.description, 2) self.assertEqual(test_obj.market_price, 3) self.assertEqual(test_obj.rental_price, 4) self.assertEqual(test_obj.brand, 5) self.assertEqual(test_obj.voltage, 6)
def test_return_as_dictionary(self): oven_dict = ElectricAppliances(60, "oven", 1800, 60, "ShittyOven", 66 ).return_as_dictionary() self.assertEqual(oven_dict['product_code'], 60) self.assertEqual(oven_dict['description'], "oven") self.assertEqual(oven_dict['market_price'], 1800) self.assertEqual(oven_dict['rental_price'], 60) self.assertEqual(oven_dict['brand'], "ShittyOven") self.assertEqual(oven_dict['voltage'], 66)
def test_return_dict(self): """Test return as dict func""" test_obj = ElectricAppliances(1, 2, 3, 4, 5, 6).return_as_dictionary() self.assertEqual(test_obj['product_code'], 1) self.assertEqual(test_obj['description'], 2) self.assertEqual(test_obj['market_price'], 3) self.assertEqual(test_obj['rental_price'], 4) self.assertEqual(test_obj['brand'], 5) self.assertEqual(test_obj['voltage'], 6)