Ejemplo n.º 1
0
    def _mock_http(self, data, headers=None, status=None):
        """Setup a mock response from the SG server.

        Only has an affect if the server has been mocked.
        """
        #test for a mock object rather than config.mock as some tests
        #force the mock to be created
        if not isinstance(self.sg._http_request, mock.Mock):
            return

        if not isinstance(data, basestring):
            data = json.dumps(data, ensure_ascii=False, encoding="utf-8")

        resp_headers = {
            'cache-control': 'no-cache',
            'connection': 'close',
            'content-length': (data and str(len(data))) or 0,
            'content-type': 'application/json; charset=utf-8',
            'date': 'Wed, 13 Apr 2011 04:18:58 GMT',
            'server': 'Apache/2.2.3 (CentOS)',
            'status': '200 OK'
        }
        if headers:
            resp_headers.update(headers)

        if not status:
            status = (200, "OK")
        #create a new mock to reset call list etc.
        self._setup_mock()
        self.sg._http_request.return_value = (status, resp_headers, data)
Ejemplo n.º 2
0
    def _mock_http(self, data, headers=None, status=None):
        """Setup a mock response from the SG server.

        Only has an affect if the server has been mocked.
        """
        #test for a mock object rather than config.mock as some tests
        #force the mock to be created
        if not isinstance(self.sg._http_request, mock.Mock):
            return

        if not isinstance(data, basestring):
            data = json.dumps(data, ensure_ascii=False, encoding="utf-8")

        resp_headers = { 'cache-control': 'no-cache',
                         'connection': 'close',
                         'content-length': (data and str(len(data))) or 0 ,
                         'content-type': 'application/json; charset=utf-8',
                         'date': 'Wed, 13 Apr 2011 04:18:58 GMT',
                         'server': 'Apache/2.2.3 (CentOS)',
                         'status': '200 OK' }
        if headers:
            resp_headers.update(headers)

        if not status:
            status = (200, "OK")
        #create a new mock to reset call list etc.
        self._setup_mock()
        self.sg._http_request.return_value = (status, resp_headers, data)