def test_create_entity(app, session): # pylint:disable=unused-argument """Assert that an Entity can be created.""" entity_info = {'businessIdentifier': 'CP1234567'} with app.app_context(): entity = EntityService.create_entity(entity_info) assert entity is not None
def test_create_entity(session): # pylint:disable=unused-argument """Assert that an Entity can be created from a dictionary.""" entity = EntityService.create_entity({ 'businessIdentifier': 'CP1234567', 'businessNumber': '791861073BC0001', 'name': 'Foobar, Inc.' }) assert entity is not None dictionary = entity.as_dict() assert dictionary['businessIdentifier'] == 'CP1234567'
def post(): """Post a new Entity using the request body.""" request_json = request.get_json() valid_format, errors = schema_utils.validate(request_json, 'entity') if not valid_format: return {'message': schema_utils.serialize(errors)}, http_status.HTTP_400_BAD_REQUEST try: response, status = EntityService.create_entity(request_json).as_dict(), http_status.HTTP_201_CREATED except BusinessException as exception: response, status = {'code': exception.code, 'message': exception.message}, exception.status_code except exc.IntegrityError: response, status = {'message': 'Business with specified identifier already exists.'}, \ http_status.HTTP_409_CONFLICT return response, status
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 == '*****@*****.**'
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'