Projet

Général

Profil

0001-misc-split-tests.patch

Lauréline Guérin, 11 juin 2021 14:37

Télécharger (9,03 ko)

Voir les différences:

Subject: [PATCH 1/2] misc: split tests

 tests/api/test_all.py   |  91 ------------------------------------
 tests/api/test_event.py | 100 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 100 insertions(+), 91 deletions(-)
 create mode 100644 tests/api/test_event.py
tests/api/test_all.py
11 11
    AbsenceReason,
12 12
    AbsenceReasonGroup,
13 13
    Agenda,
14
    Booking,
15 14
    Category,
16 15
    Desk,
17 16
    Event,
......
359 358
    resp = app.get('/api/agenda/%s/resources/' % agenda.slug, status=404)
360 359

  
361 360

  
362
def test_status(app, user):
363
    agenda = Agenda.objects.create(label='Foo bar', kind='events', minimal_booking_delay=0)
364
    event = Event.objects.create(
365
        slug='event-slug',
366
        start_datetime=(now() + datetime.timedelta(days=5)).replace(hour=10, minute=0),
367
        places=10,
368
        agenda=agenda,
369
    )
370
    agenda2 = Agenda.objects.create(label='Foo bar2', kind='events', minimal_booking_delay=0)
371
    # other event with the same slug but in another agenda
372
    Event.objects.create(
373
        slug='event-slug',
374
        start_datetime=(now() + datetime.timedelta(days=5)).replace(hour=10, minute=0),
375
        places=5,
376
        agenda=agenda2,
377
    )
378
    Booking.objects.create(event=event)
379

  
380
    app.get('/api/agenda/%s/status/%s/' % (agenda.slug, event.slug), status=401)
381

  
382
    app.authorization = ('Basic', ('john.doe', 'password'))
383
    resp = app.get('/api/agenda/%s/status/%s/' % (agenda.slug, event.slug))
384
    assert resp.json['err'] == 0
385
    assert resp.json['places']['total'] == 10
386
    assert resp.json['places']['available'] == 9
387
    assert resp.json['places']['reserved'] == 1
388
    assert resp.json == {
389
        'err': 0,
390
        'id': 'event-slug',
391
        'slug': 'event-slug',
392
        'text': str(event),
393
        'datetime': localtime(event.start_datetime).strftime('%Y-%m-%d %H:%M:%S'),
394
        'description': None,
395
        'pricing': None,
396
        'url': None,
397
        'disabled': False,
398
        'api': {
399
            'bookings_url': 'http://testserver/api/agenda/foo-bar/bookings/event-slug/',
400
            'fillslot_url': 'http://testserver/api/agenda/foo-bar/fillslot/event-slug/',
401
            'status_url': 'http://testserver/api/agenda/foo-bar/status/event-slug/',
402
        },
403
        'places': {'available': 9, 'reserved': 1, 'total': 10, 'full': False, 'has_waiting_list': False},
404
    }
405
    assert 'waiting_list_total' not in resp.json['places']
406

  
407
    Booking(event=event, in_waiting_list=True).save()
408
    event.waiting_list_places = 5
409
    event.save()
410
    resp = app.get('/api/agenda/%s/status/%s/' % (agenda.slug, event.slug))
411
    assert resp.json['places']['waiting_list_total'] == 5
412
    assert resp.json['places']['waiting_list_available'] == 4
413
    assert resp.json['places']['waiting_list_reserved'] == 1
414

  
415
    # wrong kind
416
    for kind in ['meetings', 'virtual']:
417
        agenda.kind = kind
418
        agenda.save()
419
        app.get('/api/agenda/%s/status/%s/' % (agenda.pk, event.slug), status=404)
420
        app.get('/api/agenda/%s/status/%s/' % (agenda.slug, event.slug), status=404)
421

  
422

  
423
def test_status_url(app, user):
424
    agenda = Agenda.objects.create(label='Foo bar', kind='events', minimal_booking_delay=0)
425
    event = Event.objects.create(
426
        slug='event-slug',
427
        start_datetime=(now() + datetime.timedelta(days=5)).replace(hour=10, minute=0),
428
        places=10,
429
        agenda=agenda,
430
    )
431

  
432
    app.authorization = ('Basic', ('john.doe', 'password'))
433

  
434
    app.get('/api/agenda/%s/status/%s/' % (agenda.pk, event.pk))
435
    app.get('/api/agenda/%s/status/%s/' % (agenda.slug, event.slug))
436
    app.get('/api/agenda/%s/status/%s/' % (agenda.pk, event.slug))
437
    app.get('/api/agenda/%s/status/%s/' % (agenda.slug, event.pk))
438

  
439
    # unknown event
440
    app.get('/api/agenda/%s/status/%s/' % (agenda.pk, 0), status=404)
441
    app.get('/api/agenda/%s/status/%s/' % (agenda.slug, 0), status=404)
442
    app.get('/api/agenda/%s/status/%s/' % (agenda.pk, 'foobar'), status=404)
443
    app.get('/api/agenda/%s/status/%s/' % (agenda.slug, 'foobar'), status=404)
444

  
445
    # unknown agenda
446
    app.get('/api/agenda/%s/status/%s/' % (0, event.pk), status=404)
447
    app.get('/api/agenda/%s/status/%s/' % (0, event.slug), status=404)
448
    app.get('/api/agenda/%s/status/%s/' % ('foobar', event.pk), status=404)
449
    app.get('/api/agenda/%s/status/%s/' % ('foobar', event.slug), status=404)
450

  
451

  
452 361
def test_agenda_detail_api(app):
453 362
    agenda = Agenda.objects.create(label='Foo bar', kind='events', minimal_booking_delay=0)
454 363
    event1 = Event.objects.create(
tests/api/test_event.py
1
# -*- coding: utf-8 -*-
2

  
3
import datetime
4

  
5
import pytest
6
from django.utils.timezone import localtime, now
7

  
8
from chrono.agendas.models import Agenda, Booking, Event
9

  
10
pytestmark = pytest.mark.django_db
11

  
12

  
13
def test_status(app, user):
14
    agenda = Agenda.objects.create(label='Foo bar', kind='events', minimal_booking_delay=0)
15
    event = Event.objects.create(
16
        slug='event-slug',
17
        start_datetime=(now() + datetime.timedelta(days=5)).replace(hour=10, minute=0),
18
        places=10,
19
        agenda=agenda,
20
    )
21
    agenda2 = Agenda.objects.create(label='Foo bar2', kind='events', minimal_booking_delay=0)
22
    # other event with the same slug but in another agenda
23
    Event.objects.create(
24
        slug='event-slug',
25
        start_datetime=(now() + datetime.timedelta(days=5)).replace(hour=10, minute=0),
26
        places=5,
27
        agenda=agenda2,
28
    )
29
    Booking.objects.create(event=event)
30

  
31
    app.get('/api/agenda/%s/status/%s/' % (agenda.slug, event.slug), status=401)
32

  
33
    app.authorization = ('Basic', ('john.doe', 'password'))
34
    resp = app.get('/api/agenda/%s/status/%s/' % (agenda.slug, event.slug))
35
    assert resp.json['err'] == 0
36
    assert resp.json['places']['total'] == 10
37
    assert resp.json['places']['available'] == 9
38
    assert resp.json['places']['reserved'] == 1
39
    assert resp.json == {
40
        'err': 0,
41
        'id': 'event-slug',
42
        'slug': 'event-slug',
43
        'text': str(event),
44
        'datetime': localtime(event.start_datetime).strftime('%Y-%m-%d %H:%M:%S'),
45
        'description': None,
46
        'pricing': None,
47
        'url': None,
48
        'disabled': False,
49
        'api': {
50
            'bookings_url': 'http://testserver/api/agenda/foo-bar/bookings/event-slug/',
51
            'fillslot_url': 'http://testserver/api/agenda/foo-bar/fillslot/event-slug/',
52
            'status_url': 'http://testserver/api/agenda/foo-bar/status/event-slug/',
53
        },
54
        'places': {'available': 9, 'reserved': 1, 'total': 10, 'full': False, 'has_waiting_list': False},
55
    }
56
    assert 'waiting_list_total' not in resp.json['places']
57

  
58
    Booking(event=event, in_waiting_list=True).save()
59
    event.waiting_list_places = 5
60
    event.save()
61
    resp = app.get('/api/agenda/%s/status/%s/' % (agenda.slug, event.slug))
62
    assert resp.json['places']['waiting_list_total'] == 5
63
    assert resp.json['places']['waiting_list_available'] == 4
64
    assert resp.json['places']['waiting_list_reserved'] == 1
65

  
66
    # wrong kind
67
    for kind in ['meetings', 'virtual']:
68
        agenda.kind = kind
69
        agenda.save()
70
        app.get('/api/agenda/%s/status/%s/' % (agenda.pk, event.slug), status=404)
71
        app.get('/api/agenda/%s/status/%s/' % (agenda.slug, event.slug), status=404)
72

  
73

  
74
def test_status_url(app, user):
75
    agenda = Agenda.objects.create(label='Foo bar', kind='events', minimal_booking_delay=0)
76
    event = Event.objects.create(
77
        slug='event-slug',
78
        start_datetime=(now() + datetime.timedelta(days=5)).replace(hour=10, minute=0),
79
        places=10,
80
        agenda=agenda,
81
    )
82

  
83
    app.authorization = ('Basic', ('john.doe', 'password'))
84

  
85
    app.get('/api/agenda/%s/status/%s/' % (agenda.pk, event.pk))
86
    app.get('/api/agenda/%s/status/%s/' % (agenda.slug, event.slug))
87
    app.get('/api/agenda/%s/status/%s/' % (agenda.pk, event.slug))
88
    app.get('/api/agenda/%s/status/%s/' % (agenda.slug, event.pk))
89

  
90
    # unknown event
91
    app.get('/api/agenda/%s/status/%s/' % (agenda.pk, 0), status=404)
92
    app.get('/api/agenda/%s/status/%s/' % (agenda.slug, 0), status=404)
93
    app.get('/api/agenda/%s/status/%s/' % (agenda.pk, 'foobar'), status=404)
94
    app.get('/api/agenda/%s/status/%s/' % (agenda.slug, 'foobar'), status=404)
95

  
96
    # unknown agenda
97
    app.get('/api/agenda/%s/status/%s/' % (0, event.pk), status=404)
98
    app.get('/api/agenda/%s/status/%s/' % (0, event.slug), status=404)
99
    app.get('/api/agenda/%s/status/%s/' % ('foobar', event.pk), status=404)
100
    app.get('/api/agenda/%s/status/%s/' % ('foobar', event.slug), status=404)
0
-