def add_product():
    """ Adds a product to products """
    content = request.json
    try:
        id = None
        type = None
        product = None
        if content["type"] == AbstractProduct.CELLPHONE_TYPE:
            cellphone = Cellphone(content['name'], content['price'],
                                  content['cost'], content["date_stocked"],
                                  content["date_sold"], content["is_sold"],
                                  content["camera"], content["security"],
                                  content["screen_body_ratio"])
            prod_manager.add_product(cellphone)
            id = cellphone.get_id()
            type = cellphone.get_type()
            product = cellphone
        elif content["type"] == AbstractProduct.COMPUTER_TYPE:
            computer = Computer(content["name"], content["price"],
                                content["cost"], content["date_stocked"],
                                content["date_sold"], content["is_sold"],
                                content["graphics_card"], content["case"],
                                content["memory_type"])
            prod_manager.add_product(computer)
            id = computer.get_id()
            type = computer.get_type()
            product = computer
        print("id = ", id)
        print("type = ", type)
        print("prod = ", product.to_dict())
        response = app.response_class(status=200)
    except ValueError as e:
        response = app.response_class(response=str(e), status=400)
    return response
    def test_get_product_stats(self):
        """ 070A - Valid get_product_stats """

        computer2 = Computer("IBM Thinkpad", 1400, 1000, "07/18/2019",
                             "08/21/2019", True, "Nvidia Geforce", "Dbrand",
                             "DDR4")
        computer3 = Computer("Macbook Pro", 2000, 1000, "04/11/2019",
                             "08/21/2019", True, "Nvidia Geforce", "Dbrand",
                             "DDR4")
        cellphone2 = Cellphone("iPhone 11 Pro Max", 2000, 500, "07/18/2019",
                               "08/21/2019", True, "Nvidia Geforce", "Dbrand",
                               "DDR4")
        cellphone3 = Cellphone("Samsung Galaxy Note 10", 1400, 400,
                               "07/18/2019", "08/21/2019", True,
                               "Nvidia Geforce", "Dbrand", "DDR4")
        self._product_manager.add_product(computer2)
        self._product_manager.add_product(computer3)
        self._product_manager.add_product(cellphone2)
        self._product_manager.add_product(cellphone3)

        product_stats = self._product_manager.get_product_stats()

        num_products = product_stats.get_total_num_products()
        num_computers = product_stats.get_num_computers()
        num_cellphones = product_stats.get_num_cellphones()
        avg_computer_profit = product_stats.get_avg_computer_profit()
        avg_cellphone_profit = product_stats.get_avg_cellphone_profit()
        avg_computer_shelf_time = product_stats.get_avg_computer_shelf_time()
        avg_cellphone_shelf_time = product_stats.get_avg_cellphone_shelf_time()

        self.assertEqual(6, num_products)
        self.assertEqual(3, num_computers)
        self.assertEqual(3, num_cellphones)
        self.assertEqual(600, avg_computer_profit)
        self.assertEqual(1000, avg_cellphone_profit)
        self.assertEqual(66, avg_computer_shelf_time)
        self.assertEqual(154, avg_cellphone_shelf_time)
    def setUp(self):
        """ Setup test data """
        engine = create_engine('sqlite:///test_products.sqlite')

        #Creates all the tables
        Base.metadata.create_all(engine)
        Base.metadata.bind = engine

        self.logPoint()
        self._product_manager = ProductManager("test_products.sqlite")

        computer1 = Computer("Huawei Matebook X Pro", 1600, 1200, "07/18/2019",
                             "08/21/2019", True, "Nvidia Geforce", "Dbrand",
                             "DDR4")
        self._product_manager.add_product(computer1)

        cellphone5 = Cellphone("Pixel 4", 1000, 500, "03/21/2018",
                               "04/21/2019", True, "G Camera", "Google Lock",
                               88)
        self._product_manager.add_product(cellphone5)
Beispiel #4
0
def main():
	o4f = Cellphone()
	o4f.call()
	o4f.text()
	o4f.drop()
Beispiel #5
0
def main():
    t = Cellphone()
    t.call()
    t.text()
    t.drop()
from cellphone import Cellphone

if __name__ == '__main__':
    cp = Cellphone()
    cp.call()
    cp.text()
    cp.drop()
Beispiel #7
0
def main():
    cellphone = Cellphone()
    cellphone.call()
    cellphone.text()
    cellphone.drop()
Beispiel #8
0
def main():
    c = Cellphone()
    c.call()
    c.text()
    c.drop()