Skip to content

Commit

Permalink
Added a couple of tests for the HTTP client
Browse files Browse the repository at this point in the history
  • Loading branch information
heyman committed Dec 19, 2017
1 parent 5e1ccc5 commit ccb0f56
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
29 changes: 29 additions & 0 deletions locust/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,32 @@ def test_post_redirect(self):
get_stats = global_stats.get(url, method="GET")
self.assertEqual(1, post_stats.num_requests)
self.assertEqual(0, get_stats.num_requests)

def test_cookie(self):
s = HttpSession("http://127.0.0.1:%i" % self.port)
r = s.post("/set_cookie?name=testcookie&value=1337")
self.assertEqual(200, r.status_code)
r = s.get("/get_cookie?name=testcookie")
self.assertEqual('1337', r.content.decode())

def test_head(self):
s = HttpSession("http://127.0.0.1:%i" % self.port)
r = s.head("/request_method")
self.assertEqual(200, r.status_code)
self.assertEqual("", r.content.decode())

def test_delete(self):
s = HttpSession("http://127.0.0.1:%i" % self.port)
r = s.delete("/request_method")
self.assertEqual(200, r.status_code)
self.assertEqual("DELETE", r.content.decode())

def test_options(self):
s = HttpSession("http://127.0.0.1:%i" % self.port)
r = s.options("/request_method")
self.assertEqual(200, r.status_code)
self.assertEqual("", r.content.decode())
self.assertEqual(
set(["OPTIONS", "DELETE", "PUT", "GET", "POST", "HEAD"]),
set(r.headers["allow"].split(", ")),
)
10 changes: 10 additions & 0 deletions locust/test/testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ def generate():
yield "</body></html>"
return Response(stream_with_context(generate()), mimetype="text/html")

@app.route("/set_cookie", methods=["POST"])
def set_cookie():
response = make_response("ok")
response.set_cookie(request.args.get("name"), request.args.get("value"))
return response

@app.route("/get_cookie")
def get_cookie():
return make_response(request.cookies.get(request.args.get("name"), ""))


class LocustTestCase(unittest.TestCase):
"""
Expand Down

0 comments on commit ccb0f56

Please sign in to comment.