From aafc92dd94caa1608f33f8cd1345ed0944861723 Mon Sep 17 00:00:00 2001 From: Kelly Lockhart <2926089+kelockhart@users.noreply.github.com> Date: Wed, 25 Mar 2020 16:20:31 -0400 Subject: [PATCH] Fix to not import blank author in myADS --- vault_service/tests/test_utils.py | 7 +++++-- vault_service/views/utils.py | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/vault_service/tests/test_utils.py b/vault_service/tests/test_utils.py index f864d19..bdf4d13 100644 --- a/vault_service/tests/test_utils.py +++ b/vault_service/tests/test_utils.py @@ -40,7 +40,7 @@ def test_exc(): @httpretty.activate def test_upsert_myads(self): user_id = 5 - classic_setup = {"ast_aut": "Lockwood, G.\r\nKurtz, M.", + classic_setup = {"ast_aut": "Accomazzi, A.\r\nKurtz, M.", "ast_t1": "photosphere\r\nchromosphere\r\n", "ast_t2": "\"climate change\"\r\n\"global warming\"\r\n\"solar variation\"", "email": "gwl@lowell.edi", @@ -50,7 +50,7 @@ def test_upsert_myads(self): ], "id": 2060288, "lastname": "", - "phy_aut": "Lockwood, G.", + "phy_aut": "Lockwood, G.\r\n", "phy_t1": "photosphere\r\nchromosphere\r\n", "phy_t2": "\"climate change\"\r\n\"global warming\"\r\n\"solar variation\"", "pre_aut": "Lockwood, G.", @@ -64,6 +64,9 @@ def test_upsert_myads(self): with self.app.session_scope() as session: q = session.query(MyADS).filter_by(user_id=user_id).all() self.assertEquals(len(q), 4) + # make sure the blank author is removed + self.assertEquals(q[1].data, 'author:"Lockwood, G." OR author:"Accomazzi, A." OR author:"Kurtz, M."') + self.assertEquals(len(existing_setups), 0) self.assertEquals(len(new_setups), 4) self.assertEquals(new_setups[2], {'id': 3, diff --git a/vault_service/views/utils.py b/vault_service/views/utils.py index dfdcc4a..4c27107 100644 --- a/vault_service/views/utils.py +++ b/vault_service/views/utils.py @@ -334,21 +334,21 @@ def _import_authors(classic_setups=None, user_id=None, active=True): data_all = '' if classic_setups.get('phy_aut'): author_list = classic_setups.get('phy_aut').split('\r\n') - data = ' OR '.join(['author:"' + x + '"' for x in author_list]) + data = ' OR '.join(['author:"' + x + '"' for x in author_list if x]) if data not in data_all: if len(data_all) > 0: data = ' OR ' + data data_all += data if classic_setups.get('pre_aut'): author_list = classic_setups.get('pre_aut').split('\r\n') - data = ' OR '.join(['author:"' + x + '"' for x in author_list]) + data = ' OR '.join(['author:"' + x + '"' for x in author_list if x]) if data not in data_all: if len(data_all) > 0: data = ' OR ' + data data_all += data if classic_setups.get('ast_aut'): author_list = classic_setups.get('ast_aut').split('\r\n') - data = ' OR '.join(['author:"' + x + '"' for x in author_list]) + data = ' OR '.join(['author:"' + x + '"' for x in author_list if x]) if data not in data_all: if len(data_all) > 0: data = ' OR ' + data