def test_0002(self): """ Test some failed situations for register """ response = self.client.post( '/user/sign/register', { 'token': self.token, 'username': '******', 'password': encrypt('Password233'), 'phone': '11223344556', 'CAPTCHA': 'Hello' }) self.assertEqual(response.status_code, 200) self.assertEqual( analyse_response(response).get('msg'), 'Username exists') response = self.client.post( '/user/sign/register', { 'token': self.token, 'username': '******', 'password': encrypt('Password233'), 'phone': '11223344556', 'CAPTCHA': 'Hello' }) self.assertEqual(response.status_code, 200) self.assertEqual( analyse_response(response).get('msg'), 'CAPTCHA Error')
def test_0006(self): """ Test for change password error cases """ response = self.client.post( '/user/sign/modify', { 'token': self.token, 'oldpassword': encrypt("WrongPassword233"), 'newpassword': encrypt('Stupid123') }) self.assertEqual(response.status_code, 200) data = analyse_response(response) self.assertEqual(data.get('msg'), 'Old Password Error')
def test_0005(self): """ Test for change password """ response = self.client.post( '/user/sign/modify', { 'token': self.token, 'oldpassword': encrypt("Test666"), 'newpassword': encrypt('Stupid123') }) self.assertEqual(response.status_code, 200) data = analyse_response(response) self.assertEqual(data.get('msg'), 'Success')
def test_0002(self): """ Test for `cipher.py` """ text = 'HelloWorld' encrypttext = encrypt(None) self.assertEqual(encrypttext, None) encrypttext = encrypt(text) decrypttext = decrypt(encrypttext) self.assertEqual(decrypttext, text) failedtext = decrypt('helloworld') self.assertEqual(failedtext, None) failedtext = decrypt(None) self.assertEqual(failedtext, None) failedtext = decrypt('a9c423b717956255faceab65d2cc364a') self.assertEqual(failedtext, None) failedtext = decrypt(1) self.assertEqual(failedtext, None)
def test_0003(self): """ Test some failed situations for login """ response = self.client.post( '/user/sign/login', { 'token': self.token, 'username': '******', 'password': encrypt('Password233'), }) self.assertEqual(response.status_code, 200) self.assertEqual(analyse_response(response).get('msg'), 'NoUser') response = self.client.post( '/user/sign/login', { 'token': self.token, 'username': '******', 'password': encrypt('Password233') }) self.assertEqual(response.status_code, 200) self.assertEqual( analyse_response(response).get('msg'), 'PasswordError')
def login(testcase, username, password): """register """ response = testcase.client.post( '/user/sign/login', { 'token': testcase.token, 'username': username, 'password': encrypt(password) }) testcase.assertEqual(response.status_code, 200) data = analyse_response(response) testcase.assertEqual(data.get('status'), 1)
def test_0009(self): """ Test for forget password """ response = self.client.post( '/user/sign/passwd', { 'token': self.token, 'username': '******', 'password': encrypt('NewPassword233'), 'CAPTCHA': 'GUXYNB' }) self.assertEqual(response.status_code, 200) data = analyse_response(response) self.assertEqual(data.get('msg'), 'GUXYNB')
def register(testcase, username, password, phone, permission=8): """register """ code = Initialization.verifyphone(testcase, phone) response = testcase.client.post( '/user/sign/register', { 'token': testcase.token, 'username': username, 'password': encrypt(password), 'phone': phone, 'CAPTCHA': code }) testcase.assertEqual(response.status_code, 200) data = analyse_response(response) testcase.assertEqual(data.get('status'), 1)