api: add new API to get list of agendas (#11424)

This commit is contained in:
Frédéric Péters 2016-06-19 21:23:23 +02:00
parent 4ed8c47e3d
commit c3e3e5d574
3 changed files with 22 additions and 1 deletions

View File

@ -19,6 +19,7 @@ from django.conf.urls import patterns, url
from . import views
urlpatterns = patterns('',
url(r'agenda/$', views.agendas),
url(r'agenda/(?P<pk>\w+)/datetimes/$', views.datetimes),
url(r'agenda/(?P<agenda_pk>\w+)/fillslot/(?P<event_pk>\w+)/$', views.fillslot),
url(r'agenda/(?P<agenda_pk>\w+)/status/(?P<event_pk>\w+)/$', views.slot_status),

View File

@ -22,7 +22,19 @@ from rest_framework.generics import GenericAPIView
from rest_framework.response import Response
from rest_framework.views import APIView
from ..agendas.models import Event, Booking
from ..agendas.models import Agenda, Event, Booking
class Agendas(GenericAPIView):
def get(self, request, pk=None, format=None):
response = {'data': [{
'id': x.id,
'slug': x.slug,
'text': x.label}
for x in Agenda.objects.all().order_by('label')]}
return Response(response)
agendas = Agendas.as_view()
class Datetimes(GenericAPIView):

View File

@ -46,6 +46,14 @@ def some_data():
event.save()
def test_agendas_api(app, some_data):
agenda_id = Agenda.objects.filter(label=u'Foo bar')[0].id
agenda2_id = Agenda.objects.filter(label=u'Foo bar2')[0].id
resp = app.get('/api/agenda/')
assert resp.json == {'data': [
{'text': 'Foo bar', 'id': agenda_id, 'slug': u'foo-bar'},
{'text': 'Foo bar2', 'id': agenda2_id, 'slug': u'foo-bar2'}]}
def test_datetimes_api(app, some_data):
agenda_id = Agenda.objects.filter(label=u'Foo bar')[0].id
resp = app.get('/api/agenda/%s/datetimes/' % agenda_id)