Repository: fossasia/open-event-server

Issue:
Anonymous User: the section on the event page page that shows all sessions of an event
Parent issue #782.

 `/e/ID/session` - the section on the event page page that shows all sessions of an event



Discussion:

Resolving patch:
diff --git a/open_event/views/admin/models_views/my_sessions.py b/open_event/views/admin/models_views/my_sessions.py
--- a/open_event/views/admin/models_views/my_sessions.py
+++ b/open_event/views/admin/models_views/my_sessions.py
@@ -16,7 +16,7 @@ def display_my_sessions_view(self):
                            upcoming_events_sessions=upcoming_events_sessions, past_events_sessions=past_events_sessions,
                            page_content=page_content)
 
-    @expose('/<int:session_id>')
+    @expose('/<int:session_id>/')
     @flask_login.login_required
     def display_session_view(self, session_id):
         session = DataGetter.get_sessions_of_user_by_id(session_id)
diff --git a/open_event/views/public/event_detail.py b/open_event/views/public/event_detail.py
--- a/open_event/views/public/event_detail.py
+++ b/open_event/views/public/event_detail.py
@@ -1,21 +1,39 @@
+from flask import request
 from flask.ext.restplus import abort
 from flask_admin import BaseView, expose
 from werkzeug.utils import redirect
 
+from open_event.models.session import Session
 from ...helpers.data_getter import DataGetter
 
+def get_published_event_or_abort(event_id):
+    event = DataGetter.get_event(event_id=event_id)
+    if not event or (event.state != u'Published' and event.state != 'Published'):
+        abort(404)
+    return event
+
 class EventDetailView(BaseView):
 
     @expose('/')
     def display_default(self):
         return redirect("/browse")
 
-    @expose('/<int:event_id>')
+    @expose('/<int:event_id>/')
     def display_event_detail_home(self, event_id):
-        event = DataGetter.get_event(event_id=event_id)
-        if not event or event.state != 'Published':
-            abort(404)
+        event = get_published_event_or_abort(event_id)
         accepted_sessions = DataGetter.get_sessions(event_id)
-
         return self.render('/gentelella/guest/event/details.html', event=event, accepted_sessions=accepted_sessions)
 
+    @expose('/<int:event_id>/sessions/')
+    def display_event_sessions(self, event_id):
+        event = get_published_event_or_abort(event_id)
+        tracks = DataGetter.get_tracks(event_id)
+        return self.render('/gentelella/guest/event/sessions.html', event=event, tracks=tracks)
+
+    @expose('/<int:event_id>/<slug>/')
+    def display_event_detail_home_slugged(self, event_id, slug):
+        return self.display_event_detail_home(event_id)
+
+    @expose('/<int:event_id>/<slug>/sessions/')
+    def display_event_sessions_slugged(self, event_id, slug):
+        return self.display_event_sessions(event_id)


Test patch:
diff --git a/tests/test_guest_event_page.py b/tests/test_guest_event_page.py
--- a/tests/test_guest_event_page.py
+++ b/tests/test_guest_event_page.py
@@ -1,16 +1,12 @@
 import unittest
-from datetime import datetime
 
 from open_event.helpers.data import save_to_db
-from open_event.models.session import Session
-from open_event.models.speaker import Speaker
 from tests.object_mother import ObjectMother
 from tests.utils import OpenEventTestCase
 from tests.setup_database import Setup
-from tests.auth_helper import register, logout, login
 from open_event import current_app as app
 
-class TestMySession(OpenEventTestCase):
+class TestGuestEventPage(OpenEventTestCase):
     def setUp(self):
         self.app = Setup.create_app()
 
@@ -29,5 +25,23 @@ def test_unpublished_event_view_attempt(self):
             rv = self.app.get('e/' + str(event.id), follow_redirects=True)
             self.assertEqual(rv.status_code, 404)
 
+    def test_published_event_sessions_view(self):
+        with app.test_request_context():
+            event = ObjectMother.get_event()
+            event.state = 'Published'
+            save_to_db(event, "Event Saved")
+            track = ObjectMother.get_track()
+            track.event_id = event.id
+            save_to_db(track, "Track Saved")
+            speaker = ObjectMother.get_speaker()
+            speaker.event_id = event.id
+            save_to_db(speaker, "Speaker Saved")
+            session = ObjectMother.get_session()
+            session.event_id = event.id
+            session.speakers = [speaker]
+            save_to_db(speaker, "Session Saved")
+            rv = self.app.get('e/' + str(event.id) + '/sessions/', follow_redirects=True)
+            self.assertTrue("Sessions" in rv.data, msg=rv.data)
+
 if __name__ == '__main__':
     unittest.main()