def setUp(self): self.quebec = Province("Quebec", "QC", 13) self.loblaws = Store("Loblaws", self.quebec) self.loblaws_receipt = Receipt(self.loblaws) self.bananas = Item('Bananas', 0.79, 1.8) self.napkins = Item('Napkins', 2.0, 1, True)
class test_Receipt(unittest.TestCase): def setUp(self): self.quebec = Province("Quebec", "QC", 13) self.loblaws = Store("Loblaws", self.quebec) self.loblaws_receipt = Receipt(self.loblaws) self.bananas = Item('Bananas', 0.79, 1.8) self.napkins = Item('Napkins', 2.0, 1, True) def tearDown(self): self.quebec = None self.loblaws = None self.loblaws_receipt = None self.bananas = None self.pears = None self.napkins = None def test_Receipt_add_remove_item(self): assert not self.loblaws_receipt.items self.loblaws_receipt.add_item(self.bananas) assert self.loblaws_receipt.items self.loblaws_receipt.remove_item_by_name(self.bananas.name) assert not self.loblaws_receipt.items def test_Receipt_total(self): self.assertAlmostEqual(self.loblaws_receipt.total(),0.0) self.loblaws_receipt.add_item(self.bananas) self.assertAlmostEqual(self.loblaws_receipt.total(),1.422) self.loblaws_receipt.add_item(self.napkins) self.assertAlmostEqual(self.loblaws_receipt.total(),3.682) self.loblaws_receipt.remove_item_by_name(self.bananas.name) self.assertAlmostEqual(self.loblaws_receipt.total(),2.26)