forked from wintests/pytestDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
244 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from core.rest_client import RestClient | ||
from config.settings import api_root_url | ||
|
||
|
||
class User(RestClient): | ||
|
||
def __init__(self, api_root_url, **kwargs): | ||
super(User, self).__init__(api_root_url, **kwargs) | ||
|
||
def list_all_users(self, **kwargs): | ||
return self.get("/users", **kwargs) | ||
|
||
def list_one_user(self, username, **kwargs): | ||
return self.get("/users/{}".format(username), **kwargs) | ||
|
||
def register(self, **kwargs): | ||
return self.post("/register", **kwargs) | ||
|
||
def login(self, **kwargs): | ||
return self.post("/login", **kwargs) | ||
|
||
def update(self, user_id, **kwargs): | ||
return self.put("/update/user/{}".format(user_id), **kwargs) | ||
|
||
def delete(self, user_id, **kwargs): | ||
return self.post("/delete/user/{}".format(user_id), **kwargs) | ||
|
||
|
||
user = User(api_root_url) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# 测试环境 | ||
api_root_url="http://127.0.0.1:9999" | ||
username = "wintest" | ||
password = "123456" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import pytest | ||
from config.settings import username, password | ||
from api.user import user | ||
|
||
@pytest.fixture(scope="session") | ||
def login_fixture(): | ||
header = { | ||
"Content-Type": "application/x-www-form-urlencoded" | ||
} | ||
payload = { | ||
"username": username, | ||
"password": password | ||
} | ||
loginInfo = user.login(data=payload, headers=header) | ||
yield loginInfo.json() | ||
|
||
@pytest.fixture(scope="session") | ||
def unlogin_fixture(): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
class ResultBase(): | ||
pass |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
from core.result_base import ResultBase | ||
from api.user import user | ||
|
||
|
||
def get_all_user_info(): | ||
result = ResultBase() | ||
res = user.list_all_users() | ||
result.success = False | ||
if res.json()["code"] == "0": | ||
result.success = True | ||
else: | ||
result.error = "接口返回码是 【 {} 】, 返回信息:{} ".format(res.json()["code"], res.json()["msg"]) | ||
return result | ||
|
||
|
||
def get_one_user_info(username): | ||
result = ResultBase() | ||
res = user.list_one_user(username) | ||
result.success = False | ||
if res.json()["code"] == "0": | ||
result.success = True | ||
else: | ||
result.error = "接口返回码是 【 {} 】, 返回信息:{} ".format(res.json()["code"], res.json()["msg"]) | ||
return result | ||
|
||
|
||
def register_user(username, password, telephone, sex="", address=""): | ||
result = ResultBase() | ||
json_data = { | ||
"username": username, | ||
"password": password, | ||
"sex": sex, | ||
"telephone": telephone, | ||
"address": address | ||
} | ||
header = { | ||
"Content-Type": "application/json" | ||
} | ||
res = user.register(json=json_data, headers=header) | ||
result.success = False | ||
if res.json()["code"] == 0: | ||
result.success = True | ||
else: | ||
result.error = "接口返回码是 【 {} 】, 返回信息:{} ".format(res.json()["code"], res.json()["msg"]) | ||
return result | ||
|
||
|
||
def login_user(username, password): | ||
result = ResultBase() | ||
payload = { | ||
"username": username, | ||
"password": password | ||
} | ||
header = { | ||
"Content-Type": "application/x-www-form-urlencoded" | ||
} | ||
res = user.login(data=payload, headers=header) | ||
result.success = False | ||
if res.json()["code"] == 0: | ||
result.success = True | ||
else: | ||
result.error = "接口返回码是 【 {} 】, 返回信息:{} ".format(res.json()["code"], res.json()["msg"]) | ||
return result | ||
|
||
|
||
def update_user(id, username, password, telephone, token, sex="", address=""): | ||
result = ResultBase() | ||
header = { | ||
"Content-Type": "application/json" | ||
} | ||
json_data = { | ||
"username": username, | ||
"password": password, | ||
"token": token, | ||
"sex": sex, | ||
"telephone": telephone, | ||
"address": address | ||
} | ||
res = user.update(id, json=json_data, headers=header) | ||
result.success = False | ||
if res.json()["code"] == 0: | ||
result.success = True | ||
else: | ||
result.error = "接口返回码是 【 {} 】, 返回信息:{} ".format(res.json()["code"], res.json()["msg"]) | ||
return result | ||
|
||
|
||
def delete_user(id, username, token): | ||
result = ResultBase() | ||
json_data = { | ||
"username": username, | ||
"token": token, | ||
} | ||
header = { | ||
"Content-Type": "application/json" | ||
} | ||
res = user.delete(id, json=json_data, headers=header) | ||
result.success = False | ||
if res.json()["code"] == 0: | ||
result.success = True | ||
else: | ||
result.error = "接口返回码是 【 {} 】, 返回信息:{} ".format(res.json()["code"], res.json()["msg"]) | ||
return result |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def insert_delete_user(): | ||
pass | ||
|
||
@pytest.fixture(scope="function") | ||
def delete_register_user(): | ||
pass | ||
|
||
@pytest.fixture(scope="function") | ||
def update_user_telephone(): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import pytest | ||
from operation.user import get_all_user_info, get_one_user_info | ||
|
||
|
||
def test_get_all_user_info(): | ||
result = get_all_user_info() | ||
# print(result.__dict__) | ||
assert result.success is True, result.error | ||
|
||
|
||
def test_get_get_one_user_info(): | ||
result = get_one_user_info("wintest3") | ||
# print(result.__dict__) | ||
assert result.success is True, result.error | ||
|
||
|
||
if __name__ == '__main__': | ||
pytest.main(["-q", "-s", "test_01_get_info.py"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import pytest | ||
from operation.user import register_user | ||
|
||
|
||
def test_register_user(delete_register_user): | ||
result = register_user("wintest10", "123456", "13599999999", sex="1", address="深圳市宝安区") | ||
# print(result.__dict__) | ||
assert result.success is True, result.error | ||
|
||
|
||
if __name__ == '__main__': | ||
pytest.main(["-q", "-s", "test_02_register.py"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import pytest | ||
from operation.user import login_user | ||
|
||
@pytest.mark.parametrize("") | ||
def test_login_user(): | ||
result = login_user("wintest", "123456") | ||
# print(result.__dict__) | ||
assert result.success is True, result.error | ||
|
||
|
||
if __name__ == '__main__': | ||
pytest.main(["-q", "-v", "test_03_login.py"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import pytest | ||
from operation.user import update_user | ||
|
||
|
||
def test_update_user(login_fixture, update_user_telephone): | ||
username = login_fixture.get("login_info").get("username") | ||
token = login_fixture.get("login_info").get("token") | ||
result = update_user(4, username, "123456", "13500010004", token=token, sex="0", address="") | ||
assert result.success is True, result.error | ||
|
||
if __name__ == '__main__': | ||
pytest.main(["-q", "-s", "test_04_update_user.py"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import pytest | ||
from operation.user import delete_user | ||
|
||
|
||
def test_delete_user(login_fixture, insert_delete_user): | ||
username = login_fixture.get("login_info").get("username") | ||
token = login_fixture.get("login_info").get("token") | ||
result = delete_user(7, username, token) | ||
assert result.success is True, result.error | ||
|
||
if __name__ == '__main__': | ||
pytest.main(["-q", "-s", "test_04_update_user.py"]) |
Empty file.