-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adiciona classe para validação de atributos de 'issue' * Adiciona testes automatizados
- Loading branch information
1 parent
32b8033
commit dd695ef
Showing
2 changed files
with
328 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = ( | ||
''' | ||
<article xmlns:xlink="http://www.w3.org/1999/xlink" article-type="research-article" xml:lang="en"> | ||
<front> | ||
<article-meta> | ||
<volume>56</volume> | ||
<issue>4</issue> | ||
</article-meta> | ||
</front> | ||
</article> | ||
''' | ||
) | ||
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 = ( | ||
''' | ||
<article xmlns:xlink="http://www.w3.org/1999/xlink" article-type="research-article" xml:lang="en"> | ||
<front> | ||
<article-meta> | ||
<volume> 56 </volume> | ||
<issue>4</issue> | ||
</article-meta> | ||
</front> | ||
</article> | ||
''' | ||
) | ||
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 = ( | ||
''' | ||
<article xmlns:xlink="http://www.w3.org/1999/xlink" article-type="research-article" xml:lang="en"> | ||
<front> | ||
<article-meta> | ||
<issue>4</issue> | ||
</article-meta> | ||
</front> | ||
</article> | ||
''' | ||
) | ||
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 = ( | ||
''' | ||
<article xmlns:xlink="http://www.w3.org/1999/xlink" article-type="research-article" xml:lang="en"> | ||
<front> | ||
<article-meta> | ||
<volume>56</volume> | ||
<issue>4</issue> | ||
</article-meta> | ||
</front> | ||
</article> | ||
''' | ||
) | ||
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 = ( | ||
''' | ||
<article xmlns:xlink="http://www.w3.org/1999/xlink" article-type="research-article" xml:lang="en"> | ||
<front> | ||
<article-meta> | ||
<volume>56</volume> | ||
<issue>4.</issue> | ||
</article-meta> | ||
</front> | ||
</article> | ||
''' | ||
) | ||
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 = ( | ||
''' | ||
<article xmlns:xlink="http://www.w3.org/1999/xlink" article-type="research-article" xml:lang="en"> | ||
<front> | ||
<article-meta> | ||
<volume>56</volume> | ||
</article-meta> | ||
</front> | ||
</article> | ||
''' | ||
) | ||
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 = ( | ||
''' | ||
<article xmlns:xlink="http://www.w3.org/1999/xlink" article-type="research-article" xml:lang="en"> | ||
<front> | ||
<article-meta> | ||
<volume>56</volume> | ||
<issue>4</issue> | ||
<supplement>2</supplement> | ||
</article-meta> | ||
</front> | ||
</article> | ||
''' | ||
) | ||
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 = ( | ||
''' | ||
<article xmlns:xlink="http://www.w3.org/1999/xlink" article-type="research-article" xml:lang="en"> | ||
<front> | ||
<article-meta> | ||
<volume>56</volume> | ||
<issue>4</issue> | ||
<supplement>2b</supplement> | ||
</article-meta> | ||
</front> | ||
</article> | ||
''' | ||
) | ||
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 = ( | ||
''' | ||
<article xmlns:xlink="http://www.w3.org/1999/xlink" article-type="research-article" xml:lang="en"> | ||
<front> | ||
<article-meta> | ||
<volume>56</volume> | ||
<issue>4 suppl 2</issue> | ||
</article-meta> | ||
</front> | ||
</article> | ||
''' | ||
) | ||
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) |