1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+ from googleapiclient .http import HttpMockSequence
16+ import httplib2
1517import main
18+ import mock
1619import pytest
17- from testing import Http2Mock
1820import webtest
1921
2022
23+ class HttpMockSequenceWithCredentials (HttpMockSequence ):
24+ def add_credentials (self , * args ):
25+ pass
26+
27+
2128@pytest .fixture
2229def app ():
2330 return webtest .TestApp (main .app )
@@ -29,27 +36,31 @@ def test_get(app):
2936
3037
3138def test_post (app ):
32- http = Http2Mock (responses = [{}])
39+ http = HttpMockSequenceWithCredentials ([
40+ ({'status' : '200' }, '' )])
41+ patch_http = mock .patch .object (httplib2 , 'Http' , lambda : http )
3342
34- with http :
43+ with patch_http :
3544 response = app .post ('/' , {
36453746 'submit' : 'Send simple email' })
3847
3948 assert response .status_int == 200
4049
41- http = Http2Mock (responses = [{}])
50+ http = HttpMockSequenceWithCredentials ([
51+ ({'status' : '200' }, '' )])
4252
43- with http :
53+ with patch_http :
4454 response = app .post ('/' , {
45554656 'submit' : 'Send complex email' })
4757
4858 assert response .status_int == 200
4959
50- http = Http2Mock (responses = [{'status' : 500 , 'body' : 'Test error' }])
60+ http = HttpMockSequenceWithCredentials ([
61+ ({'status' : '500' }, 'Test error' )])
5162
52- with http , pytest .raises (Exception ):
63+ with patch_http , pytest .raises (Exception ):
5364 app .post ('/' , {
54655566 'submit' : 'Send simple email' })
0 commit comments