Example #1
0
def test_end_auction(client: TestClient, superuser_token_headers: dict,
                     db: Session):
    auction = create_random_auction(db)
    amount = auction.reserve + random_float()
    bidder = create_random_user(db)
    english = EnglishAuction()
    ending_date = (datetime.now() + timedelta(days=1)).isoformat()
    english.start(db, db_obj=auction, ending_date=ending_date)
    english.bid(db, db_obj=auction, amount=amount, bidder_id=bidder.id)

    response = client.put(
        f"{settings.API_PREFIX}/v1/auctions/{auction.id}/end",
        headers=superuser_token_headers)

    assert response.status_code == 200
    content = response.json()
    db.refresh(auction)
    assert auction.state == AuctionState.ENDED
    assert content["id"]
    assert content["owner_id"]
    assert content["starting_amount"] == auction.starting_amount
    assert content["reserve"] == auction.reserve
    assert content["bid_cap"] == auction.bid_cap
    assert content["product_id"] == auction.product_id
    assert content["state"] == AuctionState.ENDED
def test_start(db: Session):
    auction = create_random_auction(db)

    assert auction.state == AuctionState.CREATED

    english = EnglishAuction()
    ending_date = (datetime.now() + timedelta(days=1)).isoformat()
    english.start(db, db_obj=auction, ending_date=ending_date)

    auction = auction_repo.get(db, id=auction.id)
    assert auction.state == AuctionState.ONGOING
def test_buy_it_now(db: Session):
    auction = create_random_auction(db)
    english = EnglishAuction()
    ending_date = (datetime.now() + timedelta(days=1)).isoformat()
    english.start(db, db_obj=auction, ending_date=ending_date)
    assert auction.state == AuctionState.ONGOING

    buyer = create_random_user(db)
    english.buy_it_now(db, db_obj=auction, buyer_id=buyer.id)
    db_obj = auction_repo.get(db, id=auction.id)

    assert db_obj.state == AuctionState.ENDED
    assert db_obj.current_bid_amount == db_obj.bid_cap
    assert db_obj.final_winner_id == buyer.id
Example #4
0
def test_get_auction(client: TestClient, superuser_token_headers: dict,
                     db: Session):
    auction = create_random_auction(db)

    response = client.get(f"{settings.API_PREFIX}/v1/auctions/{auction.id}")

    assert response.status_code == 200
    content = response.json()

    assert content["id"]
    assert content["owner_id"]
    assert content["starting_amount"] == auction.starting_amount
    assert content["reserve"] == auction.reserve
    assert content["bid_cap"] == auction.bid_cap
    assert content["product"]
Example #5
0
def test_buy_it_now(client: TestClient, superuser_token_headers: dict,
                    db: Session):
    auction = create_random_auction(db)
    english = EnglishAuction()
    english.start(db, db_obj=auction)

    response = client.post(
        f"{settings.API_PREFIX}/v1/auctions/{auction.id}/buy_it_now",
        headers=superuser_token_headers)

    assert response.status_code == 200
    content = response.json()
    db.refresh(auction)
    assert auction.final_winner
    assert auction.state == AuctionState.ENDED
def test_bid(db: Session):
    auction = create_random_auction(db)
    english = EnglishAuction()
    ending_date = (datetime.now() + timedelta(days=1)).isoformat()
    english.start(db, db_obj=auction, ending_date=ending_date)
    assert auction.state == AuctionState.ONGOING

    amount = auction.starting_amount + 1
    bidder = create_random_user(db)
    english.bid(db, db_obj=auction, amount=amount, bidder_id=bidder.id)

    db_obj = auction_repo.get(db, id=auction.id)
    assert db_obj.current_bid_amount == amount + 1.25
    assert db_obj.last_bid_at
    assert db_obj.winning_bid.amount == amount
    assert db_obj.bids
def test_end_when_reserve_not_met(db: Session):
    auction = create_random_auction(db)
    english = EnglishAuction()
    ending_date = (datetime.now() + timedelta(days=1)).isoformat()
    english.start(db, db_obj=auction, ending_date=ending_date)
    assert auction.state == AuctionState.ONGOING

    amount = auction.current_bid_amount + 2
    bidder = create_random_user(db)
    english.bid(db, db_obj=auction, amount=amount, bidder_id=bidder.id)
    db_obj = auction_repo.get(db, id=auction.id)

    assert db_obj.winning_bid

    english.end(db, db_obj=db_obj)
    assert db_obj.state == AuctionState.CANCLED
    assert not db_obj.final_winner_id
Example #8
0
def test_bid_auction(client: TestClient, superuser_token_headers: dict,
                     db: Session):
    auction = create_random_auction(db)
    amount = auction.reserve + random_float()
    english = EnglishAuction()
    english.start(db, db_obj=auction)
    data = amount

    response = client.post(
        f"{settings.API_PREFIX}/v1/auctions/{auction.id}/bid",
        headers=superuser_token_headers,
        json=data)

    assert response.status_code == 200
    content = response.json()
    db.refresh(auction)
    assert auction.winning_bid
    assert auction.last_bid_at
Example #9
0
def test_start_auction(client: TestClient, superuser_token_headers: dict,
                       db: Session):
    auction = create_random_auction(db)

    response = client.post(
        f"{settings.API_PREFIX}/v1/auctions/{auction.id}/start",
        headers=superuser_token_headers)

    assert response.status_code == 200
    content = response.json()
    db.refresh(auction)
    assert auction.state == AuctionState.ONGOING
    assert content["id"]
    assert content["owner_id"]
    assert content["starting_amount"] == auction.starting_amount
    assert content["reserve"] == auction.reserve
    assert content["bid_cap"] == auction.bid_cap
    assert content["product_id"] == auction.product_id
    assert content["state"] == AuctionState.ONGOING
Example #10
0
def test_start_auction(client: TestClient, superuser_token_headers: dict,
                       db: Session):
    auction = create_random_auction(db)
    ending_date = (datetime.now() + timedelta(days=1)).isoformat()
    data = {'ending_date': ending_date}

    response = client.put(
        f"{settings.API_PREFIX}/v1/auctions/{auction.id}/start",
        headers=superuser_token_headers,
        json=data)

    assert response.status_code == 200
    content = response.json()
    db.refresh(auction)
    assert auction.state == AuctionState.ONGOING
    assert content["id"]
    assert content["owner_id"]
    assert content["starting_amount"] == auction.starting_amount
    assert content["reserve"] == auction.reserve
    assert content["bid_cap"] == auction.bid_cap
    assert content["product_id"] == auction.product_id
    assert content["state"] == AuctionState.ONGOING