Skip to content

Commit

Permalink
Merge branch 'main' into DST-901
Browse files Browse the repository at this point in the history
  • Loading branch information
cencorroll authored Jan 28, 2025
2 parents 279ffee + 34bfced commit ee3d2a6
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 43 deletions.
23 changes: 23 additions & 0 deletions django_app/core/management/commands/delete_licence_applications.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from apply_for_a_licence.models import Licence
from django.core.management.base import BaseCommand


class Command(BaseCommand):
help = (
"Deletes licence applications when given a list of application references."
"Usage: pipenv run django_app/python manage.py delete_licence_applications <reference> <reference> ..."
)

def add_arguments(self, parser):
parser.add_argument("licence_references", nargs="+", type=str)

def handle(self, *args, **options):
for reference in options["licence_references"]:
try:
licence_object = Licence.objects.get(reference=reference)
licence_object.delete()
except Licence.DoesNotExist:
self.stdout.write(self.style.ERROR(f"Licence {reference} does not exist"))
continue

self.stdout.write(self.style.SUCCESS(f"Successfully deleted Licence application {reference}"))
43 changes: 0 additions & 43 deletions django_app/core/management/commands/drop_all_tables.py

This file was deleted.

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from apply_for_a_licence.models import Licence
from django.core.management import call_command

from tests.factories import LicenceFactory


def test_successful_delete(db):
LicenceFactory(reference="123")
LicenceFactory(reference="456")

assert Licence.objects.count() == 2

call_command("delete_licence_applications", ["123", "456"])
assert Licence.objects.count() == 0


def test_doesnt_exist_delete(db):
LicenceFactory(reference="123")

assert Licence.objects.count() == 1

call_command("delete_licence_applications", ["456"])
assert Licence.objects.count() == 1

0 comments on commit ee3d2a6

Please sign in to comment.