diff --git a/publication/utils/document.py b/publication/utils/document.py index 8331747ee..25e9e9aaa 100644 --- a/publication/utils/document.py +++ b/publication/utils/document.py @@ -169,7 +169,7 @@ def get_abstracts(self): continue yield {"language": lang, "text": text} except Exception as e: - return [] + return def get_keywords(self): for lang, keywords in ( diff --git a/publication/utils/test_document.py b/publication/utils/test_document.py index 3509c8d7b..9b999f212 100644 --- a/publication/utils/test_document.py +++ b/publication/utils/test_document.py @@ -110,3 +110,98 @@ def test_get_contribs_with_no_contribs(self): self.assertEqual(result["names"], []) self.assertEqual(result["collabs"], []) + + +class XMLArticleGetAbstractsTest(TestCase): + def test_get_abstracts_with_p_tag(self): + xml_string = """
+ + + + Abstract +

Simple abstract with a p tag.

+
+ + Resumo +

Resumo simples com uma tag p.

+
+
+
+
""" + + article_xml = _create_xml_article(xml_string) + result = list(article_xml.get_abstracts()) + + self.assertEqual( + result, + [ + {"language": "en", "text": "Simple abstract with a p tag."}, + {"language": "pt", "text": "Resumo simples com uma tag p."}, + ], + ) + + def test_get_abstracts_with_sections(self): + xml_string = """
+ + + + Abstract + Objective:

obj text.

+ Method:

method text.

+
+
+
+
""" + + article_xml = _create_xml_article(xml_string) + result = list(article_xml.get_abstracts()) + + self.assertEqual(len(result), 1) + self.assertEqual(result[0]["language"], "en") + self.assertEqual( + result[0]["text"], "Objective: obj text. Method: method text." + ) + + def test_get_abstracts_without_p_wrapper_regression_issue_1031(self): + """Regression test for scieloorg/scms-upload#1031: legacy migrated + XML (e.g. URY collection) may have abstract text sitting directly + under /, not wrapped in

. Extraction + for this case lives in packtools (scieloorg/packtools#1272, + released in 4.16.11); this test only confirms it comes through + get_abstracts() transparently.""" + xml_string = """

+ + + + Resumen: Texto do resumo sem tag p. + + + Abstract: Abstract text without a p tag. + + + +
""" + + article_xml = _create_xml_article(xml_string) + result = list(article_xml.get_abstracts()) + + self.assertEqual( + result, + [ + {"language": "es", "text": "Texto do resumo sem tag p."}, + {"language": "en", "text": "Abstract text without a p tag."}, + ], + ) + + def test_get_abstracts_with_no_abstract(self): + xml_string = """
+ + + + +
""" + + article_xml = _create_xml_article(xml_string) + result = list(article_xml.get_abstracts()) + + self.assertEqual(result, []) diff --git a/requirements/base.txt b/requirements/base.txt index 8cf9c52e6..f4975b9e3 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -90,7 +90,7 @@ iso639-lang==2.6.3 # Mantendo versão maior # SciELO Specific Packages # ======================================== # Using specific versions for stability --e git+https://github.com/scieloorg/packtools.git@4.16.8#egg=packtools +-e git+https://github.com/scieloorg/packtools.git@4.16.11#egg=packtools -e git+https://github.com/scieloorg/scielo_scholarly_data#egg=scielo_scholarly_data -e git+https://github.com/scieloorg/opac_schema.git@v2.66#egg=opac_schema -e git+https://github.com/scieloorg/scielo_migration.git@1.10.8#egg=scielo_classic_website