Skip to content

Commit

Permalink
Jornal meta validation (#370)
Browse files Browse the repository at this point in the history
* Renomeia classe de 'front_journal_meta' para 'journal_meta'

* Altera valor do atributo 'events_date'

* Adequa testes

* Adiciona classe 'ISSNValidation'

* Adiciona classe AcronymValidation

* Adiciona classe TitleValidation

* Adiciona classe PublisherValidation

* Adiciona classe JournalMetaValidation

* Adiciona testes

* Altera os atributos e valores no dicionário

* Adequa os testes para os atributos e valores modificados
  • Loading branch information
Rossi-Luciano authored Feb 10, 2023
1 parent 6bb67fa commit 32b8033
Show file tree
Hide file tree
Showing 5 changed files with 467 additions and 24 deletions.
File renamed without changes.
4 changes: 1 addition & 3 deletions packtools/sps/validation/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def history_dates_are_sorted(self, order, required_events):
'input': {
'order_of_events': order,
'required_events': required_events,
'events_date': [{key: date_dict_to_date(value)} for key, value in history_dates.items()]
'events_date': history_dates
},
'message': [],
}
Expand All @@ -86,8 +86,6 @@ def history_dates_are_sorted(self, order, required_events):
return result




def is_complete(dict_date, date_element):
result = dict(
input=dict_date,
Expand Down
112 changes: 112 additions & 0 deletions packtools/sps/validation/journal_meta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
from ..models.journal_meta import ISSN, Acronym, Title, Publisher


class ISSNValidation:
def __init__(self, xmltree):
self.xmltree = xmltree
self.journal_issns = ISSN(xmltree)

def validate_epub(self, expected_value):
resp_epub = dict(
object='issn epub',
output_expected=expected_value,
output_obteined=self.journal_issns.epub,
match=True if expected_value == self.journal_issns.epub else False
)
return resp_epub

def validate_ppub(self, expected_value):
resp_ppub = dict(
object='issn ppub',
output_expected=expected_value,
output_obteined=self.journal_issns.ppub,
match=True if expected_value == self.journal_issns.ppub else False
)
return resp_ppub


class AcronymValidation:
def __init__(self, xmltree):
self.xmltree = xmltree
self.journal_acronym = Acronym(xmltree)

def validate_text(self, expected_value):
resp_text = dict(
object='journal acronym',
output_expected=expected_value,
output_obteined=self.journal_acronym.text,
match=True if expected_value == self.journal_acronym.text else False
)
return resp_text


class TitleValidation:
def __init__(self, xmltree):
self.xmltree = xmltree
self.journal_titles = Title(xmltree)

def validate_journal_title(self, expected_value):
resp_journal_title = dict(
object='journal title',
output_expected=expected_value,
output_obteined=self.journal_titles.journal_title,
match=True if expected_value == self.journal_titles.journal_title else False
)
return resp_journal_title

def validate_abbreviated_journal_title(self, expected_value):
resp_abbreviated_journal_title = dict(
object='abbreviated journal title',
output_expected=expected_value,
output_obteined=self.journal_titles.abbreviated_journal_title,
match=True if expected_value == self.journal_titles.abbreviated_journal_title else False
)
return resp_abbreviated_journal_title


class PublisherValidation:
def __init__(self, xmltree):
self.xmltree = xmltree
self.publisher = Publisher(xmltree)

def validate_publishers_names(self, expected_values):
resp_publishers_names = dict(
object='publishers names',
output_expected=expected_values,
output_obteined=self.publisher.publishers_names,
match=True if expected_values == self.publisher.publishers_names else False
)
return resp_publishers_names


class JournalMetaValidation:
def __init__(self, xmltree):
self.xmltree = xmltree

def validate(self, expected_values):
'''
expected_values is a dict like:
{
'issn_epub': '0103-5053',
'issn_ppub': '1678-4790',
'acronym': 'hcsm',
'journal-title': 'História, Ciências, Saúde-Manguinhos',
'abbrev-journal-title': 'Hist. cienc. saude-Manguinhos',
'publisher-name': ['Casa de Oswaldo Cruz, Fundação Oswaldo Cruz']
}
'''

issn = ISSNValidation(self.xmltree)
acronym = AcronymValidation(self.xmltree)
title = TitleValidation(self.xmltree)
publisher = PublisherValidation(self.xmltree)

resp_journal_meta = [
issn.validate_epub(expected_values['issn_epub']),
issn.validate_ppub(expected_values['issn_ppub']),
acronym.validate_text(expected_values['acronym']),
title.validate_journal_title(expected_values['journal-title']),
title.validate_abbreviated_journal_title(expected_values['abbrev-journal-title']),
publisher.validate_publishers_names(expected_values['publisher-name'])
]
return resp_journal_meta
41 changes: 20 additions & 21 deletions tests/sps/validation/test_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from lxml import etree

from packtools.sps.validation import dates
from packtools.sps.utils.xml_utils import get_xml_tree


class IsCompleteDateTest(TestCase):
Expand Down Expand Up @@ -207,13 +206,13 @@ def test_is_sorted_a_sorted_date_list(self):
'input': {
'order_of_events': ["received", "rev-request", "rev-recd", "accepted", "approved"],
'required_events': ["received", "approved"],
'events_date': [
{'received': date(1998, 1, 5)},
{'rev-request': date(1998, 3, 14)},
{'rev-recd': date(1998, 5, 24)},
{'accepted': date(1998, 6, 6)},
{'approved': date(2012, 6, 1)}
]
'events_date': {
'received': {'type': 'received', 'year': '1998', 'month': '01', 'day': '05'},
'rev-request': {'type': 'rev-request', 'year': '1998', 'month': '03', 'day': '14'},
'rev-recd': {'type': 'rev-recd', 'year': '1998', 'month': '05', 'day': '24'},
'accepted': {'type': 'accepted', 'year': '1998', 'month': '06', 'day': '06'},
'approved': {'type': 'approved', 'year': '2012', 'month': '06', 'day': '01'}
}
},
'message': [],
'result': 'ok',
Expand Down Expand Up @@ -273,13 +272,13 @@ def test_is_sorted_a_unsorted_date_list(self):
'input': {
'order_of_events': ["received", "rev-request", "rev-recd", "accepted", "approved"],
'required_events': ["received", "approved"],
'events_date': [
{'received': date(1999, 1, 5)},
{'rev-request': date(1998, 3, 14)},
{'rev-recd': date(1998, 5, 24)},
{'accepted': date(1998, 6, 6)},
{'approved': date(2012, 6, 1)}
]
'events_date': {
'received': {'type': 'received', 'year': '1999', 'month': '01', 'day': '05'},
'rev-request': {'type': 'rev-request', 'year': '1998', 'month': '03', 'day': '14'},
'rev-recd': {'type': 'rev-recd', 'year': '1998', 'month': '05', 'day': '24'},
'accepted': {'type': 'accepted', 'year': '1998', 'month': '06', 'day': '06'},
'approved': {'type': 'approved', 'year': '2012', 'month': '06', 'day': '01'}
}
},
'message': [],
'result': 'error',
Expand Down Expand Up @@ -334,12 +333,12 @@ def test_is_sorted_a_date_list_without_one_date_required(self):
'input': {
'order_of_events': ["received", "rev-request", "rev-recd", "accepted", "approved"],
'required_events': ["received", "approved"],
'events_date': [
{'rev-request': date(1998, 3, 14)},
{'rev-recd': date(1998, 5, 24)},
{'accepted': date(1998, 6, 6)},
{'approved': date(2012, 6, 1)}
]
'events_date': {
'rev-request': {'type': 'rev-request', 'year': '1998', 'month': '03', 'day': '14'},
'rev-recd': {'type': 'rev-recd', 'year': '1998', 'month': '05', 'day': '24'},
'accepted': {'type': 'accepted', 'year': '1998', 'month': '06', 'day': '06'},
'approved': {'type': 'approved', 'year': '2012', 'month': '06', 'day': '01'}
}
},
'message': ['the event received is required'],
'result': 'error',
Expand Down
Loading

0 comments on commit 32b8033

Please sign in to comment.