def get(document_type): """Return the latest terms of use.""" try: if document_type == DocumentType.TERMS_OF_USE.value: token = g.jwt_oidc_token_info if token.get('accessType', None) == AccessType.ANONYMOUS.value: document_type = DocumentType.TERMS_OF_USE_DIRECTOR_SEARCH.value doc = DocumentService.fetch_latest_document(document_type) if doc is not None: doc_dict = doc.as_dict() if document_type == DocumentType.TERMS_OF_USE_PAD.value: replaced_content = Documents._replace_current_date(doc) doc_dict.update({'content': replaced_content}) response, status = doc_dict, http_status.HTTP_200_OK else: response, status = {'message': 'The requested invitation could not be found.'}, \ http_status.HTTP_404_NOT_FOUND except BusinessException as exception: response, status = { 'code': exception.code, 'message': exception.message }, exception.status_code return response, status
def get(): """Return the Affidavit.""" try: doc = DocumentService.fetch_latest_document(DocumentType.AFFIDAVIT.value) if doc is None: response, status = {'message': 'The requested document could not be found.'}, \ http_status.HTTP_404_NOT_FOUND elif doc.as_dict().get('content_type', None) == ContentType.PDF.value: # pdf has to be served as attachment return send_from_directory('static', filename=doc.as_dict()['content'], as_attachment=True) else: response, status = doc.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
def get(document_type): """Return the latest terms of use.""" try: doc = DocumentService.fetch_latest_document(document_type) if doc is not None: response, status = doc.as_dict(), http_status.HTTP_200_OK else: response, status = {'message': 'The requested invitation could not be found.'}, \ http_status.HTTP_404_NOT_FOUND except BusinessException as exception: response, status = { 'code': exception.code, 'message': exception.message }, exception.status_code return response, status
def test_find_latest_version_for_director_search(session): # pylint: disable=unused-argument """Assert that a document is rendered correctly as a dictionary.""" terms_of_use = DocumentService.find_latest_version_by_type( 'termsofuse_directorsearch') assert terms_of_use == 'd1'
def test_find_latest_version_by_invalid_type(session): # pylint: disable=unused-argument """Assert that a document is rendered correctly as a dictionary.""" terms_of_use = DocumentService.find_latest_version_by_type('sometype') assert terms_of_use is None
def test_with_no_valid_type(session): # pylint: disable=unused-argument """Assert that a document is rendered correctly as a dictionary.""" terms_of_use = DocumentService.fetch_latest_document('sometype') assert terms_of_use is None
def test_as_dict(session): # pylint: disable=unused-argument """Assert that a document is rendered correctly as a dictionary.""" _model = DocumentsModel.fetch_latest_document_by_type('termsofuse') termsofuse = DocumentService(_model) dictionary = termsofuse.as_dict() assert dictionary['type'] == 'termsofuse'
def test_find_latest_version_by_type(session): # pylint: disable=unused-argument """Assert that a document is rendered correctly as a dictionary.""" terms_of_use = DocumentService.find_latest_version_by_type('termsofuse') assert terms_of_use == get_tos_latest_version()