0002-agendas-ignore-missing-category-during-agenda-import.patch
chrono/agendas/models.py | ||
---|---|---|
438 | 438 |
try: |
439 | 439 |
data['category'] = Category.objects.get(slug=data['category']) |
440 | 440 |
except Category.DoesNotExist: |
441 |
raise AgendaImportError(_('Missing "%s" category') % data['category'])
|
|
441 |
del data['category']
|
|
442 | 442 |
if data.get('absence_reasons_group'): |
443 | 443 |
try: |
444 | 444 |
data['absence_reasons_group'] = AbsenceReasonGroup.objects.get( |
tests/test_import_export.py | ||
---|---|---|
386 | 386 |
data = json.loads(output) |
387 | 387 |
del data['categories'] |
388 | 388 | |
389 |
with pytest.raises(AgendaImportError) as excinfo:
|
|
390 |
import_site(data, overwrite=True)
|
|
391 |
assert str(excinfo.value) == 'Missing "foo" category'
|
|
389 |
import_site(data.copy(), overwrite=True)
|
|
390 |
agenda = Agenda.objects.get(slug=agenda.slug)
|
|
391 |
assert agenda.category is None
|
|
392 | 392 | |
393 | 393 |
category = Category.objects.create(label='foobar') |
394 |
with pytest.raises(AgendaImportError) as excinfo:
|
|
395 |
import_site(data, overwrite=True)
|
|
396 |
assert str(excinfo.value) == 'Missing "foo" category'
|
|
394 |
import_site(data.copy(), overwrite=True)
|
|
395 |
agenda = Agenda.objects.get(slug=agenda.slug)
|
|
396 |
assert agenda.category is None
|
|
397 | 397 | |
398 | 398 |
category = Category.objects.create(label='foo') |
399 |
import_site(data, overwrite=True) |
|
399 |
import_site(data.copy(), overwrite=True)
|
|
400 | 400 |
agenda = Agenda.objects.get(slug=agenda.slug) |
401 | 401 |
assert agenda.category == category |
402 | 402 | |
403 |
- |