コード例 #1
0
 def test_equal(self):
     item = Item()
     currency = Currency("$", "Dollar", "USD")
     currency2 = copy.deepcopy(currency)
     currency2.set_name("dollar")
     item.set_name("Apple")
     item.set_price(1)
     item.set_discount(0)
     item.set_currency(currency)
     item.set_description("A round fruit")
     item.set_id(1)
     item.set_percent_discount(False)
     item2 = copy.deepcopy(item)
     item2.set_id(2)
     self.assertNotEqual(item, item2)
     item2.set_id(item.get_id())
     item2.set_name("pear")
     self.assertNotEqual(item, item2)
     item2.set_name(item.get_name())
     item2.set_currency(currency2)
     self.assertNotEqual(item, item2)
     item2.set_currency(item.get_currency())
     item2.set_description("asdf")
     self.assertNotEqual(item, item2)
     item2.set_description(item.get_description())
     item2.set_price(0)
     self.assertNotEqual(item, item2)
     item2.set_price(item.get_price())
     item2.set_discount(1)
     self.assertNotEqual(item, item2)
     item2.set_discount(item.get_discount())
     item2.set_percent_discount(True)
     self.assertNotEqual(item, item2)
コード例 #2
0
 def test_item_repo(self):
     item1 = Item()
     currency = Currency("$", "Dollar", "USD")
     item1.set_id(1)
     item1.set_name("Apple")
     item1.set_discount(0)
     item1.set_price(2)
     item1.set_currency(currency)
     item1.set_description("A fruit")
     item_repo = ItemRepo()
     item_repo.store(item1)
     self.assertEqual(len(item_repo.get_all()), 1)
     item2 = Item()
     item2.set_name("Pear")
     item2.set_currency(currency)
     item2.set_price(3)
     item2.set_discount(0)
     item2.set_description("A fruit")
     item_repo.update(1, item2)
     self.assertEqual(item_repo.get(1), item2)
     item_repo.delete(item2.get_id())
     self.assertEqual(item_repo.get_all(), [])
     self.assertIsNone(item_repo.get(-1))