Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: related article validation #698

Open
wants to merge 37 commits into
base: master
Choose a base branch
from

Conversation

Rossi-Luciano
Copy link
Collaborator

O que esse PR faz?

Adiciona validações para related_article.

Onde a revisão poderia começar?

Por commit.

Como este poderia ser testado manualmente?

python3 -m unittest -v tests/sps/validation/test_related_articles.py

Algum cenário de contexto que queira dar?

NA.

Screenshots

NA.

Quais são tickets relevantes?

NA.

Referências

NA.

@robertatakenaka
Copy link
Member

@Rossi-Luciano revisado e aprovado até o commit 2

@Rossi-Luciano Rossi-Luciano marked this pull request as ready for review September 13, 2024 13:56
@@ -1,5 +1,5 @@
from packtools.sps.models.v2.related_articles import RelatedArticles
from packtools.sps.models import article_and_subarticles
from packtools.sps.models import article_and_subarticles, article_dates
Copy link
Member

@robertatakenaka robertatakenaka Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rossi-Luciano se não me engano, foi feita a versão v2 deste modelo... se sim... qual é o mais apropriado para usar. Por favor, coloque em forma de comentário a justificativa por usar um ou o outro. Teoricamente se foi necessário criar o v2, teria que usar o v2.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robertatakenaka para esse caso o módulo foi renomeado de dates para article_dates e não está em v2 mas é o módulo novo.

obtained_events = self.history_events
is_valid = expected_event in obtained_events
yield format_response(
title='Related article type validation',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rossi-Luciano o valor de title não condiz com o nome do método

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not correspondence_list:
raise ValidationRelatedArticleException("Function requires a dictionary with article type and history date event")

for related_article in self.related_articles:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rossi-Luciano todos os related article tem obrigatoriamente que ter uma data relacionadoa no histórico?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -234,6 +234,267 @@ def test_related_articles_does_not_have_doi(self):
with self.subTest(i):
self.assertDictEqual(obtained[i], item)

def test_related_articles_attribute_validation(self):
Copy link
Member

@robertatakenaka robertatakenaka Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rossi-Luciano o nome deste teste está muito genérico. O que de fato ele está testando? Deveria ser algo como: test_related_article_type_xxx_exige_que_exista_a_data_yyy_no_historico. Tampouco há um comentário que expresse o que de fato está sendo testado.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


expected = [
{
'title': 'Related article type validation',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rossi-Luciano title não condiz com o que está sendo validado.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
},
{
'title': 'Related article type validation',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rossi-Luciano title não condiz com o que está sendo validado.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
},
{
'title': 'Related article type validation',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rossi-Luciano title não condiz com o que está sendo validado.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 370 to 373
<date date-type="corrected">
<day>01</day>
<month>06</month>
<year>2012</year>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rossi-Luciano eu acho que está errado. Esta data é esperada no XML do artigo corrigido e não no XML da errata

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rossi-Luciano vc já fez esta validação na classe que valida errata. Considere o que já foi feito

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@robertatakenaka robertatakenaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rossi-Luciano verificar comentários

@@ -156,28 +156,3 @@ def related_article_attributes_validation(self, error_level="ERROR"):
data=related_article,
error_level=error_level
)

def related_articles_matches_history_date_validation(self, correspondence_list=None, error_level="ERROR"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rossi-Luciano isso está sendo atendido em outra classe? Era um questionamento

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -141,7 +141,7 @@ def related_article_attributes_validation(self, error_level="ERROR"):
for attrib in ("related-article-type", "id", "href", "ext-link-type"):
if not related_article[attrib]:
yield format_response(
title='Related article type validation',
title='Related article attributes validation',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rossi-Luciano gostaria que o título não tivesse validation para deixar mais curto, pois tudo é validation. Em title deixe mais específico que aspecto está sendo validado. Neste caso, use f'Related article {attrib}'

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rossi-Luciano Rossi-Luciano changed the title Feat: realated article validation Feat: related article validation Sep 21, 2024
Comment on lines 7 to 10
return [
article for article in RelatedItems(xml_tree).related_articles
if article.get("related-article-type") == expected_related_article_type
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rossi-Luciano será que o melhor não seria ter o filtro e iterar em todos os related-article? Desta forma não está escondendo possíveis defeitos no XML ao ignorar os related-article de tipo inesperados?

history_date_count = len(history_dates)
related_article_count = len(self.related_articles)

if history_date_count < related_article_count:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rossi-Luciano não acho boa a abordagem de contagem. A abordagem a ser adotada deveria ser pareada. Porque o objetivo não é saber se a quantidade bate, mas qual é o item que tem a data faltando. E vice versa, se há a data no histórico e não há o related-article.

@Rossi-Luciano
Copy link
Collaborator Author

@robertatakenaka mudei a abordagem da validação.

self.xml_tree = xml_tree
self.correspondence_list = correspondence_list
self.article_type = xml_tree.find(".").get("article-type")
self.related_articles = list(RelatedArticles(xml_tree).related_articles())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rossi-Luciano aqui está sendo recuperado todos os related_articles. Em RelatedArticles, crie método para filtrar somente os related_articles com os quais deseja trabalhar, no lugar de criar em RelatedArticlesValidation o método get_related_article_types_by_article_type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants