def auction_with_a_winner(input_dto: WithdrawingBidsInputDto) -> Auction:
    losing_bid = Bid(id=4, bidder_id=2, amount=get_dollars('5.50'))
    winning_bid = Bid(id=2, bidder_id=1, amount=get_dollars('6.00'))
    return Auction(id=2,
                   title='does not matter',
                   initial_price=get_dollars('5.00'),
                   bids=[winning_bid, losing_bid])
Exemplo n.º 2
0
def test_should_return_highest_bid_for_current_price():
    auction = create_auction(bids=[
        Bid(id=1, bidder_id=1, amount=get_dollars('20')),
        Bid(id=2, bidder_id=2, amount=get_dollars('15')),
    ])

    assert auction.current_price == get_dollars('20')
Exemplo n.º 3
0
def test_should_return_highest_bids_user_id_for_winners_list():
    auction = create_auction(bids=[
        Bid(id=1, bidder_id=1, amount=get_dollars('101')),
        Bid(id=2, bidder_id=2, amount=get_dollars('15')),
        Bid(id=3, bidder_id=3, amount=get_dollars('100')),
    ])

    assert auction.winners == [1]
Exemplo n.º 4
0
def test_gets_existing_auction(auction_model_with_a_bid: AuctionModel,
                               winning_bid_amount: Decimal) -> None:
    auction = DjangoORMAuctionsRepository().get(auction_model_with_a_bid.id)

    assert auction.id == auction_model_with_a_bid.id
    assert auction.title == auction_model_with_a_bid.title
    assert auction.initial_price == get_dollars(
        auction_model_with_a_bid.initial_price)
    assert auction.current_price == get_dollars(winning_bid_amount)
Exemplo n.º 5
0
def test_should_not_be_winning_if_bid_lower_than_current_price() -> None:
    auction = create_auction(bids=[
        Bid(id=1, bidder_id=1, amount=get_dollars('10.00'))
    ])

    lower_bid = Bid(id=None, bidder_id=2, amount=get_dollars('5.00'))
    auction.make_a_bid(lower_bid)

    assert lower_bid.bidder_id not in auction.winners
Exemplo n.º 6
0
    def get(self, auction_id: int) -> Auction:
        from auctions.models import Auction as AuctionModel

        auction_model = AuctionModel.objects.prefetch_related('bid_set').get(id=auction_id)
        return Auction(
            id=auction_model.id,
            title=auction_model.title,
            initial_price=get_dollars(auction_model.initial_price),
            bids=[
                Bid(id=bid_model.id, bidder_id=bid_model.bidder_id, amount=get_dollars(bid_model.amount))
                for bid_model in auction_model.bid_set.all()
            ]
        )
Exemplo n.º 7
0
def test_removes_withdrawn_bids(
        auction_model_with_a_bid: AuctionModel) -> None:
    bid_model = auction_model_with_a_bid.bid_set.first()
    auction = Auction(id=auction_model_with_a_bid.id,
                      title=auction_model_with_a_bid.title,
                      initial_price=get_dollars(
                          auction_model_with_a_bid.initial_price),
                      bids=[
                          Bid(bid_model.id, bid_model.bidder_id,
                              get_dollars(bid_model.amount)),
                      ])
    auction.withdrawn_bids_ids = [bid_model.id]

    DjangoORMAuctionsRepository().save(auction)

    assert auction_model_with_a_bid.bid_set.count() == 0
Exemplo n.º 8
0
def test_saves_auction_changes(auction_model_with_a_bid: AuctionModel) -> None:
    bid_model = auction_model_with_a_bid.bid_set.first()
    auction = Auction(id=auction_model_with_a_bid.id,
                      title=auction_model_with_a_bid.title,
                      initial_price=get_dollars(
                          auction_model_with_a_bid.initial_price),
                      bids=[
                          Bid(bid_model.id, bid_model.bidder_id,
                              get_dollars(bid_model.amount)),
                          Bid(None, bid_model.bidder_id,
                              get_dollars(bid_model.amount))
                      ])

    DjangoORMAuctionsRepository().save(auction)

    assert auction_model_with_a_bid.bid_set.count() == 2
Exemplo n.º 9
0
def test_should_add_withdrawn_bids_ids_to_separate_list():
    auction = create_auction(bids=[
        Bid(id=1, bidder_id=1, amount=get_dollars('50'))
    ])

    auction.withdraw_bids([1])

    assert auction.withdrawn_bids_ids == [1]
Exemplo n.º 10
0
def test_should_withdraw_the_only_bid():
    auction = create_auction(bids=[
        Bid(id=1, bidder_id=1, amount=get_dollars('50'))
    ])

    auction.withdraw_bids([1])

    assert auction.winners == []
    assert auction.current_price == auction.initial_price
def make_a_bid(request: HttpRequest, auction_id: int) -> HttpResponse:
    data = json.loads(request.body)
    input_dto = dacite.from_dict(
        placing_bid.PlacingBidInputDto, {
            'bidder_id': request.user.id,
            'auction_id': auction_id,
            'amount': get_dollars(data['amount'])
        })
    presenter = PlacingBidPresenter()
    uc = placing_bid.PlacingBidUseCase(presenter)
    uc.execute(input_dto)

    return presenter.get_http_response()
Exemplo n.º 12
0
def create_auction(bids: typing.List[Bid] = None) -> Auction:
    if not bids:
        bids = []

    return Auction(id=1, title='', initial_price=get_dollars('10'), bids=bids)
Exemplo n.º 13
0
def test_should_not_be_winning_auction_if_bids_below_initial_price():
    auction = create_auction()

    auction.make_a_bid(Bid(id=None, bidder_id=1, amount=get_dollars('5')))

    assert auction.winners == []
Exemplo n.º 14
0
def test_should_win_auction_if_is_the_only_bidder_above_initial_price():
    auction = create_auction()

    auction.make_a_bid(Bid(id=None, bidder_id=1, amount=get_dollars('11')))

    assert auction.winners == [1]
Exemplo n.º 15
0
def auction(exemplary_auction_id: int) -> Auction:
    return Auction(id=exemplary_auction_id,
                   title='irrelevant',
                   initial_price=get_dollars('2.00'),
                   bids=[])
Exemplo n.º 16
0
def amount() -> Money:
    return get_dollars('10.00')