Skip to content

Commit

Permalink
Merge pull request #3 from moumouta/master
Browse files Browse the repository at this point in the history
auth_service_test - end2end testing
  • Loading branch information
Lincyaw authored May 23, 2024
2 parents c3b32b6 + 12148bf commit a6009fa
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ MANIFEST
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
.vscode

# Installer logs
pip-log.txt
Expand Down
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
addopts = -s
2 changes: 1 addition & 1 deletion service/admin_basic_info_service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from config import *
from service.config import *


def get_welcome(client, headers):
Expand Down
62 changes: 48 additions & 14 deletions service/auth_service_test.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
from service.auth_service import *

BASE_URL = "http://10.10.10.220:30193"
headers = {
'Proxy-Connection': 'keep-alive',
'Accept': 'application/json',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36',
'Content-Type': 'application/json',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
'Connection': 'keep-alive',
}

from service.test_utils import *

def test_get_auth_hello():
client = requests.Session()
Expand Down Expand Up @@ -77,7 +66,52 @@ def test_end2end():
# 1. 查
# 2. 加
# 3. 查;验证有没有加成功
# 4. 改(如果有)
# 5. 查;验证有没有改成功
# 4. 改(如果有)(是否有 Update)
# 5. 查;验证有没有改成功(是否有update)
# 6. 删
# 7. 查;验证有没有删成功
"""
End-to-end test: query, add, update, delete
"""
client = requests.Session()
basic_auth_dto = DtoLoginUser(username='admin',
password='222222', verificationCode="123")
token = users_login(client, basic_auth_dto, headers, BASE_URL)
client.headers.update({'Authorization': f'Bearer {token}'})

# 1. Query
users_before = get_users(client, BASE_URL)
print("Users before:", users_before)

# 2. Add
new_user_dto = DtoCreateUser(userId='999990099', userName='newer0011',
password='newpassword')
new_user = create_default_user(client, new_user_dto, BASE_URL)
print("New user added:", new_user)

# 3. Query and verify addition
users_after_add = get_users(client, BASE_URL)
print("Users after addition:", users_after_add)
assert len(users_after_add) == len(users_before) + 1
assert any(user.userId == new_user_dto.userId for user in users_after_add)

# # 4. Update (if the user exists)
# updated_user_dto = DtoCreateUser(userId=new_user_dto.userId, userName='updateduser',
# password='updatedpassword')
# updated_user = create_default_user(client, updated_user_dto, BASE_URL)
# print("User updated:", updated_user)

# # 5. Query and verify update
# users_after_update = get_users(client, BASE_URL)
# print("Users after update:", users_after_update)
# assert any(user.userName == updated_user_dto.userName for user in users_after_update)

# 6. Delete
delete_result = delete_user(client, new_user_dto.userId, BASE_URL)
print("User deleted:", delete_result)

# 7. Query and verify deletion
users_after_delete = get_users(client, BASE_URL)
print("Users after deletion:", users_after_delete)
assert len(users_after_delete) == len(users_before)
assert not any(user.userId == new_user_dto.userId for user in users_after_delete)
2 changes: 1 addition & 1 deletion service/common_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import requests
from collections import defaultdict
import random
from config import BASE_URL
from service.config import BASE_URL


class HttpClient:
Expand Down
11 changes: 11 additions & 0 deletions service/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
BASE_URL = "http://10.10.10.220:31948"
headers = {
'Proxy-Connection': 'keep-alive',
'Accept': 'application/json',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36',
'Content-Type': 'application/json',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
'Connection': 'keep-alive',
}

2 changes: 1 addition & 1 deletion service/user_service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from config import *
from service.config import *

def userService_hello(client):
url = "/api/v1/userservice/users/hello"
Expand Down

0 comments on commit a6009fa

Please sign in to comment.