0001-agenda-fix-event-import-53838.patch
chrono/agendas/models.py | ||
---|---|---|
1348 | 1348 |
) |
1349 | 1349 |
data = clean_import_data(cls, data) |
1350 | 1350 |
if data.get('slug'): |
1351 |
event, _ = cls.objects.update_or_create(slug=data['slug'], defaults=data) |
|
1351 |
event, _ = cls.objects.update_or_create(agenda=data['agenda'], slug=data['slug'], defaults=data)
|
|
1352 | 1352 |
else: |
1353 | 1353 |
event = cls(**data) |
1354 | 1354 |
event.save() |
tests/test_import_export.py | ||
---|---|---|
170 | 170 |
def test_import_export_event_details(app): |
171 | 171 |
agenda = Agenda.objects.create(label='Foo Bar', kind='events') |
172 | 172 |
Event.objects.create( |
173 |
slug='event', |
|
173 | 174 |
agenda=agenda, |
174 | 175 |
description='description', |
175 | 176 |
pricing='100', |
... | ... | |
178 | 179 |
places=42, |
179 | 180 |
start_datetime=now(), |
180 | 181 |
) |
182 |
# check event (agenda, slug) unicity |
|
183 |
agenda2 = Agenda.objects.create(label='Foo Bar 2', kind='events') |
|
184 |
Event.objects.create( |
|
185 |
slug='event', |
|
186 |
agenda=agenda2, |
|
187 |
places=42, |
|
188 |
start_datetime=now(), |
|
189 |
) |
|
181 | 190 | |
182 | 191 |
output = get_output_of_command('export_site') |
183 |
assert len(json.loads(output)['agendas']) == 1
|
|
192 |
assert len(json.loads(output)['agendas']) == 2
|
|
184 | 193 |
import_site(data={}, clean=True) |
185 | 194 | |
186 | 195 |
with tempfile.NamedTemporaryFile() as f: |
... | ... | |
188 | 197 |
f.flush() |
189 | 198 |
call_command('import_site', f.name) |
190 | 199 | |
191 |
assert Agenda.objects.count() == 1 |
|
200 |
assert Agenda.objects.count() == 2 |
|
201 |
assert Event.objects.count() == 2 |
|
192 | 202 |
first_imported_event = Agenda.objects.get(label='Foo Bar').event_set.first() |
203 |
assert first_imported_event.slug == 'event' |
|
193 | 204 |
assert first_imported_event.description == 'description' |
194 | 205 |
assert first_imported_event.pricing == '100' |
195 | 206 |
assert first_imported_event.url == 'https://example.net/' |
196 | 207 |
assert first_imported_event.publication_date == datetime.date(2020, 5, 11) |
208 |
assert Agenda.objects.get(label='Foo Bar 2').event_set.first().slug == 'event' |
|
197 | 209 | |
198 | 210 | |
199 | 211 |
def test_import_export_recurring_event(app, freezer): |
200 |
- |