Exemplo n.º 1
0
def test_AuctionsRepo_UponSavingAuction_ClearsPendingEvents(
        connection: Connection, another_bidder_id: int,
        auction_model_with_a_bid: RowProxy, event_bus_mock: Mock) -> None:
    repo = SqlAlchemyAuctionsRepo(connection, event_bus_mock)
    auction = repo.get(auction_model_with_a_bid.id)
    auction.place_bid(another_bidder_id,
                      auction.current_price + get_dollars("1.00"))

    repo.save(auction)

    assert len(auction.domain_events) == 0
Exemplo n.º 2
0
def test_AuctionsRepo_UponSavingAuction_PostsPendingEventsViaEventBus(
        connection: Connection, another_bidder_id: int,
        auction_model_with_a_bid: RowProxy, event_bus_mock: Mock) -> None:
    repo = SqlAlchemyAuctionsRepo(connection, event_bus_mock)
    auction = repo.get(auction_model_with_a_bid.id)
    auction.place_bid(another_bidder_id,
                      auction.current_price + get_dollars("1.00"))

    repo.save(auction)

    event_bus_mock.post.assert_called()
Exemplo n.º 3
0
def test_saves_auction_changes(
    connection: Connection,
    another_bidder_id: int,
    bid_model: RowProxy,
    auction_model_with_a_bid: RowProxy,
    ends_at: datetime,
    event_bus_mock: Mock,
) -> None:
    new_bid_price = get_dollars(bid_model.amount * 2)
    auction = Auction(
        id=auction_model_with_a_bid.id,
        title=auction_model_with_a_bid.title,
        starting_price=get_dollars(auction_model_with_a_bid.starting_price),
        ends_at=ends_at,
        bids=[
            Bid(bid_model.id, bid_model.bidder_id,
                get_dollars(bid_model.amount)),
            Bid(None, another_bidder_id, new_bid_price),
        ],
        ended=True,
    )

    SqlAlchemyAuctionsRepo(connection, event_bus_mock).save(auction)

    assert connection.execute(select([func.count()
                                      ]).select_from(bids)).scalar() == 2
    proxy = connection.execute(
        select([
            auctions
        ]).where(auctions.c.id == auction_model_with_a_bid.id)).first()
    assert proxy.current_price == new_bid_price.amount
    assert proxy.ended
Exemplo n.º 4
0
def test_gets_existing_auction(
    connection: Connection,
    auction_model_with_a_bid: RowProxy,
    bid_model: RowProxy,
    ends_at: datetime,
    event_bus_mock: Mock,
) -> None:
    auction = SqlAlchemyAuctionsRepo(connection, event_bus_mock).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.starting_price == get_dollars(
        auction_model_with_a_bid.starting_price)
    assert auction.current_price == get_dollars(bid_model.amount)
    assert auction.ends_at == ends_at
    assert set(auction.bids) == {
        Bid(bid_model.id, bid_model.bidder_id, get_dollars(bid_model.amount))
    }
Exemplo n.º 5
0
def test_removes_withdrawn_bids(connection: Connection, bid_model: RowProxy,
                                auction_model_with_a_bid: dict,
                                ends_at: datetime,
                                event_bus_mock: Mock) -> None:
    auction = Auction(
        id=auction_model_with_a_bid.id,
        title=auction_model_with_a_bid.title,
        starting_price=get_dollars(auction_model_with_a_bid.starting_price),
        ends_at=ends_at,
        bids=[
            Bid(bid_model.id, bid_model.bidder_id,
                get_dollars(bid_model.amount))
        ],
        ended=False,
    )
    auction.withdraw_bids([bid_model.id])

    SqlAlchemyAuctionsRepo(connection, event_bus_mock).save(auction)

    assert connection.execute(select([func.count()
                                      ]).select_from(bids)).scalar() == 0
Exemplo n.º 6
0
 def auctions_repo(self, conn: Connection,
                   event_bus: EventBus) -> AuctionsRepository:
     return SqlAlchemyAuctionsRepo(conn, event_bus)