"""标签:service,resp,json,test,post,data,app From: https://www.cnblogs.com/yinzone/p/18168536
@Name: test_django_service_01.py
@Author: zengchuanyin
@Date 2024/2/25-10:56
"""
import pytest
import logging
import json
from config import get_env_msg
from service.console.djangoservice_post_console import DjangoServicePost
from service_base import ServiceBase
logging.basicConfig(level=logging.INFO)
def test_django_service_post():
data = get_env_msg()
url = f"http://{data['host']['ip']}:{data['host']['port']}"
post_data = {'aaa': 'qwe'}
header = {
'Content-Type': 'application/json'
}
app_service = ServiceBase(host=url, vpath='/service/')
resp = app_service._post(url=app_service.host + app_service.vpath, json=json.dumps(post_data), headers=header)
# 将原生http响应转为str
resp = resp.json()
# 将str转为python处理的dict
resp = json.loads(resp)
print(type(resp))
assert resp["aaa"] == "qwe1"