mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-08 17:29:34 +08:00
apiserver: add interface /api/token
This commit is contained in:
@@ -65,6 +65,17 @@ def get_customized_response():
|
|||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
@app.route('/api/token')
|
||||||
|
@validate_request
|
||||||
|
def get_token():
|
||||||
|
result = {
|
||||||
|
'success': True,
|
||||||
|
'token': utils.gen_random_string(8)
|
||||||
|
}
|
||||||
|
response = make_response(json.dumps(result))
|
||||||
|
response.headers["Content-Type"] = "application/json"
|
||||||
|
return response
|
||||||
|
|
||||||
@app.route('/api/users')
|
@app.route('/api/users')
|
||||||
@validate_request
|
@validate_request
|
||||||
def get_users():
|
def get_users():
|
||||||
|
|||||||
@@ -128,3 +128,10 @@ class TestApiServer(ApiServerUnittest):
|
|||||||
resp = self.api_client.post(url, json=expected_response)
|
resp = self.api_client.post(url, json=expected_response)
|
||||||
self.assertIn('abc', resp.headers)
|
self.assertIn('abc', resp.headers)
|
||||||
self.assertIn('123', resp.headers['abc'])
|
self.assertIn('123', resp.headers['abc'])
|
||||||
|
|
||||||
|
def test_get_token(self):
|
||||||
|
url = "%s/api/token" % self.host
|
||||||
|
resp = self.api_client.get(url)
|
||||||
|
resp_json = resp.json()
|
||||||
|
self.assertTrue(resp_json["success"])
|
||||||
|
self.assertEqual(len(resp_json["token"]), 8)
|
||||||
|
|||||||
@@ -148,3 +148,11 @@ class TestApiServerV2(ApiServerUnittest):
|
|||||||
)
|
)
|
||||||
self.assertIn('abc', resp.headers)
|
self.assertIn('abc', resp.headers)
|
||||||
self.assertIn('123', resp.headers['abc'])
|
self.assertIn('123', resp.headers['abc'])
|
||||||
|
|
||||||
|
def test_get_token(self):
|
||||||
|
url = "%s/api/token" % self.host
|
||||||
|
headers = self.prepare_headers()
|
||||||
|
resp = self.api_client.get(url, headers=headers)
|
||||||
|
resp_json = resp.json()
|
||||||
|
self.assertTrue(resp_json["success"])
|
||||||
|
self.assertEqual(len(resp_json["token"]), 8)
|
||||||
|
|||||||
Reference in New Issue
Block a user