def test_2_from_requests(self): har_req = harlib.HarRequest(self.req) self.assertEqual(har_req.method, self.req.method) self.assertEqual(har_req.url, self.req.url) self.assertEqual(har_req.httpVersion, "HTTP/1.1") self.assertEqual(har_req.get_header("X-File"), "requests") self.assertEqual(har_req.post_param("username").value, "bob") self.assertEqual(har_req.post_param("password").value, "yes")
def test_1_from_requests(self): req = requests.Request( 'GET', '%s/get' % HTTPBIN_ORIGIN, params={'username': '******', 'password': '******'}) har_req = harlib.HarRequest(req) self.assertEqual(har_req.method, req.method) self.assertEqual(har_req.url, req.url) self.assertEqual(har_req.httpVersion, "HTTP/1.1") self.assertEqual(har_req.get_param("username"), "bob") self.assertEqual(har_req.get_param("password"), "yes")
def process_response(self, request, response): try: d = {'startedDateTime': None, 'time': 0.0, 'request': harlib.HarRequest(request), 'response': harlib.HarResponse(response)} s = json.dumps(harlib.HarEntry(d).to_json(with_content=False)) logger.info(s) except Exception as err: logger.error("%s %s" % (type(err), repr(err))) return response
def test_1_from_urllib2(self): har_req = harlib.HarRequest(self.req) self.assertEqual(har_req.method, 'POST') self.assertEqual(har_req.url, '%s/post' % HTTPBIN_ORIGIN) self.assertEqual(har_req.httpVersion, 'HTTP/1.1') self.assertEqual(har_req.get_header('Accept'), '*/*') self.assertEqual(har_req.get_header('Content-Type'), 'application/x-www-form-urlencoded') self.assertEqual(har_req.postData.params[0].name, 'username') self.assertEqual(har_req.postData.params[0].value, 'bob') self.assertEqual(har_req.postData.params[1].name, 'password') self.assertEqual(har_req.postData.params[1].value, 'yes')
def test_3_to_requests(self): har_req = harlib.HarRequest(self.req) to_req = har_req.encode(requests.Request) self.assertEqualRequest(to_req, self.req)
def test_2_to_requests(self): har_preq = harlib.HarRequest(self.preq) to_preq = har_preq.encode(requests.PreparedRequest) self.assertEqualPreparedRequest(to_preq, self.preq)
def test_1_from_requests(self): har_req = harlib.HarRequest(self.preq) self.assertEqual(har_req.method, self.preq.method) self.assertEqual(har_req.url, self.preq.url) self.assertEqual(har_req.httpVersion, "HTTP/1.1")
def test_2_to_urllib2(self): har_req = harlib.HarRequest(self.req) to_req = har_req.encode(urllib.request.Request) self.assertEqualUrllib2Request(to_req, self.req)