misc: faster api datetime tests

This commit is contained in:
Lauréline Guérin 2021-02-23 10:28:43 +01:00
parent d23eafcfc6
commit ccd27f7619
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
1 changed files with 22 additions and 14 deletions

View File

@ -440,29 +440,37 @@ def test_datetimes_api(app, some_data):
assert resp.json['data'][0]['description']
def test_datetimes_api_wrong_kind(app, some_data):
agenda = Agenda.objects.filter(label=u'Foo bar')[0]
agenda.kind = 'meetings'
agenda.save()
resp = app.get('/api/agenda/%s/datetimes/' % agenda.id, status=404)
def test_datetimes_api_wrong_kind(app):
agenda = Agenda.objects.create(label='Foo bar', kind='meetings')
app.get('/api/agenda/%s/datetimes/' % agenda.slug, status=404)
def test_datetime_api_fr(app, some_data):
agenda_id = Agenda.objects.filter(label=u'Foo bar')[0].id
def test_datetime_api_fr(app):
agenda = Agenda.objects.create(label='Foo bar', kind='events', minimal_booking_delay=0)
Event.objects.create(
slug='event-slug',
start_datetime=localtime((now() + datetime.timedelta(days=5))).replace(hour=17, minute=0),
places=5,
agenda=agenda,
)
with override_settings(LANGUAGE_CODE='fr-fr'):
resp = app.get('/api/agenda/%s/datetimes/' % agenda_id)
resp = app.get('/api/agenda/%s/datetimes/' % agenda.slug)
# no seconds, hh:mm in 24-hour formats
assert resp.json['data'][0]['text'].endswith(' 17:00')
assert resp.json['data'][0]['datetime'].endswith(' 17:00:00')
assert 'data' in resp.json
def test_datetime_api_label(app, some_data):
agenda_id = Agenda.objects.filter(label=u'Foo bar 2')[0].id
event = Event.objects.filter(agenda=agenda_id)[0]
event.label = 'Hello world'
event.save()
resp = app.get('/api/agenda/%s/datetimes/' % agenda_id)
def test_datetime_api_label(app):
agenda = Agenda.objects.create(label='Foo bar', kind='events', minimal_booking_delay=0)
Event.objects.create(
label='Hello world',
slug='event-slug',
start_datetime=(now() + datetime.timedelta(days=1)),
places=5,
agenda=agenda,
)
resp = app.get('/api/agenda/%s/datetimes/' % agenda.slug)
assert 'Hello world' in [x['text'] for x in resp.json['data']]