You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
704 B

2 months ago
# import requests
# import json
#
# url = 'http://127.0.0.1:8000/choose/style/' # 确保 URL 正确
# response = requests.post(url)
# print(response.text)
from django.test import TestCase
from django.urls import reverse
from django.http import JsonResponse
import random
class ChooseStyleTestCase(TestCase):
def test_choosestyle_with_post_request(self):
# 测试有效的POST请求
url = reverse('choose_style') # 确保名称与 urls.py 中定义的一致
response = self.client.post(url)
self.assertEqual(response.status_code, 200)
self.assertTrue('error' not in response.json())
self.assertIn(response.json()['number'], [1, 2, 3, 4, 5, 6])