Example #1
0
def test_delete_contact_entity_link(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)

    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()

    updated_entity = entity.delete_contact()

    dictionary = None
    dictionary = updated_entity.as_dict()
    assert len(dictionary['contacts']) == 0

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

    exist_contact_link = ContactLinkModel.find_by_org_id(org_id)
    assert exist_contact_link
Example #2
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']
Example #3
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