From edd308503a536fc1d920940bb60ebb654c3f767e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= <zebuline@entrouvert.com>
Date: Fri, 11 Jun 2021 14:20:28 +0200
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

diff --git a/tests/api/test_all.py b/tests/api/test_all.py
index 406a24a..bf55197 100644
--- a/tests/api/test_all.py
+++ b/tests/api/test_all.py
@@ -11,7 +11,6 @@ from chrono.agendas.models import (
     AbsenceReason,
     AbsenceReasonGroup,
     Agenda,
-    Booking,
     Category,
     Desk,
     Event,
@@ -359,96 +358,6 @@ def test_agendas_resources_api(app):
     resp = app.get('/api/agenda/%s/resources/' % agenda.slug, status=404)
 
 
-def test_status(app, user):
-    agenda = Agenda.objects.create(label='Foo bar', kind='events', minimal_booking_delay=0)
-    event = Event.objects.create(
-        slug='event-slug',
-        start_datetime=(now() + datetime.timedelta(days=5)).replace(hour=10, minute=0),
-        places=10,
-        agenda=agenda,
-    )
-    agenda2 = Agenda.objects.create(label='Foo bar2', kind='events', minimal_booking_delay=0)
-    # other event with the same slug but in another agenda
-    Event.objects.create(
-        slug='event-slug',
-        start_datetime=(now() + datetime.timedelta(days=5)).replace(hour=10, minute=0),
-        places=5,
-        agenda=agenda2,
-    )
-    Booking.objects.create(event=event)
-
-    app.get('/api/agenda/%s/status/%s/' % (agenda.slug, event.slug), status=401)
-
-    app.authorization = ('Basic', ('john.doe', 'password'))
-    resp = app.get('/api/agenda/%s/status/%s/' % (agenda.slug, event.slug))
-    assert resp.json['err'] == 0
-    assert resp.json['places']['total'] == 10
-    assert resp.json['places']['available'] == 9
-    assert resp.json['places']['reserved'] == 1
-    assert resp.json == {
-        'err': 0,
-        'id': 'event-slug',
-        'slug': 'event-slug',
-        'text': str(event),
-        'datetime': localtime(event.start_datetime).strftime('%Y-%m-%d %H:%M:%S'),
-        'description': None,
-        'pricing': None,
-        'url': None,
-        'disabled': False,
-        'api': {
-            'bookings_url': 'http://testserver/api/agenda/foo-bar/bookings/event-slug/',
-            'fillslot_url': 'http://testserver/api/agenda/foo-bar/fillslot/event-slug/',
-            'status_url': 'http://testserver/api/agenda/foo-bar/status/event-slug/',
-        },
-        'places': {'available': 9, 'reserved': 1, 'total': 10, 'full': False, 'has_waiting_list': False},
-    }
-    assert 'waiting_list_total' not in resp.json['places']
-
-    Booking(event=event, in_waiting_list=True).save()
-    event.waiting_list_places = 5
-    event.save()
-    resp = app.get('/api/agenda/%s/status/%s/' % (agenda.slug, event.slug))
-    assert resp.json['places']['waiting_list_total'] == 5
-    assert resp.json['places']['waiting_list_available'] == 4
-    assert resp.json['places']['waiting_list_reserved'] == 1
-
-    # wrong kind
-    for kind in ['meetings', 'virtual']:
-        agenda.kind = kind
-        agenda.save()
-        app.get('/api/agenda/%s/status/%s/' % (agenda.pk, event.slug), status=404)
-        app.get('/api/agenda/%s/status/%s/' % (agenda.slug, event.slug), status=404)
-
-
-def test_status_url(app, user):
-    agenda = Agenda.objects.create(label='Foo bar', kind='events', minimal_booking_delay=0)
-    event = Event.objects.create(
-        slug='event-slug',
-        start_datetime=(now() + datetime.timedelta(days=5)).replace(hour=10, minute=0),
-        places=10,
-        agenda=agenda,
-    )
-
-    app.authorization = ('Basic', ('john.doe', 'password'))
-
-    app.get('/api/agenda/%s/status/%s/' % (agenda.pk, event.pk))
-    app.get('/api/agenda/%s/status/%s/' % (agenda.slug, event.slug))
-    app.get('/api/agenda/%s/status/%s/' % (agenda.pk, event.slug))
-    app.get('/api/agenda/%s/status/%s/' % (agenda.slug, event.pk))
-
-    # unknown event
-    app.get('/api/agenda/%s/status/%s/' % (agenda.pk, 0), status=404)
-    app.get('/api/agenda/%s/status/%s/' % (agenda.slug, 0), status=404)
-    app.get('/api/agenda/%s/status/%s/' % (agenda.pk, 'foobar'), status=404)
-    app.get('/api/agenda/%s/status/%s/' % (agenda.slug, 'foobar'), status=404)
-
-    # unknown agenda
-    app.get('/api/agenda/%s/status/%s/' % (0, event.pk), status=404)
-    app.get('/api/agenda/%s/status/%s/' % (0, event.slug), status=404)
-    app.get('/api/agenda/%s/status/%s/' % ('foobar', event.pk), status=404)
-    app.get('/api/agenda/%s/status/%s/' % ('foobar', event.slug), status=404)
-
-
 def test_agenda_detail_api(app):
     agenda = Agenda.objects.create(label='Foo bar', kind='events', minimal_booking_delay=0)
     event1 = Event.objects.create(
diff --git a/tests/api/test_event.py b/tests/api/test_event.py
new file mode 100644
index 0000000..c88c38d
--- /dev/null
+++ b/tests/api/test_event.py
@@ -0,0 +1,100 @@
+# -*- coding: utf-8 -*-
+
+import datetime
+
+import pytest
+from django.utils.timezone import localtime, now
+
+from chrono.agendas.models import Agenda, Booking, Event
+
+pytestmark = pytest.mark.django_db
+
+
+def test_status(app, user):
+    agenda = Agenda.objects.create(label='Foo bar', kind='events', minimal_booking_delay=0)
+    event = Event.objects.create(
+        slug='event-slug',
+        start_datetime=(now() + datetime.timedelta(days=5)).replace(hour=10, minute=0),
+        places=10,
+        agenda=agenda,
+    )
+    agenda2 = Agenda.objects.create(label='Foo bar2', kind='events', minimal_booking_delay=0)
+    # other event with the same slug but in another agenda
+    Event.objects.create(
+        slug='event-slug',
+        start_datetime=(now() + datetime.timedelta(days=5)).replace(hour=10, minute=0),
+        places=5,
+        agenda=agenda2,
+    )
+    Booking.objects.create(event=event)
+
+    app.get('/api/agenda/%s/status/%s/' % (agenda.slug, event.slug), status=401)
+
+    app.authorization = ('Basic', ('john.doe', 'password'))
+    resp = app.get('/api/agenda/%s/status/%s/' % (agenda.slug, event.slug))
+    assert resp.json['err'] == 0
+    assert resp.json['places']['total'] == 10
+    assert resp.json['places']['available'] == 9
+    assert resp.json['places']['reserved'] == 1
+    assert resp.json == {
+        'err': 0,
+        'id': 'event-slug',
+        'slug': 'event-slug',
+        'text': str(event),
+        'datetime': localtime(event.start_datetime).strftime('%Y-%m-%d %H:%M:%S'),
+        'description': None,
+        'pricing': None,
+        'url': None,
+        'disabled': False,
+        'api': {
+            'bookings_url': 'http://testserver/api/agenda/foo-bar/bookings/event-slug/',
+            'fillslot_url': 'http://testserver/api/agenda/foo-bar/fillslot/event-slug/',
+            'status_url': 'http://testserver/api/agenda/foo-bar/status/event-slug/',
+        },
+        'places': {'available': 9, 'reserved': 1, 'total': 10, 'full': False, 'has_waiting_list': False},
+    }
+    assert 'waiting_list_total' not in resp.json['places']
+
+    Booking(event=event, in_waiting_list=True).save()
+    event.waiting_list_places = 5
+    event.save()
+    resp = app.get('/api/agenda/%s/status/%s/' % (agenda.slug, event.slug))
+    assert resp.json['places']['waiting_list_total'] == 5
+    assert resp.json['places']['waiting_list_available'] == 4
+    assert resp.json['places']['waiting_list_reserved'] == 1
+
+    # wrong kind
+    for kind in ['meetings', 'virtual']:
+        agenda.kind = kind
+        agenda.save()
+        app.get('/api/agenda/%s/status/%s/' % (agenda.pk, event.slug), status=404)
+        app.get('/api/agenda/%s/status/%s/' % (agenda.slug, event.slug), status=404)
+
+
+def test_status_url(app, user):
+    agenda = Agenda.objects.create(label='Foo bar', kind='events', minimal_booking_delay=0)
+    event = Event.objects.create(
+        slug='event-slug',
+        start_datetime=(now() + datetime.timedelta(days=5)).replace(hour=10, minute=0),
+        places=10,
+        agenda=agenda,
+    )
+
+    app.authorization = ('Basic', ('john.doe', 'password'))
+
+    app.get('/api/agenda/%s/status/%s/' % (agenda.pk, event.pk))
+    app.get('/api/agenda/%s/status/%s/' % (agenda.slug, event.slug))
+    app.get('/api/agenda/%s/status/%s/' % (agenda.pk, event.slug))
+    app.get('/api/agenda/%s/status/%s/' % (agenda.slug, event.pk))
+
+    # unknown event
+    app.get('/api/agenda/%s/status/%s/' % (agenda.pk, 0), status=404)
+    app.get('/api/agenda/%s/status/%s/' % (agenda.slug, 0), status=404)
+    app.get('/api/agenda/%s/status/%s/' % (agenda.pk, 'foobar'), status=404)
+    app.get('/api/agenda/%s/status/%s/' % (agenda.slug, 'foobar'), status=404)
+
+    # unknown agenda
+    app.get('/api/agenda/%s/status/%s/' % (0, event.pk), status=404)
+    app.get('/api/agenda/%s/status/%s/' % (0, event.slug), status=404)
+    app.get('/api/agenda/%s/status/%s/' % ('foobar', event.pk), status=404)
+    app.get('/api/agenda/%s/status/%s/' % ('foobar', event.slug), status=404)
-- 
2.30.2

