diff --git a/packtools/sps/validation/article_doi.py b/packtools/sps/validation/article_doi.py index cf73c6ed8..7b9244f3d 100644 --- a/packtools/sps/validation/article_doi.py +++ b/packtools/sps/validation/article_doi.py @@ -1,8 +1,9 @@ from packtools.sps.models.article_and_subarticles import ArticleAndSubArticles -from packtools.sps.models.article_doi_with_lang import DoiWithLang from packtools.sps.models.article_contribs import ArticleContribs +from packtools.sps.models.article_doi_with_lang import DoiWithLang from packtools.sps.models.article_titles import ArticleTitles -from packtools.sps.validation.utils import format_response +from packtools.sps.validation.similarity_utils import how_similar +from packtools.sps.validation.utils import format_response, get_doi_information def _callable_extern_validate_default(doi): @@ -15,7 +16,11 @@ def __init__(self, xmltree): self.articles = ArticleAndSubArticles(self.xmltree) self.doi = DoiWithLang(self.xmltree) self.titles = ArticleTitles(self.xmltree).article_title_dict - self.authors = list(ArticleContribs(self.xmltree).contribs) + self.authors = [ + item + for item in ArticleContribs(self.xmltree).contribs + if item.get("parent") == "article" + ] def validate_doi_exists(self, error_level="CRITICAL"): """ @@ -82,20 +87,20 @@ def validate_doi_exists(self, error_level="CRITICAL"): """ for doi in self.doi.data: yield format_response( - title='Article DOI element exists', + title="Article DOI element exists", parent=doi.get("parent"), parent_id=doi.get("parent_id"), parent_article_type=doi.get("parent_article_type"), parent_lang=doi.get("lang"), item="article-id", sub_item='@pub-id-type="doi"', - validation_type='exist', + validation_type="exist", is_valid=bool(doi.get("value")), - expected=doi.get("value") or 'article DOI', + expected=doi.get("value") or "article DOI", obtained=doi.get("value"), advice=f'Provide a valid DOI for the {doi.get("parent")} represented by the following tag: ' - f'<{doi.get("parent")} article-type="{doi.get("parent_article_type")}" ' - f'id="{doi.get("parent_id")}" xml:lang="{doi.get("lang")}">', + f'<{doi.get("parent")} article-type="{doi.get("parent_article_type")}" ' + f'id="{doi.get("parent_id")}" xml:lang="{doi.get("lang")}">', data=self.doi.data, error_level=error_level, ) @@ -168,32 +173,34 @@ def validate_all_dois_are_unique(self, error_level="CRITICAL"): validated = True dois = {} for item in self.doi.data: - if item['value'] in dois: + if item["value"] in dois: validated = False - dois[item['value']] += 1 + dois[item["value"]] += 1 else: - dois[item['value']] = 1 + dois[item["value"]] = 1 diff = [doi for doi, freq in dois.items() if freq > 1] yield format_response( - title='Article DOI element is unique', + title="Article DOI element is unique", parent="article", parent_id=None, parent_article_type=self.articles.main_article_type, parent_lang=self.articles.main_lang, item="article-id", sub_item='@pub-id-type="doi"', - validation_type='unique', + validation_type="unique", is_valid=validated, - expected='Unique DOI values', + expected="Unique DOI values", obtained=list(dois.keys()), - advice='Consider replacing the following DOIs that are not unique: {}'.format(" | ".join(diff)), + advice="Consider replacing the following DOIs that are not unique: {}".format( + " | ".join(diff) + ), data=self.doi.data, error_level=error_level, ) - def validate_doi_registered(self, callable_get_data=None, error_level="CRITICAL"): + def validate_doi_registered(self, callable_get_data, error_level="CRITICAL"): """ Checks whether a DOI is registered as valid. @@ -286,7 +293,7 @@ def validate_doi_registered(self, callable_get_data=None, error_level="CRITICAL" A list of dictionaries, such as: [ { - 'title': 'Article DOI is registered (lang: en, element: doi)', + 'title': 'Registered DOI (lang: en, element: doi)', 'xpath': './article-id[@pub-id-type="doi"]', 'validation_type': 'exist', 'response': 'OK', @@ -298,127 +305,92 @@ def validate_doi_registered(self, callable_get_data=None, error_level="CRITICAL" ... ] """ - callable_get_data = callable_get_data or _callable_extern_validate_default - - for doi in self.doi.data: - expected = callable_get_data(doi.get("value")) - # verifica se houve resposta da aplicação - if expected: - validations = [] - lang = doi.get('lang') - - # valores obtidos - obtained_doi = doi.get('value') - obtained_title = self.titles.get(lang) - seen_authors = set() - obtained_authors = [] - for author in self.authors: - if 'contrib_name' in author: - full_name = f"{author['contrib_name'].get('surname', 'N/A')}, {author['contrib_name'].get('given-names', 'N/A')}" - if full_name not in seen_authors: - seen_authors.add(full_name) - obtained_authors.append(full_name) - - # valores esperados - expected_doi = expected.get(lang).get('doi') - expected_title = expected.get(lang).get('title') - expected_authors = expected.get('authors') or [] + callable_get_data = callable_get_data or get_doi_information + if not callable_get_data: + return - # validações - doi_is_valid = obtained_doi == expected_doi # verifica o valor do DOI - title_is_valid = obtained_title == expected_title # verifica a correspondência do título do artigo - authors_is_valid = len(obtained_authors) == len(expected_authors) # verifica a correspondência da quantidade de autores - - # agrega as validações - validations.append(('doi', doi_is_valid, obtained_doi, expected_doi)) - validations.append(('title', title_is_valid, obtained_title, expected_title)) - for author in zip(obtained_authors, expected_authors): - validations.append(('author', author[0] == author[1], author[0], author[1])) - - # gera os resultados das validações - for validation in validations: - yield format_response( - title='Article DOI is registered', - parent=doi.get("parent"), - parent_id=doi.get("parent_id"), - parent_article_type=doi.get("parent_article_type"), - parent_lang=doi.get("lang"), - item="article-id", - sub_item='@pub-id-type="doi"', - validation_type='exist', - is_valid=validation[1], - expected=validation[3], - obtained=validation[2], - advice='DOI not registered or validator not found, provide a value for {} element that ' - 'matches the record for DOI.'.format(validation[0]), - data=self.doi.data, - error_level=error_level, - ) - - # Resposta para o caso de quantidade de autores não corresponder - if not authors_is_valid: - if len(expected_authors) > len(obtained_authors): - diff = expected_authors[len(obtained_authors):] - item_description = 'not found' - action = ('Complete', 'in') - else: - diff = obtained_authors[len(expected_authors):] - item_description = 'surplus' - action = ('Remove', 'from') - - diff_str = ' | '.join(diff) - advice = f'{action[0]} the following items {action[1]} the XML: {diff_str}' - resp = format_response( - title='Article DOI is registered', - parent=doi.get("parent"), - parent_id=doi.get("parent_id"), - parent_article_type=doi.get("parent_article_type"), - parent_lang=doi.get("lang"), - item="article-id", - sub_item='@pub-id-type="doi"', - validation_type='exist', - is_valid=False, - expected=expected_authors, - obtained=obtained_authors, - advice=advice, - data=self.doi.data, - error_level=error_level, + for doi_data in self.doi.data: + lang = doi_data.get("lang") + xml_doi = doi_data.get("value") + xml_title = self.titles.get(lang) + xml_authors = [] + for author in self.authors: + try: + contrib_name = author["contrib_name"] + fullname = ( + f'{contrib_name["surname"]}, {contrib_name["given-names"]}' ) - resp["message"] = f'The following items are {item_description} in the XML: {diff_str}' - yield resp + xml_authors.append(fullname) + except KeyError: + pass + got = { + "title": xml_title, + "authors": xml_authors, + } + registered = callable_get_data(xml_doi) + # verifica se houve resposta da aplicação + if registered: + registered_title = registered.get(lang).get("title") + registered_authors = registered.get("authors") or [] + expected = { + "title": registered_title, + "authors": registered_authors, + } + similarity = how_similar(str(expected), str(got)) + similar = similarity > 0.98 + doi_data["similarity"] = similarity + yield format_response( + title="Registered DOI", + parent=doi_data.get("parent"), + parent_id=doi_data.get("parent_id"), + parent_article_type=doi_data.get("parent_article_type"), + parent_lang=doi_data.get("lang"), + item="article-id", + sub_item='@pub-id-type="doi"', + validation_type="registered", + is_valid=similar, + expected=expected, + obtained=got, + advice="Check the DOI number", + data=doi_data, + error_level=error_level, + ) else: # Resposta para o caso de não haver identificação do DOI yield format_response( - title='Article DOI is registered', - parent=doi.get("parent"), - parent_id=doi.get("parent_id"), - parent_article_type=doi.get("parent_article_type"), - parent_lang=doi.get("lang"), + title="Registered DOI", + parent=doi_data.get("parent"), + parent_id=doi_data.get("parent_id"), + parent_article_type=doi_data.get("parent_article_type"), + parent_lang=doi_data.get("lang"), item="article-id", sub_item='@pub-id-type="doi"', - validation_type='exist', + validation_type="registered", is_valid=False, - expected='Data registered to the DOI {}'.format(doi.get('value')), - obtained=None, - advice='Consult again after DOI has been registered', - data=self.doi.data, + expected="Data registered to the DOI {}".format(xml_doi), + obtained=got, + advice="Consult again after DOI has been registered", + data=doi_data, error_level=error_level, ) def validate_different_doi_in_translation(self, error_level="WARNING"): article_doi = self.doi.main_doi for doi in self.doi.data: - if doi["parent_article_type"] == "translation" and doi["value"] == article_doi: + if ( + doi["parent_article_type"] == "translation" + and doi["value"] == article_doi + ): yield format_response( - title='Different DOIs for tranaltions', + title="Different DOIs for tranaltions", parent=doi.get("parent"), parent_id=doi.get("parent_id"), parent_article_type=doi.get("parent_article_type"), parent_lang=doi.get("lang"), item="article-id", sub_item='@pub-id-type="doi"', - validation_type='match', + validation_type="match", is_valid=False, expected="use unique DOIs for articles and sub-articles", obtained=f"article DOI: {article_doi}, sub-article DOI: {doi['value']}", diff --git a/packtools/sps/validation/article_ids.py b/packtools/sps/validation/article_ids.py deleted file mode 100644 index 56990fe5f..000000000 --- a/packtools/sps/validation/article_ids.py +++ /dev/null @@ -1,47 +0,0 @@ -from packtools.sps.validation.utils import format_response -from packtools.sps.models.article_ids import ArticleIds - - -class ArticleIdsValidation: - def __init__(self, xml_tree): - self.xml_tree = xml_tree - self.article_ids = ArticleIds(xml_tree) - self.pub_type_id_other = self.article_ids.other - - def pub_type_id_other_has_five_digits(self): - if len(self.pub_type_id_other) != 5: - yield format_response( - title="pub-type-id=other has five digits", - parent="article", - parent_id=None, - parent_article_type=self.xml_tree.find(".").get("article-type"), - parent_lang=self.xml_tree.find(".").get("{http://www.w3.org/XML/1998/namespace}lang"), - item="article-id", - sub_item="@pub-id-type='other'", - validation_type="format", - is_valid=False, - expected="Five digits", - obtained=self.pub_type_id_other, - advice="Provide a value with five digits for ", - data=None, - error_level="ERROR", - ) - - def pub_type_id_other_is_numeric(self): - if not self.pub_type_id_other.isdigit(): - yield format_response( - title="pub-type-id=other is numeric", - parent="article", - parent_id=None, - parent_article_type=self.xml_tree.find(".").get("article-type"), - parent_lang=self.xml_tree.find(".").get("{http://www.w3.org/XML/1998/namespace}lang"), - item="article-id", - sub_item="@pub-id-type='other'", - validation_type="format", - is_valid=False, - expected="numeric value", - obtained=self.pub_type_id_other, - advice="Provide a numeric value for ", - data=None, - error_level="ERROR", - ) diff --git a/packtools/sps/validation/utils.py b/packtools/sps/validation/utils.py index 9dbb49c27..e757b9bfe 100644 --- a/packtools/sps/validation/utils.py +++ b/packtools/sps/validation/utils.py @@ -1,7 +1,7 @@ -import requests -from langdetect import detect import urllib.parse +import requests +from langdetect import detect from packtools.sps.libs.requester import fetch_data @@ -75,29 +75,25 @@ def build_response( def get_doi_information(doi): url = f"https://api.crossref.org/works/{doi}" response = fetch_data(url=url, json=True) - item = response['message'] + item = response["message"] result = {} # Extrair títulos e detectar idioma - titles = item.get('title', []) - original_titles = item.get('original-title', []) + titles = item.get("title") or [] + original_titles = item.get("original-title") or [] all_titles = titles + original_titles for title in all_titles: try: lang = detect(title) # Detecta o idioma do título except: - lang = 'unknown' - result[lang] = { - 'title': title, - 'doi': doi - } + lang = "unknown" + result[lang] = {"title": title, "doi": doi} # Adicionar autores ao resultado - result['authors'] = [ - f"{author['family']}, {author['given']}" - for author in item.get('author', []) + result["authors"] = [ + f"{author['family']}, {author['given']}" for author in item.get("author") or [] ] return result diff --git a/packtools/sps/validation/xml_validations.py b/packtools/sps/validation/xml_validations.py index 800c130c4..89a992f47 100644 --- a/packtools/sps/validation/xml_validations.py +++ b/packtools/sps/validation/xml_validations.py @@ -1,41 +1,33 @@ from packtools.sps.models.article_dates import ArticleDates - from packtools.sps.validation.aff import AffiliationsValidation from packtools.sps.validation.article_abstract import ( - HighlightsValidation, - VisualAbstractsValidation, - ArticleAbstractsValidation, -) + ArticleAbstractsValidation, HighlightsValidation, + VisualAbstractsValidation) from packtools.sps.validation.article_and_subarticles import ( - ArticleAttribsValidation, - ArticleIdValidation, - ArticleLangValidation, - ArticleTypeValidation, -) -from packtools.sps.validation.article_citations import ArticleCitationsValidation + ArticleAttribsValidation, ArticleIdValidation, ArticleLangValidation, + ArticleTypeValidation) +from packtools.sps.validation.article_citations import \ + ArticleCitationsValidation from packtools.sps.validation.article_contribs import ArticleContribsValidation -from packtools.sps.validation.article_data_availability import ( - DataAvailabilityValidation, -) +from packtools.sps.validation.article_data_availability import \ + DataAvailabilityValidation from packtools.sps.validation.article_doi import ArticleDoiValidation -from packtools.sps.validation.article_ids import ArticleIdsValidation from packtools.sps.validation.article_license import ArticleLicenseValidation -from packtools.sps.validation.article_toc_sections import ArticleTocSectionsValidation +from packtools.sps.validation.article_toc_sections import \ + ArticleTocSectionsValidation from packtools.sps.validation.article_xref import ArticleXrefValidation from packtools.sps.validation.dates import ArticleDatesValidation from packtools.sps.validation.fig import FigValidation from packtools.sps.validation.front_articlemeta_issue import Pagination from packtools.sps.validation.funding_group import FundingGroupValidation +from packtools.sps.validation.journal_meta import (JournalIdValidation, + PublisherNameValidation, + TitleValidation) # remover journal # from packtools.sps.validation.journal import xValidation -from packtools.sps.validation.journal_meta import ( - TitleValidation, - PublisherNameValidation, - JournalIdValidation, -) # PR pendente # from packtools.sps.validation.article_author_notes import xValidation @@ -156,11 +148,15 @@ def validate_article_type(xmltree, params): try: yield from validator.validate_article_type_vs_subject_similarity( subjects_list=journal_data["subjects_list"], - expected_similarity=article_type_rules["article_type_vs_subject_expected_similarity"], + expected_similarity=article_type_rules[ + "article_type_vs_subject_expected_similarity" + ], error_level=article_type_rules[ "article_type_vs_subject_expected_similarity_error_level" ], - target_article_types=article_type_rules["article_type_vs_subject_target_article_types"], + target_article_types=article_type_rules[ + "article_type_vs_subject_target_article_types" + ], ) except KeyError: pass @@ -173,22 +169,15 @@ def validate_article_ids(xmltree, params): validator = ArticleIdValidation(xmltree) yield from validator.validate_article_id_other(article_ids_rules["error_level"]) - validator = ArticleIdsValidation(xmltree) - # FIXME add article_ids_rules["error_level"] - yield from validator.pub_type_id_other_has_five_digits( - # error_level=article_ids_rules["error_level"] - ) - yield from validator.pub_type_id_other_is_numeric( - # error_level=article_ids_rules["error_level"] + validator = ArticleDoiValidation(xmltree) + yield from validator.validate_doi_exists( + error_level=article_doi_rules["error_level"] ) - validator = ArticleDoiValidation(xmltree) - yield from validator.validate_doi_exists(error_level=article_doi_rules["error_level"]) - # TODO - # yield from validator.validate_doi_registered( - # callable_get_data=article_doi_rules["doi_api_get"], - # error_level=article_doi_rules["check_deposit_error_level"], - # ) + yield from validator.validate_doi_registered( + callable_get_data=params.get("doi_api_get"), + error_level=article_doi_rules["registered_doi_error_level"], + ) yield from validator.validate_all_dois_are_unique( error_level=article_doi_rules["unique_error_level"] ) @@ -307,11 +296,9 @@ def validate_article_dates(xmltree, params): # TODO required_events depends on article_type required_events = [ - item["type"] - for item in history_dates_rules["date_list"] - if item["required"] + item["type"] for item in history_dates_rules["date_list"] if item["required"] ] - + # FIXME # try: # for related_article in related_articles: @@ -320,10 +307,7 @@ def validate_article_dates(xmltree, params): # ) # except KeyError: # pass - order = [ - item["type"] - for item in history_dates_rules["date_list"] - ] + order = [item["type"] for item in history_dates_rules["date_list"]] yield from validator.validate_history_dates( order=order, required_events=required_events, @@ -350,7 +334,7 @@ def validate_bibliographic_strip(xmltree, params): pagination_rules = params["pagination_rules"] # TODO adicionar error_level, corrigir o nome da classe - # FIXME + # FIXME # File "/Users/roberta.takenaka/github.com/scieloorg/packtools/packtools/packtools/sps/validation/front_articlemeta_issue.py", line 391, in validation_pagination_attributes_exist # yield format_response( # TypeError: format_response() missing 3 required positional arguments: 'parent_article_type', 'parent_lang', and 'error_level' diff --git a/packtools/sps/validation_rules/article_doi_rules.json b/packtools/sps/validation_rules/article_doi_rules.json index 67e5e1e18..e87afafb9 100644 --- a/packtools/sps/validation_rules/article_doi_rules.json +++ b/packtools/sps/validation_rules/article_doi_rules.json @@ -1,8 +1,8 @@ { "article_doi_rules": { "error_level": "ERROR", - "check_deposit_error_level": "ERROR", + "registered_doi_error_level": "ERROR", "unique_error_level": "ERROR", - "translation_doi_error_level": "ERROR" + "translation_doi_error_level": "ERROR", } -} \ No newline at end of file +} diff --git a/tests/sps/validation/test_article_doi.py b/tests/sps/validation/test_article_doi.py index 358a2121e..5f05a76f5 100644 --- a/tests/sps/validation/test_article_doi.py +++ b/tests/sps/validation/test_article_doi.py @@ -1,35 +1,22 @@ import unittest from packtools.sps.utils.xml_utils import get_xml_tree - from packtools.sps.validation.article_doi import ArticleDoiValidation def callable_get_data_ok(doi): return { - 'en': { - 'title': 'Title in English', - 'doi': '10.1590/2176-4573e59270' - }, - 'pt': { - 'title': 'Título em Português', - 'doi': '10.1590/2176-4573p59270' - }, - 'authors': ['Martínez-Momblán, Maria Antonia', 'Colina-Torralva, Javier'] + "en": {"title": "Title in English", "doi": "10.1590/2176-4573e59270"}, + "pt": {"title": "Título em Português", "doi": "10.1590/2176-4573p59270"}, + "authors": ["Martínez-Momblán, Maria Antonia", "Colina-Torralva, Javier"], } def callable_get_data_one_author(doi): return { - 'en': { - 'title': 'Title in English', - 'doi': '10.1590/2176-4573e59270' - }, - 'pt': { - 'title': 'Título em Português', - 'doi': '10.1590/2176-4573p59270' - }, - 'authors': ['Colina-Torralva, Javier'] + "en": {"title": "Title in English", "doi": "10.1590/2176-4573e59270"}, + "pt": {"title": "Título em Português", "doi": "10.1590/2176-4573p59270"}, + "authors": ["Colina-Torralva, Javier"], } @@ -39,26 +26,16 @@ def callable_get_data_not_registered(doi): def callable_get_data_missing_title(doi): return { - 'en': { - 'doi': '10.1590/2176-4573e59270' - }, - 'pt': { - 'doi': '10.1590/2176-4573p59270' - }, - 'authors': ['Martínez-Momblán, Maria Antonia', 'Colina-Torralva, Javier'] + "en": {"doi": "10.1590/2176-4573e59270"}, + "pt": {"doi": "10.1590/2176-4573p59270"}, + "authors": ["Martínez-Momblán, Maria Antonia", "Colina-Torralva, Javier"], } def callable_get_data_missing_authors(doi): return { - 'en': { - 'title': 'Title in English', - 'doi': '10.1590/2176-4573e59270' - }, - 'pt': { - 'title': 'Título em Português', - 'doi': '10.1590/2176-4573p59270' - } + "en": {"title": "Title in English", "doi": "10.1590/2176-4573e59270"}, + "pt": {"title": "Título em Português", "doi": "10.1590/2176-4573p59270"}, } @@ -85,65 +62,65 @@ def test_validate_doi_exists_success(self): obtained = list(ArticleDoiValidation(xml_tree).validate_doi_exists()) expected = [ { - 'title': 'Article DOI element exists', - 'parent': 'article', - 'parent_article_type': 'research-article', - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'OK', - 'expected_value': '10.1590/1518-8345.2927.3231', - 'got_value': '10.1590/1518-8345.2927.3231', - 'message': 'Got 10.1590/1518-8345.2927.3231, expected 10.1590/1518-8345.2927.3231', - 'advice': None, - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': 'research-article', - 'value': '10.1590/1518-8345.2927.3231' + "title": "Article DOI element exists", + "parent": "article", + "parent_article_type": "research-article", + "parent_id": None, + "parent_lang": "en", + "item": "article-id", + "sub_item": '@pub-id-type="doi"', + "validation_type": "exist", + "response": "OK", + "expected_value": "10.1590/1518-8345.2927.3231", + "got_value": "10.1590/1518-8345.2927.3231", + "message": "Got 10.1590/1518-8345.2927.3231, expected 10.1590/1518-8345.2927.3231", + "advice": None, + "data": [ + { + "lang": "en", + "parent": "article", + "parent_article_type": "research-article", + "value": "10.1590/1518-8345.2927.3231", }, { - 'lang': 'pt', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'value': '10.1590/2176-4573e59270' - } + "lang": "pt", + "parent": "sub-article", + "parent_article_type": "translation", + "parent_id": "s1", + "value": "10.1590/2176-4573e59270", + }, ], }, { - 'title': 'Article DOI element exists', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'parent_lang': 'pt', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'OK', - 'expected_value': '10.1590/2176-4573e59270', - 'got_value': '10.1590/2176-4573e59270', - 'message': 'Got 10.1590/2176-4573e59270, expected 10.1590/2176-4573e59270', - 'advice': None, - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': 'research-article', - 'value': '10.1590/1518-8345.2927.3231' + "title": "Article DOI element exists", + "parent": "sub-article", + "parent_article_type": "translation", + "parent_id": "s1", + "parent_lang": "pt", + "item": "article-id", + "sub_item": '@pub-id-type="doi"', + "validation_type": "exist", + "response": "OK", + "expected_value": "10.1590/2176-4573e59270", + "got_value": "10.1590/2176-4573e59270", + "message": "Got 10.1590/2176-4573e59270, expected 10.1590/2176-4573e59270", + "advice": None, + "data": [ + { + "lang": "en", + "parent": "article", + "parent_article_type": "research-article", + "value": "10.1590/1518-8345.2927.3231", }, { - 'lang': 'pt', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'value': '10.1590/2176-4573e59270' - } + "lang": "pt", + "parent": "sub-article", + "parent_article_type": "translation", + "parent_id": "s1", + "value": "10.1590/2176-4573e59270", + }, ], - } + }, ] for i, item in enumerate(expected): with self.subTest(i): @@ -170,66 +147,66 @@ def test_validate_doi_exists_without_article_doi_fail(self): obtained = list(ArticleDoiValidation(xml_tree).validate_doi_exists()) expected = [ { - 'title': 'Article DOI element exists', - 'parent': 'article', - 'parent_article_type': 'research-article', - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'CRITICAL', - 'expected_value': 'article DOI', - 'got_value': None, - 'message': 'Got None, expected article DOI', - 'advice': 'Provide a valid DOI for the article represented by the following tag: ' - '
', - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': 'research-article', - 'value': None + "title": "Article DOI element exists", + "parent": "article", + "parent_article_type": "research-article", + "parent_id": None, + "parent_lang": "en", + "item": "article-id", + "sub_item": '@pub-id-type="doi"', + "validation_type": "exist", + "response": "CRITICAL", + "expected_value": "article DOI", + "got_value": None, + "message": "Got None, expected article DOI", + "advice": "Provide a valid DOI for the article represented by the following tag: " + '
', + "data": [ + { + "lang": "en", + "parent": "article", + "parent_article_type": "research-article", + "value": None, }, { - 'lang': 'pt', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'value': '10.1590/2176-4573e59270' - } + "lang": "pt", + "parent": "sub-article", + "parent_article_type": "translation", + "parent_id": "s1", + "value": "10.1590/2176-4573e59270", + }, ], }, { - 'title': 'Article DOI element exists', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'parent_lang': 'pt', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'OK', - 'expected_value': '10.1590/2176-4573e59270', - 'got_value': '10.1590/2176-4573e59270', - 'message': 'Got 10.1590/2176-4573e59270, expected 10.1590/2176-4573e59270', - 'advice': None, - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': 'research-article', - 'value': None + "title": "Article DOI element exists", + "parent": "sub-article", + "parent_article_type": "translation", + "parent_id": "s1", + "parent_lang": "pt", + "item": "article-id", + "sub_item": '@pub-id-type="doi"', + "validation_type": "exist", + "response": "OK", + "expected_value": "10.1590/2176-4573e59270", + "got_value": "10.1590/2176-4573e59270", + "message": "Got 10.1590/2176-4573e59270, expected 10.1590/2176-4573e59270", + "advice": None, + "data": [ + { + "lang": "en", + "parent": "article", + "parent_article_type": "research-article", + "value": None, }, { - 'lang': 'pt', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'value': '10.1590/2176-4573e59270' - } + "lang": "pt", + "parent": "sub-article", + "parent_article_type": "translation", + "parent_id": "s1", + "value": "10.1590/2176-4573e59270", + }, ], - } + }, ] for i, item in enumerate(expected): with self.subTest(i): @@ -257,66 +234,66 @@ def test_validate_doi_exists_without_sub_article_doi_fail(self): obtained = list(ArticleDoiValidation(xml_tree).validate_doi_exists()) expected = [ { - 'title': 'Article DOI element exists', - 'parent': 'article', - 'parent_article_type': 'research-article', - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'OK', - 'expected_value': '10.1590/1518-8345.2927.3231', - 'got_value': '10.1590/1518-8345.2927.3231', - 'message': 'Got 10.1590/1518-8345.2927.3231, expected 10.1590/1518-8345.2927.3231', - 'advice': None, - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': 'research-article', - 'value': '10.1590/1518-8345.2927.3231' + "title": "Article DOI element exists", + "parent": "article", + "parent_article_type": "research-article", + "parent_id": None, + "parent_lang": "en", + "item": "article-id", + "sub_item": '@pub-id-type="doi"', + "validation_type": "exist", + "response": "OK", + "expected_value": "10.1590/1518-8345.2927.3231", + "got_value": "10.1590/1518-8345.2927.3231", + "message": "Got 10.1590/1518-8345.2927.3231, expected 10.1590/1518-8345.2927.3231", + "advice": None, + "data": [ + { + "lang": "en", + "parent": "article", + "parent_article_type": "research-article", + "value": "10.1590/1518-8345.2927.3231", }, { - 'lang': 'pt', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'value': None - } + "lang": "pt", + "parent": "sub-article", + "parent_article_type": "translation", + "parent_id": "s1", + "value": None, + }, ], }, { - 'title': 'Article DOI element exists', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'parent_lang': 'pt', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'CRITICAL', - 'expected_value': 'article DOI', - 'got_value': None, - 'message': 'Got None, expected article DOI', - 'advice': 'Provide a valid DOI for the sub-article represented by the following tag: ' - '', - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': 'research-article', - 'value': '10.1590/1518-8345.2927.3231' + "title": "Article DOI element exists", + "parent": "sub-article", + "parent_article_type": "translation", + "parent_id": "s1", + "parent_lang": "pt", + "item": "article-id", + "sub_item": '@pub-id-type="doi"', + "validation_type": "exist", + "response": "CRITICAL", + "expected_value": "article DOI", + "got_value": None, + "message": "Got None, expected article DOI", + "advice": "Provide a valid DOI for the sub-article represented by the following tag: " + '', + "data": [ + { + "lang": "en", + "parent": "article", + "parent_article_type": "research-article", + "value": "10.1590/1518-8345.2927.3231", }, { - 'lang': 'pt', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'value': None - } + "lang": "pt", + "parent": "sub-article", + "parent_article_type": "translation", + "parent_id": "s1", + "value": None, + }, ], - } + }, ] for i, item in enumerate(expected): with self.subTest(i): @@ -344,67 +321,67 @@ def test_validate_doi_exists_fail(self): obtained = list(ArticleDoiValidation(xml_tree).validate_doi_exists()) expected = [ { - 'title': 'Article DOI element exists', - 'parent': 'article', - 'parent_article_type': 'research-article', - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'CRITICAL', - 'expected_value': 'article DOI', - 'got_value': None, - 'message': 'Got None, expected article DOI', - 'advice': 'Provide a valid DOI for the article represented by the following tag: ' - '
', - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': 'research-article', - 'value': None + "title": "Article DOI element exists", + "parent": "article", + "parent_article_type": "research-article", + "parent_id": None, + "parent_lang": "en", + "item": "article-id", + "sub_item": '@pub-id-type="doi"', + "validation_type": "exist", + "response": "CRITICAL", + "expected_value": "article DOI", + "got_value": None, + "message": "Got None, expected article DOI", + "advice": "Provide a valid DOI for the article represented by the following tag: " + '
', + "data": [ + { + "lang": "en", + "parent": "article", + "parent_article_type": "research-article", + "value": None, }, { - 'lang': 'pt', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'value': None - } + "lang": "pt", + "parent": "sub-article", + "parent_article_type": "translation", + "parent_id": "s1", + "value": None, + }, ], }, { - 'title': 'Article DOI element exists', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'parent_lang': 'pt', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'CRITICAL', - 'expected_value': 'article DOI', - 'got_value': None, - 'message': 'Got None, expected article DOI', - 'advice': 'Provide a valid DOI for the sub-article represented by the following tag: ' - '', - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': 'research-article', - 'value': None + "title": "Article DOI element exists", + "parent": "sub-article", + "parent_article_type": "translation", + "parent_id": "s1", + "parent_lang": "pt", + "item": "article-id", + "sub_item": '@pub-id-type="doi"', + "validation_type": "exist", + "response": "CRITICAL", + "expected_value": "article DOI", + "got_value": None, + "message": "Got None, expected article DOI", + "advice": "Provide a valid DOI for the sub-article represented by the following tag: " + '', + "data": [ + { + "lang": "en", + "parent": "article", + "parent_article_type": "research-article", + "value": None, }, { - 'lang': 'pt', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'value': None - } + "lang": "pt", + "parent": "sub-article", + "parent_article_type": "translation", + "parent_id": "s1", + "value": None, + }, ], - } + }, ] for i, item in enumerate(expected): with self.subTest(i): @@ -435,33 +412,33 @@ def test_validate_all_dois_are_unique(self): expected = [ { - 'title': 'Article DOI element is unique', - 'parent': 'article', - 'parent_article_type': 'research-article', - 'parent_id': None, - 'parent_lang': 'pt', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'unique', - 'response': 'OK', - 'expected_value': 'Unique DOI values', - 'got_value': ['10.1590/2176-4573p59270', '10.1590/2176-4573e59270'], - 'message': "Got ['10.1590/2176-4573p59270', '10.1590/2176-4573e59270'], expected Unique DOI values", - 'advice': None, - 'data': [ - { - 'lang': 'pt', - 'parent': 'article', - 'parent_article_type': 'research-article', - 'value': '10.1590/2176-4573p59270' + "title": "Article DOI element is unique", + "parent": "article", + "parent_article_type": "research-article", + "parent_id": None, + "parent_lang": "pt", + "item": "article-id", + "sub_item": '@pub-id-type="doi"', + "validation_type": "unique", + "response": "OK", + "expected_value": "Unique DOI values", + "got_value": ["10.1590/2176-4573p59270", "10.1590/2176-4573e59270"], + "message": "Got ['10.1590/2176-4573p59270', '10.1590/2176-4573e59270'], expected Unique DOI values", + "advice": None, + "data": [ + { + "lang": "pt", + "parent": "article", + "parent_article_type": "research-article", + "value": "10.1590/2176-4573p59270", }, { - 'lang': 'en', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'value': '10.1590/2176-4573e59270' - } + "lang": "en", + "parent": "sub-article", + "parent_article_type": "translation", + "parent_id": "s1", + "value": "10.1590/2176-4573e59270", + }, ], } ] @@ -502,45 +479,47 @@ def test_validate_all_dois_are_not_unique(self): expected = [ { - 'title': 'Article DOI element is unique', - 'parent': 'article', - 'parent_article_type': 'research-article', - 'parent_id': None, - 'parent_lang': 'pt', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'unique', - 'response': 'CRITICAL', - 'expected_value': 'Unique DOI values', - 'got_value': ['10.1590/2176-4573p59270', '10.1590/2176-4573e59270'], - 'message': "Got ['10.1590/2176-4573p59270', '10.1590/2176-4573e59270'], expected Unique DOI values", - 'advice': 'Consider replacing the following DOIs that are not unique: 10.1590/2176-4573e59270', - 'data': [ - { - 'lang': 'pt', - 'parent': 'article', - 'parent_article_type': 'research-article', - 'value': '10.1590/2176-4573p59270' + "title": "Article DOI element is unique", + "parent": "article", + "parent_article_type": "research-article", + "parent_id": None, + "parent_lang": "pt", + "item": "article-id", + "sub_item": '@pub-id-type="doi"', + "validation_type": "unique", + "response": "CRITICAL", + "expected_value": "Unique DOI values", + "got_value": ["10.1590/2176-4573p59270", "10.1590/2176-4573e59270"], + "message": "Got ['10.1590/2176-4573p59270', '10.1590/2176-4573e59270'], expected Unique DOI values", + "advice": "Consider replacing the following DOIs that are not unique: 10.1590/2176-4573e59270", + "data": [ + { + "lang": "pt", + "parent": "article", + "parent_article_type": "research-article", + "value": "10.1590/2176-4573p59270", }, { - 'lang': 'fr', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's2', - 'value': '10.1590/2176-4573e59270'}, + "lang": "fr", + "parent": "sub-article", + "parent_article_type": "translation", + "parent_id": "s2", + "value": "10.1590/2176-4573e59270", + }, { - 'lang': 'es', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's3', - 'value': '10.1590/2176-4573e59270'}, + "lang": "es", + "parent": "sub-article", + "parent_article_type": "translation", + "parent_id": "s3", + "value": "10.1590/2176-4573e59270", + }, { - 'lang': 'en', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'value': '10.1590/2176-4573e59270' - } + "lang": "en", + "parent": "sub-article", + "parent_article_type": "translation", + "parent_id": "s1", + "value": "10.1590/2176-4573e59270", + }, ], } ] @@ -599,252 +578,70 @@ def test_validate_doi_registered_success(self):
""" xml_tree = get_xml_tree(xml_str) - obtained = list(ArticleDoiValidation(xml_tree).validate_doi_registered( - callable_get_data_ok - )) + obtained = list( + ArticleDoiValidation(xml_tree).validate_doi_registered(callable_get_data_ok) + ) + xml = { + "title": "Title in English", + "authors": [ + "Martínez-Momblán, Maria Antonia", + "Colina-Torralva, Javier", + ], + } + xml2 = { + "title": "Título em Português", + "authors": [ + "Martínez-Momblán, Maria Antonia", + "Colina-Torralva, Javier", + ], + } expected = [ { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'OK', - 'expected_value': '10.1590/2176-4573e59270', - 'got_value': '10.1590/2176-4573e59270', - 'message': 'Got 10.1590/2176-4573e59270, expected 10.1590/2176-4573e59270', - 'advice': None, - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59270' - }, - { - 'lang': 'pt', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'value': '10.1590/2176-4573p59270' - } - ], - }, - { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'OK', - 'expected_value': 'Title in English', - 'got_value': 'Title in English', - 'message': 'Got Title in English, expected Title in English', - 'advice': None, - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59270' - }, - { - 'lang': 'pt', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'value': '10.1590/2176-4573p59270' - } - ], - }, - { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'OK', - 'expected_value': 'Martínez-Momblán, Maria Antonia', - 'got_value': 'Martínez-Momblán, Maria Antonia', - 'message': 'Got Martínez-Momblán, Maria Antonia, expected Martínez-Momblán, Maria Antonia', - 'advice': None, - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59270' - }, - { - 'lang': 'pt', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'value': '10.1590/2176-4573p59270' - } - ], - }, - { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'OK', - 'expected_value': 'Colina-Torralva, Javier', - 'got_value': 'Colina-Torralva, Javier', - 'message': 'Got Colina-Torralva, Javier, expected Colina-Torralva, Javier', - 'advice': None, - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59270' - }, - { - 'lang': 'pt', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'value': '10.1590/2176-4573p59270' - } - ], - }, - { - 'title': 'Article DOI is registered', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'parent_lang': 'pt', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'OK', - 'expected_value': '10.1590/2176-4573p59270', - 'got_value': '10.1590/2176-4573p59270', - 'message': 'Got 10.1590/2176-4573p59270, expected 10.1590/2176-4573p59270', - 'advice': None, - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59270' - }, - { - 'lang': 'pt', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'value': '10.1590/2176-4573p59270' - } - ], - }, - { - 'title': 'Article DOI is registered', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'parent_lang': 'pt', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'OK', - 'expected_value': 'Título em Português', - 'got_value': 'Título em Português', - 'message': 'Got Título em Português, expected Título em Português', - 'advice': None, - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59270' - }, - { - 'lang': 'pt', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'value': '10.1590/2176-4573p59270' - } - ], + "title": "Registered DOI", + "parent": "article", + "parent_article_type": None, + "parent_id": None, + "parent_lang": "en", + "item": "article-id", + "sub_item": '@pub-id-type="doi"', + "validation_type": "registered", + "response": "OK", + "expected_value": xml, + "got_value": xml, + "message": f"Got {xml}, expected {xml}", + "advice": None, + "data": { + "similarity": 1.0, + "lang": "en", + "parent": "article", + "parent_article_type": None, + "value": "10.1590/2176-4573e59270", + }, }, { - 'title': 'Article DOI is registered', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'parent_lang': 'pt', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'OK', - 'expected_value': 'Martínez-Momblán, Maria Antonia', - 'got_value': 'Martínez-Momblán, Maria Antonia', - 'message': 'Got Martínez-Momblán, Maria Antonia, expected Martínez-Momblán, Maria Antonia', - 'advice': None, - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59270' - }, - { - 'lang': 'pt', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'value': '10.1590/2176-4573p59270' - } - ], + "title": "Registered DOI", + "parent": "sub-article", + "parent_article_type": "translation", + "parent_id": "s1", + "parent_lang": "pt", + "item": "article-id", + "sub_item": '@pub-id-type="doi"', + "validation_type": "registered", + "response": "OK", + "expected_value": xml2, + "got_value": xml2, + "message": f"Got {xml2}, expected {xml2}", + "advice": None, + "data": { + "similarity": 1.0, + "lang": "pt", + "parent": "sub-article", + "parent_article_type": "translation", + "parent_id": "s1", + "value": "10.1590/2176-4573p59270", + }, }, - { - 'title': 'Article DOI is registered', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'parent_lang': 'pt', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'OK', - 'expected_value': 'Colina-Torralva, Javier', - 'got_value': 'Colina-Torralva, Javier', - 'message': 'Got Colina-Torralva, Javier, expected Colina-Torralva, Javier', - 'advice': None, - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59270' - }, - { - 'lang': 'pt', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'value': '10.1590/2176-4573p59270' - } - ], - } - ] for i, item in enumerate(expected): with self.subTest(i): @@ -901,75 +698,76 @@ def test_validate_doi_registered_doi_is_not_registered(self):
""" xml_tree = get_xml_tree(xml_str) - obtained = list(ArticleDoiValidation(xml_tree).validate_doi_registered( - callable_get_data_not_registered - )) + obtained = list( + ArticleDoiValidation(xml_tree).validate_doi_registered( + callable_get_data_not_registered + ) + ) + + xml = { + "title": "Title in English", + "authors": [ + "Martínez-Momblán, Maria Antonia", + "Colina-Torralva, Javier", + ], + } + registered = None + xml2 = { + "title": "Título em Português", + "authors": [ + "Martínez-Momblán, Maria Antonia", + "Colina-Torralva, Javier", + ], + } expected = [ { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'CRITICAL', - 'expected_value': 'Data registered to the DOI 10.1590/2176-4573e59270', - 'got_value': None, - 'message': 'Got None, expected Data registered to the DOI 10.1590/2176-4573e59270', - 'advice': 'Consult again after DOI has been registered', - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59270' - }, - { - 'lang': 'pt', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'value': '10.1590/2176-4573p59270' - } - ], + "title": "Registered DOI", + "parent": "article", + "parent_article_type": None, + "parent_id": None, + "parent_lang": "en", + "item": "article-id", + "sub_item": '@pub-id-type="doi"', + "validation_type": "registered", + "response": "CRITICAL", + "expected_value": "Data registered to the DOI 10.1590/2176-4573e59270", + "got_value": xml, + "message": f"Got {xml}, expected Data registered to the DOI 10.1590/2176-4573e59270", + "advice": "Consult again after DOI has been registered", + "data": { + "lang": "en", + "parent": "article", + "parent_article_type": None, + "value": "10.1590/2176-4573e59270", + }, }, { - 'title': 'Article DOI is registered', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'parent_lang': 'pt', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'CRITICAL', - 'expected_value': 'Data registered to the DOI 10.1590/2176-4573p59270', - 'got_value': None, - 'message': 'Got None, expected Data registered to the DOI 10.1590/2176-4573p59270', - 'advice': 'Consult again after DOI has been registered', - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59270' - }, - { - 'lang': 'pt', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'value': '10.1590/2176-4573p59270' - } - ], - } + "title": "Registered DOI", + "parent": "sub-article", + "parent_article_type": "translation", + "parent_id": "s1", + "parent_lang": "pt", + "item": "article-id", + "sub_item": '@pub-id-type="doi"', + "validation_type": "registered", + "response": "CRITICAL", + "expected_value": "Data registered to the DOI 10.1590/2176-4573p59270", + "got_value": xml2, + "message": f"Got {xml2}, expected Data registered to the DOI 10.1590/2176-4573p59270", + "advice": "Consult again after DOI has been registered", + "data": { + "lang": "pt", + "parent": "sub-article", + "parent_article_type": "translation", + "parent_id": "s1", + "value": "10.1590/2176-4573p59270", + }, + }, ] for i, item in enumerate(expected): with self.subTest(i): - self.assertDictEqual(obtained[i], item) + self.assertDictEqual(item, obtained[i]) def test_validate_doi_registered_only_doi_is_correct(self): self.maxDiff = None @@ -1000,105 +798,40 @@ def test_validate_doi_registered_only_doi_is_correct(self):
""" xml_tree = get_xml_tree(xml_str) - obtained = list(ArticleDoiValidation(xml_tree).validate_doi_registered( - callable_get_data_ok - )) + obtained = list( + ArticleDoiValidation(xml_tree).validate_doi_registered(callable_get_data_ok) + ) + xml = { + "title": "Title English", + "authors": ["Martínez, Maria Antonia", "Colina, Javier"], + } + registered = { + "title": "Title in English", + "authors": ["Martínez-Momblán, Maria Antonia", "Colina-Torralva, Javier"], + } expected = [ { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'OK', - 'expected_value': '10.1590/2176-4573e59270', - 'got_value': '10.1590/2176-4573e59270', - 'message': 'Got 10.1590/2176-4573e59270, expected 10.1590/2176-4573e59270', - 'advice': None, - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59270' - } - ], - }, - { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'CRITICAL', - 'expected_value': 'Title in English', - 'got_value': 'Title English', - 'message': 'Got Title English, expected Title in English', - 'advice': 'DOI not registered or validator not found, provide a value for title element that ' - 'matches the record for DOI.', - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59270' - } - ], - }, - { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'CRITICAL', - 'expected_value': 'Martínez-Momblán, Maria Antonia', - 'got_value': 'Martínez, Maria Antonia', - 'message': 'Got Martínez, Maria Antonia, expected Martínez-Momblán, Maria Antonia', - 'advice': 'DOI not registered or validator not found, provide a value for author element that ' - 'matches the record for DOI.', - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59270' - } - ], - }, - { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'CRITICAL', - 'expected_value': 'Colina-Torralva, Javier', - 'got_value': 'Colina, Javier', - 'message': 'Got Colina, Javier, expected Colina-Torralva, Javier', - 'advice': 'DOI not registered or validator not found, provide a value for author element that ' - 'matches the record for DOI.', - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59270' - } - ], + "title": "Registered DOI", + "parent": "article", + "parent_article_type": None, + "parent_id": None, + "parent_lang": "en", + "item": "article-id", + "sub_item": '@pub-id-type="doi"', + "validation_type": "registered", + "response": "CRITICAL", + "expected_value": registered, + "got_value": xml, + "message": f"Got {xml}, expected {registered}", + "advice": "Check the DOI number", + "data": { + "similarity": 0.8936170212765957, + "lang": "en", + "parent": "article", + "parent_article_type": None, + "value": "10.1590/2176-4573e59270", + }, } ] for i, item in enumerate(expected): @@ -1134,105 +867,39 @@ def test_validate_doi_registered_only_title_is_correct(self):
""" xml_tree = get_xml_tree(xml_str) - obtained = list(ArticleDoiValidation(xml_tree).validate_doi_registered( - callable_get_data_ok - )) - + obtained = list( + ArticleDoiValidation(xml_tree).validate_doi_registered(callable_get_data_ok) + ) + xml = { + "title": "Title in English", + "authors": ["Martínez, Maria Antonia", "Colina, Javier"], + } + registered = { + "title": "Title in English", + "authors": ["Martínez-Momblán, Maria Antonia", "Colina-Torralva, Javier"], + } expected = [ { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'CRITICAL', - 'expected_value': '10.1590/2176-4573e59270', - 'got_value': '10.1590/2176-4573e59271', - 'message': 'Got 10.1590/2176-4573e59271, expected 10.1590/2176-4573e59270', - 'advice': 'DOI not registered or validator not found, provide a value for doi element that ' - 'matches the record for DOI.', - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59271' - } - ], - }, - { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'OK', - 'expected_value': 'Title in English', - 'got_value': 'Title in English', - 'message': 'Got Title in English, expected Title in English', - 'advice': None, - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59271' - } - ], - }, - { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'CRITICAL', - 'expected_value': 'Martínez-Momblán, Maria Antonia', - 'got_value': 'Martínez, Maria Antonia', - 'message': 'Got Martínez, Maria Antonia, expected Martínez-Momblán, Maria Antonia', - 'advice': 'DOI not registered or validator not found, provide a value for author element that ' - 'matches the record for DOI.', - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59271' - } - ], - }, - { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'CRITICAL', - 'expected_value': 'Colina-Torralva, Javier', - 'got_value': 'Colina, Javier', - 'message': 'Got Colina, Javier, expected Colina-Torralva, Javier', - 'advice': 'DOI not registered or validator not found, provide a value for author element that ' - 'matches the record for DOI.', - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59271' - } - ], + "title": "Registered DOI", + "parent": "article", + "parent_article_type": None, + "parent_id": None, + "parent_lang": "en", + "item": "article-id", + "sub_item": '@pub-id-type="doi"', + "validation_type": "registered", + "response": "CRITICAL", + "expected_value": registered, + "got_value": xml, + "message": f"Got {xml}, expected {registered}", + "advice": "Check the DOI number", + "data": { + "similarity": 0.9109947643979057, + "lang": "en", + "parent": "article", + "parent_article_type": None, + "value": "10.1590/2176-4573e59271", + }, } ] for i, item in enumerate(expected): @@ -1268,105 +935,40 @@ def test_validate_doi_registered_only_one_author_is_correct(self): """ xml_tree = get_xml_tree(xml_str) - obtained = list(ArticleDoiValidation(xml_tree).validate_doi_registered( - callable_get_data_ok - )) - + obtained = list( + ArticleDoiValidation(xml_tree).validate_doi_registered(callable_get_data_ok) + ) + # TODO + xml = { + "title": "Title English", + "authors": ["Martínez, Maria Antonia", "Colina-Torralva, Javier"], + } + registered = { + "title": "Title in English", + "authors": ["Martínez-Momblán, Maria Antonia", "Colina-Torralva, Javier"], + } expected = [ { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'CRITICAL', - 'expected_value': '10.1590/2176-4573e59270', - 'got_value': '10.1590/2176-4573e59271', - 'message': 'Got 10.1590/2176-4573e59271, expected 10.1590/2176-4573e59270', - 'advice': 'DOI not registered or validator not found, provide a value for doi element that ' - 'matches the record for DOI.', - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59271' - } - ], - }, - { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'CRITICAL', - 'expected_value': 'Title in English', - 'got_value': 'Title English', - 'message': 'Got Title English, expected Title in English', - 'advice': 'DOI not registered or validator not found, provide a value for title element that ' - 'matches the record for DOI.', - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59271' - } - ], - }, - { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'CRITICAL', - 'expected_value': 'Martínez-Momblán, Maria Antonia', - 'got_value': 'Martínez, Maria Antonia', - 'message': 'Got Martínez, Maria Antonia, expected Martínez-Momblán, Maria Antonia', - 'advice': 'DOI not registered or validator not found, provide a value for author element that ' - 'matches the record for DOI.', - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59271' - } - ], - }, - { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'OK', - 'expected_value': 'Colina-Torralva, Javier', - 'got_value': 'Colina-Torralva, Javier', - 'message': 'Got Colina-Torralva, Javier, expected Colina-Torralva, Javier', - 'advice': None, - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59271' - } - ], + "title": "Registered DOI", + "parent": "article", + "parent_article_type": None, + "parent_id": None, + "parent_lang": "en", + "item": "article-id", + "sub_item": '@pub-id-type="doi"', + "validation_type": "registered", + "response": "CRITICAL", + "expected_value": registered, + "got_value": xml, + "message": f"Got {xml}, expected {registered}", + "advice": "Check the DOI number", + "data": { + "similarity": 0.9441624365482234, + "lang": "en", + "parent": "article", + "parent_article_type": None, + "value": "10.1590/2176-4573e59271", + }, } ] for i, item in enumerate(expected): @@ -1402,79 +1004,41 @@ def test_validate_doi_registered_no_expected_authors(self): """ xml_tree = get_xml_tree(xml_str) - obtained = list(ArticleDoiValidation(xml_tree).validate_doi_registered( - callable_get_data_missing_authors - )) - + obtained = list( + ArticleDoiValidation(xml_tree).validate_doi_registered( + callable_get_data_missing_authors + ) + ) + xml = { + "title": "Title in English", + "authors": ["Martínez-Momblán, Maria Antonia", "Colina-Torralva, Javier"], + } + registered = { + "title": "Title in English", + "authors": [], + } expected = [ { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'OK', - 'expected_value': '10.1590/2176-4573e59270', - 'got_value': '10.1590/2176-4573e59270', - 'message': 'Got 10.1590/2176-4573e59270, expected 10.1590/2176-4573e59270', - 'advice': None, - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59270' - } - ], - }, - { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'OK', - 'expected_value': 'Title in English', - 'got_value': 'Title in English', - 'message': 'Got Title in English, expected Title in English', - 'advice': None, - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59270' - } - ], - }, - { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'CRITICAL', - 'expected_value': [], - 'got_value': ['Martínez-Momblán, Maria Antonia', 'Colina-Torralva, Javier'], - 'message': 'The following items are surplus in the XML: Martínez-Momblán, Maria Antonia | Colina-Torralva, Javier', - 'advice': 'Remove the following items from the XML: Martínez-Momblán, Maria Antonia | Colina-Torralva, Javier', - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59270' - } - ], + "title": "Registered DOI", + "parent": "article", + "parent_article_type": None, + "parent_id": None, + "parent_lang": "en", + "item": "article-id", + "sub_item": '@pub-id-type="doi"', + "validation_type": "registered", + "response": "CRITICAL", + "expected_value": registered, + "got_value": xml, + "message": f"Got {xml}, expected {registered}", + "advice": "Check the DOI number", + "data": { + "similarity": 0.5945945945945946, + "lang": "en", + "parent": "article", + "parent_article_type": None, + "value": "10.1590/2176-4573e59270", + }, } ] for i, item in enumerate(expected): @@ -1496,79 +1060,40 @@ def test_validate_doi_registered_no_obtained_authors(self): """ xml_tree = get_xml_tree(xml_str) - obtained = list(ArticleDoiValidation(xml_tree).validate_doi_registered( - callable_get_data_ok - )) - + obtained = list( + ArticleDoiValidation(xml_tree).validate_doi_registered(callable_get_data_ok) + ) + # TODO + xml = { + "title": "Title in English", + "authors": [], + } + registered = { + "title": "Title in English", + "authors": ["Martínez-Momblán, Maria Antonia", "Colina-Torralva, Javier"], + } expected = [ { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'OK', - 'expected_value': '10.1590/2176-4573e59270', - 'got_value': '10.1590/2176-4573e59270', - 'message': 'Got 10.1590/2176-4573e59270, expected 10.1590/2176-4573e59270', - 'advice': None, - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59270' - } - ], - }, - { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'OK', - 'expected_value': 'Title in English', - 'got_value': 'Title in English', - 'message': 'Got Title in English, expected Title in English', - 'advice': None, - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59270' - } - ], - }, - { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'CRITICAL', - 'expected_value': ['Martínez-Momblán, Maria Antonia', 'Colina-Torralva, Javier'], - 'got_value': [], - 'message': 'The following items are not found in the XML: Martínez-Momblán, Maria Antonia | Colina-Torralva, Javier', - 'advice': 'Complete the following items in the XML: Martínez-Momblán, Maria Antonia | Colina-Torralva, Javier', - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59270' - } - ], + "title": "Registered DOI", + "parent": "article", + "parent_article_type": None, + "parent_id": None, + "parent_lang": "en", + "item": "article-id", + "sub_item": '@pub-id-type="doi"', + "validation_type": "registered", + "response": "CRITICAL", + "expected_value": registered, + "got_value": xml, + "message": f"Got {xml}, expected {registered}", + "advice": "Check the DOI number", + "data": { + "similarity": 0.5945945945945946, + "lang": "en", + "parent": "article", + "parent_article_type": None, + "value": "10.1590/2176-4573e59270", + }, } ] for i, item in enumerate(expected): @@ -1604,103 +1129,45 @@ def test_validate_doi_registered_expected_one_author_obtained_two_authors(self): """ xml_tree = get_xml_tree(xml_str) - obtained = list(ArticleDoiValidation(xml_tree).validate_doi_registered( - callable_get_data_one_author - )) + obtained = list( + ArticleDoiValidation(xml_tree).validate_doi_registered( + callable_get_data_one_author + ) + ) + xml = { + "title": "Title in English", + "authors": [ + "Martínez-Momblán, Maria Antonia", + "Colina-Torralva, Javier", + ], + } + registered = { + "title": "Title in English", + "authors": ["Colina-Torralva, Javier"], + } expected = [ { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'OK', - 'expected_value': '10.1590/2176-4573e59270', - 'got_value': '10.1590/2176-4573e59270', - 'message': 'Got 10.1590/2176-4573e59270, expected 10.1590/2176-4573e59270', - 'advice': None, - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59270' - } - ], - }, - { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'OK', - 'expected_value': 'Title in English', - 'got_value': 'Title in English', - 'message': 'Got Title in English, expected Title in English', - 'advice': None, - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59270' - } - ], - }, - { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'CRITICAL', - 'expected_value': 'Colina-Torralva, Javier', - 'got_value': 'Martínez-Momblán, Maria Antonia', - 'message': 'Got Martínez-Momblán, Maria Antonia, expected Colina-Torralva, Javier', - 'advice': 'DOI not registered or validator not found, provide a value for author element that ' - 'matches the record for DOI.', - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59270' - } - ], - }, - { - 'title': 'Article DOI is registered', - 'parent': 'article', - 'parent_article_type': None, - 'parent_id': None, - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'exist', - 'response': 'CRITICAL', - 'expected_value': ['Colina-Torralva, Javier'], - 'got_value': ['Martínez-Momblán, Maria Antonia', 'Colina-Torralva, Javier'], - 'message': 'The following items are surplus in the XML: Colina-Torralva, Javier', - 'advice': 'Remove the following items from the XML: Colina-Torralva, Javier', - 'data': [ - { - 'lang': 'en', - 'parent': 'article', - 'parent_article_type': None, - 'value': '10.1590/2176-4573e59270' - } - ], + "title": "Registered DOI", + "parent": "article", + "parent_article_type": None, + "parent_id": None, + "parent_lang": "en", + "item": "article-id", + "sub_item": '@pub-id-type="doi"', + "validation_type": "registered", + "response": "CRITICAL", + "expected_value": registered, + "got_value": xml, + "message": f"Got {xml}, expected {registered}", + "advice": "Check the DOI number", + "data": { + "similarity": 0.7976878612716763, + "lang": "en", + "parent": "article", + "parent_article_type": None, + "value": "10.1590/2176-4573e59270", + }, } ] for i, item in enumerate(expected): @@ -1728,37 +1195,39 @@ def test_validate_different_doi_in_translation(self): """ xml_tree = get_xml_tree(xml_str) - obtained = list(ArticleDoiValidation(xml_tree).validate_different_doi_in_translation()) + obtained = list( + ArticleDoiValidation(xml_tree).validate_different_doi_in_translation() + ) expected = [ { - 'title': 'Different DOIs for tranaltions', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'parent_lang': 'en', - 'item': 'article-id', - 'sub_item': '@pub-id-type="doi"', - 'validation_type': 'match', - 'response': 'WARNING', - 'expected_value': 'use unique DOIs for articles and sub-articles', - 'got_value': 'article DOI: 10.1590/2176-4573p59270, sub-article DOI: 10.1590/2176-4573p59270', - 'message': 'Got article DOI: 10.1590/2176-4573p59270, sub-article DOI: 10.1590/2176-4573p59270, ' - 'expected use unique DOIs for articles and sub-articles', - 'advice': 'consider using different DOIs for article and sub-article', - 'data': [ - { - 'lang': 'pt', - 'parent': 'article', - 'parent_article_type': 'research-article', - 'value': '10.1590/2176-4573p59270' + "title": "Different DOIs for tranaltions", + "parent": "sub-article", + "parent_article_type": "translation", + "parent_id": "s1", + "parent_lang": "en", + "item": "article-id", + "sub_item": '@pub-id-type="doi"', + "validation_type": "match", + "response": "WARNING", + "expected_value": "use unique DOIs for articles and sub-articles", + "got_value": "article DOI: 10.1590/2176-4573p59270, sub-article DOI: 10.1590/2176-4573p59270", + "message": "Got article DOI: 10.1590/2176-4573p59270, sub-article DOI: 10.1590/2176-4573p59270, " + "expected use unique DOIs for articles and sub-articles", + "advice": "consider using different DOIs for article and sub-article", + "data": [ + { + "lang": "pt", + "parent": "article", + "parent_article_type": "research-article", + "value": "10.1590/2176-4573p59270", }, { - 'lang': 'en', - 'parent': 'sub-article', - 'parent_article_type': 'translation', - 'parent_id': 's1', - 'value': '10.1590/2176-4573p59270' - } + "lang": "en", + "parent": "sub-article", + "parent_article_type": "translation", + "parent_id": "s1", + "value": "10.1590/2176-4573p59270", + }, ], } ] @@ -1767,5 +1236,5 @@ def test_validate_different_doi_in_translation(self): self.assertDictEqual(obtained[i], item) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/tests/sps/validation/test_article_ids.py b/tests/sps/validation/test_article_ids.py deleted file mode 100644 index 6f767c253..000000000 --- a/tests/sps/validation/test_article_ids.py +++ /dev/null @@ -1,83 +0,0 @@ -from unittest import TestCase -from lxml import etree - -from packtools.sps.validation.article_ids import ArticleIdsValidation - - -class ArticleIdValidationTest(TestCase): - def test_pub_type_id_other_has_five_digits(self): - self.maxDiff = None - xml_tree = etree.fromstring( - """ -
- - - 1234 - - -
- """ - ) - obtained = list(ArticleIdsValidation(xml_tree).pub_type_id_other_has_five_digits()) - expected = [ - { - "advice": "Provide a value with five digits for ", - "data": None, - "expected_value": "Five digits", - "got_value": "1234", - "item": "article-id", - "message": "Got 1234, expected Five digits", - "parent": "article", - "parent_article_type": "research-article", - "parent_id": None, - "parent_lang": "pt", - "response": "ERROR", - "sub_item": "@pub-id-type='other'", - "title": "pub-type-id=other has five digits", - "validation_type": "format", - } - - ] - for i, item in enumerate(expected): - with self.subTest(i): - self.assertDictEqual(obtained[i], item) - - def test_pub_type_id_other_is_numeric(self): - self.maxDiff = None - xml_tree = etree.fromstring( - """ -
- - - abcd - - -
- """ - ) - obtained = list(ArticleIdsValidation(xml_tree).pub_type_id_other_is_numeric()) - expected = [ - { - "advice": "Provide a numeric value for ", - "data": None, - "expected_value": "numeric value", - "got_value": "abcd", - "item": "article-id", - "message": "Got abcd, expected numeric value", - "parent": "article", - "parent_article_type": "research-article", - "parent_id": None, - "parent_lang": "pt", - "response": "ERROR", - "sub_item": "@pub-id-type='other'", - "title": "pub-type-id=other is numeric", - "validation_type": "format", - } - ] - for i, item in enumerate(expected): - with self.subTest(i): - self.assertDictEqual(obtained[i], item) - -