test: add backend calc contract coverage
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import base64
|
||||
import json
|
||||
import sys
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
||||
|
||||
from main import application
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client():
|
||||
return TestClient(application)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def alter_token():
|
||||
payload = {
|
||||
'alter': 'MDAwMDAw',
|
||||
'equVersion': '0',
|
||||
'time': int(time.time() * 1000),
|
||||
}
|
||||
return base64.b64encode(json.dumps(payload).encode('utf-8')).decode('utf-8')
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def minimal_calc_config():
|
||||
parts = [
|
||||
'武器',
|
||||
'副武器',
|
||||
'称号',
|
||||
'上衣',
|
||||
'头肩',
|
||||
'下装',
|
||||
'腰带',
|
||||
'鞋',
|
||||
'手镯',
|
||||
'项链',
|
||||
'戒指',
|
||||
'辅助装备',
|
||||
'魔法石',
|
||||
'耳环',
|
||||
]
|
||||
return {
|
||||
'equips': {
|
||||
part: {
|
||||
'id': '',
|
||||
'reinforce': 0,
|
||||
'reinforceType': 0,
|
||||
'enchant': '0',
|
||||
'refine': 0,
|
||||
'adaptation': 0,
|
||||
}
|
||||
for part in parts
|
||||
},
|
||||
'oaths': {},
|
||||
'emblems': {},
|
||||
'skills': {},
|
||||
'avatar': {},
|
||||
'sundry': {},
|
||||
'jades': {},
|
||||
'options': {},
|
||||
'DSB': False,
|
||||
'BUFF': False,
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
def test_calc_response_contract(client, alter_token, minimal_calc_config):
|
||||
response = client.post(
|
||||
'/api/calc',
|
||||
headers={'alter-token': alter_token},
|
||||
json=minimal_calc_config,
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
payload = response.json()
|
||||
assert payload['code'] == 200
|
||||
assert payload['message'] == 'Success'
|
||||
assert isinstance(payload['data'], dict)
|
||||
|
||||
data = payload['data']
|
||||
assert set(['uuid', 'skills', 'info', 'suits', 'buffer']).issubset(data)
|
||||
assert isinstance(data['uuid'], str)
|
||||
assert isinstance(data['skills'], list)
|
||||
assert isinstance(data['info'], list)
|
||||
assert isinstance(data['buffer'], bool)
|
||||
Reference in New Issue
Block a user