def update_item(item_id): """ Updates a furniture item using the given item_id, from the furniture store """ item_id = int(item_id) data = request.json response_dict = {'status': 200} item = my_store.get(item_id) if item: # Create a new item with all the updated properties # and assign the same ID to it as the item being # replaced. item_type = data.pop('type', None) updated_item = None if item_type == Bed.FURNITURE_TYPE: updated_item = Bed(**data) elif item_type == Sofa.FURNITURE_TYPE: data["number_of_seats"] = int(data["number_of_seats"]) data["number_of_cushions"] = int(data["number_of_cushions"]) updated_item = Sofa(**data) updated_item.id = item_id my_store.update(updated_item) response_dict["response"] = ("Item of ID " + str(item_id) + " successfully updated.") else: response_dict['status'] = 404 response_dict[ "response"] = "No item was found corresponding to the given item_id" return app.response_class(**response_dict)
def setUp(self): """ setUp method for testing methods of the FurnitureManager class """ engine = create_engine("sqlite:///test_furniture.sqlite") # Creates all the tables Base.metadata.create_all(engine) Base.metadata.bind = engine self.manager = FurnitureManager("test_furniture.sqlite") self.beds = { "Bed1": ["001", "2019", "Ikea", 24.99, 44.99, "190x100cm", "25cm"], "Bed2": [ "002", "2015", "HelloFurniture", 124.99, 144.99, "190x100cm", "25cm", ], } self.sofas = { "Sofa1": ["003", "2012", "HelloFurniture", 99.99, 119.99, 4, 6] } self.Bed1 = Bed( self.beds["Bed1"][0], self.beds["Bed1"][1], self.beds["Bed1"][2], self.beds["Bed1"][3], self.beds["Bed1"][4], self.beds["Bed1"][5], self.beds["Bed1"][6], ) self.Bed2 = Bed( self.beds["Bed2"][0], self.beds["Bed2"][1], self.beds["Bed2"][2], self.beds["Bed2"][3], self.beds["Bed2"][4], self.beds["Bed2"][5], self.beds["Bed2"][6], ) self.Sofa1 = Sofa( self.sofas["Sofa1"][0], self.sofas["Sofa1"][1], self.sofas["Sofa1"][2], self.sofas["Sofa1"][3], self.sofas["Sofa1"][4], self.sofas["Sofa1"][5], self.sofas["Sofa1"][6], )
def main(): '''start the sofa''' parser = OptionParser() parser.add_option('-r', '--roboteq_path', dest='roboteq_path', default="/dev/ttyACM0", help="path to roboteq controller") parser.add_option('-s', '--status_path', dest="status_path", default="/var/run/sofa_status", help="path to runtime status file") parser.add_option('-l', '--listen', dest='listen', default="0.0.0.0:31337", help="ip:port to listen on for joystick data") (options, _) = parser.parse_args() atexit.register(lambda: shutdown(options.status_path)) sofa = Sofa(roboteq_path=options.roboteq_path, status_path=options.status_path, listen=options.listen) sofa.run()
def add_item(): """ Creates and adds a new item to the furniture shop using the JSON info provided """ data = request.json response_dict = {"status": 200, "response": None} try: item_type = data.pop("type", None) item_id = None if item_type == Bed.FURNITURE_TYPE: item_id = my_store.add(Bed(**data)) elif item_type == Sofa.FURNITURE_TYPE: item_id = my_store.add(Sofa(**data)) response_dict["response"] = "Id of new item added: " + str(item_id) except (ValueError, KeyError) as e: response_dict["status"] = 400 response_dict["response"] = str(e) return app.response_class(**response_dict)
class TestSofa(unittest.TestCase): """ Unit tests for Sofa class """ def setUp(self): """ Generated the object """ self.test_sofa = Sofa("001", "2019", "BrandX", 99.99, 139.99, 3, 5) def tearDown(self): """ Destroys the object """ self.test_sofa = None self.log_point() def log_point(self): currentTest = self.id().split(".")[-1] callingFunction = inspect.stack()[1][3] print("in %s - %s()" % (currentTest, callingFunction)) def test_sofa_valid_parameters(self): """ 010A - Valid constructor """ self.assertIsNotNone(self.test_sofa, "Sofa must be defined") def test_sofa_invalid_parameters(self): """ 010B - Invalid constructor """ # invalid data type for number of seats self.assertRaises(ValueError, Sofa, "001", "2019", "BrandX", 99.99, 139.99, "3", 5) # invalid data type for number of cushions self.assertRaises(ValueError, Sofa, "001", "2019", "BrandX", 99.99, 139.99, 3, "5") # invalid value for number of seats self.assertRaises(ValueError, Sofa, "001", "2019", "BrandX", 99.99, 139.99, 0, "5") # invalid value for number of cushions self.assertRaises(ValueError, Sofa, "001", "2019", "BrandX", 99.99, 139.99, "3", 0) self.assertRaises(ValueError, Sofa, "001", "2019", "BrandX", 99.99, 139.99, "", 5) self.assertRaises(ValueError, Sofa, "001", "2019", "BrandX", 99.99, 139.99, 3, "") self.assertRaises(ValueError, Sofa, "001", "2019", "BrandX", 99.99, 139.99, None, 5) self.assertRaises(ValueError, Sofa, "001", "2019", "BrandX", 99.99, 139.99, 3, None) def test_get_number_of_seats_valid(self): """ 020A - Valid number of seats """ self.assertEqual(self.test_sofa.number_of_seats, 3, "Number of seats must be 3") def test_get_number_of_cushions_valid(self): """ 030A - Valid number of cushions """ self.assertEqual(self.test_sofa.number_of_cushions, 5, "Number of cushions must be 5") def test_get_item_type_valid(self): """ 040A - Valid furniture type """ self.assertEqual(self.test_sofa.get_item_type(), "sofa", "Item type must be 'sofa'") def test_get_item_description(self): """ 050 A - Valid item description """ self.assertEqual( self.test_sofa.get_item_description(), "sofa with serial number 001 manufactured by BrandX with 3 number of seats and 5 number of " "cushions is available for $139.99", "Output must match 'sofa 001 manufactured by BrandX with 3 number of seats and 5 " "number of cushions is available for $139.99'", ) def test_to_dict_valid(self): """ 060 A - Valid to_dict test""" self.assertEqual( self.test_sofa.to_dict(), { "id": None, "type": "sofa", "item_serial_num": "001", "item_brand": "BrandX", "year_manufactured": "2019", "cost": 99.99, "price": 139.99, "is_sold": False, "number_of_seats": 3, "number_of_cushions": 5, }, )
def setUp(self): """ Generated the object """ self.test_sofa = Sofa("001", "2019", "BrandX", 99.99, 139.99, 3, 5)
#coding:gbk from sofa import Sofa from bed import Bed sofa = Sofa() bed = Bed() sofa.print_define() sofa.print_classify("µÍ±³É³·¢") sofa.print_colour("ºìÉ«") bed.print_define() bed.print_classify("ƽ°å") bed.print_colour("°×·ã")
beds["Bed1"][6], ) Bed2 = Bed( beds["Bed2"][0], beds["Bed2"][1], beds["Bed2"][2], beds["Bed2"][3], beds["Bed2"][4], beds["Bed2"][5], beds["Bed2"][6], ) Sofa1 = Sofa( sofas["Sofa1"][0], sofas["Sofa1"][1], sofas["Sofa1"][2], sofas["Sofa1"][3], sofas["Sofa1"][4], sofas["Sofa1"][5], sofas["Sofa1"][6], ) # qwerty.add(Bed1) # qwerty.add(Bed2) # qwerty.add(Sofa1) # print(qwerty.get(1)) # print(qwerty.get(2)) # print(qwerty.get(3)) # print('\nGetting f*****g everything!') # print(qwerty.get_all()) # print('\n') # # qwerty.delete(2)
import csv import random import string from sofa import Sofa from selection_sort import Selection_sort from heap_sort import Heap_sort if __name__ == '__main__': with open('sofas.csv') as file: reader = csv.reader(file) list_for_sofa = list(reader) list_of_sofa = [] for sofa in list_for_sofa: list_of_sofa.append(Sofa(sofa[0],sofa[1],sofa[2],sofa[3])) selection_sort = Selection_sort(list_of_sofa) selection_sorted = selection_sort.sort_by_width_desc() for el in selection_sorted: print(el) print('') heap_sort = Heap_sort(list_of_sofa) heap_sorted = heap_sort.heapsort_by_lenth_asc() for el in heap_sorted: print(el)