def test_add(self): repository = InMemoryProductRepository() product = Product(name='The Last of Us Part II', sku='AHJU-49685', cost=10.00, price=220.00, inventory_quantity=150) product_id = repository.add(product) created_product = repository.get_by_id(product_id) self.assertIsInstance(product_id, str) self.assertEqual('1', product_id) self.assertEqual('1', created_product.id) self.assertEqual(product.name, created_product.name) self.assertEqual(product.sku, created_product.sku) self.assertEqual(product.price, created_product.price) self.assertEqual(product.inventory_quantity, created_product.inventory_quantity) self.assertEqual( '2', repository.add( Product(name='The Last of Us Part II', sku='AHJU-496851', cost=10.00, price=220.00, inventory_quantity=150)))
def test_list(self): repository = InMemoryProductRepository() first_product = Product(name='The Last of Us Part II', sku='AHJU-49685', cost=10.00, price=220.00, inventory_quantity=150) second_product = Product(name='God of war', sku='AHJU-49681', cost=20.00, price=220.00, inventory_quantity=80) first_product_id = repository.add(first_product) second_product_id = repository.add(second_product) created_products = repository.list() self.assertIsInstance(created_products, list) self.assertEqual(2, len(created_products)) self.assertEqual(first_product_id, created_products[0].id) self.assertEqual(first_product.name, created_products[0].name) self.assertEqual(first_product.sku, created_products[0].sku) self.assertEqual(first_product.price, created_products[0].price) self.assertEqual(first_product.inventory_quantity, created_products[0].inventory_quantity) self.assertEqual(second_product_id, created_products[1].id) self.assertEqual(second_product.name, created_products[1].name) self.assertEqual(second_product.sku, created_products[1].sku) self.assertEqual(second_product.price, created_products[1].price) self.assertEqual(second_product.inventory_quantity, created_products[1].inventory_quantity)
def test_update(self): repository = InMemoryProductRepository() product = Product(name='Last of Us Part II', sku='AHJU-4968', cost=2.00, price=100.00, inventory_quantity=100) product_id = repository.add(product) repository.add( Product(name='Bloodborne', sku='AHJU-1458', cost=50.00, price=200.00, inventory_quantity=70)) product.define_id(product_id) product.update_infos(name='The Last of Us Part II', cost=10.00, price=220.00, inventory_quantity=150) repository.update(product) product = repository.get_by_id('1') self.assertEqual(product.id, '1') self.assertEqual(product.name, 'The Last of Us Part II') self.assertEqual(product.cost, 10.00) self.assertEqual(product.price, 220.00) self.assertEqual(product.inventory_quantity, 150)
def test_add_should_raise_skuExistsError_when_another_product_has_the_same_sku( self): repository = InMemoryProductRepository() product = Product(name='The Last of Us Part II', sku='AHJU-49685', cost=10.00, price=220.00, inventory_quantity=150) product_id = repository.add(product) created_product = repository.get_by_id(product_id) self.assertIsInstance(product_id, str) self.assertEqual('1', product_id) self.assertEqual('1', created_product.id) self.assertEqual(product.name, created_product.name) self.assertEqual(product.sku, created_product.sku) self.assertEqual(product.price, created_product.price) self.assertEqual(product.inventory_quantity, created_product.inventory_quantity) with self.assertRaises(skuExistsError): self.assertEqual('2', repository.add(product))
def test_remove(self): repository = InMemoryProductRepository() product = Product(name='The Last of Us Part II', sku='AHJU-49685', cost=10.00, price=220.00, inventory_quantity=150) product_id = repository.add(product) repository.remove(product_id) with self.assertRaises(NotFound): repository.get_by_id(product_id)
def test_list_with_skus(self): repository = InMemoryProductRepository() first_product = Product(name='The Last of Us Part II', sku='AHJU-49685', cost=10.00, price=220.00, inventory_quantity=150) second_product = Product(name='God of war', sku='AHJU-49684', cost=20.00, price=220.00, inventory_quantity=80) third_product = Product(name='Horizon Zero Dawn', sku='AHJU-49610', cost=20.00, price=220.00, inventory_quantity=80) first_product_id = repository.add(first_product) second_product_id = repository.add(second_product) repository.add(third_product) skus_products = repository.list_with_skus(['AHJU-49685', 'AHJU-49684']) self.assertIsInstance(skus_products, list) self.assertEqual(2, len(skus_products)) self.assertEqual(first_product_id, skus_products[0].id) self.assertEqual(first_product.name, skus_products[0].name) self.assertEqual(first_product.sku, skus_products[0].sku) self.assertEqual(first_product.price, skus_products[0].price) self.assertEqual(first_product.inventory_quantity, skus_products[0].inventory_quantity) self.assertEqual(second_product_id, skus_products[1].id) self.assertEqual(second_product.name, skus_products[1].name) self.assertEqual(second_product.sku, skus_products[1].sku) self.assertEqual(second_product.price, skus_products[1].price) self.assertEqual(second_product.inventory_quantity, skus_products[1].inventory_quantity)
def test_get_by_id_should_raise_not_found_when_cant_find_kit(self): repository = InMemoryProductRepository() with self.assertRaises(NotFound): repository.get_by_id('1')
def test_remove_should_raise_not_found_when_cant_find_product(self): repository = InMemoryProductRepository() with self.assertRaises(NotFound): repository.remove(1)