def test_reset_password_with_invalid_field(self): tester_signup("*****@*****.**", "anotheruser", "another", "20201231") # 没上线 client = Client() response = client.patch(change_password_url(self.user.id), { "old_password": self.password, "new_password": "******" }, content_type='application/json') self.assertEqual(response.status_code, 401) response = tester_login("*****@*****.**", "anotheruser", client) self.assertEqual(response.status_code, 200) # 少字段 response = tester_login(self.email, self.password, client) self.assertEqual(response.status_code, 200) response = client.patch(change_password_url(self.user.id), {"new_password": "******"}, content_type='application/json') self.assertEqual(response.status_code, 403) response = client.patch(change_password_url(self.user.id), { "password": "******", "new_password": "******" }, content_type='application/json') self.assertEqual(response.status_code, 403) # 旧密码错误 response = client.patch(change_password_url(self.user.id), { "old_password": "******", "new_email": '*****@*****.**', "new_password": "******", }, content_type='application/json') self.assertEqual(response.status_code, 403) response = tester_login("*****@*****.**", "anotheruser", client) self.assertEqual(response.status_code, 200) # 邮箱没有被修改 # 新密码强度不够 response = client.patch(change_password_url(self.user.id), { "old_password": "******", "new_password": "******" }, content_type='application/json') self.assertEqual(response.status_code, 400) # 邮箱不合法 response = client.patch(change_password_url(self.user.id), { "old_password": "******", "new_email": "qwerty" }, content_type='application/json') self.assertEqual(response.status_code, 400) # 邮箱已被占用 response = client.patch(change_password_url(self.user.id), { "old_password": "******", "new_email": '*****@*****.**', 'new_password': "******" }, content_type='application/json') self.assertEqual(response.status_code, 400) response = tester_login("*****@*****.**", "anotheruser", client) self.assertEqual(response.status_code, 200) # 密码没有被修改
def test_get_user_list(self): tester_signup('*****@*****.**', 'qwerty', 'account', '1234567') user = User.objects.filter(username='******')[0] user.userprofile.experience = 1 user.userprofile.save() tester_signup('*****@*****.**', 'qwerty', 'account1', '12345678') user = User.objects.create(username="******", first_name="user") UserProfile.objects.create(user=user, student_id='233', about="你好,世界!", experience="5") self.assertEqual(User.objects.count(), 4) client = Client() response = client.get(user_list_url) self.assertEqual(response.status_code, 200) # 未登录,get 返回 200 tester_login(client=client) response = client.get(user_list_url) self.assertEqual(response.status_code, 200) json_content = response.json() results = json_content['results'] self.check_order(results) self.assertEqual([5, 1, 0, 0], list(map(lambda u: u['experience'], results))) # 可见结果经过排序
def setUp(self): tester_signup() tester_signup("*****@*****.**", "supersuper", "superuser", "1297391") tester_signup("*****@*****.**", "useruser", "user", "1297392") tester_signup("*****@*****.**", "anotheruser", "anotheruser", "1297393") self.superuser = User.objects.filter(first_name="superuser")[0] self.superuser.is_superuser = True self.superuser.save() self.admin = User.objects.filter(first_name="admin")[0] self.admin.is_admin = True self.admin.save() self.user = User.objects.filter(first_name="user")[0] self.another_user = User.objects.filter(first_name="anotheruser")[0] tester_create_activity('First Salon', '2020-01-02T20:00+08:00', 'MS Shanghai', [self.user.id]) self.activity = Activity.objects.first() self.second_activity = Activity.objects.create( title='Second Salon', datetime='2021-02-28 08:00+08:00', location='MS Seattle') Activity.objects.get(title='Second Salon').presenter.add( *list(User.objects.all())) self.assertEqual(Activity.objects.count(), 2)
def setUp(self): tester_signup() tester_signup("*****@*****.**", "supersuper", "superuser", "1297391") tester_signup("*****@*****.**", "useruser", "user", "1297392") tester_signup("*****@*****.**", "anotheruser", "anotheruser", "1297393") self.admin = User.objects.filter(first_name="admin")[0]
def setUp(self): tester_signup() tester_signup("*****@*****.**", "supersuper", "superuser", "1297391") tester_signup("*****@*****.**", "useruser", "user", "1297392") tester_signup("*****@*****.**", "anotheruser", "anotheruser", "1297393") self.ids = list(map(lambda u: u.id, User.objects.all())) self.assertEqual(Activity.objects.count(), 0)
def setUp(self): tester_signup( "*****@*****.**", "adminadmin", 'admin', "20210101", ) u = User.objects.get(first_name='admin') u.is_staff = True u.save() tester_signup('*****@*****.**', 'qwerty', 'superuser', '1234567') u = User.objects.get(first_name='superuser') u.userprofile.experience = 1 u.is_superuser = True u.userprofile.save() u.save() tester_signup('*****@*****.**', 'qwerty', 'user', '12345679') u = User(username="******", first_name="another_user", last_name="clever", last_login=now(), date_joined=now()) up = UserProfile(user=u, student_id='233', about="你好,世界!", experience=5) u.save() up.save() self.assertEqual(User.objects.count(), 4)
def setUp(self): tester_signup(self.email, self.password, 'Admin', '20210101') self.user = User.objects.filter(username=self.email).first()
def setUp(self): tester_signup()