Example #1
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 #2
0
 def test_update_should_raise_not_found_when_cant_find_product(self):
     repository = MongoProductRepository(self.mongo_db)
     product = Product(id='5f566e9c1022bd08188d674b',
                       name='Last of Us Part II',
                       sku='AHJU-4968',
                       cost=2.00,
                       price=100.00,
                       inventory_quantity=100)
     with self.assertRaises(NotFound):
         repository.update(product)
Example #3
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 #4
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)
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_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 #7
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 #8
0
# -*- coding: utf-8 -*-

from src import configurations, web_app as web_app_module
from src import connections
from src.kitmanagement import endpoints as kitmanagement_endpoints
from src.kitmanagement.application_services import ProductsService, KitsService, CalculatedKitsService
from src.kitmanagement.repositories import InMemoryProductRepository, InMemoryKitRepository, MongoProductRepository, MongoKitRepository

config = configurations.get_config()
web_app = web_app_module.get_web_app()
api = web_app_module.get_api()

connections.register(web_app)

# INFO: If you dont like databases, just use an inmemory repository
# product_repository = InMemoryProductRepository()
# kit_repository = InMemoryKitRepository()

product_repository = MongoProductRepository(connections.mongo_kit_db)
kit_repository = MongoKitRepository(connections.mongo_kit_db)

products_service = ProductsService(product_repository, kit_repository)
kits_service = KitsService(kit_repository, product_repository)
calculated_kits_service = CalculatedKitsService(kit_repository,
                                                product_repository)

kitmanagement_endpoints.register(
    products_service=products_service,
    kits_service=kits_service,
    calculated_kits_service=calculated_kits_service)
Example #9
0
 def test_remove_should_raise_not_found_when_cant_find_product(self):
     repository = MongoProductRepository(self.mongo_db)
     with self.assertRaises(NotFound):
         repository.remove('5f566e9c1022bd08188d674b')