Skip to content

Commit

Permalink
swisscovery: remove << and >> characters in the title when importing
Browse files Browse the repository at this point in the history
* Closes rero#701.

Co-Authored-by: Bertrand Zuchuat <bertrand.zuchuat@rero.ch>
  • Loading branch information
Garfield-fr committed Feb 21, 2022
1 parent 7eebf8e commit 57c552d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions sonar/modules/swisscovery/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

"""Swisscovery rest views."""

import re

import requests
import xmltodict
from flask import Blueprint, current_app, jsonify, request
Expand Down Expand Up @@ -66,8 +68,18 @@ def get_record():

record = SRUSchema().dump(record)

# Remove << and >> in the title value
pattern = re.compile('<<(.+)>>', re.S)
if 'title' in record:
for title in record['title']:
if 'mainTitle' in title:
for mainTitle in title['mainTitle']:
mainTitle['value'] = re.sub(
pattern, r'\1', mainTitle['value'])

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


return jsonify(record)
8 changes: 8 additions & 0 deletions tests/api/swisscovery/test_swisscovery_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,11 @@ def test_document_type(client, submitter):
assert res.status_code == 200
data = res.json
assert data['metadata']['documentType'] == 'coar:c_db06'


def test_title_remove_char(client, submitter):
"""Test for the removal of << and >> characters in the title."""
login_user_via_session(client, email=submitter['email'])
res = client.get(url_for('swisscovery.get_record',query='2070406237'))
assert res.status_code == 200
assert res.json['title'][0]['mainTitle'][0]['value'] == 'La vie est belle'

0 comments on commit 57c552d

Please # to comment.