def _collection_in_record(record, collection): """Returns True if record is in collection""" colls = force_force_list(record.get("980__", [])) for coll in colls: coll = force_force_list(coll.get('a', [])) if collection in [c.lower() for c in coll]: return True return False
def _get_title(self): """Return record titles""" record_title = '' if 'titles' in self.record: titles = force_force_list(self.record['titles']) for title in titles: if 'title' in title: record_title = title['title'] break return re.sub(r'(?<!\\)([#&%])', r'\\\1', record_title) else: return record_title
def authors_rule(self, key, value): value = force_force_list(value) orcid_authors = [] for index, author in enumerate(value): orcid_authors.append({ 'credit-name': value[index].get('full_name'), 'contributor-orcid': value[index].get('orcid') if 'orcid' in value[index] else '', 'contributor-attributes': { 'contributor-role': 'AUTHOR', 'contributor-sequence': ('FIRST' if index is 0 else 'ADDITIONAL') } }) if index is 19: break return {"contributor": orcid_authors}
def test_force_force_list_converts_tuples_to_lists(): expected = ['foo', 'bar', 'baz'] result = force_force_list(('foo', 'bar', 'baz')) assert expected == result
def test_force_force_list_wraps_strings_in_a_list(): expected = ['foo'] result = force_force_list('foo') assert expected == result
def test_force_force_list_returns_empty_list_on_none(): expected = [] result = force_force_list(None) assert expected == result