mp_message/tests/test_chat.py

32 lines
872 B
Python
Raw Normal View History

import threading
import jwt
import uvicorn
from config import Config
from main import app
from httpx import Client
server_thread = threading.Thread(target=uvicorn.run, args=(app,), daemon=True,
kwargs={"host": "127.0.0.1", "port": 8000, "reload": False})
server_thread.start()
client = Client(base_url="http://127.0.0.1:8000")
def test_create_chat():
# Complete authorization
resp = client.post('/api/v1/auth', json={'username': 1})
assert resp.status_code == 200
token = resp.json()['access_token']
resp = client.post('/api/v1/chat', json={'name': 'test_chat'}, headers={'Authorization': f'Bearer {token}'})
print(resp.json())
assert resp.status_code == 201
assert 'id' in resp.json()
assert resp.json()['id'] > 0
assert 'name' in resp.json()
assert resp.json()['name'] == 'test_chat'