Repository: fossasia/open-event-server

Issue:
ICalExporter not working
https://github.com/fossasia/open-event-server/blob/97e94f2ce14d20341253822b5456c93bef590c71/app/api/helpers/ICalExporter.py#L48-L53

There is no email attribute on event object.

Fix the method and write tests


Discussion:
@iamareebjamal We have tests for ical exports. Will fix this method. 
Yes, but we don't have tests which fail for this case which is equal to having no tests
@iamareebjamal What kind of a privacy scenario are we considering here when it comes to using `speaker.email` ?
I don't know, maybe it's discussed on the PR in which it was implemented
@iamareebjamal Based on my limited understanding of this issue, I need to ask how can an email be related to an event? Are we referring to the email of the organizer instead?
Yes, @roshnet, it's supposed to be the email of owner/organizer. But `event.email` is not a field

Resolving patch:
diff --git a/app/api/helpers/ICalExporter.py b/app/api/helpers/ICalExporter.py
--- a/app/api/helpers/ICalExporter.py
+++ b/app/api/helpers/ICalExporter.py
@@ -47,8 +47,7 @@ def export(event_id):
 
             for speaker in session.speakers:
                 # Ref: http://icalendar.readthedocs.io/en/latest/usage.html#file-structure
-                # can use speaker.email below but privacy reasons
-                attendee = vCalAddress('MAILTO:' + event.email if event.email else 'undefined@email.com')
+                attendee = vCalAddress('MAILTO:' + speaker.email if speaker.email else 'undefined@email.com')
                 attendee.params['cn'] = vText(speaker.name)
                 event_component.add('attendee', attendee)
 
diff --git a/app/models/speaker.py b/app/models/speaker.py
--- a/app/models/speaker.py
+++ b/app/models/speaker.py
@@ -90,7 +90,7 @@ def __init__(self,
         self.sponsorship_required = sponsorship_required
         self.event_id = event_id
         self.user_id = user_id
-        self.deleted_at = deleted_at,
+        self.deleted_at = deleted_at
         self.complex_field_values = complex_field_values
 
     @staticmethod


Test patch:
diff --git a/tests/all/integration/api/helpers/test_icalexporter.py b/tests/all/integration/api/helpers/test_icalexporter.py
--- a/tests/all/integration/api/helpers/test_icalexporter.py
+++ b/tests/all/integration/api/helpers/test_icalexporter.py
@@ -1,18 +1,16 @@
 import unittest
 import icalendar
-from app import current_app as app
 
-from tests.all.integration.setup_database import Setup
-from tests.all.integration.utils import OpenEventTestCase
+from app import current_app as app
 from app.factories.session import SessionFactory
+from app.factories.speaker import SpeakerFactory
 from app.api.helpers.ICalExporter import ICalExporter
+from tests.all.integration.utils import OpenEventTestCase
 
 
 class TestICalExporter(OpenEventTestCase):
-    def setUp(self):
-        self.app = Setup.create_app()
 
-    def test_export(self):
+    def test_export_basic(self):
         """Test to export ical format event"""
         with app.test_request_context():
             test_session = SessionFactory()
@@ -22,6 +20,22 @@ def test_export(self):
             self.assertEqual(test_cal['x-wr-calname'], 'example')
             self.assertEqual(test_cal['x-wr-caldesc'],  'Schedule for sessions at example')
 
+    def test_export_subcomponents(self):
+        """Test to check presence of subcomponents"""
+        with app.test_request_context():
+            test_session = SessionFactory()
+
+            speaker = SpeakerFactory(name="xyz", email="test@xyz.com", user_id=1)
+            test_session.speakers = [speaker]
+
+            test_cal = icalendar.Calendar.from_ical(ICalExporter().export(test_session.event_id))
+
+            cal_content_lines = test_cal.content_lines()
+            self.assertIn('URL:http://localhost/v1/events?identifier={}'.format(test_session.event.identifier),
+                          cal_content_lines)
+            self.assertIn('LOCATION:example', cal_content_lines)
+            self.assertIn('ATTENDEE;CN=xyz:MAILTO:test@xyz.com', cal_content_lines)
+
 
 if __name__ == '__main__':
     unittest.main()