Projet

Général

Profil

0001-api-param-to-exclude-som-meeting_types-66866.patch

Lauréline Guérin, 13 septembre 2022 16:03

Télécharger (3,91 ko)

Voir les différences:

Subject: [PATCH] api: param to exclude som meeting_types (#66866)

 chrono/api/views.py           |  4 +++
 tests/api/test_meetingtype.py | 49 ++++++++++++++++++++++++++++++++++-
 2 files changed, 52 insertions(+), 1 deletion(-)
chrono/api/views.py
1223 1223
            raise Http404('agenda found, but it does not accept meetings')
1224 1224

  
1225 1225
        meeting_types = []
1226
        exclude = request.GET.get('exclude') or ''
1227
        exclude = [x.strip() for x in exclude.split(',')]
1226 1228
        for meeting_type in agenda.iter_meetingtypes():
1229
            if meeting_type.slug in exclude:
1230
                continue
1227 1231
            meeting_types.append(
1228 1232
                {
1229 1233
                    'text': meeting_type.label,
tests/api/test_meetingtype.py
8 8
def test_agendas_meetingtypes_api(app):
9 9
    agenda = Agenda.objects.create(label='Foo bar meeting', kind='meetings')
10 10
    MeetingType.objects.create(agenda=agenda, label='Blah', duration=30)
11
    MeetingType.objects.create(agenda=agenda, label='Blah 2', duration=20)
12
    MeetingType.objects.create(agenda=agenda, label='Blah 3', duration=10)
11 13
    resp = app.get('/api/agenda/%s/meetings/' % agenda.slug)
12 14
    expected_resp = {
13 15
        'data': [
......
18 20
                'api': {
19 21
                    'datetimes_url': 'http://testserver/api/agenda/foo-bar-meeting/meetings/blah/datetimes/',
20 22
                },
21
            }
23
            },
24
            {
25
                'text': 'Blah 2',
26
                'id': 'blah-2',
27
                'duration': 20,
28
                'api': {
29
                    'datetimes_url': 'http://testserver/api/agenda/foo-bar-meeting/meetings/blah-2/datetimes/',
30
                },
31
            },
32
            {
33
                'text': 'Blah 3',
34
                'id': 'blah-3',
35
                'duration': 10,
36
                'api': {
37
                    'datetimes_url': 'http://testserver/api/agenda/foo-bar-meeting/meetings/blah-3/datetimes/',
38
                },
39
            },
22 40
        ]
23 41
    }
24 42
    assert resp.json == expected_resp
25 43

  
44
    resp = app.get('/api/agenda/%s/meetings/' % agenda.slug, params={'exclude': 'blah-2 ,blah,unknown'})
45
    expected_resp2 = {
46
        'data': [
47
            {
48
                'text': 'Blah 3',
49
                'id': 'blah-3',
50
                'duration': 10,
51
                'api': {
52
                    'datetimes_url': 'http://testserver/api/agenda/foo-bar-meeting/meetings/blah-3/datetimes/',
53
                },
54
            },
55
        ]
56
    }
57
    assert resp.json == expected_resp2
58

  
26 59
    # deleted meeting type does not show up
27 60
    MeetingType.objects.create(agenda=agenda, slug='deleted-meeting-type', duration=43, deleted=True)
28 61
    resp = app.get('/api/agenda/%s/meetings/' % agenda.slug)
......
96 129
        ]
97 130
    }
98 131

  
132
    resp = app.get('/api/agenda/%s/meetings/' % virt_agenda.slug, params={'exclude': 'unknown, meeting2'})
133
    assert resp.json == {
134
        'data': [
135
            {
136
                'text': 'Meeting1',
137
                'id': 'meeting1',
138
                'duration': 30,
139
                'api': {
140
                    'datetimes_url': 'http://testserver/api/agenda/virtual-agenda/meetings/meeting1/datetimes/',
141
                },
142
            },
143
        ]
144
    }
145

  
99 146
    # Several real agendas
100 147

  
101 148
    bar_agenda = Agenda.objects.create(label='Bar', kind='meetings')
102
-