Ejemplo n.º 1
0
  def testSimianRequestWithError(self):
    """Test _SimianRequest() with an error status returned."""
    method = 'zGET'
    url = '/url'
    headers = {'foo': 'bar'}
    output_filename = None

    error_response = client.Response(status=401, body='fooerror')

    self.mox.StubOutWithMock(self.client, 'Do')
    self.client.Do(
        method, url, body=None, headers=headers,
        output_filename=output_filename).AndReturn(error_response)

    self.mox.ReplayAll()
    self.assertRaises(
        client.SimianServerError,
        self.client._SimianRequest, method, url, headers=headers)
    self.mox.VerifyAll()
Ejemplo n.º 2
0
  def testSimianRequest(self):
    """Test _SimianRequest()."""
    method = 'zGET'
    url = '/url'
    headers = {'foo': 'bar'}
    output_filename = None

    good_response = client.Response(status=200, body='hello there')

    self.mox.StubOutWithMock(self.client, 'Do')
    self.client.Do(
        method, url, body=None, headers=headers,
        output_filename=output_filename).AndReturn(good_response)

    self.mox.ReplayAll()
    self.assertEqual(
        good_response.body,
        self.client._SimianRequest(method, url, headers=headers))
    self.mox.VerifyAll()
Ejemplo n.º 3
0
    def testSimianRequest(self):
        """Test _SimianRequest()."""
        method = 'zGET'
        url = '/url'
        headers = {'foo': 'bar'}
        output_filename = None

        good_response = client.Response(status=200, body='hello there')

        with mock.patch.object(self.client, 'Do',
                               return_value=good_response) as do_mock:
            self.assertEqual(
                good_response.body,
                self.client._SimianRequest(method, url, headers=headers))

            do_mock.assert_called_once_with(method,
                                            url,
                                            body=None,
                                            headers=headers,
                                            output_filename=output_filename)
Ejemplo n.º 4
0
    def testSimianRequestWithError(self):
        """Test _SimianRequest() with an error status returned."""
        method = 'zGET'
        url = '/url'
        headers = {'foo': 'bar'}
        output_filename = None

        error_response = client.Response(status=401, body='fooerror')

        with mock.patch.object(self.client, 'Do',
                               return_value=error_response) as do_mock:
            self.assertRaises(client.SimianServerError,
                              self.client._SimianRequest,
                              method,
                              url,
                              headers=headers)

            do_mock.assert_called_once_with(method,
                                            url,
                                            body=None,
                                            headers=headers,
                                            output_filename=output_filename)