def test_delete_contact_for_user_no_contact(session): # pylint: disable=unused-argument """Assert that deleting a contact for a user with no contact raises the right exception.""" factory_user_model(user_info=TestUserInfo.user_test) with pytest.raises(BusinessException) as exception: UserService.delete_contact(TestJwtClaims.user_test) assert exception.value.code == Error.DATA_NOT_FOUND.name
def test_delete_contact_for_user_no_contact(session): # pylint: disable=unused-argument """Assert that deleting a contact for a user with no contact raises the right exception.""" factory_user_model(username='******', roles='{edit,uma_authorization,basic}', keycloak_guid='1b20db59-19a0-4727-affe-c6f64309fd04') with pytest.raises(BusinessException) as exception: UserService.delete_contact(TEST_TOKEN) assert exception.value.code == Error.DATA_NOT_FOUND.name
def test_delete_contact_user_link(session, auth_mock, keycloak_mock): # pylint:disable=unused-argument """Assert that a contact can not be deleted if contact link exists.""" user_with_token = TestUserInfo.user_test user_with_token['keycloak_guid'] = TestJwtClaims.edit_role['sub'] user_model = factory_user_model(user_info=user_with_token) user = UserService(user_model) org = OrgService.create_org(TestOrgInfo.org1, user_id=user.identifier) org_dictionary = org.as_dict() org_id = org_dictionary['id'] contact = factory_contact_model() contact_link = ContactLinkModel() contact_link.contact = contact contact_link.user = user_model contact_link.org = org._model # pylint:disable=protected-access contact_link = contact_link.flush() contact_link.commit() deleted_contact = UserService.delete_contact(TestJwtClaims.edit_role) assert deleted_contact is None delete_contact_link = ContactLinkModel.find_by_user_id(user.identifier) assert not delete_contact_link exist_contact_link = ContactLinkModel.find_by_org_id(org_id) assert exist_contact_link
def test_delete_contact_user_link(session, auth_mock): # pylint:disable=unused-argument """Assert that a contact can not be deleted if contact link exists.""" user_model = factory_user_model(user_info=TestUserInfo.user_test) user = UserService(user_model) org = OrgService.create_org(TestOrgInfo.org1, user_id=user.identifier) org_dictionary = org.as_dict() org_id = org_dictionary['id'] contact = factory_contact_model() contact_link = ContactLinkModel() contact_link.contact = contact contact_link.user = user_model contact_link.org = org._model # pylint:disable=protected-access contact_link.commit() updated_user = user.delete_contact(TestJwtClaims.user_test) dictionary = None dictionary = updated_user.as_dict() assert len(dictionary['contacts']) == 0 delete_contact_link = ContactLinkModel.find_by_user_id(user.identifier) assert not delete_contact_link exist_contact_link = ContactLinkModel.find_by_org_id(org_id) assert exist_contact_link
def test_delete_contact_for_user(session): # pylint: disable=unused-argument """Assert that a contact can be deleted for a user.""" factory_user_model(user_info=TestUserInfo.user_test) user = UserService.add_contact(TestJwtClaims.user_test, TestContactInfo.contact1) assert user is not None dictionary = user.as_dict() assert dictionary['contacts'] assert len(dictionary['contacts']) == 1 updated_user = UserService.delete_contact(TestJwtClaims.user_test) assert updated_user is not None dictionary = updated_user.as_dict() assert dictionary.get('contacts') == []
def test_delete_contact_for_user(session): # pylint: disable=unused-argument """Assert that a contact can be deleted for a user.""" user_with_token = TestUserInfo.user_test user_with_token['keycloak_guid'] = TestJwtClaims.user_test['sub'] factory_user_model(user_info=user_with_token) contact = UserService.add_contact(TestJwtClaims.user_test, TestContactInfo.contact1).as_dict() assert contact is not None deleted_contact = UserService.delete_contact(TestJwtClaims.user_test).as_dict() assert deleted_contact is not None contacts = UserService.get_contacts(TestJwtClaims.user_test) assert contacts.get('contacts') == []
def test_delete_contact_for_user(session): # pylint: disable=unused-argument """Assert that a contact can be deleted for a user.""" factory_user_model(username='******', roles='{edit,uma_authorization,basic}', keycloak_guid='1b20db59-19a0-4727-affe-c6f64309fd04') user = UserService.add_contact(TEST_TOKEN, TEST_CONTACT_INFO) assert user is not None dictionary = user.as_dict() assert dictionary['contacts'] assert len(dictionary['contacts']) == 1 updated_user = UserService.delete_contact(TEST_TOKEN) assert updated_user is not None dictionary = updated_user.as_dict() assert dictionary.get('contacts') == []
def test_delete_contact_for_user_no_user(session): # pylint: disable=unused-argument """Assert that deleting a contact for a non-existent user raises the right exception.""" with pytest.raises(BusinessException) as exception: UserService.delete_contact(TestJwtClaims.user_test) assert exception.value.code == Error.DATA_NOT_FOUND.name