def test_update_inexistent_customer(): repo = FakeCustomerRepository() repo.save(entities.Customer(id=1, name='Alice', email='*****@*****.**')) service = UpdateCustomer(repo) with pytest.raises(exceptions.CustomerNotFound): service({'id': 2, 'name': 'Alicia', 'email': '*****@*****.**'})
def test_delete_customer_with_success(): repo = FakeCustomerRepository() repo.save(entities.Customer(id=1, name='Alice', email='*****@*****.**')) service = DeleteCustomer(repo) service({'customer_id': 1}) assert repo.get_by_email('*****@*****.**') is None
def test_delete_inexistent_customer(): repo = FakeCustomerRepository() repo.save(entities.Customer(id=1, name='Alice', email='*****@*****.**')) service = DeleteCustomer(repo) with pytest.raises(exceptions.CustomerNotFound): service({'customer_id': 2})
def test_update_customer_with_email_of_another_customer(): repo = FakeCustomerRepository() repo.save(entities.Customer(id=1, name='Alice', email='*****@*****.**')) repo.save(entities.Customer(id=2, name='Carla', email='*****@*****.**')) service = UpdateCustomer(repo) with pytest.raises(exceptions.CustomerAlreadyRegistered): service({'id': 1, 'name': 'Carla', 'email': '*****@*****.**'})
def test_update_customer_with_success(): repo = FakeCustomerRepository() repo.save(entities.Customer(id=1, name='Alice', email='*****@*****.**')) service = UpdateCustomer(repo) service({'id': 1, 'name': 'Alicia', 'email': '*****@*****.**'}) customer = repo.get_by_id(1) assert customer.name == 'Alicia' assert customer.email == '*****@*****.**'
def test_add_product_to_wishlist_response(): repo = FakeCustomerRepository() product_api = FakeProductAPI(['a33b099f-fe56-46af-901e-7cef5d7ab9c4']) repo.save(entities.Customer(id=1, name='Alice', email='*****@*****.**')) service = AddProductToWishlist(repo, product_api) response = service({ 'customer_id': 1, 'product_id': 'a33b099f-fe56-46af-901e-7cef5d7ab9c4' }) assert response == {'wishlist': ['a33b099f-fe56-46af-901e-7cef5d7ab9c4']}
def test_create_customer_response_dto(): repo = FakeCustomerRepository() repo.save(entities.Customer(id=1, name='Alice', email='*****@*****.**')) service = UpdateCustomer(repo) response_dto = service({ 'id': 1, 'name': 'Alicia', 'email': '*****@*****.**' }) expected_dto = {'id': 1, 'name': 'Alicia', 'email': '*****@*****.**'} assert response_dto == expected_dto
def test_add_inexistent_product_to_wishlist(): repo = FakeCustomerRepository() product_api = FakeProductAPI(['a33b099f-fe56-46af-901e-7cef5d7ab9c4']) repo.save(entities.Customer(id=1, name='Alice', email='*****@*****.**')) service = AddProductToWishlist(repo, product_api) with pytest.raises(exceptions.ProductNotFound): service({ 'customer_id': 1, 'product_id': 'd6f0530a-f71e-48e8-b3aa-3d71b14cf016' })
def test_add_product_to_wishlist_with_success(): repo = FakeCustomerRepository() product_api = FakeProductAPI(['a33b099f-fe56-46af-901e-7cef5d7ab9c4']) repo.save(entities.Customer(id=1, name='Alice', email='*****@*****.**')) service = AddProductToWishlist(repo, product_api) service({ 'customer_id': 1, 'product_id': 'a33b099f-fe56-46af-901e-7cef5d7ab9c4' }) customer = repo.get_by_email('*****@*****.**') assert 'a33b099f-fe56-46af-901e-7cef5d7ab9c4' in { wished_product.product_id for wished_product in customer.wishlist }
def test_add_same_product_twice_to_wishlist(): repo = FakeCustomerRepository() product_api = FakeProductAPI(['a33b099f-fe56-46af-901e-7cef5d7ab9c4']) repo.save(entities.Customer(id=1, name='Alice', email='*****@*****.**')) service = AddProductToWishlist(repo, product_api) service({ 'customer_id': 1, 'product_id': 'a33b099f-fe56-46af-901e-7cef5d7ab9c4' }) with pytest.raises(exceptions.ProductAlreadAddedToWishlist): service({ 'customer_id': 1, 'product_id': 'a33b099f-fe56-46af-901e-7cef5d7ab9c4' })
def test_remove_product_from_wishlist_response(): repo = FakeCustomerRepository() customer = Customer( id=1, name='Alice', email='*****@*****.**', wishlist={ WishedProduct('735e774f-0dbd-4656-852f-b0985c321090'), WishedProduct('00bd0eb1-0832-476c-8f44-5494a39c96d8'), }, ) repo.save(customer) service = RemoveProductFromWishlist(repo) response = service({ 'customer_id': 1, 'product_id': '735e774f-0dbd-4656-852f-b0985c321090' }) assert response == {'wishlist': ['00bd0eb1-0832-476c-8f44-5494a39c96d8']}
def test_remove_product_from_wishlist_with_success(): repo = FakeCustomerRepository() customer = Customer( id=1, name='Alice', email='*****@*****.**', wishlist={ WishedProduct('735e774f-0dbd-4656-852f-b0985c321090'), WishedProduct('00bd0eb1-0832-476c-8f44-5494a39c96d8'), }, ) repo.save(customer) service = RemoveProductFromWishlist(repo) service({ 'customer_id': 1, 'product_id': '735e774f-0dbd-4656-852f-b0985c321090' }) customer = repo.get_by_email('*****@*****.**') assert '735e774f-0dbd-4656-852f-b0985c321090' not in { wished_product.product_id for wished_product in customer.wishlist }