@@ -103,6 +103,15 @@ def it_presents_a_complete_user_record_correctly(self):
103103 expect (user .unsubscribed_from_emails )
104104 expect ("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11" ) == user .user_agent_data
105105
106+ def it_allows_update_last_request_at (self ):
107+ payload = {
108+ 'user_id' : '1224242' ,
109+ 'update_last_request_at' : True ,
110+ 'custom_attributes' : {}
111+ }
112+ httpretty .register_uri (post , r ("/users" ), body = json .dumps (payload ))
113+ User (user_id = '1224242' , update_last_request_at = True )
114+
106115 def it_allows_easy_setting_of_custom_data (self ):
107116 now = datetime .utcnow ()
108117 now_ts = time .mktime (now .timetuple ())
@@ -163,29 +172,64 @@ def it_saves_a_user_always_sends_custom_attributes(self):
163172 expect (user .email ) == 'jo@example.com'
164173 expect (user .custom_attributes ) == {}
165174
166-
167175 @httpretty .activate
168176 def it_saves_a_user_with_a_company (self ):
169177 user = User (
170178 email = "jo@example.com" , user_id = "i-1224242" ,
171- companies = [ {'company_id' : 6 , 'name' : 'Intercom' },{ 'company_id' : 8 , 'name' : 'Intercom2' }] )
172-
179+ company = {'company_id' : 6 , 'name' : 'Intercom' })
180+
173181 body = json .dumps ({
174182 'email' : 'jo@example.com' ,
175183 'user_id' : 'i-1224242' ,
176184 'companies' : [{
177185 'company_id' : 6 ,
178- 'name' : 'Intercom2 '
186+ 'name' : 'Intercom '
179187 }]
180188 })
181189 httpretty .register_uri (
182190 post , r (r"/users" ), body = body )
183191 user .save ()
184192 expect (user .email ) == 'jo@example.com'
185193 expect (len (user .companies )) == 1
186- # from intercom.user import create_class_instance
187- # Company = create_class_instance('Company')
188- # expect(user.companies[0]).to.be_instance_of(Company.__class__)
194+
195+ @httpretty .activate
196+ def it_saves_a_user_with_companies (self ):
197+ user = User (
198+ email = "jo@example.com" , user_id = "i-1224242" ,
199+ companies = [{'company_id' : 6 , 'name' : 'Intercom' }])
200+ body = json .dumps ({
201+ 'email' : 'jo@example.com' ,
202+ 'user_id' : 'i-1224242' ,
203+ 'companies' : [{
204+ 'company_id' : 6 ,
205+ 'name' : 'Intercom'
206+ }]
207+ })
208+ httpretty .register_uri (
209+ post , r (r"/users" ), body = body )
210+ user .save ()
211+ expect (user .email ) == 'jo@example.com'
212+ expect (len (user .companies )) == 1
213+
214+ @httpretty .activate
215+ def it_can_save_a_user_with_a_none_email (self ):
216+ user = User (
217+ email = None , user_id = "i-1224242" ,
218+ companies = [{'company_id' : 6 , 'name' : 'Intercom' }])
219+ body = json .dumps ({
220+ 'custom_attributes' : {},
221+ 'email' : None ,
222+ 'user_id' : 'i-1224242' ,
223+ 'companies' : [{
224+ 'company_id' : 6 ,
225+ 'name' : 'Intercom'
226+ }]
227+ })
228+ httpretty .register_uri (
229+ post , r (r"/users" ), body = body )
230+ user .save ()
231+ expect (user .email ) is None
232+ expect (user .user_id ) is 'i-1224242'
189233
190234 @httpretty .activate
191235 def it_deletes_a_user (self ):
0 commit comments