def verify_valid_bid_insertion_at_auction_start(test, cursor, auction_id,
                                                auction_start, user_id):
    starting_bid_count = count_from_table(cursor, 'bid')

    amount = int(round(time.time() * 1000))

    cursor.execute(f"insert into bid "
                   f"values ("
                   f"{auction_id}, "
                   f"'{user_id}', "
                   f"'{auction_start}',"
                   f"{amount}"
                   f");")
    starting_bid_count += 1
    test.assertEqual(starting_bid_count, count_from_table(cursor, 'bid'))
def verify_deny_bid_after_auction_ends(test, cursor, auction_end, auction_id,
                                       user_id):
    starting_bid_count = count_from_table(cursor, 'bid')

    try:
        cursor.execute(f"insert into bid "
                       f"values ("
                       f"{auction_id}, "
                       f"'{user_id}', "
                       f"'{add_hours_to_date_string(auction_end, 4)}',"
                       f"123456"
                       f");")
        test.assertTrue(
            False, "Databased failed to check bid time is before auction end")
    except sqlite3.IntegrityError as e:
        test.assertEqual("Bids must be before the auction ends.", str(e))
    test.assertEqual(starting_bid_count, count_from_table(cursor, 'bid'))
def verify_table_denies_duplicates_on_unique_columns(test, cursor, table_name,
                                                     unique_columns,
                                                     column_names):
    starting_item_count = count_from_table(cursor, table_name)
    existing_item_from_table = get_existing_item_from_key(
        cursor, table_name, unique_columns)
    new_item_duplicate_on_unique_columns = concatenate_filler_values_for_non_unique_columns(
        existing_item_from_table, unique_columns, column_names)
    verify_deny_insert_record_that_is_duplicated_on_unique_columns(
        test, cursor, new_item_duplicate_on_unique_columns, table_name,
        unique_columns)
    verify_item_count_did_not_increase(test, cursor, starting_item_count,
                                       table_name)
def verify_deny_insert_category_with_non_existent_auction(
        test, cursor, non_existent_auction_id):
    starting_join_count = count_from_table(cursor, 'join_auction_category')
    try:
        cursor.execute(f"insert into join_auction_category "
                       f"values (null, {non_existent_auction_id}, 1);")
        test.assertTrue(
            False,
            f"Database failed to throw error on Foreign Key for auction ID: {non_existent_auction_id}"
        )
    except sqlite3.IntegrityError as e:
        test.assertTrue(str(e).__contains__("FOREIGN KEY constraint failed"))
    verify_item_count_did_not_increase(test, cursor, starting_join_count,
                                       'join_auction_category')
def verify_deny_insert_bid_for_auction_at_the_same_time(
        test, cursor, existing_auction_id, second_user_id, valid_bid_time):
    original_bid_count = count_from_table(cursor, 'bid')
    try:
        cursor.execute(f"insert into bid "
                       f"values ("
                       f"{existing_auction_id}, "
                       f"'{second_user_id}', "
                       f"'{valid_bid_time}', "
                       f"1234567);")
        test.assertTrue(
            False,
            "Database failed to deny bid for the same auction at the same time"
        )
    except sqlite3.IntegrityError as e:
        test.assertEqual(str(e),
                         "UNIQUE constraint failed: bid.auction_id, bid.time")
    verify_item_count_did_not_increase(test, cursor, original_bid_count, 'bid')
def verify_item_count_did_not_increase(test, cursor, starting_item_count,
                                       table_name):
    test.assertEqual(starting_item_count, count_from_table(cursor, table_name))
def verify_deny_seller_bid(test, cursor, bid_count):
    test.assertEqual(bid_count, count_from_table(cursor, 'bid'),
                     "Database allowed new bid from seller of auction.")
def verify_bid_added_to_table(test, cursor):
    starting_bid_count = count_from_table(cursor, 'bid')
    insert_fresh_bid(cursor)
    test.assertEqual(starting_bid_count + 1, count_from_table(cursor, 'bid'))