mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
HttpSession can be called with full url or with only path
This commit is contained in:
@@ -5,8 +5,8 @@ from ate.context import Context
|
||||
|
||||
class TestRunner(object):
|
||||
|
||||
def __init__(self):
|
||||
self.client = HttpSession()
|
||||
def __init__(self, base_url=None):
|
||||
self.client = HttpSession(base_url)
|
||||
self.context = Context()
|
||||
|
||||
def init_context(self, config_dict, level):
|
||||
|
||||
@@ -15,20 +15,22 @@ class TestHttpClient(ApiServerUnittest):
|
||||
url = "%s/api/users" % self.host
|
||||
return self.api_client.delete(url)
|
||||
|
||||
def create_user(self, uid, name, password):
|
||||
url = "%s/api/users/%d" % (self.host, uid)
|
||||
def test_request_with_full_url(self):
|
||||
url = "%s/api/users/1000" % self.host
|
||||
data = {
|
||||
'name': name,
|
||||
'password': password
|
||||
'name': 'user1',
|
||||
'password': '123456'
|
||||
}
|
||||
return self.api_client.post(url, json=data)
|
||||
|
||||
def test_create_user_not_existed(self):
|
||||
resp = self.create_user(1000, 'user1', '123456')
|
||||
resp = self.api_client.post(url, json=data)
|
||||
self.assertEqual(201, resp.status_code)
|
||||
self.assertEqual(True, resp.json()['success'])
|
||||
|
||||
def test_create_user_existed(self):
|
||||
resp = self.create_user(1000, 'user1', '123456')
|
||||
resp = self.create_user(1000, 'user1', '123456')
|
||||
self.assertEqual(500, resp.status_code)
|
||||
def test_request_without_base_url(self):
|
||||
url = "/api/users/1000"
|
||||
data = {
|
||||
'name': 'user1',
|
||||
'password': '123456'
|
||||
}
|
||||
resp = self.api_client.post(url, json=data)
|
||||
self.assertEqual(201, resp.status_code)
|
||||
self.assertEqual(True, resp.json()['success'])
|
||||
|
||||
@@ -6,7 +6,8 @@ from test.base import ApiServerUnittest
|
||||
class TestRunner(ApiServerUnittest):
|
||||
|
||||
def setUp(self):
|
||||
self.test_runner = runner.TestRunner()
|
||||
base_url = "http://127.0.0.1:5000"
|
||||
self.test_runner = runner.TestRunner(base_url)
|
||||
self.clear_users()
|
||||
|
||||
def clear_users(self):
|
||||
@@ -31,7 +32,7 @@ class TestRunner(ApiServerUnittest):
|
||||
testcase = {
|
||||
"name": "create user which does not exist",
|
||||
"request": {
|
||||
"url": "http://127.0.0.1:5000/api/users/1000",
|
||||
"url": "/api/users/1000",
|
||||
"method": "POST",
|
||||
"headers": {
|
||||
"content-type": "application/json"
|
||||
|
||||
Reference in New Issue
Block a user