예제 #1
0
 def post(self, ):
     new_product = ProductModel(
         product_name=request.json['product_name'],
         price=request.json['price']
     )
     db.session.add(new_product)
     db.session.commit()
     return new_product, 201 
    def test_ap1_special_rule(self, app, test_product_code, test_num_of_objs, product_list_expected, data_dict_expected):
        with app.app_context():
            test_product_obj =  ProductModel.find_by_product_codes([test_product_code])[0]

            test_product_list, test_discount_data_dict = Transactions.ap1_special_rule(test_num_of_objs, test_product_obj)

        assert len(test_product_list) == product_list_expected
        assert test_discount_data_dict.get('num_to_apply') is data_dict_expected
예제 #3
0
    def get_item_objs_by_code(self):
        """
        get the Product data models represented in the current basket instance

        :return: dict obj representing the Product(s) data model
        """

        item_data_dict = ProductModel.find_by_product_codes(self.calc_unique_item_types_in_basket())

        return {row['product_code']: row for row in item_data_dict}
    def test_instance_init(self, app, test_product_code, test_product_code_link, test_special_code):
        with app.app_context():
            test_product_obj =  ProductModel.find_by_product_codes([test_product_code])[0]
        
            test_list_specials_obj = [SpecialModel.find_by_special_product_code_link(test_product_code_link)]

        test_obj = Transactions(test_product_obj, test_list_specials_obj)

        assert test_obj.basket_item['product_code'] in test_product_code
        assert test_obj.specials_data_list[0]['special_code'] in test_special_code
    def test_calc_multi_special(self, app, test_product_code, test_product_code_link, test_special_code):
        with app.app_context():
            test_product_obj =  ProductModel.find_by_product_codes([test_product_code])[0]
        
            test_list_specials_obj = [SpecialModel.find_by_special_product_code_link(test_product_code_link)]

        test_obj = Transactions(test_product_obj, test_list_specials_obj)

        for test_item in test_obj.calc_multi_special():
            assert 'specials' in test_item
            assert 'special_discount' in test_item
예제 #6
0
    def test__check_for_specials_and_discounts(self, app, test_product_occurences, test_product_code, specials_type):
        test_item_list = [test_product_code] * test_product_occurences[test_product_code]
        test_obj = Basket(test_item_list)
        test_product_obj = {}.setdefault(test_product_code, {})

        with app.app_context():
            test_product_obj[test_product_code] =  ProductModel.find_by_product_codes([test_product_code])[0]

            test_obj._check_for_specials_and_discounts(test_product_occurences, test_product_obj)

        assert test_obj.processed_basket_list[0]['specials'][0]['special_code'] in specials_type
            
예제 #7
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('title',
                            required=True,
                            help='O campo título é obrigatório')
        payload = parser.parse_args()

        product = ProductModel()
        product.title = payload.title

        db.session.add(product)
        db.session.commit()

        return marshal(product, products_schema, 'product')
예제 #8
0
    def test_calc_basket_items(self, app, test_product_list, test_product_code, option):
        test_item_list = test_product_list
        test_obj = Basket(test_item_list)

        test_list_specials_obj = None
        test_product_obj = None

        with app.app_context():
            test_product_obj_list =  ProductModel.find_by_product_codes([test_product_code])
            

            if option:
                test_list_specials_obj = [SpecialModel.find_by_special_product_code_link(option)]
                test_product_obj = test_product_obj_list[0]


            test_obj.calc_basket_items(test_product_obj_list, test_product_obj, test_list_specials_obj)

            for item in test_obj.processed_basket_list:
                if not option:
                    assert 'specials' not in item
                else:
                    assert 'product_price' in item
예제 #9
0
def index():
    items = ProductModel.get_all_items()

    cart_list = get_cart_items()

    return render_template('market/index.html', items=items, cart_list=cart_list)