data: raise a CommandError if import-site fails when roles are missing (#35289)
This commit is contained in:
parent
8df192e455
commit
d782655ff4
|
@ -17,7 +17,7 @@
|
|||
import json
|
||||
import sys
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.utils.encoding import force_text
|
||||
|
||||
from combo.data.utils import import_site, MissingGroups
|
||||
|
@ -45,4 +45,4 @@ class Command(BaseCommand):
|
|||
if_empty=options['if_empty'],
|
||||
clean=options['clean'])
|
||||
except MissingGroups as e:
|
||||
sys.stderr.write(force_text(e) + '\n')
|
||||
raise CommandError(e)
|
||||
|
|
|
@ -10,6 +10,7 @@ import pytest
|
|||
from django.contrib.auth.models import Group
|
||||
from django.core.files import File
|
||||
from django.core.management import call_command
|
||||
from django.core.management.base import CommandError
|
||||
from django.utils.encoding import force_bytes, force_text
|
||||
from django.utils.six import BytesIO, StringIO
|
||||
|
||||
|
@ -161,6 +162,13 @@ def test_group_restrictions_import_export(app, some_data):
|
|||
|
||||
assert excinfo.value.names == ['A Group']
|
||||
|
||||
with pytest.raises(CommandError, match='Missing groups: A Group'):
|
||||
with tempfile.NamedTemporaryFile() as f:
|
||||
f.write(force_bytes(output))
|
||||
f.flush()
|
||||
call_command('import_site', f.name, clean=True)
|
||||
assert Page.objects.count() == 0
|
||||
|
||||
group = Group(name='A Group')
|
||||
group.save()
|
||||
|
||||
|
|
Loading…
Reference in New Issue