2626
2727get = httpretty .GET
2828post = httpretty .POST
29+ put = httpretty .PUT
30+ delete = httpretty .DELETE
2931r = re .compile
3032
3133def fixture (fixture ):
@@ -34,10 +36,7 @@ def fixture(fixture):
3436
3537@httpretty .activate
3638def test_users ():
37- httpretty .register_uri (
38- httpretty .GET ,
39- re .compile (r"/v1/users" ),
40- body = fixture ('v1-users' ))
39+ httpretty .register_uri (get , r (r"/v1/users" ), body = fixture ('v1-users' ))
4140 expect (len (User .all ())).should .be .greater_than (0 )
4241
4342@httpretty .activate
@@ -122,3 +121,59 @@ class BadGatewayError(Exception):
122121 User .find .when .called_with (email = 'somebody@example.com' ).should .throw (BadGatewayError )
123122 Intercom .endpoints = ("http://example.com" , "http://api.example.com" )
124123 User .find .when .called_with (email = 'not-found@example.com' ).should .throw (BadGatewayError )
124+
125+ @httpretty .activate
126+ def test_doctest ():
127+ import doctest
128+ import intercom
129+
130+ def request_callback (method , uri , headers ):
131+ parsed_body = httpretty .last_request ().parsed_body
132+ # handle the user updates
133+ if 'name' in parsed_body :
134+ return (200 , headers , fixture ('v1-user-updated' ))
135+ return (200 , headers , fixture ('v1-user' ))
136+
137+ httpretty .register_uri (get , r (r'/v1/users$' ), body = fixture ('v1-users' ), match_querystring = True )
138+ httpretty .register_uri (get , r (r'/v1/users\?page=1' ), body = fixture ('v1-users' ), match_querystring = True )
139+ httpretty .register_uri (post , r (r'/v1/users$' ), body = fixture ('v1-user' ), match_querystring = True )
140+ httpretty .register_uri (put , r (r'/v1/users$' ), body = request_callback , match_querystring = True )
141+ httpretty .register_uri (delete , r (r'/v1/users$' ), body = fixture ('v1-user' ), match_querystring = True )
142+ httpretty .register_uri (get , r (r"/v1/users\?email=somebody" ), body = fixture ('v1-user' ), match_querystring = True )
143+ httpretty .register_uri (get , r (r"/v1/users\?user_id=123" ), body = fixture ('v1-user' ), match_querystring = True )
144+ httpretty .register_uri (get , r (r"/v1/users\?email=not-found" ), status = 404 , match_querystring = True )
145+ httpretty .register_uri (get , r (r"/v1/users\?email=server-error" ), status = 500 , match_querystring = True )
146+ httpretty .register_uri (get , r (r"/v1/users\?email=authentication-error" ), status = 401 , match_querystring = True )
147+
148+ httpretty .register_uri (get , r (r"/v1/tags\?name=Free" ), body = fixture ('v1-tag' ))
149+ httpretty .register_uri (get , r (r"/v1/tags" ), body = fixture ('v1-tag' ))
150+ httpretty .register_uri (post , r (r"/v1/tags" ), body = fixture ('v1-tag' ))
151+ httpretty .register_uri (put , r (r"/v1/tags" ), body = fixture ('v1-tag' ))
152+
153+ httpretty .register_uri (post , r (r"/v1/users/notes" ), body = fixture ('v1-users-note' ))
154+
155+ httpretty .register_uri (get , r (r'/v1/users/message_threads$' ), body = fixture ('v1-users-message_threads' ), match_querystring = True )
156+ httpretty .register_uri (post , r (r'/v1/users/message_threads$' ), body = fixture ('v1-users-message_thread' ), match_querystring = True )
157+ httpretty .register_uri (put , r (r'/v1/users/message_threads$' ), body = fixture ('v1-users-message_thread' ), match_querystring = True )
158+ httpretty .register_uri (get , r (r"/v1/users/message_threads\?thread_id=5591" ), body = fixture ('v1-users-message_thread' ), match_querystring = True )
159+ httpretty .register_uri (get , r (r"/v1/users/message_threads\?email=somebody" ), body = fixture ('v1-users-message_threads' ), match_querystring = True )
160+
161+ httpretty .register_uri (post , r (r"/v1/users/impressions" ), body = fixture ('v1-users-impressions' ))
162+
163+ (failure_count , test_count ) = doctest .testfile ("../../intercom/user.py" )
164+ expect (failure_count ).to .equal (0 )
165+
166+ (failure_count , test_count ) = doctest .testfile ("../../intercom/tag.py" )
167+ expect (failure_count ).to .equal (0 )
168+
169+ (failure_count , test_count ) = doctest .testfile ("../../intercom/note.py" )
170+ expect (failure_count ).to .equal (0 )
171+
172+ (failure_count , test_count ) = doctest .testfile ("../../intercom/message_thread.py" )
173+ expect (failure_count ).to .equal (0 )
174+
175+ (failure_count , test_count ) = doctest .testfile ("../../intercom/impression.py" )
176+ expect (failure_count ).to .equal (0 )
177+
178+ (failure_count , test_count ) = doctest .testfile ("../../intercom/intercom.py" )
179+ expect (failure_count ).to .equal (0 )
0 commit comments