4
4
5
5
Unless required by applicable law or agreed to in writing, software?distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6
6
"""
7
+ import unittest
7
8
from httpretty import HTTPretty , httprettified
8
- from nose . tools import eq_ , raises
9
+ from pytest import raises
9
10
from pyexchange import Exchange2010Service
10
11
11
12
from pyexchange .connection import ExchangeNTLMAuthConnection
15
16
from .fixtures import *
16
17
from .. import wip
17
18
18
- class Test_PopulatingANewEvent ():
19
+ class Test_PopulatingANewEvent (unittest . TestCase ):
19
20
""" Tests all the attribute setting works when creating a new event """
20
21
calendar = None
21
22
22
23
@classmethod
23
- def setUpAll (cls ):
24
+ def setUpClass (cls ):
24
25
25
26
cls .calendar = Exchange2010Service (connection = ExchangeNTLMAuthConnection (url = FAKE_EXCHANGE_URL ,
26
27
username = FAKE_EXCHANGE_USERNAME ,
@@ -33,124 +34,130 @@ def test_canary(self):
33
34
34
35
def test_events_created_dont_have_an_id (self ):
35
36
event = self .calendar .event ()
36
- eq_ ( event .id , None )
37
+ assert event .id is None
37
38
38
39
def test_can_add_a_subject (self ):
39
40
event = self .calendar .event (subject = TEST_EVENT .subject )
40
- eq_ ( event .subject , TEST_EVENT .subject )
41
+ assert event .subject == TEST_EVENT .subject
41
42
42
43
def test_can_add_a_location (self ):
43
44
event = self .calendar .event (location = TEST_EVENT .location )
44
- eq_ ( event .location , TEST_EVENT .location )
45
+ assert event .location == TEST_EVENT .location
45
46
46
47
def test_can_add_an_html_body (self ):
47
48
event = self .calendar .event (html_body = TEST_EVENT .body )
48
- eq_ ( event .html_body , TEST_EVENT .body )
49
- eq_ ( event .text_body , None )
50
- eq_ ( event .body , TEST_EVENT .body )
49
+ assert event .html_body == TEST_EVENT .body
50
+ assert event .text_body is None
51
+ assert event .body == TEST_EVENT .body
51
52
52
53
def test_can_add_a_text_body (self ):
53
54
event = self .calendar .event (text_body = TEST_EVENT .body )
54
- eq_ ( event .text_body , TEST_EVENT .body )
55
- eq_ ( event .html_body , None )
56
- eq_ ( event .body , TEST_EVENT .body )
55
+ assert event .text_body == TEST_EVENT .body
56
+ assert event .html_body is None
57
+ assert event .body == TEST_EVENT .body
57
58
58
59
def test_can_add_a_start_time (self ):
59
60
event = self .calendar .event (start = TEST_EVENT .start )
60
- eq_ ( event .start , TEST_EVENT .start )
61
+ assert event .start == TEST_EVENT .start
61
62
62
63
def test_can_add_an_end_time (self ):
63
64
event = self .calendar .event (end = TEST_EVENT .end )
64
- eq_ ( event .end , TEST_EVENT .end )
65
+ assert event .end == TEST_EVENT .end
65
66
66
67
def test_can_add_attendees_via_email (self ):
67
68
event = self .calendar .event (attendees = PERSON_REQUIRED_ACCEPTED .email )
68
- eq_ ( len (event .attendees ), 1 )
69
- eq_ ( len (event .required_attendees ), 1 )
70
- eq_ ( len (event .optional_attendees ), 0 )
71
- eq_ ( event .attendees [0 ].email , PERSON_REQUIRED_ACCEPTED .email )
69
+ assert len (event .attendees ) == 1
70
+ assert len (event .required_attendees ) == 1
71
+ assert len (event .optional_attendees ) == 0
72
+ assert event .attendees [0 ].email == PERSON_REQUIRED_ACCEPTED .email
72
73
73
74
def test_can_add_multiple_attendees_via_email (self ):
74
75
event = self .calendar .event (attendees = [PERSON_REQUIRED_ACCEPTED .email , PERSON_REQUIRED_TENTATIVE .email ])
75
- eq_ ( len (event .attendees ), 2 )
76
- eq_ ( len (event .required_attendees ), 2 )
77
- eq_ ( len (event .optional_attendees ), 0 )
76
+ assert len (event .attendees ) == 2
77
+ assert len (event .required_attendees ) == 2
78
+ assert len (event .optional_attendees ) == 0
78
79
79
80
def test_can_add_attendees_via_named_tuple (self ):
80
81
81
82
person = ExchangeEventAttendee (name = PERSON_OPTIONAL_ACCEPTED .name , email = PERSON_OPTIONAL_ACCEPTED .email , required = PERSON_OPTIONAL_ACCEPTED .required )
82
83
83
84
event = self .calendar .event (attendees = person )
84
- eq_ ( len (event .attendees ), 1 )
85
- eq_ ( len (event .required_attendees ), 0 )
86
- eq_ ( len (event .optional_attendees ), 1 )
87
- eq_ ( event .attendees [0 ].email , PERSON_OPTIONAL_ACCEPTED .email )
85
+ assert len (event .attendees ) == 1
86
+ assert len (event .required_attendees ) == 0
87
+ assert len (event .optional_attendees ) == 1
88
+ assert event .attendees [0 ].email == PERSON_OPTIONAL_ACCEPTED .email
88
89
89
90
def test_can_assign_to_required_attendees (self ):
90
91
91
92
event = self .calendar .event (attendees = PERSON_REQUIRED_ACCEPTED .email )
92
93
event .required_attendees = [PERSON_REQUIRED_ACCEPTED .email , PERSON_OPTIONAL_ACCEPTED .email ]
93
94
94
- eq_ ( len (event .attendees ), 2 )
95
- eq_ ( len (event .required_attendees ), 2 )
96
- eq_ ( len (event .optional_attendees ), 0 )
95
+ assert len (event .attendees ) == 2
96
+ assert len (event .required_attendees ) == 2
97
+ assert len (event .optional_attendees ) == 0
97
98
98
99
def test_can_assign_to_optional_attendees (self ):
99
100
100
101
event = self .calendar .event (attendees = PERSON_REQUIRED_ACCEPTED .email )
101
102
event .optional_attendees = PERSON_OPTIONAL_ACCEPTED .email
102
103
103
- eq_ ( len (event .attendees ), 2 )
104
- eq_ ( len (event .required_attendees ), 1 )
105
- eq_ ( len (event .optional_attendees ), 1 )
106
- eq_ ( event .required_attendees [0 ].email , PERSON_REQUIRED_ACCEPTED .email )
107
- eq_ ( event .optional_attendees [0 ].email , PERSON_OPTIONAL_ACCEPTED .email )
104
+ assert len (event .attendees ) == 2
105
+ assert len (event .required_attendees ) == 1
106
+ assert len (event .optional_attendees ) == 1
107
+ assert event .required_attendees [0 ].email == PERSON_REQUIRED_ACCEPTED .email
108
+ assert event .optional_attendees [0 ].email == PERSON_OPTIONAL_ACCEPTED .email
108
109
109
110
110
111
def test_can_add_resources (self ):
111
112
event = self .calendar .event (resources = [RESOURCE .email ])
112
- eq_ ( len (event .resources ), 1 )
113
- eq_ ( event .resources [0 ].email , RESOURCE .email )
114
- eq_ ( event .conference_room .email , RESOURCE .email )
113
+ assert len (event .resources ) == 1
114
+ assert event .resources [0 ].email == RESOURCE .email
115
+ assert event .conference_room .email == RESOURCE .email
115
116
116
117
117
- class Test_CreatingANewEvent (object ):
118
+ class Test_CreatingANewEvent (unittest . TestCase ):
118
119
service = None
119
120
event = None
120
121
121
122
@classmethod
122
- def setUpAll (cls ):
123
+ def setUpClass (cls ):
123
124
cls .service = Exchange2010Service (connection = ExchangeNTLMAuthConnection (url = FAKE_EXCHANGE_URL , username = FAKE_EXCHANGE_USERNAME , password = FAKE_EXCHANGE_PASSWORD ))
124
125
125
126
def setUp (self ):
126
127
self .event = self .service .calendar ().event (start = TEST_EVENT .start , end = TEST_EVENT .end )
127
128
128
- @raises (ValueError )
129
129
def test_events_must_have_a_start_date (self ):
130
130
self .event .start = None
131
- self .event .create ()
132
131
133
- @raises (ValueError )
132
+ with raises (ValueError ):
133
+ self .event .create ()
134
+
134
135
def test_events_must_have_an_end_date (self ):
135
136
self .event .end = None
136
- self .event .create ()
137
137
138
- @raises (ValueError )
138
+ with raises (ValueError ):
139
+ self .event .create ()
140
+
139
141
def test_event_end_date_must_come_after_start_date (self ):
140
142
self .event .start , self .event .end = self .event .end , self .event .start
141
- self .event .create ()
142
143
143
- @raises (ValueError )
144
+ with raises (ValueError ):
145
+ self .event .create ()
146
+
144
147
def cant_delete_a_newly_created_event (self ):
145
- self .event .delete ()
146
148
147
- @raises (ValueError )
149
+ with raises (ValueError ):
150
+ self .event .delete ()
151
+
148
152
def cant_update_a_newly_created_event (self ):
149
- self .event .update ()
150
153
151
- @raises (ValueError )
154
+ with raises (ValueError ):
155
+ self .event .update ()
156
+
152
157
def cant_resend_invites_for_a_newly_created_event (self ):
153
- self .event .resend_invitations ()
158
+
159
+ with raises (ValueError ):
160
+ self .event .resend_invitations ()
154
161
155
162
@httprettified
156
163
def test_can_set_subject (self ):
@@ -237,7 +244,6 @@ def test_attendees(self):
237
244
for email in attendees :
238
245
assert email in HTTPretty .last_request .body .decode ('utf-8' )
239
246
240
- @raises (ValueError )
241
247
def test_resources_must_have_an_email_address (self ):
242
248
243
249
HTTPretty .register_uri (HTTPretty .POST , FAKE_EXCHANGE_URL ,
@@ -246,8 +252,9 @@ def test_resources_must_have_an_email_address(self):
246
252
247
253
attendees = [PERSON_WITH_NO_EMAIL_ADDRESS ]
248
254
249
- self .event .attendees = attendees
250
- self .event .create ()
255
+ with raises (ValueError ):
256
+ self .event .attendees = attendees
257
+ self .event .create ()
251
258
252
259
@httprettified
253
260
def test_resources (self ):
0 commit comments