From dd695ef556f20360d51ff88be551df342e839b1e Mon Sep 17 00:00:00 2001 From: Luciano <41302084+Rossi-Luciano@users.noreply.github.com> Date: Wed, 15 Feb 2023 08:04:54 -0300 Subject: [PATCH] Validation issue (#375) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Adiciona classe para validação de atributos de 'issue' * Adiciona testes automatizados --- .../sps/validation/front_articlemeta_issue.py | 106 +++++++++ .../test_front_articlemeta_issue.py | 222 ++++++++++++++++++ 2 files changed, 328 insertions(+) create mode 100644 packtools/sps/validation/front_articlemeta_issue.py create mode 100644 tests/sps/validation/test_front_articlemeta_issue.py diff --git a/packtools/sps/validation/front_articlemeta_issue.py b/packtools/sps/validation/front_articlemeta_issue.py new file mode 100644 index 000000000..bea0df13f --- /dev/null +++ b/packtools/sps/validation/front_articlemeta_issue.py @@ -0,0 +1,106 @@ +from ..models.front_articlemeta_issue import ArticleMetaIssue + + +class IssueValidation: + def __init__(self, xmltree): + self.xmltree = xmltree + self.article_issue = ArticleMetaIssue(xmltree) + + def validate_volume(self, expected_value): + """ + Checks the correctness of a volume. + + Parameters + ---------- + expected_value : str + Correct value for volume. + + Returns + ------- + dict + A dictionary as described in the example. + + Examples + -------- + >>> validate_volume('23') + + { + 'object': 'volume', + 'output_expected': '23', + 'output_obteined': '23', + 'match': True + } + """ + resp_vol = dict( + object='volume', + output_expected=expected_value, + output_obteined=self.article_issue.volume, + match=True if expected_value == self.article_issue.volume else False + ) + return resp_vol + + def validate_issue(self, expected_value): + """ + Checks the correctness of a issue. + + Parameters + ---------- + expected_value : str + Correct value for issue. + + Returns + ------- + dict + A dictionary as described in the example. + + Examples + -------- + >>> validate_issue('4') + + { + 'object': 'issue', + 'output_expected': '4', + 'output_obteined': '4', + 'match': True + } + """ + resp_issue = dict( + object='issue', + output_expected=expected_value, + output_obteined=self.article_issue.issue, + match=True if expected_value == self.article_issue.issue else False + ) + return resp_issue + + def validate_supplement(self, expected_value): + """ + Checks the correctness of a supplement. + + Parameters + ---------- + expected_value : str + Correct value for supplement. + + Returns + ------- + dict + A dictionary as described in the example. + + Examples + -------- + >>> validate_supplement('5') + + { + 'object': 'supplement', + 'output_expected': '5', + 'output_obteined': '5b', + 'match': False + } + """ + resp_suppl = dict( + object='supplement', + output_expected=expected_value, + output_obteined=self.article_issue.suppl, + match=True if expected_value == self.article_issue.suppl else False + ) + return resp_suppl diff --git a/tests/sps/validation/test_front_articlemeta_issue.py b/tests/sps/validation/test_front_articlemeta_issue.py new file mode 100644 index 000000000..64e2d9967 --- /dev/null +++ b/tests/sps/validation/test_front_articlemeta_issue.py @@ -0,0 +1,222 @@ +from unittest import TestCase +from lxml import etree + +from packtools.sps.validation.front_articlemeta_issue import IssueValidation + + +class IssueTest(TestCase): + def test_volume_matches(self): + xml = ( + ''' +
+ + + 56 + 4 + + +
+ ''' + ) + xmltree = etree.fromstring(xml) + + expected = dict( + object='volume', + output_expected='56', + output_obteined='56', + match=True + ) + obtained = IssueValidation(xmltree).validate_volume('56') + self.assertDictEqual(expected, obtained) + + def test_volume_no_matches(self): + xml = ( + ''' +
+ + + 56 + 4 + + +
+ ''' + ) + xmltree = etree.fromstring(xml) + + expected = dict( + object='volume', + output_expected='56', + output_obteined=' 56 ', + match=False + ) + obtained = IssueValidation(xmltree).validate_volume('56') + self.assertDictEqual(expected, obtained) + + def test_volume_no_volume(self): + xml = ( + ''' +
+ + + 4 + + +
+ ''' + ) + xmltree = etree.fromstring(xml) + + expected = dict( + object='volume', + output_expected='56', + output_obteined=None, + match=False + ) + obtained = IssueValidation(xmltree).validate_volume('56') + self.assertDictEqual(expected, obtained) + + def test_issue_matches(self): + xml = ( + ''' +
+ + + 56 + 4 + + +
+ ''' + ) + xmltree = etree.fromstring(xml) + + expected = dict( + object='issue', + output_expected='4', + output_obteined='4', + match=True + ) + obtained = IssueValidation(xmltree).validate_issue('4') + self.assertDictEqual(expected, obtained) + + def test_issue_no_matches(self): + xml = ( + ''' +
+ + + 56 + 4. + + +
+ ''' + ) + xmltree = etree.fromstring(xml) + + expected = dict( + object='issue', + output_expected='4', + output_obteined='4.', + match=False + ) + obtained = IssueValidation(xmltree).validate_issue('4') + self.assertDictEqual(expected, obtained) + + def test_issue_no_issue(self): + xml = ( + ''' +
+ + + 56 + + +
+ ''' + ) + xmltree = etree.fromstring(xml) + + expected = dict( + object='issue', + output_expected='4', + output_obteined=None, + match=False + ) + obtained = IssueValidation(xmltree).validate_issue('4') + self.assertDictEqual(expected, obtained) + + def test_suppl_matches(self): + xml = ( + ''' +
+ + + 56 + 4 + 2 + + +
+ ''' + ) + xmltree = etree.fromstring(xml) + + expected = dict( + object='supplement', + output_expected='2', + output_obteined='2', + match=True + ) + obtained = IssueValidation(xmltree).validate_supplement('2') + self.assertDictEqual(expected, obtained) + + def test_suppl_no_matches(self): + xml = ( + ''' +
+ + + 56 + 4 + 2b + + +
+ ''' + ) + xmltree = etree.fromstring(xml) + + expected = dict( + object='supplement', + output_expected='2', + output_obteined='2b', + match=False + ) + obtained = IssueValidation(xmltree).validate_supplement('2') + self.assertDictEqual(expected, obtained) + + def test_suppl_implicit(self): + xml = ( + ''' +
+ + + 56 + 4 suppl 2 + + +
+ ''' + ) + xmltree = etree.fromstring(xml) + + expected = dict( + object='supplement', + output_expected='2', + output_obteined='2', + match=True + ) + obtained = IssueValidation(xmltree).validate_supplement('2') + self.assertDictEqual(expected, obtained)