diff --git a/api/room/schema_query.py b/api/room/schema_query.py index 7c9ad7a06..a1a522347 100644 --- a/api/room/schema_query.py +++ b/api/room/schema_query.py @@ -280,7 +280,9 @@ def resolve_all_rooms(self, info, **kwargs): def resolve_all_remote_rooms(self, info, return_all=None): page_token = None filter = map_remote_room_location_to_filter() - location = 'all' if return_all else get_user_from_db().location + location = get_user_from_db().location + if not filter.get(location) or return_all: + location = 'all' remote_rooms = [] while True: calendar_list = get_google_api_calendar_list(pageToken=page_token) diff --git a/fixtures/room/query_room_fixtures.py b/fixtures/room/query_room_fixtures.py index d9467b9a4..fa907acd6 100644 --- a/fixtures/room/query_room_fixtures.py +++ b/fixtures/room/query_room_fixtures.py @@ -15,9 +15,20 @@ "data": { "allRemoteRooms": { "rooms": [] - } } } +} + +all_remote_rooms_with_argument_return_all_true_query = ''' + query{ + allRemoteRooms(returnAll: true){ + rooms{ + calendarId + name + } + } +} +''' paginated_rooms_query = ''' query { diff --git a/tests/base.py b/tests/base.py index d44febaff..78d1ad96b 100644 --- a/tests/base.py +++ b/tests/base.py @@ -211,18 +211,18 @@ def setUp(self, mock_verify_calendar_id): ) structure.save() parent_node = OfficeStructure( - id='C56A4180-65AA-42EC-A945-5FD21DEC0518', - name='Epic Tower', - tag='Lagos Building', - location_id=1 + id='C56A4180-65AA-42EC-A945-5FD21DEC0518', + name='Epic Tower', + tag='Lagos Building', + location_id=1 ) parent_node.save() child_node = OfficeStructure( - id='C56A4180-65AA-42EC-A945-5FD21DEC0519', - name='Gold Coast', - tag='First Floor', - parent_id='C56A4180-65AA-42EC-A945-5FD21DEC0518', - location_id=1 + id='C56A4180-65AA-42EC-A945-5FD21DEC0519', + name='Gold Coast', + tag='First Floor', + parent_id='C56A4180-65AA-42EC-A945-5FD21DEC0518', + location_id=1 ) child_node.save() db_session.commit() diff --git a/tests/test_rooms/test_query_rooms.py b/tests/test_rooms/test_query_rooms.py index 17d3201fe..4ac386486 100644 --- a/tests/test_rooms/test_query_rooms.py +++ b/tests/test_rooms/test_query_rooms.py @@ -15,7 +15,8 @@ room_query_with_non_existant_id_response, all_remote_rooms_query, paginated_rooms_query_blank_page, - all_dummy_rooms_response + all_dummy_rooms_response, + all_remote_rooms_with_argument_return_all_true_query ) from helpers.calendar.credentials import get_google_api_calendar_list @@ -52,23 +53,6 @@ def test_query_actual_remote_rooms(self, mock_get_json): "calendar.google.com" ) - @patch("api.room.schema_query.get_google_api_calendar_list", spec=True, - return_value=get_calendar_list_mock_data()) - def test_query_test_remote_rooms(self, mock_get_json): - """ - Mocks google calendar to return test rooms - on the staging enviroment. - Returns: - - Test rooms - Test rooms have the key words; - - Test or Dummy - """ - CommonTestCases.admin_token_assert_equal( - self, - all_remote_rooms_query, - all_dummy_rooms_response - ) - @patch("helpers.calendar.credentials.Credentials") def test_calendar_list_function(self, mocked_method): ''' @@ -78,6 +62,20 @@ def test_calendar_list_function(self, mocked_method): get_google_api_calendar_list() assert mocked_method.called + @patch("api.room.schema_query.get_google_api_calendar_list", spec=True, + return_value=get_calendar_list_mock_data()) + def test_all_remote_rooms_with_argument_return_all_true(self, + mock_get_json): + """ + returning all remote rooms with true as + a value to the returnAll argument + """ + CommonTestCases.admin_token_assert_equal( + self, + all_remote_rooms_with_argument_return_all_true_query, + all_dummy_rooms_response + ) + def test_query_room_with_id(self): response = self.app_test.post('/mrm?query='+room_query_by_id) actual_response = json.loads(response.data)