Skip to content

Commit 8f9bbd4

Browse files
committed
Adicionar packtools.stylechecker.validate_style e melhorar msgs no template #820
[views.py] - fixes para o caso que o stylechecker não retorne todos os campos de erro (line, column, message, level) - ``notice_detail`` agora adiciona uma msg de erro explicativo para mostar no template, e também escreve mais informação sobre o erro no logger. - troca inocação do método ``validate`` pelo ``validate_style`` [articletrack/tests/xml_tests_files/with_style_errors.xml] - novo xml com erros para ser anotados. [test_pages.py] - ajustes nos tests. [notice_detail.html] - ajustes para mostrar a msg de error para o usuário.
1 parent 9146690 commit 8f9bbd4

File tree

5 files changed

+1276
-1904
lines changed

5 files changed

+1276
-1904
lines changed

scielomanager/articletrack/templates/articletrack/notice_detail.html

+4-3
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ <h3>{% trans 'Notices' %}:</h3>
137137
<li>
138138
<a href="#annotations" data-toggle="tab">
139139
{% trans "Style Checking" %}
140-
{% if not xml_data.can_be_analyzed %}
140+
{% if not xml_data.can_be_analyzed.0 %}
141141
{# could not be analyzed #}
142142
&nbsp;
143143
<span class="badge badge-warning"></span>
@@ -201,10 +201,11 @@ <h3>{% trans 'Notices' %}:</h3>
201201
</div>
202202
<div class="tab-pane" id="annotations">
203203
{# annotations #}
204-
{% if not xml_data.can_be_analyzed %}
204+
{% if not xml_data.can_be_analyzed.0 %}
205205
{# could not be analyzed #}
206206
<div class="alert alert-warning">
207-
<i class="icon-minus-sign"></i> {% trans "The XML could not be analyzed" %}
207+
<h4><i class="icon-minus-sign"></i> {% trans "The XML could not be analyzed" %}</h4>
208+
<p>{{ xml_data.can_be_analyzed.1 }}</p>
208209
</div>
209210
{% elif not xml_data.annotations %}
210211
{# xml without annotations #}

scielomanager/articletrack/tests/tests_pages.py

+9-10
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def get_xml_uri(self, attempt_id, target_name):
244244
xml_data = response.context['xml_data']
245245

246246
self.assertEqual(response.status_code, 200)
247-
self.assertTrue(xml_data['can_be_analyzed'])
247+
self.assertTrue(xml_data['can_be_analyzed'][0])
248248
self.assertIsNone(xml_data['annotations'])
249249
self.assertEqual(xml_data['uri'], expected_response['uri'])
250250
self.assertIsNone(xml_data['validation_errors'])
@@ -276,7 +276,7 @@ def get_xml_uri(self, attempt_id, target_name):
276276
xml_data = response.context['xml_data']
277277

278278
self.assertEqual(response.status_code, 200)
279-
self.assertFalse(xml_data['can_be_analyzed'])
279+
self.assertFalse(xml_data['can_be_analyzed'][0])
280280
self.assertIsNone(xml_data['annotations'])
281281
self.assertEqual(xml_data['uri'], expected_response['uri'])
282282
self.assertIsNone(xml_data['validation_errors'])
@@ -287,7 +287,7 @@ def test_annotations_of_error(self):
287287
notice = self._makeOne()
288288

289289
# MOCK/REPLACE/FAKE/PIMP MY BALAIO!!!
290-
target_xml = "to_be_annotated.xml"
290+
target_xml = "with_style_errors.xml"
291291
expected_response = {
292292
"filename": "1415-4757-gmb-37-0210.xml",
293293
"uri": self._get_path_of_test_xml(target_xml)
@@ -306,19 +306,18 @@ def get_xml_uri(self, attempt_id, target_name):
306306
reverse('notice_detail', args=[notice.checkin.pk]),
307307
user=self.user)
308308
xml_data = response.context['xml_data']
309-
310309
self.assertEqual(response.status_code, 200)
311-
self.assertTrue(xml_data['can_be_analyzed'])
310+
self.assertTrue(xml_data['can_be_analyzed'][0])
312311
self.assertIsNotNone(xml_data['annotations'])
313312
self.assertEqual(xml_data['uri'], expected_response['uri'])
314313
self.assertEqual(xml_data['file_name'], expected_response['filename'])
315314
self.assertIsNotNone(xml_data['validation_errors'])
316-
self.assertEqual('7', xml_data['validation_errors']['error_lines'])
315+
self.assertEqual('', xml_data['validation_errors']['error_lines'])
317316
self.assertEqual(1, len(xml_data['validation_errors']['results']))
318317
expected_validation_errors = {
319-
'column': 0,
320-
'line': 7,
321-
'message': u"Element 'article-meta': This element is not expected. Expected is ( journal-meta ).",
318+
'column': '--',
319+
'line': '--',
320+
'message': u"Element 'funding-group': This element is not filled-in correctly.",
322321
'level': u'ERROR'
323322
}
324323
self.assertEqual([expected_validation_errors], xml_data['validation_errors']['results'])
@@ -350,7 +349,7 @@ def get_xml_uri(self, attempt_id, target_name):
350349
xml_data = response.context['xml_data']
351350

352351
self.assertEqual(response.status_code, 200)
353-
self.assertFalse(xml_data['can_be_analyzed'])
352+
self.assertFalse(xml_data['can_be_analyzed'][0])
354353
self.assertIsNone(xml_data['annotations'])
355354
self.assertEqual(xml_data['uri'], expected_response['uri'])
356355
self.assertEqual(xml_data['file_name'], expected_response['filename'])

0 commit comments

Comments
 (0)