Example #1
0
def test_get_basket_table_quantity(mock_db_connect):
    mock_db_connect.return_value = db_connect
    add_to_basket1('test_cart_id1', 'Bonsai', 2)
    add_to_basket1('test_cart_id1', 'Peace Lily', 1)
    response = get_basket_table_quantity()
    assert response == '3'
    remove_record_from_basket_table('test_cart_id1')
Example #2
0
def test_get_record_from_basket_table(mock_db_connect):
    mock_db_connect.return_value = db_connect
    #add item to basket
    add_to_basket1('test_cart_id1', 'Devils Ivy', 1)
    response = get_record_from_basket_table('test_cart_id1', 'Devils Ivy')
    assert response == {
        'record': [('1', 'Devils Ivy', 'test_cart_id1', 15, 1,
                    '2020-04-11 00:00:00', 'time')]
    }
    remove_record_from_basket_table('test_cart_id1')
Example #3
0
def test_restore_basket_table_to_zero(mock_db_connect):
    mock_db_connect.return_value = db_connect
    add_to_basket1('cartid', 'Peace Lily', 6)
    old_basket_quantity = get_basket_table_quantity()
    print(old_basket_quantity)
    response = restore_basket_table_to_zero()
    new_basket_quantity = get_basket_table_quantity()
    print(new_basket_quantity)
    assert int(old_basket_quantity) - 6 == int(new_basket_quantity)
    assert response == "all quantity updated to 0"
    update_stock_quantity('Peace Lily', 500)
Example #4
0
def test_remove_record_from_basket_table(mock_db_connect):
    mock_db_connect.return_value = db_connect
    add_to_basket1('test_cart_id1', 'Palm Tree', 1)

    old_stock_quantity = get_plant_quantity('Palm Tree')

    remove_record_from_basket_table('test_cart_id1')
    new_stock_quantity = get_plant_quantity('Palm Tree')

    assert get_basket_from_basket_table('test_cart_id1') == {'basket': []}
    assert int(new_stock_quantity) == int(old_stock_quantity) + 1
Example #5
0
def test_remove_one_item_from_basket_table(mock_db_connect):
    mock_db_connect.return_value = db_connect
    add_to_basket1('test_cart_id1', 'Bonsai', 1)
    # we need to make sure that the item gets added and removed so we should store what is currently in basket and then show that it is no longer there

    old_stock_quantity = get_plant_quantity('Bonsai')

    remove_one_item_from_basket_table('test_cart_id1', 'Bonsai')
    new_stock_quantity = get_plant_quantity('Bonsai')

    assert get_basket_from_basket_table('test_cart_id1') == {'basket': []}
    assert int(new_stock_quantity) == int(old_stock_quantity) + 1
Example #6
0
def test_get_basket_from_basket_table(mock_db_connect):
    mock_db_connect.return_value = db_connect
    # Add an item to the basket
    add_to_basket1('test_cart_id1', 'Olive Tree', 1)
    # Add an extra basket item to the basket to show it only gets the first basket
    add_to_basket1('test_cart_id2', 'Lemon Tree', 1)
    response = get_basket_from_basket_table('test_cart_id1')
    assert response == {
        'basket': [('1', 'Olive Tree', 'test_cart_id1', 50, 1,
                    '2020-04-11 00:00:00', 'time')]
    }
    remove_record_from_basket_table('test_cart_id1')
    remove_record_from_basket_table('test_cart_id2')
Example #7
0
def test_get_all_basket_table_data(mock_db_connect):
    mock_db_connect.return_value = db_connect
    # Add an item to the basket
    add_to_basket1('test_cart_id1', 'Monstera Deliciosa', 1)
    add_to_basket1('test_cart_id2', 'Peace Lily', 1)
    response = get_all_basket_table_data()
    assert response == {
        'basket_table': [('1', 'Monstera Deliciosa', 'test_cart_id1', 15, 1,
                          '2020-04-11 00:00:00', 'time'),
                         ('1', 'Peace Lily', 'test_cart_id2', 20, 1,
                          '2020-04-11 00:00:00', 'time')]
    }
    # Remove record
    remove_record_from_basket_table('test_cart_id1')
    remove_record_from_basket_table('test_cart_id2')
Example #8
0
def test_add_to_basket1(mock_db_connect):
    mock_db_connect.return_value = db_connect
    #stock
    oldstockquantity = int(get_plant_quantity('Spider Plant'))
    #call the add to basket function
    add_to_basket1('test_cart_id1', 'Spider Plant', 1)
    newstockquantity = int(get_plant_quantity('Spider Plant'))
    assert oldstockquantity - newstockquantity == 1
    #basket
    response = get_basket_from_basket_table('test_cart_id1')
    assert response == {
        'basket': [('1', 'Spider Plant', 'test_cart_id1', 8, 1,
                    '2020-04-11 00:00:00', 'time')]
    }
    remove_record_from_basket_table('test_cart_id1')
    update_stock_quantity('Spider Plant', oldstockquantity)