Refines the sanity check header, fixes other test issues

This commit is contained in:
Trenton Holmes 2022-05-30 17:29:30 -07:00
parent 0a34a4a7ad
commit be304e37b4
4 changed files with 11 additions and 7 deletions

View File

@ -38,7 +38,10 @@ class SanityCheckMessages:
for doc_pk in self._messages: for doc_pk in self._messages:
if doc_pk is not None: if doc_pk is not None:
doc = all_docs.get(pk=doc_pk) doc = all_docs.get(pk=doc_pk)
logger.info(f"Document: {doc.pk}, title: {doc.title}") logger.info(
f"Detected following issue(s) with document #{doc.pk},"
f" titled {doc.title}",
)
for msg in self._messages[doc_pk]: for msg in self._messages[doc_pk]:
logger.log(msg["level"], msg["message"]) logger.log(msg["level"], msg["message"])

View File

@ -6,6 +6,7 @@ import tempfile
from pathlib import Path from pathlib import Path
from unittest import mock from unittest import mock
import pytest
from django.core.management import call_command from django.core.management import call_command
from django.test import override_settings from django.test import override_settings
from django.test import TestCase from django.test import TestCase
@ -190,7 +191,7 @@ class TestExportImport(DirectoriesMixin, TestCase):
self.assertEqual(Document.objects.get(id=self.d4.id).title, "wow_dec") self.assertEqual(Document.objects.get(id=self.d4.id).title, "wow_dec")
messages = check_sanity() messages = check_sanity()
# everything is alright after the test # everything is alright after the test
self.assertEqual(len(messages), 0, str([str(m) for m in messages])) self.assertEqual(len(messages), 0)
def test_exporter_with_filename_format(self): def test_exporter_with_filename_format(self):
shutil.rmtree(os.path.join(self.dirs.media_dir, "documents")) shutil.rmtree(os.path.join(self.dirs.media_dir, "documents"))

View File

@ -63,9 +63,9 @@ class TestSanityCheck(DirectoriesMixin, TestCase):
self.assertTrue(messages.has_error) self.assertTrue(messages.has_error)
with self.assertLogs() as capture: with self.assertLogs() as capture:
messages.log_messages() messages.log_messages()
self.assertRegex( self.assertEqual(
capture.records[0].message, capture.records[0].message,
f"Document: {doc.pk}, title: {doc.title}", f"Detected following issue(s) with document #{doc.pk}, titled {doc.title}",
) )
self.assertRegex(capture.records[1].message, messageRegex) self.assertRegex(capture.records[1].message, messageRegex)

View File

@ -538,7 +538,7 @@ class TestTasks(DirectoriesMixin, TestCase):
@mock.patch("documents.tasks.sanity_checker.check_sanity") @mock.patch("documents.tasks.sanity_checker.check_sanity")
def test_sanity_check_error(self, m): def test_sanity_check_error(self, m):
messages = SanityCheckMessages() messages = SanityCheckMessages()
messages.error("Some error") messages.error(None, "Some error")
m.return_value = messages m.return_value = messages
self.assertRaises(SanityCheckFailedException, tasks.sanity_check) self.assertRaises(SanityCheckFailedException, tasks.sanity_check)
m.assert_called_once() m.assert_called_once()
@ -546,7 +546,7 @@ class TestTasks(DirectoriesMixin, TestCase):
@mock.patch("documents.tasks.sanity_checker.check_sanity") @mock.patch("documents.tasks.sanity_checker.check_sanity")
def test_sanity_check_warning(self, m): def test_sanity_check_warning(self, m):
messages = SanityCheckMessages() messages = SanityCheckMessages()
messages.warning("Some warning") messages.warning(None, "Some warning")
m.return_value = messages m.return_value = messages
self.assertEqual( self.assertEqual(
tasks.sanity_check(), tasks.sanity_check(),
@ -557,7 +557,7 @@ class TestTasks(DirectoriesMixin, TestCase):
@mock.patch("documents.tasks.sanity_checker.check_sanity") @mock.patch("documents.tasks.sanity_checker.check_sanity")
def test_sanity_check_info(self, m): def test_sanity_check_info(self, m):
messages = SanityCheckMessages() messages = SanityCheckMessages()
messages.info("Some info") messages.info(None, "Some info")
m.return_value = messages m.return_value = messages
self.assertEqual( self.assertEqual(
tasks.sanity_check(), tasks.sanity_check(),