diff --git a/account/tests.py b/account/tests.py index bbdf1e92..b1f14d08 100644 --- a/account/tests.py +++ b/account/tests.py @@ -140,12 +140,12 @@ class UserAdminAPITest(APITestCase): def setUp(self): self.client = APIClient() self.url = reverse("user_admin_api") - user = User.objects.create(username="testx", real_name="xx", admin_type=SUPER_ADMIN) - user.set_password("testxx") - user.save() - user = User.objects.create(username="testy", real_name="yy", admin_type=SUPER_ADMIN) - user.set_password("testyy") - user.save() + self.user = User.objects.create(username="testx", real_name="xx", admin_type=SUPER_ADMIN) + self.user.set_password("testxx") + self.user.save() + self.user = User.objects.create(username="testy", real_name="yy", admin_type=SUPER_ADMIN) + self.user.set_password("testyy") + self.user.save() self.client.login(username="testx", password="testxx") # 以下是编辑用户的测试 @@ -164,19 +164,19 @@ class UserAdminAPITest(APITestCase): self.assertEqual(response.data, {"code": 1, "data": u"该用户不存在!"}) def test_username_exists(self): - data = {"id": 1, "username": "testy", "real_name": "test00", + data = {"id": self.user.id, "username": "testy", "real_name": "test00", "password": "testaa", "email": "60@qq.com", "admin_type": "2"} response = self.client.put(self.url, data=data) self.assertEqual(response.data, {"code": 1, "data": u"昵称已经存在"}) def test_user_edit_not_password_successfully(self): - data = {"id": 1, "username": "test0", "real_name": "test00", + data = {"id": self.user.id, "username": "test0", "real_name": "test00", "email": "60@qq.com", "admin_type": "2"} response = self.client.put(self.url, data=data) self.assertEqual(response.data["code"], 0) def test_user_edit_change_password_successfully(self): - data = {"id": 1, "username": "test0", "real_name": "test00", "password": "111111", + data = {"id": self.user.id, "username": "test0", "real_name": "test00", "password": "111111", "email": "60@qq.com", "admin_type": "2"} response = self.client.put(self.url, data=data) self.assertEqual(response.data["code"], 0) diff --git a/contest/tests.py b/contest/tests.py index 052829f3..adbf00b6 100644 --- a/contest/tests.py +++ b/contest/tests.py @@ -370,7 +370,7 @@ class ContestProblemAdminAPItEST(APITestCase): def test_query_contest_problem_exists_by_contest_id(self): self.client.login(username="test3", password="testaa") - response = self.client.get(self.url + "?contest_id=1") + response = self.client.get(self.url + "?contest_id="+ str(self.global_contest.id)) self.assertEqual(response.data["code"], 0) self.assertEqual(len(response.data["data"]), 0) diff --git a/problem/tests.py b/problem/tests.py index ab6d8985..2a7aecc3 100644 --- a/problem/tests.py +++ b/problem/tests.py @@ -144,7 +144,7 @@ class ProblemAdminTest(APITestCase): self.assertEqual(response.data, {"code": 1, "data": u"题目不存在"}) def test_query_problem_exists(self): - data = {"problem_id": 1} + data = {"problem_id": self.problem.id} response = self.client.get(self.url, data=data) self.assertEqual(response.data["code"], 0)