datasource: use form_var_meeting_type_raw for chrono auto mt ds (#78969)
gitea/wcs/pipeline/head This commit looks good Details

This commit is contained in:
Lauréline Guérin 2023-06-23 14:56:38 +02:00 committed by Lauréline Guérin
parent c7aa285c08
commit ba08cfbc5c
2 changed files with 52 additions and 6 deletions

View File

@ -174,8 +174,8 @@ def test_collect_agenda_data(pub, chrono_url):
},
{
'slug': 'agenda-meetings-meetings-A-mtdynamic',
'text': 'Meetings A - Slots of type form_var_meeting_type',
'url': 'http://chrono.example.net/api/agenda/meetings-A/meetings/{{ form_var_meeting_type }}/datetimes/',
'text': 'Meetings A - Slots of type form_var_meeting_type_raw',
'url': 'http://chrono.example.net/api/agenda/meetings-A/meetings/{{ form_var_meeting_type_raw }}/datetimes/',
},
{
'slug': 'agenda-meetings-meetings-A-mt-mt-1',
@ -194,8 +194,8 @@ def test_collect_agenda_data(pub, chrono_url):
},
{
'slug': 'agenda-virtual-virtual-B-mtdynamic',
'text': 'Virtual B - Slots of type form_var_meeting_type',
'url': 'http://chrono.example.net/api/agenda/virtual-B/meetings/{{ form_var_meeting_type }}/datetimes/',
'text': 'Virtual B - Slots of type form_var_meeting_type_raw',
'url': 'http://chrono.example.net/api/agenda/virtual-B/meetings/{{ form_var_meeting_type_raw }}/datetimes/',
},
{
'slug': 'agenda-virtual-virtual-B-mt-mt-3',
@ -401,6 +401,45 @@ def test_build_agenda_datasources(mock_collect, pub, chrono_url):
datasource4 = NamedDataSource.get(4 + 4)
assert datasource4.external_status is None
# check temporay migration code for mtdynamic datasources
mock_collect.return_value = [
{
'slug': 'slug-A',
'text': 'Events A',
'url': 'http://chrono.example.net/api/agenda/events-A/datetimes/',
},
{
'slug': 'slug-B',
'text': 'Events B',
'url': 'http://chrono.example.net/api/agenda/events-B/datetimes/',
},
{
'slug': 'agenda-meetings-meetings-A-mtdynamic',
'text': 'Meetings A - Slots of type form_var_meeting_type_raw',
'url': 'http://chrono.example.net/api/agenda/meetings-A/meetings/{{ form_var_meeting_type_raw }}/datetimes/',
},
]
build_agenda_datasources(pub)
assert NamedDataSource.count() == 4 + 4
datasource5 = NamedDataSource.get(4 + 5)
assert datasource5.slug == 'chrono_ds_agendameetingsmeetingsamtdynamic'
assert datasource5.data_source == {
'type': 'json',
'value': '{{ agendas_url }}api/agenda/meetings-A/meetings/{{ form_var_meeting_type_raw }}/datetimes/',
}
datasource5.data_source[
'value'
] = '{{ agendas_url }}api/agenda/meetings-A/meetings/{{ form_var_meeting_type }}/datetimes/'
datasource5.store()
build_agenda_datasources(pub)
assert NamedDataSource.count() == 4 + 4
datasource5 = NamedDataSource.get(4 + 5)
assert datasource5.slug == 'chrono_ds_agendameetingsmeetingsamtdynamic'
assert datasource5.data_source == {
'type': 'json',
'value': '{{ agendas_url }}api/agenda/meetings-A/meetings/{{ form_var_meeting_type_raw }}/datetimes/',
}
def test_agenda_datasources_migration(pub, chrono_url):
pub.load_site_options()

View File

@ -1172,8 +1172,8 @@ def collect_agenda_data(publisher):
agenda_data.append(
{
'slug': 'agenda-%s-%s-mtdynamic' % (agenda['kind'], agenda['id']),
'text': _('%s - Slots of type form_var_meeting_type') % agenda['text'],
'url': '%s{{ form_var_meeting_type }}/datetimes/' % agenda['api']['meetings_url'],
'text': _('%s - Slots of type form_var_meeting_type_raw') % agenda['text'],
'url': '%s{{ form_var_meeting_type_raw }}/datetimes/' % agenda['api']['meetings_url'],
}
)
# get also meeting types
@ -1212,7 +1212,14 @@ def build_agenda_datasources(publisher, **kwargs):
# build datasources from chrono
for agenda in agenda_data:
url = translate_url(publisher, agenda['url'])
# migration code, 2023-06-23, to remove later
datasource = existing_datasources.get(url)
if datasource is None and url.endswith('{{ form_var_meeting_type_raw }}/datetimes/'):
old_url = url.replace('form_var_meeting_type_raw', 'form_var_meeting_type')
datasource = existing_datasources.get(old_url)
if datasource:
existing_datasources.pop(old_url)
datasource.data_source['value'] = url
if datasource is None:
datasource = NamedDataSource()
datasource.slug = datasource.get_new_slug('chrono_ds_%s' % agenda['slug'])