From b7d310ef90d0373dfa93efdddd86e1c6ca524627 Mon Sep 17 00:00:00 2001 From: jonaswinkler Date: Tue, 22 Dec 2020 13:04:08 +0100 Subject: [PATCH 1/2] more tests --- src/documents/checks.py | 2 +- src/documents/tests/test_checks.py | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/documents/checks.py b/src/documents/checks.py index b6da5bfc9..ba55b1397 100644 --- a/src/documents/checks.py +++ b/src/documents/checks.py @@ -51,6 +51,6 @@ def parser_check(app_configs, **kwargs): if len(parsers) == 0: return [Error("No parsers found. This is a bug. The consumer won't be " - "able to onsume any documents without parsers.")] + "able to consume any documents without parsers.")] else: return [] diff --git a/src/documents/tests/test_checks.py b/src/documents/tests/test_checks.py index 1027c11a0..ee4fbe8d1 100644 --- a/src/documents/tests/test_checks.py +++ b/src/documents/tests/test_checks.py @@ -1,9 +1,12 @@ import unittest +from unittest import mock +from django.core.checks import Error from django.test import TestCase from .factories import DocumentFactory -from ..checks import changed_password_check +from .. import document_consumer_declaration +from ..checks import changed_password_check, parser_check from ..models import Document @@ -15,3 +18,13 @@ class ChecksTestCase(TestCase): def test_changed_password_check_no_encryption(self): DocumentFactory.create(storage_type=Document.STORAGE_TYPE_UNENCRYPTED) self.assertEqual(changed_password_check(None), []) + + def test_parser_check(self): + + self.assertEqual(parser_check(None), []) + + with mock.patch('documents.checks.document_consumer_declaration.send') as m: + m.return_value = [] + + self.assertEqual(parser_check(None), [Error("No parsers found. This is a bug. The consumer won't be " + "able to consume any documents without parsers.")]) From 6968e228e17391bc78cf1e1142f8537199036012 Mon Sep 17 00:00:00 2001 From: jonaswinkler Date: Tue, 22 Dec 2020 13:04:22 +0100 Subject: [PATCH 2/2] increase indexing speed --- src/documents/management/commands/document_index.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/documents/management/commands/document_index.py b/src/documents/management/commands/document_index.py index 7dfdbaa42..08e20e1d2 100644 --- a/src/documents/management/commands/document_index.py +++ b/src/documents/management/commands/document_index.py @@ -1,4 +1,5 @@ from django.core.management import BaseCommand +from django.db import transaction from documents.mixins import Renderable from documents.tasks import index_reindex, index_optimize @@ -18,8 +19,8 @@ class Command(Renderable, BaseCommand): def handle(self, *args, **options): self.verbosity = options["verbosity"] - - if options['command'] == 'reindex': - index_reindex() - elif options['command'] == 'optimize': - index_optimize() + with transaction.atomic(): + if options['command'] == 'reindex': + index_reindex() + elif options['command'] == 'optimize': + index_optimize()