api: param to exclude som meeting_types (#66866)

This commit is contained in:
Lauréline Guérin 2022-09-13 16:02:42 +02:00
parent dac8f1d5a9
commit 531a92975d
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 52 additions and 1 deletions

View File

@ -1223,7 +1223,11 @@ class MeetingList(APIView):
raise Http404('agenda found, but it does not accept meetings')
meeting_types = []
exclude = request.GET.get('exclude') or ''
exclude = [x.strip() for x in exclude.split(',')]
for meeting_type in agenda.iter_meetingtypes():
if meeting_type.slug in exclude:
continue
meeting_types.append(
{
'text': meeting_type.label,

View File

@ -8,6 +8,8 @@ pytestmark = pytest.mark.django_db
def test_agendas_meetingtypes_api(app):
agenda = Agenda.objects.create(label='Foo bar meeting', kind='meetings')
MeetingType.objects.create(agenda=agenda, label='Blah', duration=30)
MeetingType.objects.create(agenda=agenda, label='Blah 2', duration=20)
MeetingType.objects.create(agenda=agenda, label='Blah 3', duration=10)
resp = app.get('/api/agenda/%s/meetings/' % agenda.slug)
expected_resp = {
'data': [
@ -18,11 +20,42 @@ def test_agendas_meetingtypes_api(app):
'api': {
'datetimes_url': 'http://testserver/api/agenda/foo-bar-meeting/meetings/blah/datetimes/',
},
}
},
{
'text': 'Blah 2',
'id': 'blah-2',
'duration': 20,
'api': {
'datetimes_url': 'http://testserver/api/agenda/foo-bar-meeting/meetings/blah-2/datetimes/',
},
},
{
'text': 'Blah 3',
'id': 'blah-3',
'duration': 10,
'api': {
'datetimes_url': 'http://testserver/api/agenda/foo-bar-meeting/meetings/blah-3/datetimes/',
},
},
]
}
assert resp.json == expected_resp
resp = app.get('/api/agenda/%s/meetings/' % agenda.slug, params={'exclude': 'blah-2 ,blah,unknown'})
expected_resp2 = {
'data': [
{
'text': 'Blah 3',
'id': 'blah-3',
'duration': 10,
'api': {
'datetimes_url': 'http://testserver/api/agenda/foo-bar-meeting/meetings/blah-3/datetimes/',
},
},
]
}
assert resp.json == expected_resp2
# deleted meeting type does not show up
MeetingType.objects.create(agenda=agenda, slug='deleted-meeting-type', duration=43, deleted=True)
resp = app.get('/api/agenda/%s/meetings/' % agenda.slug)
@ -96,6 +129,20 @@ def test_virtual_agendas_meetingtypes_api(app):
]
}
resp = app.get('/api/agenda/%s/meetings/' % virt_agenda.slug, params={'exclude': 'unknown, meeting2'})
assert resp.json == {
'data': [
{
'text': 'Meeting1',
'id': 'meeting1',
'duration': 30,
'api': {
'datetimes_url': 'http://testserver/api/agenda/virtual-agenda/meetings/meeting1/datetimes/',
},
},
]
}
# Several real agendas
bar_agenda = Agenda.objects.create(label='Bar', kind='meetings')