Exemplo n.º 1
0
def test_delete_contact(session):  # pylint:disable=unused-argument
    """Assert that a contact can be deleted to an Entity."""
    entity_model = factory_entity_model()
    entity = EntityService(entity_model)
    entity.add_contact(TestContactInfo.contact1)

    updated_entity = entity.delete_contact()
    dictionary = updated_entity.as_dict()
    assert not dictionary['contacts']
Exemplo n.º 2
0
def test_add_contact_duplicate(session):  # pylint:disable=unused-argument
    """Assert that a contact cannot be added to an Entity if that Entity already has a contact."""
    entity_model = factory_entity_model()
    entity = EntityService(entity_model)
    entity.add_contact(TestContactInfo.contact1)

    with pytest.raises(BusinessException) as exception:
        entity.add_contact(TestContactInfo.contact2)
    assert exception.value.code == Error.DATA_ALREADY_EXISTS.name
Exemplo n.º 3
0
def test_get_contact_by_business_identifier(session):  # pylint:disable=unused-argument
    """Assert that a contact can be retrieved by the associated business id."""
    entity_model = factory_entity_model()
    entity = EntityService(entity_model)
    entity.add_contact(TestContactInfo.contact1)

    contact = entity.get_contact()
    assert contact is not None
    assert contact.email == TestContactInfo.contact1['email']
Exemplo n.º 4
0
def test_add_contact_duplicate(session):  # pylint:disable=unused-argument
    """Assert that a contact cannot be added to an Entity if that Entity already has a contact."""
    entity_model = factory_entity_model(business_identifier='CP1234567')
    entity = EntityService(entity_model)
    entity.add_contact(TEST_CONTACT_INFO)

    with pytest.raises(BusinessException) as exception:
        entity.add_contact(TEST_UPDATED_CONTACT_INFO)
    assert exception.value.code == Error.DATA_ALREADY_EXISTS.name
Exemplo n.º 5
0
def test_get_contact_by_business_identifier(session):  # pylint:disable=unused-argument
    """Assert that a contact can be retrieved by the associated business id."""
    entity_model = factory_entity_model(business_identifier='CP1234567')
    entity = EntityService(entity_model)
    entity.add_contact(TEST_CONTACT_INFO)

    contact = entity.get_contact()
    assert contact is not None
    assert contact.email == TEST_CONTACT_INFO['email']
Exemplo n.º 6
0
def test_add_contact(session):  # pylint:disable=unused-argument
    """Assert that a contact can be added to an Entity."""
    entity_model = factory_entity_model()
    entity = EntityService(entity_model)
    entity.add_contact(TestContactInfo.contact1)

    dictionary = entity.as_dict()
    assert dictionary['contacts']
    assert len(dictionary['contacts']) == 1
    assert dictionary['contacts'][0]['email'] == TestContactInfo.contact1['email']
Exemplo n.º 7
0
def test_add_contact(session):  # pylint:disable=unused-argument
    """Assert that a contact can be added to an Entity."""
    entity_model = factory_entity_model(business_identifier='CP1234567')
    entity = EntityService(entity_model)
    entity.add_contact(TEST_CONTACT_INFO)

    dictionary = entity.as_dict()
    assert dictionary['contacts']
    assert len(dictionary['contacts']) == 1
    assert dictionary['contacts'][0]['email'] == TEST_CONTACT_INFO['email']
Exemplo n.º 8
0
def test_delete_contact_no_entity(session, auth_mock):  # pylint:disable=unused-argument
    """Assert that a contact can not be deleted without entity."""
    entity_model = factory_entity_model()
    entity = EntityService(entity_model)
    entity.add_contact(TestContactInfo.contact1)

    updated_entity = entity.delete_contact()

    with pytest.raises(BusinessException) as exception:
        updated_entity.delete_contact()

    assert exception.value.code == Error.DATA_NOT_FOUND.name
Exemplo n.º 9
0
def test_update_contact(session):  # pylint:disable=unused-argument
    """Assert that a contact for an existing Entity can be updated."""
    entity_model = factory_entity_model()
    entity = EntityService(entity_model)
    entity.add_contact(TestContactInfo.contact1)

    dictionary = entity.as_dict()
    assert len(dictionary['contacts']) == 1
    assert dictionary['contacts'][0]['email'] == TestContactInfo.contact1['email']

    entity.update_contact(TestContactInfo.contact2)

    dictionary = None
    dictionary = entity.as_dict()
    assert len(dictionary['contacts']) == 1
    assert dictionary['contacts'][0]['email'] == TestContactInfo.contact2['email']
Exemplo n.º 10
0
def test_update_contact(session):  # pylint:disable=unused-argument
    """Assert that a contact for an existing Entity can be updated."""
    entity_model = factory_entity_model(business_identifier='CP1234567')
    entity = EntityService(entity_model)
    entity.add_contact(TEST_CONTACT_INFO)

    dictionary = entity.as_dict()
    assert len(dictionary['contacts']) == 1
    assert dictionary['contacts'][0]['email'] == \
        TEST_CONTACT_INFO['email']

    entity.update_contact(TEST_UPDATED_CONTACT_INFO)

    dictionary = None
    dictionary = entity.as_dict()
    assert len(dictionary['contacts']) == 1
    assert dictionary['contacts'][0]['email'] == \
        TEST_UPDATED_CONTACT_INFO['email']
Exemplo n.º 11
0
def test_update_contact(app, session):  # pylint:disable=unused-argument
    """Assert that a contact for an entity can be updated."""
    entity_info = {'businessIdentifier': 'CP1234567'}

    with app.app_context():
        entity = EntityService.create_entity(entity_info)
        contact_info = {'emailAddress': '*****@*****.**'}
        EntityService.add_contact(entity.business_identifier, contact_info)

        contact_info['phoneNumber'] = '(555)-555-5555'
        updated_entity = EntityService.update_contact(
            entity.business_identifier, contact_info)

        assert updated_entity

        updated_contact = EntityService.get_contact_for_business(
            updated_entity.business_identifier)

        assert updated_contact is not None
        assert updated_contact.phone == '(555)-555-5555'
Exemplo n.º 12
0
    def post(business_identifier):
        """Add a new contact for the Entity identified by the provided id."""
        request_json = request.get_json()
        valid_format, errors = schema_utils.validate(request_json, 'contact')
        if not valid_format:
            return {'message': schema_utils.serialize(errors)}, http_status.HTTP_400_BAD_REQUEST

        try:
            response, status = EntityService.add_contact(business_identifier, request_json).as_dict(), \
                http_status.HTTP_201_CREATED
        except BusinessException as exception:
            response, status = {'code': exception.code, 'message': exception.message}, exception.status_code
        return response, status
Exemplo n.º 13
0
def test_add_contact(app, session):  # pylint:disable=unused-argument
    """Assert that a contact can be added to an Entity."""
    entity_info = {'businessIdentifier': 'CP1234567'}

    with app.app_context():
        entity = EntityService.create_entity(entity_info)
        contact_info = {'emailAddress': '*****@*****.**'}
        updated_entity = EntityService.add_contact(entity.business_identifier,
                                                   contact_info)

        assert updated_entity is not None

        contact = EntityService.get_contact_for_business(
            updated_entity.business_identifier)

        assert contact is not None
        assert contact.email == '*****@*****.**'