Esempio n. 1
0
 def test_delete_order(self):
     _db = Database.instance(":memory:")
     try:
         create_order_table()
     except Exception as e:
         print(e)
     order = Order('test',
                   'test-order',
                   city="test",
                   state="test",
                   address="test")
     order.product_id("test")
     order.price(10)
     order.quantity(100)
     order.save()
     order = GetOrders('test')
     orders = order.query()
     print(orders)
     assert len(orders) >= 1
     assert orders[0].get("product_id", "NE") == "test"
     order = DeleteOrdersByUser('test')
     order.delete()
     order = GetOrders('test')
     orders = order.query()
     print(orders)
     assert len(orders) == 0
Esempio n. 2
0
 def test_dop_orders(self):
     """
     Test drop the orders table
     """
     _db = Database.instance(":memory:")
     try:
         create_order_table()
     except Exception as e:
         print(e)
     drop_order_table()
Esempio n. 3
0
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)
Esempio n. 4
0
 def test_create_order(self):
     """
     Test creating an order
     """
     _db = Database.instance(":memory:")
     try:
         create_order_table()
     except Exception as e:
         print(e)
     order = Order('test',
                   'test-order',
                   city="test",
                   state="test",
                   address="test")
     order.price(10)
     order.quantity(100)
     order.save()
Esempio n. 5
0
 def test_update_record(self):
     """
     Test updating a record
     """
     _db = Database.instance(":memory:", "orders", ORDER_TABLE_MAPPING)
     try:
         create_order_table()
     except Exception as e:
         print(e)
     order = Order("test_author", "test", "active", "test", "test", "test")
     order.quantity(1)
     order.price(2)
     order.save()
     orders = GetOrders("test_author")
     records = orders.query()
     assert len(records) == 1
     cancel = CancelOrder("test_id")
     cancel.cancel()
     orders = GetOrders("test_author")
     records = orders.query()
     assert len(records) == 1
     order = records[0]
     assert order["status"] == "cancelled"
Esempio n. 6
0
 def test_create_order_table(self):
     _db = Database.instance(":memory:")
     try:
         create_order_table()
     except Exception as e:
         print(e)