diff --git a/src/documents/consumer.py b/src/documents/consumer.py index 1d5036318..7d4f2facf 100644 --- a/src/documents/consumer.py +++ b/src/documents/consumer.py @@ -32,7 +32,8 @@ class Consumer: 5. Delete the document and image(s) """ - def __init__(self, consume=settings.CONSUMPTION_DIR, scratch=settings.SCRATCH_DIR): + def __init__(self, consume=settings.CONSUMPTION_DIR, + scratch=settings.SCRATCH_DIR): self.logger = logging.getLogger(__name__) self.logging_group = None diff --git a/src/documents/management/commands/document_consumer.py b/src/documents/management/commands/document_consumer.py index eb3e38a2e..8efdbe54e 100644 --- a/src/documents/management/commands/document_consumer.py +++ b/src/documents/management/commands/document_consumer.py @@ -30,17 +30,25 @@ class Command(BaseCommand): BaseCommand.__init__(self, *args, **kwargs) def add_arguments(self, parser): - parser.add_argument("directory", default=settings.CONSUMPTION_DIR, nargs='?') - parser.add_argument("--loop-time", default=settings.CONSUMER_LOOP_TIME, type=int) + parser.add_argument( + "directory", + default=settings.CONSUMPTION_DIR, + nargs="?" + ) + parser.add_argument( + "--loop-time", + default=settings.CONSUMER_LOOP_TIME, + type=int + ) parser.add_argument("--mail-delta", default=10, type=int) - parser.add_argument("--oneshot", action='store_true') + parser.add_argument("--oneshot", action="store_true") def handle(self, *args, **options): self.verbosity = options["verbosity"] - directory = options['directory'] - loop_time = options['loop_time'] - mail_delta = datetime.timedelta(minutes=options['mail_delta']) + directory = options["directory"] + loop_time = options["loop_time"] + mail_delta = datetime.timedelta(minutes=options["mail_delta"]) try: self.file_consumer = Consumer(consume=directory) @@ -58,7 +66,7 @@ class Command(BaseCommand): "Starting document consumer at {}".format(directory) ) - if options['oneshot']: + if options["oneshot"]: self.loop(mail_delta=mail_delta) else: try: diff --git a/src/documents/tests/test_consumer.py b/src/documents/tests/test_consumer.py index b7fca45e7..edb2e8754 100644 --- a/src/documents/tests/test_consumer.py +++ b/src/documents/tests/test_consumer.py @@ -16,7 +16,6 @@ class TestConsumer(TestCase): self.DummyParser ) - @mock.patch("documents.consumer.Consumer.CONSUME") @mock.patch("documents.consumer.os.makedirs") @mock.patch("documents.consumer.os.path.exists", return_value=True) @mock.patch("documents.consumer.document_consumer_declaration.send") @@ -33,17 +32,16 @@ class TestConsumer(TestCase): (None, lambda _: {"weight": 1, "parser": DummyParser2}), ) - self.assertEqual(Consumer()._get_parser_class("doc.pdf"), DummyParser2) + self.assertEqual(Consumer(consume=".")._get_parser_class("doc.pdf"), + DummyParser2) - @mock.patch("documents.consumer.Consumer.CONSUME") @mock.patch("documents.consumer.os.makedirs") @mock.patch("documents.consumer.os.path.exists", return_value=True) @mock.patch("documents.consumer.document_consumer_declaration.send") def test__get_parser_class_0_parsers(self, m, *args): m.return_value = ((None, lambda _: None),) - self.assertIsNone(Consumer()._get_parser_class("doc.pdf")) + self.assertIsNone(Consumer(consume=".")._get_parser_class("doc.pdf")) - @mock.patch("documents.consumer.Consumer.CONSUME") @mock.patch("documents.consumer.os.makedirs") @mock.patch("documents.consumer.os.path.exists", return_value=True) @mock.patch("documents.consumer.document_consumer_declaration.send") @@ -51,7 +49,7 @@ class TestConsumer(TestCase): m.return_value = ( (None, lambda _: {"weight": 0, "parser": self.DummyParser}), ) - return Consumer() + return Consumer(consume=".") class TestAttributes(TestCase):