def test_update_product(self):
     """
     Test update a product
     """
     _db = Database.instance(":memory:")
     try:
         create_product_table()
     except Exception as e:
         print(e)
     product = Product(1, 10.0, 20.0, 'test', 'test')
     product.save()
     product = GetProduct()
     product.by_product_id('test')
     products = product.query()
     print(products)
     assert len(products) >= 1
     product = UpdateProduct()
     product.set_quantity(100)
     product.update()
     product = GetProduct()
     product.by_product_id('test')
     products = product.query()
     print(products)
     assert len(products) >= 1
     assert products[0].get("quantity", 0) == 100
 def test_create_product_table(self):
     """
     Tests creating the product table
     """
     _db = Database.instance(":memory:")
     try:
         create_product_table()
     except Exception as e:
         print(e)
 def test_drop_products_table(self):
     """
     Test drop the products table
     """
     _db = Database.instance(":memory:")
     try:
         create_product_table()
     except Exception as e:
         print(e)
     drop_product_table()
 def test_create_product(self):
     """
     Test creating a product
     """
     _db = Database.instance(":memory:")
     try:
         create_product_table()
     except Exception as e:
         print(e)
     product = Product(1, 10.0, 20.0, 'test', 'test')
     product.save()
def create_tables(csv, create, headers, database, build_tables):
    """
    Prepares the database

    :param csv:     Whether to upload a csv
    :param create:  Whether to create tables
    :param headers: Any csv headers
    :param database:  Database or path to database to use
    :param build_tables:  Whether to create tables
    """
    if csv and create.lower() == "true":
        if headers:
            headers = json.loads(headers)
        else:
            product_headers = {
                "product_id": "varchar",
                "quantity": "integer",
                "wholesale_price": "double precision",
                "sale_price": "double precision",
                "supplier_id": "varchar"
            }
            order_headers = {
                "date": "integer",
                "author_id": "varchar",
                "zip": "varchar",
                "product_id": "varchar",
                "quantity": "integer"
            }
            order_mappings = {
                "date": "utc",
                "author_id": "varchar",
                "zip": "varchar",
                "product_id": "varchar",
                "quantity": "integer"
            }
        if build_tables:
            build_db(database, "products", headers)
            create_product_table()
            create_order_table()
            create_users_table()
        else:
            _db = Database.instance(database)
        upload_csv("product_data.csv",
                   product_headers.keys(),
                   table="products",
                   has_headers=True)
        upload_csv("order_data.csv",
                   order_headers.keys(),
                   table="orders",
                   has_headers=True,
                   csv_mappings=order_mappings)
    else:
        _db = Database.instance(database)
 def test_update_product(self):
     """
     Test updating a product
     """
     _db = Database.instance(":memory:")
     try:
         create_product_table()
     except Exception as e:
         print(e)
     product = Product(1, 10.0, 20.0, 'test', 'test')
     product.save()
     product = GetProduct()
     product.by_product_id('test')
     products = product.query()
     print(products)
     assert len(products) == 1