Skip to content

Commit

Permalink
Fix: funding source validation (#669)
Browse files Browse the repository at this point in the history
* Altera para a utilização do método correto

* Adiciona teste
  • Loading branch information
Rossi-Luciano authored Aug 1, 2024
1 parent 736d716 commit 8446b6f
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packtools/sps/validation/funding_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def funding_sources_exist_validation(self, error_level="ERROR"):
advice = 'Provide value for funding source'
else:
is_valid = True
data = self.funding_group_object.data(self.special_chars_funding, self.special_chars_award_id)
data = self.funding_group_object.extract_funding_data(self.special_chars_funding, self.special_chars_award_id)
yield format_response(
title=title,
parent="article",
Expand All @@ -76,7 +76,7 @@ def funding_sources_exist_validation(self, error_level="ERROR"):

def award_id_format_validation(self, callable_validation=None, error_level="ERROR"):
callable_validation = callable_validation or _callable_extern_validate_default
data = self.funding_group_object.data(self.special_chars_funding, self.special_chars_award_id)
data = self.funding_group_object.extract_funding_data(self.special_chars_funding, self.special_chars_award_id)
for funding in self.funding_group:
for award_id in funding.get("award-id"):
is_valid = callable_validation(award_id)
Expand Down
58 changes: 58 additions & 0 deletions tests/sps/validation/test_funding_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from packtools.sps.utils.xml_utils import get_xml_tree
from packtools.sps.validation.funding_group import FundingGroupValidation
from packtools.sps.utils import xml_utils


def callable_validation_success(award_id):
Expand Down Expand Up @@ -1181,6 +1182,63 @@ def test_award_id_format_validation_fail_without_award_id(self):
obtained = list(FundingGroupValidation(xml_tree).award_id_format_validation(callable_validation_fail))
self.assertEqual([], obtained)

def test_funding_sources_validation_fix_bug(self):
self.maxDiff = None
xml_tree = xml_utils.get_xml_tree('tests/samples/1518-8787-rsp-56-37.xml')
obtained = list(FundingGroupValidation(
xml_tree,
special_chars_funding=['.', ','],
special_chars_award_id=['/', '.', '-']
).funding_sources_exist_validation())

expected = [
{
"title": "Funding source element validation",
"parent": "article",
"parent_article_type": "other",
"parent_id": None,
"parent_lang": "en",
"item": "award-group",
"sub_item": "funding-source",
"validation_type": "exist",
"response": "OK",
"expected_value": "at least 1 value for funding source and at least 1 value "
"for award id",
"got_value": "1 values for funding source and 1 values for award id",
"message": "Got 1 values for funding source and 1 values for award id, "
"expected at least 1 value for funding source and at least 1 value "
"for award id",
"advice": None,
"data": {
"ack": [],
"article_lang": "en",
"article_type": "other",
"award_groups": [
{"award-id": ["442776/2019-5"], "funding-source": ["CNPq"]},
{"award-id": ["2018/14384-9"], "funding-source": ["Fapesp"]},
],
"fn_financial_information": [
{
"fn-type": "financial-disclosure",
"look-like-award-id": ["442776/2019-5"],
"look-like-funding-source": [],
}
],
"funding_sources": ["CNPq", "Fapesp"],
"funding_statement": "Funding: Conselho Nacional de Desenvolvimento "
"Científico e Tecnológico (CNPq - "
"442776/2019-5). Fundação de Amparo à Pesquisa "
"do Estado de São Paulo (Fapesp - "
"2018/14384-9).",
"principal_award_recipients": [],
},
}
]

for i, item in enumerate(expected):
with self.subTest(i):
self.assertDictEqual(obtained[i], item)


if __name__ == '__main__':
unittest.main()

0 comments on commit 8446b6f

Please sign in to comment.