コード例 #1
0
class Test_WhenRemovingAProductThatDoesNotExists(BasketTest):
    def given_a_basket(self) -> None:
        self.exn: Union[Exception, None] = None
        self.basket = Basket([
            events.BasketCreated(self.BASKET_ID),
            events.ItemAdded(BasketTest.BASKET_ID, "apple", 1),
        ])

    def because_we_remove_an_unknown_item(self) -> None:
        try:
            self.basket.remove("sausages")
        except Exception as e:
            self.exn = e

    def test_it_should_not_empty_the_items(self) -> None:
        self.given_a_basket()
        self.because_we_remove_an_unknown_item()
        assert not self.basket.is_empty()

    def test_it_should_raise_a_key_error(self) -> None:
        self.given_a_basket()
        self.because_we_remove_an_unknown_item()
        assert isinstance(self.exn, KeyError)

    def test_it_should_not_raise_any_events(self) -> None:
        self.given_a_basket()
        self.because_we_remove_an_unknown_item()
        assert self.raised_no_events()
コード例 #2
0
class When_removing_a_product:
    def given_a_basket(self):
        self.basket = Basket()
        self.basket.add_item("apple", 2)

    def because_we_remove_an_item(self):
        self.basket.remove("apple")

    def it_should_empty_the_items(self):
        assert self.basket.is_empty()
コード例 #3
0
class When_removing_a_product_that_doesnt_exist:
    def given_a_basket(self):
        self.basket = Basket()
        self.basket.add_item("apple")

    def because_we_remove_an_item(self):
        try:
            self.basket.remove("sausages")
        except Exception as e:
            self.exn = e

    def it_should_not_empty_the_items(self):
        assert not self.basket.is_empty()

    def it_should_raise_a_key_error(self):
        assert isinstance(self.exn, KeyError)
コード例 #4
0
class Test_WhenRemovingAProduct(BasketTest):
    def given_a_basket(self) -> None:
        self.basket = Basket([
            events.BasketCreated(self.BASKET_ID),
            events.ItemAdded(BasketTest.BASKET_ID, "apple", 2),
        ])

    def because_we_remove_an_item(self) -> None:
        self.basket.remove("apple")

    def test_it_should_empty_the_items(self) -> None:
        self.given_a_basket()
        self.because_we_remove_an_item()
        assert self.basket.is_empty()

    def test_it_should_raise_item_removed(self) -> None:
        self.given_a_basket()
        self.because_we_remove_an_item()
        assert self.has_event(events.ItemRemoved)
        assert self.event.basket_id == self.BASKET_ID
        assert self.event.product == "apple"  # type: ignore