From cf2431db94c87f77e2344cc3eaee03f6d831bc23 Mon Sep 17 00:00:00 2001 From: Gianni Pante Date: Wed, 18 Nov 2020 14:38:27 +0100 Subject: [PATCH] data: fix responsibilityStatement conversion In the build_responsibility_data function, the square brackets [] are no more considered as trailing punctuation to be removed. * Closes #1406. Co-Authored-by: Gianni Pante --- rero_ils/dojson/utils.py | 4 +-- tests/unit/test_documents_dojson.py | 46 +++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/rero_ils/dojson/utils.py b/rero_ils/dojson/utils.py index ca6b0bec60..d3e4f19301 100644 --- a/rero_ils/dojson/utils.py +++ b/rero_ils/dojson/utils.py @@ -1502,14 +1502,14 @@ def build_responsibility_data(responsibility_data): for data_std in data_std_items: out_data = [] data_value = remove_trailing_punctuation( - data_std.lstrip(), ',.[]', ':;/-=') + data_std.lstrip(), ',.', ':;/-=') if data_value: out_data.append({'value': data_value}) if lang: try: data_lang_value = \ remove_trailing_punctuation( - data_lang_items[index].lstrip(), ',.[]', ':;/-=') + data_lang_items[index].lstrip(), ',.', ':;/-=') if not data_lang_value: raise Exception('missing data') except Exception as err: diff --git a/tests/unit/test_documents_dojson.py b/tests/unit/test_documents_dojson.py index fa79eddd48..5beaad9daa 100644 --- a/tests/unit/test_documents_dojson.py +++ b/tests/unit/test_documents_dojson.py @@ -354,6 +354,52 @@ def test_marc21_to_pid(): assert data.get('pid') is None +def test_marc21_to_title_245_with_sufield_c_having_square_bracket(): + """Test dojson test_marc21_to_title_245_without_246. + + - field 245 with subfields $a $b $c + - subfields 245 $a without '=' + - subfields 245 $c with '[]' + - field 246 is not present + """ + + marc21xml = """ + + 110729s2011 xx ||| | ||||00| |und d + + R006114538 + + + Ma ville en vert : + pour un retour de la nature / + [Robert Klant ... [et al.] ; [Kitty B.] + + + """ + marc21json = create_record(marc21xml) + data = marc21.do(marc21json) + assert data.get('title') == [ + { + 'type': 'bf:Title', + 'mainTitle': [ + {'value': 'Ma ville en vert'} + ], + 'subtitle': [ + {'value': 'pour un retour de la nature'} + ], + } + ] + assert data.get('responsibilityStatement') == [ + [ + {'value': '[Robert Klant ... [et al.]'} + ], + [ + {'value': '[Kitty B.]'} + ] + ] + + def test_marc21_to_title_245_with_two_246(): """Test dojson title with a 245 and two 246.