management: Don't use sys.exit(1).

Using sys.exit in a management command makes it impossible
to unit test the code in question.  The correct approach to do the same
thing in Django management commands is to raise CommandError.

Followup of b570c0dafa
This commit is contained in:
Vishnu Ks
2019-05-04 02:50:39 +05:30
committed by Tim Abbott
parent 687f1bcdaf
commit 123bcea518
26 changed files with 82 additions and 120 deletions

View File

@@ -2,7 +2,7 @@
from argparse import ArgumentParser
from typing import Any
from django.core.management.base import BaseCommand
from django.core.management.base import BaseCommand, CommandError
from zerver.lib.actions import do_delete_old_unclaimed_attachments
from zerver.models import get_old_unclaimed_attachments
@@ -36,8 +36,7 @@ class Command(BaseCommand):
print("")
if not options["for_real"]:
print("This was a dry run. Pass -f to actually delete.")
exit(1)
raise CommandError("This was a dry run. Pass -f to actually delete.")
do_delete_old_unclaimed_attachments(delta_weeks)
print("")