예제 #1
0
 def test_it_returns_a_task_using_post_given_a_post_http_method(self):
     a_request = MagicMock(spec_set=Request)
     a_request.method = HttpMethod.POST
     a_request.post_data = {}
     task = Task("some_task", a_request)
     action = task.as_locust_action()
     assert action.startswith("response = self.client.post(")
예제 #2
0
 def test_it_injects_headers(self):
     a_request = MagicMock(spec_set=Request)
     a_request.method = HttpMethod.GET
     a_request.headers = [Header(name="some_header", value="some_value")]
     task = Task("some_task", a_request)
     action = task.as_locust_action()
     assert "some_value" in action
예제 #3
0
 def test_it_encodes_data_in_task_for_text_mime(self):
     decoded_value = '{"formatted": "54,95 €"}'
     a_request = MagicMock(spec_set=Request)
     a_request.method = HttpMethod.POST
     a_request.post_data = {"text": decoded_value}
     task = Task("some_task", a_request)
     action = task.as_locust_action()
     assert str(decoded_value.encode()) in action
예제 #4
0
 def test_it_returns_a_task_using_delete_given_a_delete_http_method(self):
     a_request = MagicMock(spec_set=Request)
     a_request.method = HttpMethod.DELETE
     a_request.url = urlparse(
         "http://www.some.web.site/?some_name=some_value")
     task = Task("some_task", a_request)
     action = task.as_locust_action()
     assert action.startswith("response = self.client.delete(")
     assert "?some_name=some_value" in action
예제 #5
0
 def test_it_returns_a_task_using_put_given_a_put_http_method(self):
     a_request = MagicMock(spec_set=Request)
     a_request.method = HttpMethod.PUT
     a_request.post_data = {"text": "{'some key': 'some value'}"}
     a_request.query = [QueryPair(name="some name", value="some value")]
     task = Task("some_task", a_request)
     action = task.as_locust_action()
     assert action.startswith("response = self.client.put(")
     assert "params={'some name': 'some value'}" in action
     assert "data=b\"{'some key': 'some value'}\"" in action
예제 #6
0
 def test_post_processing_returns_an_indented_string_given_an_indentation(
         self):
     a_request = MagicMock(spec_set=Request)
     a_request.method = HttpMethod.GET
     task = Task("some_task", a_request)
     new_post_processings = (*task.locust_postprocessing,
                             "def some_function():")
     task = task._replace(locust_postprocessing=new_post_processings)
     action = task.as_locust_action(indentation=2)
     assert "  def some_function():" in action
예제 #7
0
 def test_it_encodes_data_in_task_for_json_mime(self):
     decoded_value = '{"formatted": "54,95 €"}'
     a_request = MagicMock(spec_set=Request)
     a_request.method = HttpMethod.POST
     a_request.post_data = {
         "text": decoded_value,
         "mimeType": "application/json"
     }
     task = Task("some_task", a_request)
     action = task.as_locust_action()
     assert str(json.loads(decoded_value)) in action
예제 #8
0
 def test_it_returns_a_task_using_options_given_an_options_http_method(
         self):
     a_request = MagicMock(spec_set=Request)
     a_request.method = HttpMethod.OPTIONS
     a_request.headers = [
         Header(name="Access-Control-Request-Method", value="POST")
     ]
     task = Task("some_task", a_request)
     action = task.as_locust_action()
     assert action.startswith("response = self.client.options(")
     assert "headers={'Access-Control-Request-Method': 'POST'" in action
예제 #9
0
 def test_it_returns_action_from_locust_request(self):
     a_request = MagicMock(spec_set=Request)
     a_request.method = HttpMethod.GET
     locust_request = LocustRequest(method=HttpMethod.GET,
                                    url=repr("http://locust-task"),
                                    headers={})
     task = Task("some_task",
                 request=a_request,
                 locust_request=locust_request)
     action = task.as_locust_action()
     assert action.startswith(
         "response = self.client.get(url='http://locust-task'")
예제 #10
0
 def test_it_respects_sub_indentation_levels(self):
     a_request = MagicMock(spec_set=Request)
     a_request.method = HttpMethod.GET
     task = Task("some_task", a_request)
     new_pre_processings = (
         *task.locust_preprocessing,
         "\n  def function():\n   if True:\n    print(True)",
     )
     task = task._replace(locust_preprocessing=new_pre_processings)
     action = task.as_locust_action(indentation=1)
     assert action.startswith(
         " \n def function():\n  if True:\n   print(True)")
예제 #11
0
 def test_it_applies_indentation_to_all_pre_processings(self):
     a_request = MagicMock(spec_set=Request)
     a_request.method = HttpMethod.GET
     task = Task("some_task", a_request)
     new_pre_processings = (
         *task.locust_preprocessing,
         "def some_function():",
         "def some_other_function():",
     )
     task = task._replace(locust_preprocessing=new_pre_processings)
     action = task.as_locust_action(indentation=2)
     assert action.startswith(
         "  def some_function():\n\n  def some_other_function():")
예제 #12
0
 def test_it_converts_post_params_to_post_text(self):
     a_request = MagicMock(spec_set=Request)
     a_request.method = HttpMethod.POST
     a_request.post_data = {
         "mimeType":
         "application/json",
         "params": [
             {
                 "name": "username",
                 "value": "some user"
             },
             {
                 "name": "password",
                 "value": "some password"
             },
         ],
     }
     task = Task("some task", a_request)
     action = task.as_locust_action()
     assert "'username': '******'" in action
     assert "'password': '******'" in action
예제 #13
0
 def test_it_returns_a_string(self):
     a_request = MagicMock(spec_set=Request)
     a_request.method = HttpMethod.GET
     task = Task("some_task", a_request)
     assert isinstance(task.as_locust_action(), str)
예제 #14
0
 def test_it_returns_an_error_given_an_unsupported_http_method(self):
     a_request_with_an_unsupported_http_method = MagicMock()
     task = Task("some_task", a_request_with_an_unsupported_http_method)
     with pytest.raises(ValueError):
         task.as_locust_action()
예제 #15
0
 def test_it_provides_timeout_to_requests(self):
     a_request = MagicMock(spec_set=Request)
     a_request.method = HttpMethod.GET
     task = Task("some_task", a_request)
     action = task.as_locust_action()
     assert f"timeout={TIMEOUT}" in action