more tests

This commit is contained in:
jonaswinkler 2020-12-29 21:01:18 +01:00
parent 6581cff8dc
commit e24b40de29

View File

@ -1,10 +1,12 @@
from datetime import datetime from datetime import datetime
from unittest import mock
from django.test import TestCase from django.test import TestCase
from django.utils import timezone from django.utils import timezone
from documents import tasks from documents import tasks
from documents.models import Document from documents.models import Document
from documents.sanity_checker import SanityError, SanityFailedError
from documents.tests.utils import DirectoriesMixin from documents.tests.utils import DirectoriesMixin
@ -22,3 +24,19 @@ class TestTasks(DirectoriesMixin, TestCase):
def test_train_classifier(self): def test_train_classifier(self):
tasks.train_classifier() tasks.train_classifier()
@mock.patch("documents.tasks.sanity_checker.check_sanity")
def test_sanity_check(self, m):
m.return_value = []
tasks.sanity_check()
m.assert_called_once()
m.reset_mock()
m.return_value = [SanityError("")]
self.assertRaises(SanityFailedError, tasks.sanity_check)
m.assert_called_once()
def test_culk_update_documents(self):
doc1 = Document.objects.create(title="test", content="my document", checksum="wow", added=timezone.now(),
created=timezone.now(), modified=timezone.now())
tasks.bulk_update_documents([doc1.pk])