Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add --force flag to cleardb
Marcin Gębala45c2fe2fa583
diff --git a/saleor/core/management/commands/cleardb.py b/saleor/core/management/commands/cleardb.pyindex b131e3c4f3..f9d6146d5d 100644--- a/saleor/core/management/commands/cleardb.py+++ b/saleor/core/management/commands/cleardb.py@@ -31,10 +31,16 @@ class Command(BaseCommand):action="store_true",help="Delete staff user accounts (doesn't delete superuser accounts).",)+ parser.add_argument(+ "--force",+ action="store_true",+ help="Allows running the cleardb command in DEBUG=False mode.",+ )def handle(self, **options):- if not settings.DEBUG:- raise CommandError("Cannot clear the database in DEBUG=True mode.")+ force = options.get("force", False)+ if not settings.DEBUG and not force:+ raise CommandError("Cannot clear the database in DEBUG=False mode.")Checkout.objects.all().delete()self.stdout.write("Removed checkouts")diff --git a/tests/test_core.py b/tests/test_core.pyindex 4d2974a01f..eb98885a64 100644--- a/tests/test_core.py+++ b/tests/test_core.py@@ -302,6 +302,11 @@ def test_cleardb_exits_with_debug_off():call_command("cleardb")+@override_settings(DEBUG=False)+def test_cleardb_passes_with_force_flag_in_debug_off():+ call_command("cleardb", "--force")++@override_settings(DEBUG=True)def test_cleardb_delete_staff_parameter(staff_user):# cleardb without delete_staff flag keeps staff users