Repository: fossasia/open-event-server

Issue:
Add session related endpoints to docs 
Parent issue #4009.


Discussion:
kept on hold due to #4076 
Removing `on-hold`

Resolving patch:
diff --git a/app/api/__init__.py b/app/api/__init__.py
--- a/app/api/__init__.py
+++ b/app/api/__init__.py
@@ -194,7 +194,7 @@
 
 # sessions
 api.route(SessionListPost, 'session_list_post', '/sessions')
-api.route(SessionList, 'session_list', '/sessions', '/events/<int:event_id>/sessions',
+api.route(SessionList, 'session_list', '/events/<int:event_id>/sessions',
           '/events/<event_identifier>/sessions',
           '/tracks/<int:track_id>/sessions', '/session-types/<int:session_type_id>/sessions',
           '/microlocations/<int:microlocation_id>/sessions', '/speakers/<int:speaker_id>/sessions')
diff --git a/app/api/microlocations.py b/app/api/microlocations.py
--- a/app/api/microlocations.py
+++ b/app/api/microlocations.py
@@ -61,6 +61,7 @@ def before_post(self, args, kwargs, data):
         if not has_access('is_coorganizer', event_id=data['event']):
             raise ForbiddenException({'source': ''}, 'Co-organizer access is required.')
 
+    methods = ['POST', ]
     schema = MicrolocationSchema
     data_layer = {'session': db.session,
                   'model': Microlocation}
diff --git a/app/factories/session.py b/app/factories/session.py
--- a/app/factories/session.py
+++ b/app/factories/session.py
@@ -3,6 +3,8 @@
 import app.factories.common as common
 from app.factories.event import EventFactoryBasic
 from app.factories.session_type import SessionTypeFactory
+from app.factories.track import TrackFactory
+from app.factories.microlocation import MicrolocationFactory
 
 
 class SessionFactory(factory.alchemy.SQLAlchemyModelFactory):
@@ -12,6 +14,8 @@ class Meta:
 
     event = factory.RelatedFactory(EventFactoryBasic)
     session_type = factory.RelatedFactory(SessionTypeFactory)
+    track = factory.RelatedFactory(TrackFactory)
+    microlocation = factory.RelatedFactory(MicrolocationFactory)
     title = common.string_
     subtitle = common.string_
     level = common.int_
@@ -31,3 +35,5 @@ class Meta:
     is_mail_sent = True
     event_id = 1
     session_type_id = 1
+    track_id = 1
+    microlocation_id = 1


Test patch:
diff --git a/tests/hook_main.py b/tests/hook_main.py
--- a/tests/hook_main.py
+++ b/tests/hook_main.py
@@ -437,19 +437,6 @@ def microlocation_delete(transaction):
 
 
 # ------------------------- Sessions -------------------------
-@hooks.before("Sessions > Sessions Collection > List All Sessions")
-def session_get_list(transaction):
-    """
-    GET /events/1/sessions
-    :param transaction:
-    :return:
-    """
-    with stash['app'].app_context():
-        session = SessionFactory()
-        db.session.add(session)
-        db.session.commit()
-
-
 @hooks.before("Sessions > Sessions Collection > Create Sessions")
 def session_post(transaction):
     """
@@ -502,6 +489,71 @@ def session_delete(transaction):
         db.session.commit()
 
 
+@hooks.before("Sessions > List Sessions under an Event > List Sessions")
+def event_session(transaction):
+    """
+    GET /events/1/sessions
+    :param transaction:
+    :return:
+    """
+    with stash['app'].app_context():
+        session = SessionFactory()
+        db.session.add(session)
+        db.session.commit()
+
+
+@hooks.before("Sessions > List Sessions under a Track > List Sessions")
+def track_session(transaction):
+    """
+    GET /tracks/1/sessions
+    :param transaction:
+    :return:
+    """
+    with stash['app'].app_context():
+        session = SessionFactory()
+        db.session.add(session)
+        db.session.commit()
+
+
+@hooks.before("Sessions > List Sessions under a Session Type > List Sessions")
+def session_type_session(transaction):
+    """
+    GET /session-types/1/sessions
+    :param transaction:
+    :return:
+    """
+    with stash['app'].app_context():
+        session = SessionFactory()
+        db.session.add(session)
+        db.session.commit()
+
+
+@hooks.before("Sessions > List Sessions under a Microlocation > List Sessions")
+def microlocation_session(transaction):
+    """
+    GET /microlations/1/sessions
+    :param transaction:
+    :return:
+    """
+    with stash['app'].app_context():
+        session = SessionFactory()
+        db.session.add(session)
+        db.session.commit()
+
+
+@hooks.before("Sessions > List Sessions under a Speaker > List Sessions")
+def speaker_session(transaction):
+    """
+    GET /speakers/1/sessions
+    :param transaction:
+    :return:
+    """
+    with stash['app'].app_context():
+        speaker = SpeakerFactory()
+        db.session.add(speaker)
+        db.session.commit()
+
+
 # ------------------------- Session Type -------------------------
 @hooks.before("Session Type > Session Type Collection > Create Session Type")
 def session_type_post(transaction):