Example #1
0
    def _load_from_file(self, id):
        fname = self._get_fname_for_id(id)
        #
        #    Due to some concurrency issues, we need to perform this check
        #    before we try to read the .trace file.
        #
        if not os.path.exists(fname):

            for _ in xrange(1 / 0.05):
                time.sleep(0.05)
                if os.path.exists(fname):
                    break
            else:
                msg = 'Timeout expecting trace file to be written "%s"' % fname
                raise IOError(msg)

        #
        #    Ok... the file exists, but it might still be being written
        #
        req_res = open(fname, 'rb')
        request_dict, response_dict = msgpack.load(req_res)
        req_res.close()

        request = HTTPRequest.from_dict(request_dict)
        response = HTTPResponse.from_dict(response_dict)
        return (request, response)
Example #2
0
    def _load_from_file(self, id):
        fname = self._get_fname_for_id(id)
        #
        #    Due to some concurrency issues, we need to perform this check
        #    before we try to read the .trace file.
        #
        if not os.path.exists(fname):

            for _ in xrange(1 / 0.05):
                time.sleep(0.05)
                if os.path.exists(fname):
                    break
            else:
                msg = 'Timeout expecting trace file to be written "%s"' % fname
                raise IOError(msg)

        #
        #    Ok... the file exists, but it might still be being written
        #
        req_res = open(fname, 'rb')
        request_dict, response_dict = msgpack.load(req_res)
        req_res.close()
        
        request = HTTPRequest.from_dict(request_dict)
        response = HTTPResponse.from_dict(response_dict)
        return (request, response)
Example #3
0
    def test_from_dict(self):
        html = 'header <b>ABC</b>-<b>DEF</b>-<b>XYZ</b> footer'
        headers = Headers([('Content-Type', 'text/html')])
        orig_resp = self.create_resp(headers, html)

        msg = msgpack.dumps(orig_resp.to_dict())
        loaded_dict = msgpack.loads(msg)

        loaded_resp = HTTPResponse.from_dict(loaded_dict)

        self.assertEqual(orig_resp, loaded_resp)
        self.assertEqual(orig_resp.__dict__.values(),
                         loaded_resp.__dict__.values())
Example #4
0
 def test_from_dict(self):
     html = 'header <b>ABC</b>-<b>DEF</b>-<b>XYZ</b> footer'
     headers = Headers([('Content-Type', 'text/html')])
     orig_resp = self.create_resp(headers, html)
     
     msg = msgpack.dumps(orig_resp.to_dict())
     loaded_dict = msgpack.loads(msg)
     
     loaded_resp = HTTPResponse.from_dict(loaded_dict)
     
     self.assertEqual(orig_resp, loaded_resp)
     self.assertEqual(orig_resp.__dict__.values(),
                      loaded_resp.__dict__.values())
Example #5
0
    def test_from_dict_encodings(self):
        for body, charset in TEST_RESPONSES.values():
            html = body.encode(charset)
            resp = self.create_resp(Headers([('Content-Type', 'text/xml')]),
                                    html)

            msg = msgpack.dumps(resp.to_dict())
            loaded_dict = msgpack.loads(msg)

            loaded_resp = HTTPResponse.from_dict(loaded_dict)

            self.assertEquals(
                smart_unicode(html,
                              DEFAULT_CHARSET,
                              ESCAPED_CHAR,
                              on_error_guess=False), loaded_resp.body)
Example #6
0
    def test_from_dict_encodings(self):
        for body, charset in TEST_RESPONSES.values():
            html = body.encode(charset)
            resp = self.create_resp(Headers([('Content-Type', 'text/xml')]),
                                    html)
            
            msg = msgpack.dumps(resp.to_dict())
            loaded_dict = msgpack.loads(msg)
            
            loaded_resp = HTTPResponse.from_dict(loaded_dict)

            self.assertEquals(
                smart_unicode(html, DEFAULT_CHARSET,
                              ESCAPED_CHAR, on_error_guess=False),
                loaded_resp.body
            )