示例#1
0
def test_delete_contact_org_link(session, auth_mock):  # pylint:disable=unused-argument
    """Assert that a contact can not be deleted if it's still being used by an entity."""
    entity_model = factory_entity_model()
    entity = EntityService(entity_model)

    org = factory_org_service()
    org_dictionary = org.as_dict()
    org_id = org_dictionary['id']

    contact = factory_contact_model()

    contact_link = ContactLinkModel()
    contact_link.contact = contact
    contact_link.entity = entity._model  # pylint:disable=protected-access
    contact_link.org = org._model  # pylint:disable=protected-access
    contact_link.commit()

    OrgService.delete_contact(org_id=org_id)
    org = OrgService.find_by_org_id(org_id)
    response = OrgService.get_contacts(org_id)

    assert len(response['contacts']) == 0

    delete_contact_link = ContactLinkModel.find_by_entity_id(entity.identifier)
    assert delete_contact_link

    exist_contact_link = ContactLinkModel.find_by_org_id(org_id)
    assert not exist_contact_link
示例#2
0
def test_delete_contact_no_org(session, auth_mock):  # pylint:disable=unused-argument
    """Assert that a contact can not be deleted if it doesn't exist."""
    org = factory_org_service()
    org_dictionary = org.as_dict()
    OrgService.add_contact(org_dictionary['id'], TestContactInfo.contact1)

    OrgService.delete_contact(org_dictionary['id'])

    with pytest.raises(BusinessException) as exception:
        OrgService.delete_contact(org_dictionary['id'])

    assert exception.value.code == Error.DATA_NOT_FOUND.name
示例#3
0
 def delete(org_id):
     """Delete the contact info for the specified org."""
     try:
         response, status = OrgService.delete_contact(org_id).as_dict(), http_status.HTTP_200_OK
     except BusinessException as exception:
         response, status = {'code': exception.code, 'message': exception.message}, exception.status_code
     return response, status