Esempio n. 1
0
def test_title():
    """Test title."""
    # No title
    document = {}
    assert DepositDocumentSchema().dump(document) == {}

    document = {
        'title': [{
            'mainTitle': [{
                'language':
                'ger',
                'value':
                '¿Política exterior o política de cooperación?'
            }],
            'subtitle': [{
                'language':
                'ger',
                'value':
                'una aproximación constructivista al estudio de la política exterior colombiana'
            }],
            'type':
            'bf:Title'
        }]
    }
    assert DepositDocumentSchema().dump(document) == {
        'metadata': {
            'title':
            '¿Política exterior o política de cooperación?',
            'subtitle':
            'una aproximación constructivista al estudio de la política exterior colombiana'
        }
    }
Esempio n. 2
0
def test_publication_place():
    """Test publication place."""
    # No provision activity
    document = {}
    assert DepositDocumentSchema().dump(document) == {}

    # No statement
    document = {'provisionActivity': [{}]}
    assert DepositDocumentSchema().dump(document) == {}

    document = {
        'provisionActivity': [{
            'statement': [{
                'type': 'bf:Place',
                'label': {
                    'value': 'Place 1'
                }
            }, {
                'type': 'bf:Place',
                'label': {
                    'value': 'Place 2'
                }
            }]
        }]
    }
    assert DepositDocumentSchema().dump(document) == {
        'metadata': {
            'publicationPlace': 'Place 1'
        }
    }
Esempio n. 3
0
def test_abstracts():
    """Test abstracts."""
    # No abstracts
    assert DepositDocumentSchema().dump({}) == {}

    document = {
        'abstracts': [{
            'language': 'fre',
            'value': 'Abstract FRE'
        }, {
            'language': 'eng',
            'value': 'Abstract ENG'
        }]
    }
    assert DepositDocumentSchema().dump(document) == {
        'metadata': {
            'abstracts': [{
                'language': 'fre',
                'abstract': 'Abstract FRE'
            }, {
                'language': 'eng',
                'abstract': 'Abstract ENG'
            }]
        }
    }
Esempio n. 4
0
def test_publisher():
    """Test publisher."""
    # No provision activity
    document = {}
    assert DepositDocumentSchema().dump(document) == {}

    # No statement
    document = {'provisionActivity': [{}]}
    assert DepositDocumentSchema().dump(document) == {}

    document = {
        'provisionActivity': [{
            'statement': [{
                'type': 'bf:Agent',
                'label': {
                    'value': 'Agent 1'
                }
            }, {
                'type': 'bf:Agent',
                'label': {
                    'value': 'Agent 2'
                }
            }]
        }]
    }
    assert DepositDocumentSchema().dump(document) == {
        'metadata': {
            'publisher': 'Agent 1'
        }
    }
Esempio n. 5
0
def test_notes():
    """Test notes."""
    # No note
    document = {}
    assert DepositDocumentSchema().dump(document) == {}

    document = {'notes': ['Note 1', 'Note 2']}
    assert DepositDocumentSchema().dump(document) == {
        'metadata': {
            'notes': ['Note 1', 'Note 2']
        }
    }
Esempio n. 6
0
def test_document_type():
    """Test document type."""
    # No document type
    document = {}
    assert DepositDocumentSchema().dump(document) == {}

    document = {'documentType': 'coar:c_2f33'}
    assert DepositDocumentSchema().dump(document) == {
        'metadata': {
            'documentType': 'coar:c_2f33'
        }
    }
Esempio n. 7
0
def test_other_material_characteristics():
    """Test other material characteristics."""
    document = {'formats': ['24 cm']}
    assert DepositDocumentSchema().dump(document) == {
        'metadata': {
            'formats': ['24 cm']
        }
    }
Esempio n. 8
0
def test_extent():
    """Test extent."""
    document = {'extent': '1 Bd.'}
    assert DepositDocumentSchema().dump(document) == {
        'metadata': {
            'extent': '1 Bd.'
        }
    }
Esempio n. 9
0
def test_content_note():
    """Test content note."""
    document = {'contentNote': ['Note 1', 'Note 2']}
    assert DepositDocumentSchema().dump(document) == {
        'metadata': {
            'contentNote': ['Note 1', 'Note 2']
        }
    }
Esempio n. 10
0
def test_additional_materials():
    """Test additional materials."""
    document = {'additionalMaterials': '30 pl.'}
    assert DepositDocumentSchema().dump(document) == {
        'metadata': {
            'additionalMaterials': '30 pl.'
        }
    }
Esempio n. 11
0
def test_formats():
    """Test formats."""
    document = {
        'otherMaterialCharacteristics': 'Other material characteristics'
    }
    assert DepositDocumentSchema().dump(document) == {
        'metadata': {
            'otherMaterialCharacteristics': 'Other material characteristics'
        }
    }
Esempio n. 12
0
def test_language():
    """Test language."""
    # No language
    document = {}
    assert DepositDocumentSchema().dump(document) == {}

    document = {
        'language': [{
            'type': 'bf:Language',
            'value': 'fre'
        }, {
            'type': 'bf:Language',
            'value': 'ger'
        }]
    }
    assert DepositDocumentSchema().dump(document) == {
        'metadata': {
            'language': 'fre'
        }
    }
Esempio n. 13
0
def test_date():
    """Test date."""
    # No provision activity
    document = {}
    assert DepositDocumentSchema().dump(document) == {}

    # No start date
    document = {'provisionActivity': [{}]}
    assert DepositDocumentSchema().dump(document) == {}

    document = {
        'provisionActivity': [{
            'type': 'bf:Publication',
            'startDate': '2012'
        }]
    }
    assert DepositDocumentSchema().dump(document) == {
        'metadata': {
            'documentDate': '2012'
        }
    }
Esempio n. 14
0
def test_series():
    """Test series."""
    # No serie
    document = {}
    assert DepositDocumentSchema().dump(document) == {}

    document = {
        'series': [{
            'name': 'Serie 1',
            'number': '12'
        }, {
            'name': 'Serie 2'
        }]
    }
    assert DepositDocumentSchema().dump(document) == {
        'metadata': {
            'series': [{
                'name': 'Serie 1',
                'number': '12'
            }, {
                'name': 'Serie 2'
            }]
        }
    }
Esempio n. 15
0
def test_contribution():
    """Test contribution."""
    # No contribution
    assert DepositDocumentSchema().dump({}) == {}

    document = {
        'contribution': [{
            'agent': {
                'type': 'bf:Person',
                'preferred_name': 'Thilmany, Christian. Herrmann',
                'date_of_birth': '1710',
                'date_of_death': '1767'
            },
            'role': ['cre']
        }]
    }
    assert DepositDocumentSchema().dump(document) == {
        'contributors': [{
            'name': 'Thilmany, Christian. Herrmann',
            'role': 'cre',
            'date_of_birth': '1710',
            'date_of_death': '1767'
        }]
    }
Esempio n. 16
0
def get_record():
    """Get record."""
    search_type = request.args.get('type', 'all_for_ui')
    query = request.args.get('query')
    format = request.args.get('format', 'document')

    if not search_type or not query:
        return jsonify({}), 400

    params = {
        'operation': 'searchRetrieve',
        'version':
        current_app.config.get('SONAR_APP_SWISSCOVERY_SEARCH_VERSION'),
        'recordSchema': 'marcxml',
        'maximumRecords': '1',
        'startRecord': '1',
        'query': f'({search_type}="{query}")'
    }
    response = requests.get(
        current_app.config.get('SONAR_APP_SWISSCOVERY_SEARCH_URL'),
        params=params)
    result = xmltodict.parse(response.text)

    if not result['sru:searchRetrieveResponse'].get(
            'sru:records') or not result['sru:searchRetrieveResponse'][
                'sru:records'].get('sru:record'):
        return jsonify({}), 200

    # Get only relevant XML part.
    record = xmltodict.unparse(result['sru:searchRetrieveResponse']
                               ['sru:records']['sru:record']['sru:recordData'],
                               full_document=False)

    record = SRUSchema().dump(record)

    # Regular expression to remove the << and >> around a value in the title
    # Ex: <<La>> vie est belle => La vie est belle
    pattern = re.compile('<<(.+)>>', re.S)
    for title in record.get('title',[]):
        for mainTitle in title.get('mainTitle', []):
            mainTitle['value'] = re.sub(pattern, r'\1', mainTitle['value'])

    # Serialize for deposit.
    if format == 'deposit':
        record = DepositDocumentSchema().dump(record)


    return jsonify(record)
Esempio n. 17
0
def test_identified_by():
    """Test identified by."""
    document = {
        'identifiedBy': [{
            'type': 'bf:Doi',
            'value': '10/12345'
        }, {
            'type': 'bf:Isbn',
            'value': '987654'
        }, {
            'type': 'bf:Issn',
            'value': '123456'
        }, {
            'type': 'bf:IssnL',
            'value': '567890'
        }, {
            'type': 'bf:Urn',
            'value': 'urn-value'
        }, {
            'type': 'uri',
            'value': 'https://uri.com'
        }]
    }
    assert DepositDocumentSchema().dump(document) == {
        'metadata': {
            'identifiedBy': [{
                'type': 'bf:Doi',
                'value': '10/12345'
            }, {
                'type': 'bf:Isbn',
                'value': '987654'
            }, {
                'type': 'bf:Issn',
                'value': '123456'
            }, {
                'type': 'bf:IssnL',
                'value': '567890'
            }, {
                'type': 'bf:Urn',
                'value': 'urn-value'
            }, {
                'type': 'uri',
                'value': 'https://uri.com'
            }]
        }
    }
Esempio n. 18
0
def test_dissertation():
    """Test dissertation."""
    document = {
        'dissertation': {
            'degree': 'Diss. Claremont. Complément',
            'grantingInstitution': 'Granting',
            'date': '2019'
        }
    }
    assert DepositDocumentSchema().dump(document) == {
        'metadata': {
            'dissertation': {
                'degree': 'Diss. Claremont. Complément',
                'grantingInstitution': 'Granting',
                'date': '2019'
            }
        }
    }
Esempio n. 19
0
def test_edition_statement():
    """Test edition statement."""
    document = {
        'editionStatement': {
            'editionDesignation': {
                'value': '1st edition'
            },
            'responsibility': {
                'value': 'Resp.'
            }
        }
    }
    assert DepositDocumentSchema().dump(document) == {
        'metadata': {
            'editionStatement': {
                'editionDesignation': {
                    'value': '1st edition'
                },
                'responsibility': {
                    'value': 'Resp.'
                }
            }
        }
    }
Esempio n. 20
0
def test_part_of():
    """Test part of."""
    # No part of
    document = {}
    assert DepositDocumentSchema().dump(document) == {}

    document = {
        'partOf': [{
            'document': {
                'title':
                'Document title 1',
                'contribution': ['Contributor 1', 'Contributor 2'],
                'identifiedBy': [{
                    'type': 'bf:Issn',
                    'value': 'ISSN'
                }, {
                    'type': 'bf:Isbn',
                    'value': 'ISBN'
                }]
            },
            'numberingVolume': '22',
            'numberingIssue': '4',
            'numberingPages': '485-512',
            'numberingYear': '2004'
        }, {
            'document': {
                'title': 'Document title 2'
            },
            'numberingVolume': '22',
            'numberingIssue': '4',
            'numberingYear': '2004'
        }, {
            'document': {
                'title': 'Document title 3',
            },
            'numberingPages': '243-263'
        }, {
            'document': {
                'title': 'Document title 4'
            },
            'numberingIssue': '16',
            'numberingYear': '2011'
        }]
    }
    assert DepositDocumentSchema().dump(document) == {
        'metadata': {
            'publication': {
                'publishedIn':
                'Document title 1',
                'volume':
                '22',
                'number':
                '4',
                'pages':
                '485-512',
                'year':
                '2004',
                'editors': ['Contributor 1', 'Contributor 2'],
                'identifiedBy': [{
                    'type': 'bf:Issn',
                    'value': 'ISSN'
                }, {
                    'type': 'bf:Isbn',
                    'value': 'ISBN'
                }]
            }
        }
    }