From 680e2dc62c4c6403b8c984b308d642237edec261 Mon Sep 17 00:00:00 2001
From: Helge Jung <hej@c3pb.de>
Date: Sat, 26 Dec 2020 03:07:21 +0100
Subject: [PATCH] API: unit test for schedule/event endpoint

---
 src/api/tests/__init__.py |  2 ++
 src/api/tests/schedule.py | 61 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)
 create mode 100644 src/api/tests/schedule.py

diff --git a/src/api/tests/__init__.py b/src/api/tests/__init__.py
index 63b4d921c..82daa5fb6 100644
--- a/src/api/tests/__init__.py
+++ b/src/api/tests/__init__.py
@@ -1,4 +1,6 @@
+from .bbb import *  # noqa: F401, F403
 from .engelsystem import *  # noqa: F401, F403
+from .schedule import *  # noqa: F401, F403
 from .workadventure import *  # noqa: F401, F403
 
 __all__ = '*'
diff --git a/src/api/tests/schedule.py b/src/api/tests/schedule.py
new file mode 100644
index 000000000..afeea7f0a
--- /dev/null
+++ b/src/api/tests/schedule.py
@@ -0,0 +1,61 @@
+import json
+
+from django.test import TestCase
+from django.urls import reverse
+from rest_framework.authtoken.models import Token
+
+from core.models import Assembly, Conference, Event, PlatformUser, Room
+
+
+class ScheduleTest(TestCase):
+    def test_push_event(self):
+        conf = Conference(slug='conf', name='TestConf', is_public=True)
+        conf.save()
+        conf.tracks.create(name='Community').save()
+        assembly = Assembly(name='TestAssembly', slug='asmbly', conference=conf)
+        assembly.save()
+        room = Room(conference=conf, assembly=assembly, name='Foo Room', room_type=Room.RoomType.STAGE)
+        room.save()
+
+        user = PlatformUser(username='bernd', is_active=True)
+        user.save()
+
+        token = Token(user=user)
+        token.save()
+
+        event = Event(conference=conf, assembly=assembly, name='Example Event')
+        event.save()
+
+        update = {
+            "url": "https://fahrplan.events.ccc.de/rc3/2020/Fahrplan/events/11583.html",
+            "id": 11583,
+            "guid": str(event.id),
+            "logo": None,
+            "date": "2020-12-27T12:20:00+01:00",
+            "start": "12:20",
+            "duration": "00:30",
+            "room": "foo room",
+            "slug": "rc3-11583-rc3_eroffnung",
+            "title": "#rC3 Er\u00f6ffnung",
+            "subtitle": "",
+            "track": "Community",
+            "type": "Talk",
+            "language": "de",
+            "abstract": "Willkommen zur ersten und hoffentlich einzigen Remote Chaos Experience!",
+            "description": "",
+            "recording_license": "",
+            "do_not_record": False,
+            "persons": [{"id": 14151, "public_name": "blubbel"}],
+            "links": [],
+            "attachments": []
+        }
+
+        url = reverse('api:event-schedule', kwargs={'conference': conf.slug, 'pk': event.pk})
+
+        with self.modify_settings(API_USERS={'append': user.username}):
+            resp = self.client.post(url, json.dumps(update), content_type='application/json', HTTP_AUTHORIZATION=f'Token {token.key}')
+
+        self.assertEqual(201, resp.status_code, f'Unexpected result from POST: {resp.content}')
+
+        event.refresh_from_db()
+        self.assertTrue('rC3' in event.name, f'Expected "rC3" in event name "{event.name}".')
-- 
GitLab