style & test

This commit is contained in:
Ovv 2018-02-25 19:20:51 +01:00 committed by Daniel Quinn
parent d1a57b5d68
commit 8fefafb844
3 changed files with 21 additions and 14 deletions

View File

@ -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

View File

@ -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:

View File

@ -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):