Пример #1
0
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_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
Пример #3
0
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_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})
Пример #5
0
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 == '*****@*****.**'
Пример #6
0
    def __call__(self, payload):
        if self.customer_repository.has_customer_with_email(payload.get('email')):
            raise exceptions.CustomerAlreadyRegistered

        customer = entities.Customer(
            id=None, name=payload.get('name'), email=payload.get('email')
        )

        self.customer_repository.save(customer)

        return CreateCustomerResponse().dump(customer)
Пример #7
0
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']}
Пример #8
0
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
Пример #9
0
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'
        })
Пример #10
0
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
    }
Пример #11
0
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'
        })