def test_add_contact_duplicate(session): # pylint:disable=unused-argument """Assert that a contact cannot be added to an Org if that Org already has a contact.""" org = factory_org_service() org_dictionary = org.as_dict() OrgService.add_contact(org_dictionary['id'], TestContactInfo.contact1) with pytest.raises(BusinessException) as exception: OrgService.add_contact(org_dictionary['id'], TestContactInfo.contact2) assert exception.value.code == Error.DATA_ALREADY_EXISTS.name
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
def test_add_contact(session): # pylint:disable=unused-argument """Assert that a contact can be added to an org.""" org = factory_org_service() org_dictionary = org.as_dict() contact = OrgService.add_contact(org_dictionary['id'], TestContactInfo.contact1) dictionary = contact.as_dict() assert dictionary['email'] == TestContactInfo.contact1['email']
def post(org_id): """Create a new contact for the specified org.""" 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 = OrgService.add_contact(org_id, 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
def test_update_contact(session): # pylint:disable=unused-argument """Assert that a contact for an existing Org can be updated.""" org = factory_org_service() org_dictionary = org.as_dict() contact = OrgService.add_contact(org_dictionary['id'], TestContactInfo.contact1) dictionary = contact.as_dict() assert dictionary['email'] == TestContactInfo.contact1['email'] updated_contact = OrgService.update_contact(org_dictionary['id'], TestContactInfo.contact2) dictionary = updated_contact.as_dict() assert dictionary['email'] == TestContactInfo.contact2['email']