示例#1
0
 def test_5_auth_token_in_json(self):
     """测试放在json里的token"""
     create_user(username='******', password='******')
     token = get_token(self.client, username='******', password='******')
     response = self.client.delete(url_for('user_token_bp.user_token_api'),
                                   json=dict(token=token))
     self.assertEqual(response.status_code, 204)
示例#2
0
 def test_4_auth_token_in_query_string(self):
     """测试放在query string里的token"""
     create_user(username='******', password='******')
     token = get_token(self.client, username='******', password='******')
     response = self.client.delete(
         url_for('user_token_bp.user_token_api', token=token), )
     self.assertEqual(response.status_code, 204)
示例#3
0
 def test_3_get_a_single_user(self):
     """管理员获取用户详情"""
     admin = create_admin(username='******', password='******')
     token = get_token(self.client, username='******', password='******')
     response = self.client.get(url_for(
         'user_bp.users_api_with_id', user_id=admin.id), json=dict(
     ), headers=gen_auth_headers(token))
     self.assertEqual(response.status_code, 200)
示例#4
0
 def test_2_create_a_single_user(self):
     """管理员创建新用户"""
     create_admin(username='******', password='******')
     token = get_token(self.client, username='******', password='******')
     response = self.client.post(url_for('user_bp.users_api'), json=dict(
         username='******',
         password='******'
     ), headers=gen_auth_headers(token))
     self.assertEqual(response.status_code, 201)
示例#5
0
 def test_1_get_a_list_of_users(self):
     """管理员获取用户列表"""
     create_admin(username='******', password='******')
     token = get_token(self.client, username='******', password='******')
     response = self.client.get(
         url_for('user_bp.users_api'),
         headers=gen_auth_headers(token, is_json=False)
     )
     self.assertEqual(response.status_code, 200)
示例#6
0
 def test_4_change_a_single_user(self):
     """管理员修改用户详情"""
     admin = create_admin(username='******', password='******')
     token = get_token(self.client, username='******', password='******')
     response = self.client.put(url_for(
         'user_bp.users_api_with_id', user_id=admin.id),
         json=dict(fullname='test'),
         headers=gen_auth_headers(token)
     )
     # print(response.json)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.json['data']['fullname'], 'test')