示例#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)
示例#2
0
 def add(self, product: Product) -> str:
     product = deepcopy(product)
     product.define_id(self.__next_id())
     self.__raise_if_sku_already_exists(product.sku)
     self.__products.append(product)
     return product.id
示例#3
0
 def create_product(self, product_creation_command: dict) -> Product:
     product = Product(**product_creation_command)
     product_id = self.__product_repository.add(product)
     product.define_id(product_id)
     return product