test_django_service_post

"""
@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"
posted @ 2024-04-30 18:11  遇事不决,量子力学  阅读(5)  评论(0编辑  收藏  举报