From ce7b5a38bab6000e742ce267aa0a7205e1cbb193 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= <zebuline@entrouvert.com>
Date: Mon, 24 Aug 2020 15:03:53 +0200
Subject: [PATCH] api: always return accept and suspend urls (#41773)

---
 chrono/api/views.py | 14 ++++++--------
 tests/test_api.py   | 10 +++++-----
 2 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/chrono/api/views.py b/chrono/api/views.py
index f0a27f0..eda38f2 100644
--- a/chrono/api/views.py
+++ b/chrono/api/views.py
@@ -996,19 +996,17 @@ class Fillslots(APIView):
                 'cancel_url': request.build_absolute_uri(
                     reverse('api-cancel-booking', kwargs={'booking_pk': primary_booking.id})
                 ),
+                'accept_url': request.build_absolute_uri(
+                    reverse('api-accept-booking', kwargs={'booking_pk': primary_booking.pk})
+                ),
+                'suspend_url': request.build_absolute_uri(
+                    reverse('api-suspend-booking', kwargs={'booking_pk': primary_booking.pk})
+                ),
                 'ics_url': request.build_absolute_uri(
                     reverse('api-booking-ics', kwargs={'booking_pk': primary_booking.id})
                 ),
             },
         }
-        if in_waiting_list:
-            response['api']['accept_url'] = request.build_absolute_uri(
-                reverse('api-accept-booking', kwargs={'booking_pk': primary_booking.id})
-            )
-        else:
-            response['api']['suspend_url'] = request.build_absolute_uri(
-                reverse('api-suspend-booking', kwargs={'booking_pk': primary_booking.pk})
-            )
         if agenda.accept_meetings():
             response['end_datetime'] = format_response_datetime(events[-1].end_datetime)
             response['duration'] = (events[-1].end_datetime - events[-1].start_datetime).seconds // 60
diff --git a/tests/test_api.py b/tests/test_api.py
index 780dc9d..90a0385 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -750,7 +750,7 @@ def test_booking_api(app, some_data, user):
     resp = app.post('/api/agenda/%s/fillslot/%s/' % (agenda.slug, event.id))
     Booking.objects.get(id=resp.json['booking_id'])
     assert resp.json['datetime'] == localtime(event.start_datetime).strftime('%Y-%m-%d %H:%M:%S')
-    assert 'accept_url' not in resp.json['api']
+    assert 'accept_url' in resp.json['api']
     assert 'suspend_url' in resp.json['api']
     assert 'cancel_url' in resp.json['api']
     assert 'ics_url' in resp.json['api']
@@ -952,7 +952,7 @@ def test_booking_api_fillslots(app, some_data, user):
     primary_booking_id = resp.json['booking_id']
     Booking.objects.get(id=primary_booking_id)
     assert resp.json['datetime'] == localtime(event.start_datetime).strftime('%Y-%m-%d %H:%M:%S')
-    assert 'accept_url' not in resp.json['api']
+    assert 'accept_url' in resp.json['api']
     assert 'suspend_url' in resp.json['api']
     assert 'cancel_url' in resp.json['api']
     assert urlparse.urlparse(resp.json['api']['suspend_url']).netloc
@@ -1869,7 +1869,7 @@ def test_waiting_list_booking(app, some_data, user):
     assert resp.json['err'] == 0
     assert resp.json['in_waiting_list'] is True
     assert 'accept_url' in resp.json['api']
-    assert 'suspend_url' not in resp.json['api']
+    assert 'suspend_url' in resp.json['api']
     assert 'cancel_url' in resp.json['api']
     assert 'ics_url' in resp.json['api']
     assert urlparse.urlparse(resp.json['api']['accept_url']).netloc
@@ -2266,7 +2266,7 @@ def test_multiple_booking_api(app, some_data, user):
     resp = app.post('/api/agenda/%s/fillslot/%s/?count=3' % (agenda.slug, event.id))
     Booking.objects.get(id=resp.json['booking_id'])
     assert resp.json['datetime'] == localtime(event.start_datetime).strftime('%Y-%m-%d %H:%M:%S')
-    assert 'accept_url' not in resp.json['api']
+    assert 'accept_url' in resp.json['api']
     assert 'cancel_url' in resp.json['api']
     assert Event.objects.get(id=event.id).booked_places == 3
 
@@ -2361,7 +2361,7 @@ def test_multiple_booking_api_fillslots(app, some_data, user):
     cancel_url = resp.json['api']['cancel_url']
     assert Booking.objects.filter(primary_booking=booking).count() == 5
     assert resp.json['datetime'] == localtime(events[0].start_datetime).strftime('%Y-%m-%d %H:%M:%S')
-    assert 'accept_url' not in resp.json['api']
+    assert 'accept_url' in resp.json['api']
     assert 'cancel_url' in resp.json['api']
     assert 'ics_url' in resp.json['api']
     resp_events = resp.json['events']
-- 
2.27.0

