コード例 #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
コード例 #2
0
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
コード例 #3
0
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
コード例 #4
0
ファイル: auctions.py プロジェクト: robovoid123/EasyAuction
def bid_in_auction(*,
                   id: int,
                   amount: float = Body(...),
                   db: Session = Depends(get_db),
                   current_user: User = Depends(get_current_active_user)):
    auction = auction_repo.get(db, id=id)
    if not auction:
        raise AUCTION_NOT_FOUND_EXCEPTION
    english = EnglishAuction()
    return english.bid(db,
                       db_obj=auction,
                       amount=amount,
                       bidder_id=current_user.id)
コード例 #5
0
ファイル: auctions.py プロジェクト: BirajKhanal/EasyAuction
def bid_in_auction(*, id: int,
                   amount: float = Body(...),
                   db: Session = Depends(get_db),
                   current_user: User = Depends(get_current_active_user)):
    auction = auction_repo.get(db, id=id)
    if not auction:
        raise AUCTION_NOT_FOUND_EXCEPTION

    if auction.state != AuctionState.ONGOING:
        if auction.state == AuctionState.CREATED:
            raise AUCTION_NOT_STARTED_EXCEPTION
        elif auction.state == AuctionState.ENDED:
            raise AUCTION_ENDED_EXCEPTION
        elif auction.state == AuctionState.CANCLED:
            raise AUCTION_CANCELED_EXCEPTION

    english = EnglishAuction()
    return english.bid(db, db_obj=auction, amount=amount, bidder_id=current_user.id)