Example #1
0
    def test_update(self):
        repository = MongoProductRepository(self.mongo_db)
        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(product_id)
        self.assertEqual(product.id, product_id)
        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)
Example #2
0
    def test_list(self):
        repository = MongoProductRepository(self.mongo_db)
        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)
Example #3
0
    def test_add_should_raise_skuExistsError_when_another_product_has_the_same_sku(
            self):
        repository = MongoProductRepository(self.mongo_db)

        product = Product(name='The Last of Us Part II',
                          sku='AHJU-49685',
                          cost=10.00,
                          price=220.00,
                          inventory_quantity=150)

        repository.add(product)

        with self.assertRaises(skuExistsError):
            repository.add(product)
Example #4
0
    def test_list_with_skus(self):
        repository = MongoProductRepository(self.mongo_db)

        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)
Example #5
0
    def test_remove(self):
        repository = MongoProductRepository(self.mongo_db)

        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)
Example #6
0
    def test_get_by_sku(self):
        repository = MongoProductRepository(self.mongo_db)
        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_sku('AHJU-49685')

        self.assertIsInstance(created_product, Product)
        self.assertEqual(product_id, 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)