def test_it_supports_urlencoded_post_requests(self): url = "http://abc.de" r = LocustRequest.from_request( Request( timestamp=MagicMock(), method=HttpMethod.POST, url=urlparse(url), har_entry={"entry": "data"}, headers={"a": "b"}, post_data={ "mimeType": "application/x-www-form-urlencoded", "params": [{"name": "x", "value": "y"}], "text": "z=7", }, ) ) assert lreq_to_expr(r) == py.FunctionCall( name="self.client.post", named_args={ "url": py.Literal(url), "name": py.Literal(url), "headers": py.Literal({"a": "b"}), "timeout": py.Literal(TIMEOUT), "allow_redirects": py.Literal(False), "data": py.Literal(b"z=7"), "params": py.Literal([(b"x", b"y")]), }, )
def test_it_supports_patch_requests_with_payload(self): url = "http://abc.de" r = LocustRequest.from_request( Request( timestamp=MagicMock(), method=HttpMethod.PATCH, url=urlparse(url), har_entry={"entry": "data"}, headers={"a": "b"}, query=[QueryPair("c", "d")], post_data={ "mimeType": "application/json", "params": [{"name": "x", "value": "y"}], "text": """{"z": 7}""", }, ) ) assert lreq_to_expr(r) == py.FunctionCall( name="self.client.patch", named_args={ "url": py.Literal(url), "name": py.Literal(url), "headers": py.Literal({"a": "b"}), "timeout": py.Literal(TIMEOUT), "allow_redirects": py.Literal(False), "json": py.Literal({"z": 7}), "params": py.Literal([(b"x", b"y"), (b"c", b"d")]), }, )
def test_it_supports_json_post_requests(self): url = "http://abc.de" r = Request( timestamp=MagicMock(), method=HttpMethod.POST, url=urlparse(url), har_entry={"entry": "data"}, headers={"a": "b"}, post_data={ "mimeType": "application/json", "params": [{"name": "x", "value": "y"}], "text": """{"z": 7}""", }, ) assert req_to_expr(r) == py.FunctionCall( name="self.client.post", named_args={ "url": py.Literal(url), "name": py.Literal(url), "headers": py.Literal({"a": "b"}), "timeout": py.Literal(TIMEOUT), "allow_redirects": py.Literal(False), "json": py.Literal({"z": 7}), "params": py.Literal([(b"x", b"y")]), }, )
def test_it_uses_the_custom_name_if_provided(self): url = "http://abc.de" name = "my-req" r = Request( name=name, timestamp=MagicMock(), method=HttpMethod.GET, url=urlparse(url), har_entry={"entry": "data"}, ) assert req_to_expr(r) == py.FunctionCall( name="self.client.get", named_args={ "url": py.Literal(url), "name": py.Literal(name), "timeout": py.Literal(TIMEOUT), "allow_redirects": py.Literal(False), }, )
def test_it_supports_empty_post_requests(self): url = "http://abc.de" r = Request( timestamp=MagicMock(), method=HttpMethod.POST, url=urlparse(url), har_entry={"entry": "data"}, headers={"a": "b"}, post_data=None, ) assert req_to_expr(r) == py.FunctionCall( name="self.client.post", named_args={ "url": py.Literal(url), "name": py.Literal(url), "headers": py.Literal({"a": "b"}), "timeout": py.Literal(TIMEOUT), "allow_redirects": py.Literal(False), }, )
def test_it_supports_get_requests(self): url = "http://abc.de" r = Request( timestamp=MagicMock(), method=HttpMethod.GET, url=urlparse(url), har_entry={"entry": "data"}, headers={"a": "b"}, query=[QueryPair("x", "y")], # query is currently ignored for GET ) assert req_to_expr(r) == py.FunctionCall( name="self.client.get", named_args={ "url": py.Literal(url), "name": py.Literal(url), "headers": py.Literal({"a": "b"}), "timeout": py.Literal(TIMEOUT), "allow_redirects": py.Literal(False), }, )
def test_it_supports_patch_requests_without_payload(self): url = "http://abc.de" r = Request( timestamp=MagicMock(), method=HttpMethod.PATCH, url=urlparse(url), har_entry={"entry": "data"}, headers={"a": "b"}, query=[QueryPair("c", "d")], post_data=None, ) assert req_to_expr(r) == py.FunctionCall( name="self.client.patch", named_args={ "url": py.Literal(url), "name": py.Literal(url), "headers": py.Literal({"a": "b"}), "timeout": py.Literal(TIMEOUT), "allow_redirects": py.Literal(False), "params": py.Literal([(b"c", b"d")]), }, )