示例#1
0
class TestInventory(TestCase):
    """ tests modules in inventory_class.py """
    def setUp(self):
        self.product_code = 199021
        self.description = 'na'
        self.market_price = 100
        self.rental_price = 500

        self.check_inventory = Inventory(self.product_code, self.description,
                                         self.market_price, self.rental_price)

    def test_init(self):
        """ check initialization of variables """
        self.assertEqual(self.check_inventory.product_code, self.product_code)
        self.assertEqual(self.check_inventory.description, self.description)
        self.assertEqual(self.check_inventory.market_price, self.market_price)
        self.assertEqual(self.check_inventory.rental_price, self.rental_price)

    def test_return_as_dict(self):
        """ check dictionary output """
        dict_output = self.check_inventory.return_as_dict()

        self.assertEqual(dict_output['product_code'], self.product_code)
        self.assertEqual(dict_output['description'], self.description)
        self.assertEqual(dict_output['market_price'], self.market_price)
        self.assertEqual(dict_output['rental_price'], self.rental_price)
示例#2
0
class InventoryTests(TestCase):
    """Tests for the Inventory class."""
    def setUp(self):
        self.inv = Inventory("A1", "Test", 100, 10)

    def test_init(self):
        """Test object instantiation."""
        self.assertEqual(self.inv.product_code, "A1")
        self.assertEqual(self.inv.description, "Test")
        self.assertEqual(self.inv.market_price, 100)
        self.assertEqual(self.inv.rental_price, 10)

    def test_return_dict(self):
        """Test return_as_dict method."""
        # expected dict to return
        inv_dict = {
            'product_code': "A1",
            'description': "Test",
            'market_price': 100,
            'rental_price': 10
        }

        self.assertEqual(inv_dict, self.inv.return_as_dict())