Projet

Général

Profil

0006-api-subscription-delete-endpoint-60861.patch

Lauréline Guérin, 27 janvier 2022 10:43

Télécharger (2,91 ko)

Voir les différences:

Subject: [PATCH 6/6] api: subscription delete endpoint (#60861)

 chrono/api/views.py            |  5 +++++
 tests/api/test_subscription.py | 41 ++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
chrono/api/views.py
1956 1956
        )
1957 1957
        return Response(response)
1958 1958

  
1959
    def delete(self, request, *args, **kwargs):
1960
        self.subscription.delete()
1961
        response = {'err': 0}
1962
        return Response(response)
1963

  
1959 1964

  
1960 1965
subscription = SubscriptionAPI.as_view()
1961 1966

  
tests/api/test_subscription.py
258 258
        agenda.kind = kind
259 259
        agenda.save()
260 260
        app.get('/api/agenda/%s/subscription/%s/' % (agenda.slug, subscription.pk), status=404)
261

  
262

  
263
def test_api_delete_subscription(app, user):
264
    agenda = Agenda.objects.create(label='Foo bar', kind='events')
265
    subscription = Subscription.objects.create(
266
        agenda=agenda,
267
        user_external_id='xxx',
268
        user_first_name='Foo',
269
        user_last_name='BAR',
270
        user_email='foo@bar.com',
271
        user_phone_number='06',
272
        extra_data={'foo': 'bar'},
273
        date_start=datetime.date(year=2021, month=9, day=1),
274
        date_end=datetime.date(year=2021, month=10, day=1),
275
    )
276
    other_agenda = Agenda.objects.create(label='Foo bar', kind='events')
277
    other_subscription = Subscription.objects.create(
278
        agenda=other_agenda,
279
        user_external_id='xxx',
280
        date_start=datetime.date(year=2021, month=9, day=1),
281
        date_end=datetime.date(year=2021, month=10, day=1),
282
    )
283

  
284
    resp = app.delete('/api/agenda/%s/subscription/%s/' % (agenda.slug, subscription.pk), status=401)
285

  
286
    app.authorization = ('Basic', ('john.doe', 'password'))
287

  
288
    app.delete('/api/agenda/%s/subscription/%s/' % (agenda.slug, other_subscription.pk), status=404)
289
    app.delete('/api/agenda/%s/subscription/%s/' % (agenda.slug, 0), status=404)
290
    app.delete('/api/agenda/%s/subscription/%s/' % ('unknown', subscription.pk), status=404)
291
    for kind in ['meetings', 'virtual']:
292
        agenda.kind = kind
293
        agenda.save()
294
        app.delete('/api/agenda/%s/subscription/%s/' % (agenda.slug, subscription.pk), status=404)
295

  
296
    agenda.kind = 'events'
297
    agenda.save()
298

  
299
    resp = app.delete('/api/agenda/%s/subscription/%s/' % (agenda.slug, subscription.pk))
300
    assert resp.json['err'] == 0
301
    assert Subscription.objects.filter(pk=subscription.pk).exists() is False
261
-