コード例 #1
0
    def test_get_products_with_appropriate_price(self):
        p1 = Product(id_="X1", name="Toy X1", price=10.3)
        p2 = Product(id_="X2", name="Toy X2", price=8.3)
        c = Catalogue({p1.id: p1, p2.id: p2})
        filtered_products = c.get_products_with_appropriate_price(lambda price: price < 10.0)

        self.assertDictEqual({p2.id: p2}, filtered_products)
コード例 #2
0
ファイル: test_catalogue.py プロジェクト: Blaxuu/Python
    def test_add_product(self):
        p = Product(id_="P", name="X", price=0)
        c = Catalogue()
        c.add_product(p)
        p.name = "Y"

        self.assertEqual("X", c.inventory["P"].name)
コード例 #3
0
ファイル: test_catalogue.py プロジェクト: Blaxuu/Python
    def test_get_products_by_name_part_case_sensitive(self):
        p1 = Product(id_="X1", name="TOY uppercase", price=10)
        p2 = Product(id_="X2", name="toy lowercase", price=10)
        c = Catalogue({p1.id: p1, p2.id: p2})
        filtered_products = c.get_products_by_name_part("toy")

        self.assertDictEqual({p2.id: p2}, filtered_products)
コード例 #4
0
 def test_inventory_overflow_init(self):
     p1 = Product(id_="P1", name="", price=0)
     p2 = Product(id_="P2", name="", price=0)
     p3 = Product(id_="P3", name="", price=0)
     big_inventory = {"1": p1, "2": p2, "3": p3}
     with self.assertRaises(InventoryOverflowException):
         c = Catalogue(big_inventory)
コード例 #5
0
ファイル: test_catalogue.py プロジェクト: Blaxuu/Python
    def test_add_too_many_products_in_a_batch(self):
        p1 = Product(id_="P1", name="", price=0)
        p2 = Product(id_="P2", name="", price=0)
        p3 = Product(id_="P3", name="", price=0)
        c = Catalogue()
        self.assertEqual(2, c.add_products([p1, p2, p3]))

        self.assertDictEqual({p1.id: p1, p2.id: p2}, c.inventory)
コード例 #6
0
ファイル: test_catalogue.py プロジェクト: Blaxuu/Python
 def test_inventory_overflow_add_product(self):
     p1 = Product(id_="P1", name="", price=0)
     p2 = Product(id_="P2", name="", price=0)
     p3 = Product(id_="P3", name="", price=0)
     c = Catalogue()
     c.add_product(p1)
     c.add_product(p2)
     with self.assertRaises(InventoryOverflowException):
         c.add_product(p3)
コード例 #7
0
ファイル: test_catalogue.py プロジェクト: Blaxuu/Python
    def test_init(self):
        p = Product(id_="P", name="", price=0)
        inventory = {p.id: p}
        c = Catalogue(inventory)
        del inventory[p.id]

        self.assertEqual(1, len(c.inventory))
コード例 #8
0
ファイル: test_product.py プロジェクト: Blaxuu/Python
 def test_generate_id(self):
     self.assertEqual("X1_2", Product.generate_id("X1"))
     self.assertEqual("AB_3", Product.generate_id("A B"))
コード例 #9
0
ファイル: test_product.py プロジェクト: Blaxuu/Python
 def test_too_high_price(self):
     product = Product(id_="RB01", name="Robot", price=200)
     self.assertEqual(100, product.price)
コード例 #10
0
ファイル: test_product.py プロジェクト: Blaxuu/Python
 def test_eq(self):
     self.assertEqual(Product(id_="P1", name="", price=0), Product(id_="P1", name="", price=0))
     self.assertNotEqual(Product(id_="P1", name="X", price=0), Product(id_="P1", name="", price=0))
コード例 #11
0
ファイル: test_product.py プロジェクト: Blaxuu/Python
 def test_str_fractional_price(self):
     product = Product(id_="RB01", name="Robot", price=10.2)
     self.assertEqual("Robot [RB01] : $10.20", str(product))
コード例 #12
0
ファイル: test_product.py プロジェクト: Blaxuu/Python
 def test_str_integer_price(self):
     product = Product(id_="RB01", name="Robot", price=10)
     self.assertEqual("Robot [RB01] : $10.00", str(product))
コード例 #13
0
ファイル: test_product.py プロジェクト: Blaxuu/Python
 def test_create_from_str(self):
     self.assertEqual(
         Product(id_="RB 1", name="Toy robot", price=10.3),
         Product.from_string("id=RB 1;name=Toy robot;price=10.3"))
コード例 #14
0
ファイル: test_catalogue.py プロジェクト: Blaxuu/Python
 def test_inventory_overflow_init(self):
     p1 = Product(id_="P1", name="", price=0)
     p2 = Product(id_="P2", name="", price=0)
     p3 = Product(id_="P3", name="", price=0)
     with self.assertRaises(InventoryOverflowException):
         Catalogue({p1.id: p1, p2.id: p2, p3.id: p3})
コード例 #15
0
ファイル: test_catalogue.py プロジェクト: Blaxuu/Python
    def test_contains_key_is_present(self):
        p = Product(id_="P", name="", price=0)
        c = Catalogue()
        c.add_product(p)

        self.assertTrue(p.id in c)
コード例 #16
0
ファイル: test_product.py プロジェクト: Blaxuu/Python
 def test_init_no_id(self):
     product = Product(id_=None, name="Robot", price=10.2)
     self.assertEqual("Robot_5", product.id)
     self.assertEqual("Robot", product.name)
     self.assertEqual(10.2, product.price)
コード例 #17
0
ファイル: test_product.py プロジェクト: Blaxuu/Python
 def test_init(self):
     product = Product(id_="RB01", name="Robot", price=10.2)
     self.assertEqual("RB01", product.id)
     self.assertEqual("Robot", product.name)
     self.assertEqual(10.2, product.price)
コード例 #18
0
ファイル: test_product.py プロジェクト: Blaxuu/Python
 def test_init_name_too_long(self):
     with self.assertRaises(ValueError):
         Product(id_="RB01", name="Robot with a remote control", price=10)