def test_create(self): """ 测试创建用户 实际并不迫切需要此测试 """ user = User.create( name='test_user', mobile=13800138000 ) _user = User.get(User.mobile == 13800138000) self.assertEqual(user.id, _user.id)
def test_reset_password(self): user = User.create(name='test4', mobile="13838003804", password=User.create_password("123456")) new_password = "******" url = "api/2/auth/reset_password" body = { "username": "******", "verify_code": "8888", "new_password": new_password } response = self.fetch(url, method="POST", body=json.dumps(body)) self.assertEqual(200, response.code, response.body.decode()) user = User.get(id=user.id) result = User.check_password(user.password, new_password) self.assertEqual(True, result, result)
def test_patch_user(self): user = User.create(name="user name") url = self.OBJECT_PATH.format(user_id=user.id) body = { "name": "new name", "gender": "f", "dob": "1990-01-01", "mobule": "12345678901" } self.auth_user = user response = self.fetch(url, method="PATCH", body=json.dumps(body), headers={"Content-Type": "application/json"}) self.assertEqual(204, response.code, response.body.decode()) updated = User.get(id=user.id) self.assertEqual("new name", updated.name, updated) self.assertEqual("f", updated.gender, updated) self.assertEqual("1990-01-01", updated.dob.strftime("%Y-%m-%d"), updated) self.assertIsNone(updated.mobile, updated)
def test_delete_user(self): user = User.create( name='will be deleted' ) _user = User.get(id=user.id) _user.delete_instance()