예제 #1
0
 def test_product_creation(self):
     """
     Test product creation.
     """
     product = Product('Table', 50, 100, 15)
     assert product.cost == 50
     assert product.price == 100
     assert product.weight == 15
예제 #2
0
 def test_product_creation_exception_str(self):
     """
     Test product creation with string passed to decimal field.
     """
     try:
         product = Product('Table', 'one', 100, 15)
         self.assertFail()
     except Exception as inst:
         self.assertEqual(str(inst), 'Cost value should be decimal.')
예제 #3
0
 def test_product_creation_exception(self):
     """
     Test product creation raises exception when price passed to constructor 
     is less then product cost.
     """
     try:
         product = Product('Table', 105, 100, 15)
         self.assertFail()
     except Exception as inst:
         self.assertEqual(str(inst), 'Price cannot be below cost.')
예제 #4
0
def products():
    data = json.loads(request.data)
    product = Product(
        data['name'],
        data['category'],
        data['description'],
        data['price']
    )
    product.save()
    return jsonify(data)
예제 #5
0
 def test_check_creation(self):
     """
     Test check creation.
     """
     customer = Customer('Lili', 10, 'EUR')
     product = Product('Chocolate', 50, 100, 15)
     buy = Buy(customer, product.id, 1)
     check = Check.print_check(buy.id, customer.currency)
     self.assertEqual(
         check,
         """1 Chocolate purchased for 3.00EUR\nDiscount amount: 0.33EUR""")
 def test_add_product(self):
     product = Product("test", "product test", "12311231256", 10)
     self.product_service.add(product)
     conn = sqlite3.connect("inventory")
     cursor = conn.execute("SELECT * FROM product WHERE name = ?",
                           [product.name])
     db_object = cursor.fetchone()
     conn.close()
     self.assertEqual(db_object[1], product.name)
     self.assertEqual(db_object[2], product.description)
     self.assertEqual(db_object[3], product.bar_code)
     self.assertEqual(db_object[4], product.qtd)
예제 #7
0
 def list(self):
     connection = self.get_connection()
     cur = connection.execute("SELECT * FROM product")
     result = cur.fetchall()
     products = []
     for product in result:
         products.append(
             Product(_id=product[0],
                     name=product[1],
                     description=product[2],
                     bar_code=product[3],
                     qtd=product[4]))
     return products
예제 #8
0
파일: eccomerce.py 프로젝트: HelenShy/tasks
 def add_product():
     """
     Add new product.
     """
     name = input("\nProduct name:\n")
     cost = input("\nProduct cost:\n")
     price = input("\nProduct price:\n")
     weight = input("\nProduct weight:\n")
     try:
         product = Product(name, cost, price, weight)
         bcolors.print_success(
             '{} was successfully added to product list!'.format(
                 product.name))
     except ValueError as e:
         bcolors.print_fail(str(e))
예제 #9
0
 def test_buy_creation(self):
     """
     Test buy creation.
     """
     customer = Customer('Nancy', 20, 'EUR')
     product = Product('Chocolate', 50, 100, 15)
     buy = Buy(customer, product.id, 2)
     assert buy.total_weight == 30
     assert buy.total_amount == 160
     assert buy.discount_amount == 40
     self.assertEqual(
         buy.total_amount_in_currency,
         decimal.Decimal(5.33).quantize(decimal.Decimal('.01'),
                                        rounding=decimal.ROUND_DOWN))
     assert Buy.get_by_id(buy.id).customer.id == customer.id
     assert Buy.get_by_id(buy.id).product_id == product.id
예제 #10
0
def add_product():
    if request.method == 'POST':
        category_obj_db = Category.objects.get(name_category=request.form.get('category'))
        product_dict = {
            'name_product': request.form.get('name_product'),
            'quantity': request.form.get('quantity'),
            'price': request.form.get('price'),
            'product_for_sale': request.form.get('bool'),
            'category': category_obj_db
        }
        product_obj = Product(**product_dict)
        product_obj.save()
        category_obj_db = Category.objects
        return render_template("add_product.html", data=category_obj_db)
    if request.method == 'GET':
        category_obj_db = Category.objects
        return render_template('add_product.html', data=category_obj_db)
 def test_list_products(self):
     product = Product("test", "product test", "12311231256", 10)
     self.product_service.add(product)
     result = self.product_service.list()
     self.assertEqual(1, len(result))
예제 #12
0
 def test_product_get_by_id(self):
     """
     Test Product method get_by_id.
     """
     product = Product('Book', 10, 15, 2)
     assert Product.get_by_id(product.id).name == 'Book'
예제 #13
0
from models.products import Product, Category

category_obj = Category('vegetables')
category_obj_db = Category.objects.get(name_category='vegetables')
print(category_obj_db)

product_dict = {
    'name_product': 'tomato',
    'quantity': 200,
    'price': 15.50,
    'product_for_sale': True,
    'category': category_obj_db
}

#category_obj.save()

product_obj = Product(**product_dict)
product_obj.save()
예제 #14
0
 def __init__(self):
     self.__inventory = {
         '0': Product('0', 'Powerthirst Shocklate', 1.00, 10),
         '1': Product('1', 'Brawndo', 1.50, 10, 'The thirst mutilator'),
         '2': Product('1', 'Soylent Green', 0.50, 100, 'Totally not people')
     }