feat: teacher-student relation
This commit is contained in:
@@ -46,7 +46,7 @@ class CmsRelationTest(CacheTestCase):
|
||||
self.assertEqual(stu_client.get(REL_URL).status_code, 403)
|
||||
|
||||
def test_create_and_list(self):
|
||||
resp = self.client.post(REL_URL, {'teacher': self.doc.id, 'student': self.stu.id})
|
||||
resp = self.client.post(REL_URL, {'teacher_phone': '13932000002', 'student_phone': '13932000003'})
|
||||
self.assertEqual(resp.status_code, 201, resp.content)
|
||||
self.assertEqual(resp.json()['teacher_phone'], '13932000002')
|
||||
self.assertEqual(resp.json()['student_phone'], '13932000003')
|
||||
@@ -55,19 +55,25 @@ class CmsRelationTest(CacheTestCase):
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
self.assertEqual(len(resp.json()['results']), 1)
|
||||
|
||||
def test_create_missing_phone_400(self):
|
||||
resp = self.client.post(REL_URL, {'teacher_phone': '13932000002'})
|
||||
self.assertEqual(resp.status_code, 400, resp.content)
|
||||
self.assertEqual(resp.json()['code'], 'CMS_VALIDATION_ERROR')
|
||||
|
||||
def test_create_duplicate(self):
|
||||
self.client.post(REL_URL, {'teacher': self.doc.id, 'student': self.stu.id})
|
||||
resp = self.client.post(REL_URL, {'teacher': self.doc.id, 'student': self.stu.id})
|
||||
self.client.post(REL_URL, {'teacher_phone': '13932000002', 'student_phone': '13932000003'})
|
||||
resp = self.client.post(REL_URL, {'teacher_phone': '13932000002', 'student_phone': '13932000003'})
|
||||
self.assertEqual(resp.status_code, 400, resp.content)
|
||||
self.assertEqual(resp.json()['code'], 'CMS_REL_EXISTS')
|
||||
|
||||
def test_teacher_must_be_doctor(self):
|
||||
# 用学生当 teacher → 无效 pk
|
||||
resp = self.client.post(REL_URL, {'teacher': self.stu.id, 'student': self.stu.id})
|
||||
# 用学生手机号当带教老师 → 解析不到 doctor
|
||||
resp = self.client.post(REL_URL, {'teacher_phone': '13932000003', 'student_phone': '13932000003'})
|
||||
self.assertEqual(resp.status_code, 400, resp.content)
|
||||
self.assertEqual(resp.json()['code'], 'CMS_REL_TEACHER_NOT_FOUND')
|
||||
|
||||
def test_scope_other_institution_student_rejected(self):
|
||||
resp = self.client.post(REL_URL, {'teacher': self.doc.id, 'student': self.other_stu.id})
|
||||
resp = self.client.post(REL_URL, {'teacher_phone': '13932000002', 'student_phone': '13932000004'})
|
||||
self.assertEqual(resp.status_code, 403, resp.content)
|
||||
self.assertEqual(resp.json()['code'], 'CMS_REL_SCOPE_FORBIDDEN')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user