-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
46 additions
and
43 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
django_app/core/management/commands/delete_licence_applications.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}")) |
This file was deleted.
Oops, something went wrong.
Empty file.
23 changes: 23 additions & 0 deletions
23
tests/test_unit/test_core/test_management_commands/test_delete_licence_applications.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |