|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +"""WebexTeamsAPI Rooms API fixtures and tests. |
| 3 | +
|
| 4 | +Copyright (c) 2016-2020 Cisco and/or its affiliates. |
| 5 | +
|
| 6 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | +of this software and associated documentation files (the "Software"), to deal |
| 8 | +in the Software without restriction, including without limitation the rights |
| 9 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | +copies of the Software, and to permit persons to whom the Software is |
| 11 | +furnished to do so, subject to the following conditions: |
| 12 | +
|
| 13 | +The above copyright notice and this permission notice shall be included in all |
| 14 | +copies or substantial portions of the Software. |
| 15 | +
|
| 16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | +SOFTWARE. |
| 23 | +""" |
| 24 | + |
| 25 | +import itertools |
| 26 | + |
| 27 | +import pytest |
| 28 | + |
| 29 | +import webexteamssdk |
| 30 | +from tests.utils import create_string |
| 31 | + |
| 32 | + |
| 33 | +# Helper Functions |
| 34 | + |
| 35 | +def is_valid_room_tab(obj): |
| 36 | + return isinstance(obj, webexteamssdk.RoomTab) and obj.id is not None |
| 37 | + |
| 38 | + |
| 39 | +def are_valid_room_tabs(iterable): |
| 40 | + return all([is_valid_room_tab(obj) for obj in iterable]) |
| 41 | + |
| 42 | + |
| 43 | +# Fixtures |
| 44 | + |
| 45 | +@pytest.fixture(scope="session") |
| 46 | +def group_room(api): |
| 47 | + room = api.rooms.create(title=create_string("Group Room")) |
| 48 | + |
| 49 | + yield room |
| 50 | + |
| 51 | + api.rooms.delete(room.id) |
| 52 | + |
| 53 | + |
| 54 | +@pytest.fixture(scope="session") |
| 55 | +def direct_rooms(api, direct_messages): |
| 56 | + return [ |
| 57 | + api.rooms.get(message.roomId) |
| 58 | + for message in direct_messages |
| 59 | + ] |
| 60 | + |
| 61 | + |
| 62 | +@pytest.fixture(scope="session") |
| 63 | +def team_room(api, team): |
| 64 | + team_room = api.rooms.create( |
| 65 | + title=create_string("Team Room"), |
| 66 | + teamId=team.id, |
| 67 | + ) |
| 68 | + |
| 69 | + yield team_room |
| 70 | + |
| 71 | + api.rooms.delete(team_room.id) |
| 72 | + |
| 73 | + |
| 74 | +@pytest.fixture(scope="session") |
| 75 | +def list_of_rooms(api, group_room, direct_rooms, team_room): |
| 76 | + return list(api.rooms.list()) |
| 77 | + |
| 78 | + |
| 79 | +@pytest.fixture |
| 80 | +def temp_room(api): |
| 81 | + room = api.rooms.create(title=create_string("Temp Room")) |
| 82 | + |
| 83 | + yield room |
| 84 | + |
| 85 | + try: |
| 86 | + api.rooms.delete(room.id) |
| 87 | + except webexteamssdk.ApiError: |
| 88 | + pass |
| 89 | + |
| 90 | + |
| 91 | +@pytest.fixture |
| 92 | +def add_rooms(api): |
| 93 | + rooms = [] |
| 94 | + |
| 95 | + def inner(num_rooms): |
| 96 | + for i in range(num_rooms): |
| 97 | + rooms.append(api.rooms.create(create_string("Additional Room"))) |
| 98 | + return rooms |
| 99 | + |
| 100 | + yield inner |
| 101 | + |
| 102 | + for room in rooms: |
| 103 | + try: |
| 104 | + api.rooms.delete(room.id) |
| 105 | + except webexteamssdk.ApiError: |
| 106 | + pass |
| 107 | + |
| 108 | + |
| 109 | +# Tests |
| 110 | + |
| 111 | +def test_list_all_room_tabs(list_of_room_tabs): |
| 112 | + assert len(list_of_room_tabs) > 0 |
| 113 | + assert are_valid_room_tabs(list_of_room_tabs) |
| 114 | + |
| 115 | + |
| 116 | +# def test_list_rooms_with_paging(api, list_of_rooms, add_rooms): |
| 117 | +# page_size = 1 |
| 118 | +# pages = 3 |
| 119 | +# num_rooms = pages * page_size |
| 120 | +# if len(list_of_rooms) < num_rooms: |
| 121 | +# add_rooms(num_rooms - len(list_of_rooms)) |
| 122 | +# rooms = api.rooms.list(max=page_size) |
| 123 | +# rooms_list = list(itertools.islice(rooms, num_rooms)) |
| 124 | +# assert len(rooms_list) == num_rooms |
| 125 | +# assert are_valid_rooms(rooms_list) |
| 126 | + |
| 127 | + |
| 128 | +# def test_list_group_rooms(api, group_room): |
| 129 | +# group_rooms_list = list(api.rooms.list(type='group')) |
| 130 | +# assert len(group_rooms_list) > 0 |
| 131 | +# assert are_valid_rooms(group_rooms_list) |
| 132 | + |
| 133 | + |
| 134 | +# def test_list_team_rooms(api, team, team_room): |
| 135 | +# team_rooms_list = list(api.rooms.list(teamId=team.id)) |
| 136 | +# assert len(team_rooms_list) > 0 |
| 137 | +# assert are_valid_rooms(team_rooms_list) |
| 138 | + |
| 139 | + |
| 140 | +# def test_list_direct_rooms(api, direct_rooms): |
| 141 | +# direct_rooms_list = list(api.rooms.list(type='direct')) |
| 142 | +# assert len(direct_rooms_list) > 0 |
| 143 | +# assert are_valid_rooms(direct_rooms_list) |
| 144 | + |
| 145 | + |
| 146 | +# def test_create_group_room(group_room): |
| 147 | +# assert is_valid_room(group_room) |
| 148 | + |
| 149 | + |
| 150 | +# def test_create_team_room(team_room): |
| 151 | +# assert is_valid_room(team_room) |
| 152 | + |
| 153 | + |
| 154 | +# def test_get_room_details(api, group_room): |
| 155 | +# room = api.rooms.get(group_room.id) |
| 156 | +# assert is_valid_room(room) |
| 157 | + |
| 158 | + |
| 159 | +# def test_get_room_meeting_info(api, group_room): |
| 160 | +# room_meeting_info = api.rooms.get_meeting_info(group_room.id) |
| 161 | +# assert is_valid_room_meeting_info(room_meeting_info) |
| 162 | + |
| 163 | + |
| 164 | +# def test_update_room_title(api, group_room): |
| 165 | +# new_title = create_string("Updated Group Room") |
| 166 | +# room = api.rooms.update(group_room.id, title=new_title) |
| 167 | +# assert is_valid_room(room) |
| 168 | +# assert room.title == new_title |
| 169 | + |
| 170 | + |
| 171 | +# def test_delete_room(api, temp_room): |
| 172 | +# api.rooms.delete(temp_room.id) |
0 commit comments