Skip to content

Commit

Permalink
FastHttpUser: Add test cases for complex content-type strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberw committed Oct 7, 2023
1 parent 2cde086 commit dfdd610
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions locust/test/test_fasthttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,16 @@ class MyUser(FastHttpUser):
locust = MyUser(self.environment)
self.assertEqual(200, locust.client.head("/request_method").status_code)

def test_complex_content_type(self):
class MyUser(FastHttpUser):
host = "http://127.0.0.1:%i" % self.port

locust = MyUser(self.environment)

self.assertEqual("stuff", locust.client.get("/content_type_missing_charset").text)
self.assertEqual("stuff", locust.client.get("/content_type_regular").text)
self.assertEqual("stuff", locust.client.get("/content_type_with_extra_stuff").text)

def test_log_request_name_argument(self):
self.response = ""

Expand Down
21 changes: 21 additions & 0 deletions locust/test/testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,27 @@ def rest():
return request.json


@app.route("/content_type_missing_charset")
def content_type_missing_charset():
resp = make_response("stuff")
resp.headers["Content-Type"] = "Content-Type: application/json;"
return resp


@app.route("/content_type_regular")
def content_type_regular():
resp = make_response("stuff")
resp.headers["Content-Type"] = "Content-Type: application/json; charset=utf-8;"
return resp


@app.route("/content_type_with_extra_stuff")
def content_type_with_extra_stuff():
resp = make_response("stuff")
resp.headers["Content-Type"] = "Content-Type: application/json; charset=utf-8; api-version=3.0"
return resp


class LocustTestCase(unittest.TestCase):
"""
Test case class that restores locust.events.EventHook listeners on tearDown, so that it is
Expand Down

0 comments on commit dfdd610

Please sign in to comment.