summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ishtar_common/management/commands/ishtar_maintenance.py10
-rw-r--r--ishtar_common/tests.py5
2 files changed, 13 insertions, 2 deletions
diff --git a/ishtar_common/management/commands/ishtar_maintenance.py b/ishtar_common/management/commands/ishtar_maintenance.py
index d57fb575e..d6e7ae5de 100644
--- a/ishtar_common/management/commands/ishtar_maintenance.py
+++ b/ishtar_common/management/commands/ishtar_maintenance.py
@@ -331,8 +331,14 @@ class Command(BaseCommand):
'--clean', dest='clean', action='store_true',
default=False,
help="[operation_missing_parcels] Delete orphan parcel after fix")
+ parser.add_argument(
+ '--test', dest='test', action='store_true',
+ default=False,
+ help="Used on tests: no sys.exit")
def handle(self, *args, **options):
+ if options["test"]:
+ options["quiet"] = True
if options["task"] not in TASKS.keys():
msg = f"{options['task']} is not a valid task. Available tasks are:\n"
msg += "\n".join(TASKS.keys())
@@ -344,7 +350,11 @@ class Command(BaseCommand):
if not errors:
if not quiet:
sys.stdout.write(f"[{get_time()}] Task {options['task']} finished\n")
+ if options["test"]:
+ return
sys.exit()
if not quiet:
sys.stdout.write("\n".join(errors))
+ if options["test"]:
+ return
sys.exit(1)
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index d15675769..e7e665a6f 100644
--- a/ishtar_common/tests.py
+++ b/ishtar_common/tests.py
@@ -271,8 +271,9 @@ class CommandsTestCase(TestCase):
)
parcel_nb = Parcel.objects.count()
out = StringIO()
- call_command("clean_ishtar", stdout=out)
- # no operation or file attached - the parcel should have disappear
+ call_command("ishtar_maintenance", "fix_missing_parcels", "--clean", "--test",
+ stdout=out)
+ # no operation or file attached - the parcel should have disappeared
self.assertEqual(parcel_nb - 1, Parcel.objects.count())
self.assertEqual(Parcel.objects.filter(pk=p.pk).count(), 0)