Example #1
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 #2
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 #3
0
    def test_get_by_id(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_id(product_id)

        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)
Example #4
0
 def test_get_by_id_should_raise_not_found_when_cant_find_product(self):
     repository = MongoProductRepository(self.mongo_db)
     with self.assertRaises(NotFound):
         repository.get_by_id('5f566e9c1022bd08188d674b')