def test_doi(minimal_document): """Test DOI serialization.""" result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert 'citation_doi' not in result minimal_document['identifiedBy'] = [{'type': 'bf:Doi', 'value': '111111'}] result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert '<meta name="citation_doi" content="111111">' in result
def test_title(minimal_document): """Test name.""" result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert '<meta name="citation_title" content="Title of the document">' in \ result # No title minimal_document.pop('title', None) result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert 'citation_title' not in result
def test_journal_title(app, minimal_document): """Test journal title.""" # No partOf result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert 'citation_journal_title' not in result minimal_document['partOf'] = [{'document': {'title': 'Host document'}}] result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert '<meta name="citation_journal_title" content="Host document">' in \ result
def test_language(minimal_document): """Test inLanguage serialization.""" # No language result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert 'citation_language' not in result # Take the first language minimal_document['language'] = [{'value': 'eng'}, {'value': 'fre'}] result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert '<meta name="citation_language" content="en">' in result
def detail(pid_value, view='global'): """Document detail page.""" record = DocumentRecord.get_record_by_pid(pid_value) if not record or record.get('hiddenFromPublic'): abort(404) # Add restriction, link and thumbnail to files if record.get('_files'): # Check if organisation's record forces to point file to an external # url record['external_url'] = has_external_urls_for_files(record) populate_files_properties(record) # Import is here to avoid a circular reference error. from sonar.modules.documents.serializers import google_scholar_v1, \ schemaorg_v1 # Get schema org data schema_org_data = json.dumps( schemaorg_v1.transform_record(record['pid'], record)) # Get scholar data google_scholar_data = google_scholar_v1.transform_record( record['pid'], record) # Resolve $ref properties record = record.replace_refs() return render_template('documents/record.html', pid=pid_value, record=record, schema_org_data=schema_org_data, google_scholar_data=google_scholar_data)
def test_authors(minimal_document, contributors): """Test authors serialization.""" minimal_document.update({'contribution': contributors}) result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) for author in ['Creator 1', 'Creator 2']: assert '<meta name="citation_author" content="{author}">'.format( author=author) in result
def test_pdf_url(minimal_document): """Test PDF URL serialization.""" result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert 'citation_pdf_url' not in result minimal_document.files['test.pdf'] = BytesIO(b'File content') minimal_document.files['test.pdf']['type'] = 'file' result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert '<meta name="citation_pdf_url" content="http://localhost/documents'\ '/1000/files/test.pdf">' in result minimal_document.files['test.pdf']['force_external_url'] = True minimal_document.files['test.pdf'][ 'external_url'] = 'https://some.domain/file.pdf' result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert '<meta name="citation_pdf_url" content="https://some.domain/' \ 'file.pdf">' in result
def test_keywords(minimal_document): """Test subjects serialization.""" result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert 'citation_keywords' not in result minimal_document['subjects'] = [{ 'label': { 'language': 'eng', 'value': ['Subject 1', 'Subject 2'] } }, { 'label': { 'language': 'fre', 'value': ['Sujet 1', 'Sujet 2'] } }] result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert '<meta name="citation_keywords" content="Subject 1 ; Subject 2 ; '\ 'Sujet 1 ; Sujet 2">' in result
def detail(pid, record, template=None, **kwargs): r"""Document detailed view. Sends record_viewed signal and renders template. :param pid: PID object. :param record: Record object. :param template: Template to render. :param \*\*kwargs: Additional view arguments based on URL rule. :returns: The rendered template. """ # Add restriction, link and thumbnail to files if record.get('_files'): # Check if organisation's record forces to point file to an external # url record['external_url'] = has_external_urls_for_files(record) populate_files_properties(record) # Import is here to avoid a circular reference error. from sonar.modules.documents.serializers import google_scholar_v1, \ schemaorg_v1 # Get schema org data schema_org_data = json.dumps( schemaorg_v1.transform_record(record['pid'], record)) # Get scholar data google_scholar_data = google_scholar_v1.transform_record( record['pid'], record) # Resolve $ref properties record = record.replace_refs() # Record is masked if record.is_masked: abort(403) # Send signal when record is viewed record_viewed.send( current_app._get_current_object(), pid=pid, record=record, ) return render_template(template, pid=pid, record=record, view=kwargs.get('view'), schema_org_data=schema_org_data, google_scholar_data=google_scholar_data)
def test_volume(app, minimal_document): """Test volume.""" # No partOf result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert 'citation_volume' not in result # No volume minimal_document['partOf'] = [{'document': {'title': 'Host document'}}] result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert 'citation_volume' not in result # Only one page minimal_document['partOf'] = [{ 'document': { 'title': 'Host document' }, 'numberingVolume': '1' }] result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert '<meta name="citation_volume" content="1">' in result
def test_pages(app, minimal_document): """Test pages.""" # No part of result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert 'citation_pages' not in result # No pages minimal_document['partOf'] = [{'document': {'title': 'Host document'}}] result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert 'citation_pages' not in result # OK minimal_document['partOf'] = [{ 'document': { 'title': 'Host document' }, 'numberingPages': '123-125' }] result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert '<meta name="citation_pages" content="123-125">' in result
def test_publication_date(minimal_document): """Test publication date.""" result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert 'citation_publication_date' not in result minimal_document.update({ 'provisionActivity': [{ 'type': 'bf:Agent', 'startDate': '2019' }, { 'type': 'bf:Publication', }, { 'type': 'bf:Publication', 'startDate': '2019' }, { 'type': 'bf:Publication', 'startDate': '2020-01-01' }] }) result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert '<meta name="citation_publication_date" content="2019">' in result
def test_last_page(app, minimal_document): """Test last page.""" # No partOf result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert 'citation_lastpage' not in result # No pages minimal_document['partOf'] = [{'document': {'title': 'Host document'}}] result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert 'citation_lastpage' not in result # Only one page minimal_document['partOf'] = [{ 'document': { 'title': 'Host document' }, 'numberingPages': '123' }] result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert 'citation_lastpage' not in result # Set of pages minimal_document['partOf'] = [{ 'document': { 'title': 'Host document' }, 'numberingPages': '123-130' }] result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert '<meta name="citation_lastpage" content="130">' in result # Exotic formatting minimal_document['partOf'] = [{ 'document': { 'title': 'Host document' }, 'numberingPages': '123, 134-135' }] result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert 'citation_lastpage' not in result # Page end not found minimal_document['partOf'] = [{ 'document': { 'title': 'Host document' }, 'numberingPages': 'pages' }] result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert 'citation_lastpage' not in result
def test_abstract_html_url(minimal_document): """Test HTML URL serialization.""" result = google_scholar_v1.transform_record(minimal_document['pid'], minimal_document) assert '<meta name="citation_abstract_html_url" content="http://' \ 'localhost/global/documents/1000">' in result