修改测试中使用相对id的地方,原来测试里用了很多id是自己设置的常量,可能引发了错误

This commit is contained in:
sxw@401 2015-09-05 16:25:05 +08:00
parent fd0d5be3bf
commit 75b1bf749e
3 changed files with 11 additions and 11 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)