Projet

Général

Profil

0001-api-only-use-event-slug-in-URLs-when-it-is-set-38081.patch

Frédéric Péters, 29 novembre 2019 13:37

Télécharger (2,99 ko)

Voir les différences:

Subject: [PATCH] api: only use event slug in URLs when it is set (#38081)

 chrono/api/views.py | 4 ++--
 tests/test_api.py   | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)
chrono/api/views.py
211 211
                                      reverse('api-fillslot',
212 212
                                          kwargs={
213 213
                                              'agenda_identifier': agenda.slug,
214
                                              'event_identifier': x.slug,
214
                                              'event_identifier': x.slug or x.id,
215 215
                                      })),
216 216
                                  'status_url': request.build_absolute_uri(
217 217
                                      reverse('api-event-status',
218 218
                                          kwargs={
219 219
                                              'agenda_identifier': agenda.slug,
220
                                              'event_identifier': x.slug,
220
                                              'event_identifier': x.slug or x.id,
221 221
                                      }))
222 222
                                  },
223 223
                              } for x in entries]}
tests/test_api.py
225 225
    agenda = Agenda.objects.get(label=u'Foo bar2')
226 226
    resp = app.get('/api/agenda/%s/datetimes/' % agenda.slug)
227 227
    for datum in resp.json['data']:
228
        assert urlparse.urlparse(datum['api']['status_url']).path == '/api/agenda/%s/status/%s/' % (agenda.slug, datum['slug'])
228
        assert urlparse.urlparse(datum['api']['status_url']).path == '/api/agenda/%s/status/%s/' % (
229
                agenda.slug, datum['slug'] or datum['id'])
229 230

  
230 231
def test_datetimes_api_meetings_agenda(app, meetings_agenda):
231 232
    meeting_type = MeetingType.objects.get(agenda=meetings_agenda)
......
337 338
    for agenda_key in (agenda.slug, agenda.id):  # acces datetimes via agenda slug or id (legacy)
338 339
        resp_datetimes = app.get('/api/agenda/%s/datetimes/' % agenda_key)
339 340
        event_fillslot_url = [x for x in resp_datetimes.json['data'] if x['id'] == event.id][0]['api']['fillslot_url']
340
        assert urlparse.urlparse(event_fillslot_url).path == '/api/agenda/%s/fillslot/%s/' % (agenda.slug, event.slug)
341
        assert urlparse.urlparse(event_fillslot_url).path == '/api/agenda/%s/fillslot/%s/' % (agenda.slug, event.slug or event.id)
341 342

  
342 343
    app.authorization = ('Basic', ('john.doe', 'password'))
343 344
    resp = app.post('/api/agenda/%s/fillslot/%s/' % (agenda.slug, event.id))
344
-