diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-03-02 17:17:13 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-03-02 17:17:13 +0100 |
commit | 0ae332323c6710a68601c1a1f28499408eb1a321 (patch) | |
tree | a71db0c7433170f518c2e67dcf92e5c1105a0cb1 | |
parent | e84473ef8a97229d26dd20d245e0e38eeb47529e (diff) | |
download | Ishtar-0ae332323c6710a68601c1a1f28499408eb1a321.tar.bz2 Ishtar-0ae332323c6710a68601c1a1f28499408eb1a321.zip |
Fix test for command call
-rw-r--r-- | ishtar_common/management/commands/ishtar_maintenance.py | 10 | ||||
-rw-r--r-- | ishtar_common/tests.py | 5 |
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) |