1
+ # -*- coding: utf-8 -*-
2
+ """WebexTeamsAPI MeetingRegistrants API fixtures and tests.
3
+
4
+ Copyright (c) 2016-2024 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 pytest
26
+ import datetime
27
+
28
+ import webexteamssdk
29
+
30
+ from tests .utils import create_string
31
+
32
+ # Helper Functions
33
+
34
+ def is_valid_registrant (obj ):
35
+ return isinstance (obj , webexteamssdk .MeetingRegistrant ) and obj .id is not None
36
+
37
+ def get_start_end_time ():
38
+ now = datetime .datetime .now ()
39
+ start = (now + datetime .timedelta (days = 1 )).strftime ('%Y-%m-%dT%H:%M:%S' ) # tomorrow same time
40
+ end = (now + datetime .timedelta (days = 1 , hours = 1 )).strftime ('%Y-%m-%dT%H:%M:%S' ) # tomorrow 1 hour later
41
+ return {'start' : start , 'end' : end }
42
+
43
+
44
+
45
+ # Fixtures
46
+
47
+ @pytest .fixture (scope = "session" )
48
+ def meeting (api ):
49
+
50
+ meeting = api .meetings .create (
51
+ title = create_string ("Meeting" ),
52
+ ** get_start_end_time ()
53
+ )
54
+
55
+ yield meeting
56
+
57
+ try :
58
+ api .meetings .delete (meeting .id )
59
+ except webexteamssdk .ApiError :
60
+ pass
61
+
62
+ @pytest .fixture (scope = "session" )
63
+ def webinar (api ):
64
+ webinar = api .meetings .create (
65
+ title = create_string ("Webinar" ),
66
+ scheduledType = "webinar" ,
67
+ registration = {
68
+ 'autoAcceptRequest' : True ,
69
+ 'requireFirstName' : True ,
70
+ 'requireLastName' : True ,
71
+ 'requireEmail' : True
72
+ },
73
+ ** get_start_end_time ()
74
+ )
75
+
76
+ yield webinar
77
+
78
+ try :
79
+ api .meetings .delete (webinar .id )
80
+ except webexteamssdk .ApiError :
81
+ pass
82
+
83
+ @pytest .fixture (scope = "session" )
84
+ def registrant (api , webinar ):
85
+ registrant = api .meeting_registrants .create (
86
+ webinar .id ,
87
+ firstName = create_string ("FirstName" ),
88
+ lastName = create_string ("LastName" ),
89
+
90
+ )
91
+
92
+ yield registrant
93
+
94
+ try :
95
+ api .meeting_registrants .delete (webinar .id , registrant .id )
96
+ except webexteamssdk .ApiError :
97
+ pass
98
+
99
+
100
+ # Tests
101
+
102
+ def test_register_for_meeting (api , meeting ):
103
+ # it is expected that registration does not work for a plain meeting
104
+ with pytest .raises (webexteamssdk .ApiError ) as ex_info :
105
+ api .meeting_registrants .create (
106
+ meeting .id ,
107
+ firstName = create_string ("FirstName" ),
108
+ lastName = create_string ("LastName" ),
109
+
110
+ )
111
+ assert ex_info .value .status_code == 400
112
+ assert ex_info .value .response .json ()['errors' ][0 ]['description' ] == "Registration is not supported for this meeting series."
113
+
114
+
115
+ def test_register_for_webinar (api , registrant ):
116
+ assert is_valid_registrant (registrant )
117
+
118
+ def test_get_registrant (api , webinar , registrant ):
119
+ assert is_valid_registrant (api .meeting_registrants .get (webinar .id , registrant .id ))
120
+
121
+ def test_list_registrants (api , webinar , registrant ):
122
+ registrants_list = list (api .meeting_registrants .list (webinar .id ))
123
+ assert len (registrants_list ) > 0
124
+ assert registrant .id in [item .id for item in registrants_list ]
125
+
126
+ def test_unregister (api , webinar , registrant ):
127
+ api .meeting_registrants .delete (webinar .id , registrant .id )
0 commit comments