def test_process_bid_closed_sell(): sell = {'close_time': 20, 'item': 'toaster_5', 'reserve_price': 10.0, 'timestamp': 10, 'user_id': 1, 'bids': {}, 'bid_count': 0} app.process_sell(sell) bid = {'bid_amount': 7.5, 'item': 'toaster_5', 'timestamp': 21, 'user_id': 8} assert app.proccess_bid(bid) is None assert database.get('toaster_5')['bids'] == {} assert database.get('toaster_5')['bid_count'] == 0
def test_process_bid_second_bid_same_user(): sell = {'close_time': 20, 'item': 'toaster_3', 'reserve_price': 10.0, 'timestamp': 10, 'user_id': 1, 'bid_count': 1, 'highest_bid': 7.5, 'lowest_bid': 7.5, 'bids': { 8: {'user_id': 8, 'amount': 7.5, 'timestamp': 12} }} app.process_sell(sell) bid = {'bid_amount': 8, 'item': 'toaster_3', 'timestamp': 13, 'user_id': 8} assert app.proccess_bid( bid) == {'user_id': 8, 'amount': 8, 'timestamp': 13} assert database.get('toaster_3')['bids'] == { 8: {'user_id': 8, 'amount': 8, 'timestamp': 13} } assert database.get('toaster_3')['bid_count'] == 2
def test_process_bid_lower_second_bid(): sell = {'close_time': 20, 'item': 'toaster_4', 'reserve_price': 10.0, 'timestamp': 10, 'user_id': 1, 'bid_count': 1, 'bids': { 9: {'user_id': 9, 'amount': 8, 'timestamp': 13} }} app.process_sell(sell) bid = {'bid_amount': 7.5, 'item': 'toaster_4', 'timestamp': 14, 'user_id': 9} assert app.proccess_bid(bid) is None assert database.get('toaster_4')['bids'] == { 9: {'user_id': 9, 'amount': 8, 'timestamp': 13} } assert database.get('toaster_4')['bid_count'] == 1
def test_process_bid_first_bid(): sell = {'close_time': 20, 'item': 'toaster_2', 'reserve_price': 10.0, 'timestamp': 10, 'user_id': 1, 'bids': {}, 'bid_count': 0, 'highest_bid': 0, 'lowest_bid': math.inf} app.process_sell(sell) bid = {'bid_amount': 7.5, 'item': 'toaster_2', 'timestamp': 12, 'user_id': 8} assert app.proccess_bid( bid) == {'user_id': 8, 'amount': 7.5, 'timestamp': 12} result = database.get('toaster_2') assert result['bids'] == {8: { 'user_id': 8, 'amount': 7.5, 'timestamp': 12 }} assert result['bid_count'] == 1 assert result['highest_bid'] == 7.5 assert result['lowest_bid'] == 7.5
def test_process_bid_no_sell(): bid = {'bid_amount': 7.5, 'item': 'toaster_4', 'timestamp': 14, 'user_id': 8} assert app.proccess_bid(bid) is None