@@ -39,31 +39,50 @@ class SubmissionAPITestSetup:
3939 @classmethod
4040 def create_test_users (cls ):
4141 """創建測試用戶"""
42+ from user .models import UserProfile
43+
4244 # 普通學生
4345 cls .student1 = User .objects .create_user (
4446 username = 'api_student1' ,
4547 email = 'api_student1@test.com' ,
4648 password = 'testpass123'
4749 )
50+ # 設置郵箱驗證
51+ profile1 , _ = UserProfile .objects .get_or_create (user = cls .student1 )
52+ profile1 .email_verified = True
53+ profile1 .save ()
54+
4855 cls .student2 = User .objects .create_user (
4956 username = 'api_student2' ,
5057 email = 'api_student2@test.com' ,
5158 password = 'testpass123'
5259 )
60+ # 設置郵箱驗證
61+ profile2 , _ = UserProfile .objects .get_or_create (user = cls .student2 )
62+ profile2 .email_verified = True
63+ profile2 .save ()
5364
5465 # 老師
5566 cls .teacher = User .objects .create_user (
5667 username = 'api_teacher' ,
5768 email = 'api_teacher@test.com' ,
5869 password = 'testpass123'
5970 )
71+ # 設置郵箱驗證
72+ profile_teacher , _ = UserProfile .objects .get_or_create (user = cls .teacher )
73+ profile_teacher .email_verified = True
74+ profile_teacher .save ()
6075
6176 # TA
6277 cls .ta = User .objects .create_user (
6378 username = 'api_ta' ,
6479 email = 'api_ta@test.com' ,
6580 password = 'testpass123'
6681 )
82+ # 設置郵箱驗證
83+ profile_ta , _ = UserProfile .objects .get_or_create (user = cls .ta )
84+ profile_ta .email_verified = True
85+ profile_ta .save ()
6786
6887 # 管理員
6988 cls .admin = User .objects .create_user (
@@ -73,6 +92,11 @@ def create_test_users(cls):
7392 is_staff = True ,
7493 is_superuser = True
7594 )
95+ # 設置郵箱驗證
96+ profile_admin , _ = UserProfile .objects .get_or_create (user = cls .admin )
97+ profile_admin .email_verified = True
98+ profile_admin .save ()
99+
76100
77101 @classmethod
78102 def create_test_courses (cls ):
@@ -117,6 +141,7 @@ def create_test_problems(cls):
117141 description = 'API測試:給定一個整數數組,返回兩個數字的索引' ,
118142 course_id = cls .course1 ,
119143 creator_id = cls .teacher , # 添加必需的 creator_id
144+ is_public = 'course' , # 設置為課程可見
120145 difficulty = Problems .Difficulty .EASY
121146 )
122147
@@ -126,6 +151,7 @@ def create_test_problems(cls):
126151 description = 'API測試:反轉一個單鏈表' ,
127152 course_id = cls .course2 ,
128153 creator_id = cls .teacher , # 添加必需的 creator_id
154+ is_public = 'course' , # 設置為課程可見
129155 difficulty = Problems .Difficulty .MEDIUM
130156 )
131157
@@ -136,6 +162,7 @@ def create_test_problems(cls):
136162 description = 'API測試:用於測試權限的題目(關聯到 course2)' ,
137163 course_id = cls .course2 , # 修改:不能為 None,使用 course2
138164 creator_id = cls .teacher , # 添加必需的 creator_id
165+ is_public = 'course' , # 設置為課程可見
139166 difficulty = Problems .Difficulty .HARD
140167 )
141168
@@ -290,6 +317,11 @@ def test_create_submission_success(self):
290317
291318 response = self .client .post (self .get_submission_create_url (), data )
292319
320+ # 調試:打印響應內容
321+ if response .status_code != status .HTTP_201_CREATED :
322+ print (f"\n 錯誤狀態碼: { response .status_code } " )
323+ print (f"響應內容: { response .data } " )
324+
293325 # 驗證 NOJ 格式響應 (通過 api_response 包裝)
294326 self .assertEqual (response .status_code , status .HTTP_201_CREATED )
295327 message = self .get_api_message (response )
0 commit comments