コード例 #1
0
    def testError_Redirects(self, mock_fetch, _):
        redirect = mock.Mock(status_code=httplib.FOUND,
                             headers={'Location': 'https://foo.com'})
        mock_fetch.side_effect = (redirect, ) * 5
        with self.assertRaises(urlfetch.Error):
            intermodule_utils.SubmitIntermoduleRequest('some-module',
                                                       '/api/path/whatever')

        self.assertEqual(5, mock_fetch.call_count)
コード例 #2
0
    def testSuccess_WithData(self, mock_fetch, _):
        response = intermodule_utils.SubmitIntermoduleRequest(
            'some-module', '/api/path/whatever', data={'foo': 'bar'})

        self.assertEqual(httplib.OK, response.status_code)
        self.assertEqual('{}', response.content)

        mock_fetch.assert_called_once_with('https://%s/api/path/whatever' %
                                           _TEST_DOMAIN,
                                           method=urlfetch.POST,
                                           payload='foo=bar',
                                           headers=mock.ANY,
                                           deadline=mock.ANY,
                                           follow_redirects=False)
コード例 #3
0
    def testSuccess_Redirects(self, mock_fetch, _):
        def GenRedirect(url):
            return mock.Mock(status_code=httplib.FOUND,
                             headers={'Location': url})

        # Rediret 4 times and succeed on the fifth.
        success = mock.Mock(status_code=httplib.OK, content='{}')
        redirect_urls = ['https://foo%d.com' % i for i in xrange(4)]
        mock_fetch.side_effect = [GenRedirect(url)
                                  for url in redirect_urls] + [success]

        response = intermodule_utils.SubmitIntermoduleRequest(
            'some-module', '/api/path/whatever')

        self.assertEqual(httplib.OK, response.status_code)
        self.assertEqual('{}', response.content)

        self.assertEqual(5, mock_fetch.call_count)

        for expected, call in zip(redirect_urls,
                                  mock_fetch.call_args_list[1:]):
            observed = call[0][0]
            self.assertEqual(expected, observed)
コード例 #4
0
    def testSuccess_NoReturnedData(self, mock_fetch, _):
        response = intermodule_utils.SubmitIntermoduleRequest(
            'some-module', '/api/path/whatever', data={'foo': 'bar'})

        self.assertEqual(httplib.OK, response.status_code)
        self.assertEqual('', response.content)
コード例 #5
0
 def testError(self, *_):
     with self.assertRaises(urlfetch.Error):
         intermodule_utils.SubmitIntermoduleRequest('some-module',
                                                    '/api/path/whatever')