From 2fb550ffcee6d76478cd929327acb4f3c262950f Mon Sep 17 00:00:00 2001
From: Jennifer Richards <jennifer@staff.ietf.org>
Date: Tue, 9 Apr 2024 13:21:35 -0300
Subject: [PATCH] feat: add room_id param to createRoom API (#7308)

* feat: add room_id param to createRoom API

* test: update tests_helpers.py
---
 ietf/meeting/helpers.py       |  1 +
 ietf/meeting/tests_helpers.py | 25 ++++++++++++++-----------
 ietf/utils/meetecho.py        |  6 +++++-
 ietf/utils/tests_meetecho.py  |  9 ++++++---
 4 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/ietf/meeting/helpers.py b/ietf/meeting/helpers.py
index c0e250cdc..7f1c85990 100644
--- a/ietf/meeting/helpers.py
+++ b/ietf/meeting/helpers.py
@@ -1099,6 +1099,7 @@ def create_interim_session_conferences(sessions):
             try:
                 confs = meetecho_manager.create(
                     group=session.group,
+                    session_id=session.pk,
                     description=str(session),
                     start_time=ts.utc_start_time(),
                     duration=ts.duration,
diff --git a/ietf/meeting/tests_helpers.py b/ietf/meeting/tests_helpers.py
index 9ce3c21cb..b118b9f04 100644
--- a/ietf/meeting/tests_helpers.py
+++ b/ietf/meeting/tests_helpers.py
@@ -487,7 +487,7 @@ class InterimTests(TestCase):
         mock.reset_mock()
         mock_conf_mgr.create.return_value = [
             Conference(
-                manager=mock_conf_mgr, id=1, public_id='some-uuid', description='desc',
+                manager=mock_conf_mgr, id=int(sessions[0].pk), public_id='some-uuid', description='desc',
                 start_time=timeslots[0].utc_start_time(), duration=timeslots[0].duration, url='fake-meetecho-url',
                 deletion_token='please-delete-me',
             ),
@@ -498,6 +498,7 @@ class InterimTests(TestCase):
             mock_conf_mgr.create.call_args[1],
             {
                 'group': sessions[0].group,
+                'session_id': sessions[0].id,
                 'description': str(sessions[0]),
                 'start_time': timeslots[0].utc_start_time(),
                 'duration': timeslots[0].duration,
@@ -512,12 +513,12 @@ class InterimTests(TestCase):
         mock.reset_mock()
         mock_conf_mgr.create.side_effect = [
             [Conference(
-                manager=mock_conf_mgr, id=1, public_id='some-uuid', description='desc',
+                manager=mock_conf_mgr, id=int(sessions[0].pk), public_id='some-uuid', description='desc',
                 start_time=timeslots[0].utc_start_time(), duration=timeslots[0].duration, url='different-fake-meetecho-url',
                 deletion_token='please-delete-me',
             )],
             [Conference(
-                manager=mock_conf_mgr, id=2, public_id='another-uuid', description='desc',
+                manager=mock_conf_mgr, id=int(sessions[1].pk), public_id='another-uuid', description='desc',
                 start_time=timeslots[1].utc_start_time(), duration=timeslots[1].duration, url='another-fake-meetecho-url',
                 deletion_token='please-delete-me-too',
             )],
@@ -528,16 +529,18 @@ class InterimTests(TestCase):
             mock_conf_mgr.create.call_args_list,
             [
                 ({
-                    'group': sessions[0].group,
-                    'description': str(sessions[0]),
-                    'start_time': timeslots[0].utc_start_time(),
-                    'duration': timeslots[0].duration,
+                     'group': sessions[0].group,
+                     'session_id': sessions[0].id,
+                     'description': str(sessions[0]),
+                     'start_time': timeslots[0].utc_start_time(),
+                     'duration': timeslots[0].duration,
                  },),
                 ({
-                    'group': sessions[1].group,
-                    'description': str(sessions[1]),
-                    'start_time': timeslots[1].utc_start_time(),
-                    'duration': timeslots[1].duration,
+                     'group': sessions[1].group,
+                     'session_id': sessions[1].id,
+                     'description': str(sessions[1]),
+                     'start_time': timeslots[1].utc_start_time(),
+                     'duration': timeslots[1].duration,
                  },),
             ]
         )
diff --git a/ietf/utils/meetecho.py b/ietf/utils/meetecho.py
index e842ca012..2f5f14676 100644
--- a/ietf/utils/meetecho.py
+++ b/ietf/utils/meetecho.py
@@ -115,6 +115,7 @@ class MeetechoAPI:
     def schedule_meeting(
         self,
         wg_token: str,
+        room_id: int,
         description: str,
         start_time: datetime.datetime,
         duration: datetime.timedelta,
@@ -139,6 +140,7 @@ class MeetechoAPI:
           }
 
         :param wg_token: token retrieved via retrieve_wg_tokens()
+        :param room_id: int id to identify the room (will be echoed as room.id) 
         :param description: str describing the meeting
         :param start_time: starting time as a datetime
         :param duration: duration as a timedelta
@@ -151,6 +153,7 @@ class MeetechoAPI:
                 "meeting/interim/createRoom",
                 api_token=wg_token,
                 json={
+                    "room_id": room_id,
                     "description": description,
                     "start_time": self._serialize_time(start_time),
                     "duration": self._serialize_duration(duration),
@@ -455,9 +458,10 @@ class ConferenceManager(Manager):
         response = self.api.fetch_meetings(self.wg_token(group))
         return Conference.from_api_dict(self, response["rooms"])
 
-    def create(self, group, description, start_time, duration, extrainfo=""):
+    def create(self, group, session_id, description, start_time, duration, extrainfo=""):
         response = self.api.schedule_meeting(
             wg_token=self.wg_token(group),
+            room_id=int(session_id),
             description=description,
             start_time=start_time,
             duration=duration,
diff --git a/ietf/utils/tests_meetecho.py b/ietf/utils/tests_meetecho.py
index 39f36969b..1aef5894e 100644
--- a/ietf/utils/tests_meetecho.py
+++ b/ietf/utils/tests_meetecho.py
@@ -82,7 +82,7 @@ class APITests(TestCase):
                 'rooms': {
                     '3d55bce0-535e-4ba8-bb8e-734911cf3c32': {
                         'room': {
-                            'id': 18,
+                            'id': 18,  # should match room_id in api.schedule_meeting() below
                             'start_time': '2021-09-14 10:00:00',
                             'duration': 130,
                             'description': 'interim-2021-wgname-01',
@@ -97,6 +97,7 @@ class APITests(TestCase):
         api = MeetechoAPI(API_BASE, CLIENT_ID, CLIENT_SECRET)
         api_response = api.schedule_meeting(
             wg_token='my-token',
+            room_id=18,
             start_time=datetime.datetime(2021, 9, 14, 10, 0, 0, tzinfo=datetime.timezone.utc),
             duration=datetime.timedelta(minutes=130),
             description='interim-2021-wgname-01',
@@ -116,6 +117,7 @@ class APITests(TestCase):
         self.assertEqual(
             request.json(),
             {
+                'room_id': 18,
                 'duration': 130,
                 'start_time': '2021-09-14 10:00:00',
                 'extrainfo': 'message for staff',
@@ -485,7 +487,7 @@ class ConferenceManagerTests(TestCase):
             'rooms': {
                 'session-1-uuid': {
                     'room': {
-                        'id': 1,
+                        'id': 1,  # value should match session_id param to cm.create() below 
                         'start_time': datetime.datetime(2022,2,4,1,2,3, tzinfo=datetime.timezone.utc),
                         'duration': datetime.timedelta(minutes=45),
                         'description': 'some-description',
@@ -496,7 +498,7 @@ class ConferenceManagerTests(TestCase):
             },
         }
         cm = ConferenceManager(settings.MEETECHO_API_CONFIG)
-        result = cm.create('group', 'desc', 'starttime', 'dur', 'extra')
+        result = cm.create('group', '1', 'desc', 'starttime', 'dur', 'extra')
         self.assertEqual(
             result,
             [Conference(
@@ -515,6 +517,7 @@ class ConferenceManagerTests(TestCase):
             kwargs,
             {
                 'wg_token': 'atoken',
+                'room_id': 1,
                 'description': 'desc',
                 'start_time': 'starttime',
                 'duration': 'dur',