class TestLoginWithBadCredential(HttpRunner): config = (Config("N-用户名或密码错误,登陆失败").variables( **{ "client": "${ios()}", "email": "${generate_email()}", "password": "******", })) teststeps = [ Step(RunTestCase("注册一个用户").call(RegisterNewUser)), Step( RunApiLoginV2("登陆时密码错误").with_variables( **{ "password": "******", "user_type": login_settings.user_type_registered }).request().validate().assert_startswith( "body.code", login_v2_error_code.invalid_password)), Step( RunApiLoginV2("登陆时邮箱错误").with_variables( **{ "email": "FAKE-EMAIL", "user_type": login_settings.user_type_registered }).request().validate().assert_startswith( "body.code", login_v2_error_code.account_not_exist)), Step(RunTestCase("正常登陆").call(LoginV2).export("account_id", "token")), Step(RunTestCase("注销用户").call(DeleteUser)) ]
class TestVerifyEmailWithCorrectCode(HttpRunner): config = (Config( "P-/cloud/v2/user/verifyEmailByCodeV2,email 和 verifyEmail 不同,code 正确,可以认证通过" ).variables( **{ "client": "${get_client_from_orm_by_id(1)}", "register_email": "${generate_email()}", "verify_email": "${generate_email()}", "password": "******", })) teststeps = [ Step( RunTestCase("使用 registerWithNoAuth 注册,然后使用不同的新的邮箱认证").call( RegisterAndVerifyWithDiffEmailV2)), Step( RunApiLoginV2("loginV2 使用认证邮箱可以登陆成功").with_variables( email="$verify_email", user_type=login_settings.user_type_registered).request(). extract().with_jmespath("body.result.accountID", "account_id").with_jmespath( "body.result.token", "token").validate().assert_equal( "body.result.verifyEmail", "$verify_email")), Step( RunApiLoginV2("使用原注册邮箱无法登陆").with_variables( email="$register_email", user_type=login_settings.user_type_registered).request(). extract().validate().assert_startswith( "body.code", login_v2_error_code.account_not_exist)), Step(RunTestCase("注销").call(DeleteUser)) ]
class TestRegisterAndVerifyYolandaAccount(HttpRunner): config = ( Config("P-注册yolanda账号,添加认证邮箱") .variables( **{ "client": "${get_client_from_orm_by_id(1)}", "user_country_code": "US", "password_md5": get_md5_hex_digest("123456") } ) .export(*["account_id", "token"]) ) teststeps = [ Step( RunTestCase("注册未验证的Yolanda用户") .call(YolandaRegister) .export("email", "password") ), Step( RunApiLoginV2("登陆后查看 verifyEmail 字段的值") .with_variables(user_type=login_settings.user_type_registered) .request() .extract() .with_jmespath("body.result.accountID", "account_id") .with_jmespath("body.result.token", "token") .validate() .assert_equal("body.result.verifyEmail", "", "使用 registerWithNoAuth 注册后,verifyEmail 应该为空") ), Step( RunTestCase("获取认证邮箱时发送的验证码") .with_variables(type="verifyEmail") .call(GetVerifyCode) .export("verify_code") ), Step( RunTestCase("验证邮箱验证码") .with_variables(**{"code": "$verify_code"}) .call(VerifyEmailByCodeV2) ), Step( RunApiLoginV2("登陆后查看 verifyEmail 是否已更新") .with_variables(user_type=login_settings.user_type_registered) .request() .extract() .with_jmespath("body.result.accountID", "account_id") .with_jmespath("body.result.token", "token") .validate() .assert_equal("body.result.verifyEmail", "$email") ) ]
class TestFailToLoginWithPlainPassword(HttpRunner): config = (Config("N-使用 md5 加密过的密码注册后,使用对应明文密码无法登陆").variables( **{ "client": "${get_client_from_orm_by_id(1)}", "email": "${generate_email()}", "register_password": get_md5_hex_digest("123456"), "login_password": "******", "user_type": login_settings.user_type_registered })) teststeps = [ Step( RunTestCase("使用 md5 加密过的密码注册").with_variables( password="******").call(RegisterNewUser)), Step( RunApiLoginV2("使用明文密码登陆").with_variables( password="******").request().validate(). assert_startswith("to_string(body.code)", str(login_v2_error_code.invalid_password))), Step( RunTestCase("使用 md5 加密过的密码登陆").with_variables( password="******").call(LoginV2).export( "account_id", "token")), Step(RunTestCase("注销").call(DeleteUser)) ]
class TestLoginWithPlainPasswordAfterRegisterWithMD5Password(HttpRunner): config = (Config("N-使用 md5 加密过的密码注册后,使用对应明文密码无法登陆").variables( **{ "client": "${get_client_from_orm_by_id(1)}", "email": "${generate_email()}", "register_password": hashed_password, "login_password": plain_password, "account_id": None, "token": None })) teststeps = [ Step( RunTestCase("获取验证码").with_variables(**{ "type": "upgradeGuest" }).call(GetVerifyCode)), Step( RunTestCase("升级游客为正式用户").with_variables( password="******").call(UpgradeGuest)), Step( RunApiLoginV2("使用明文登陆(登陆失败)").with_variables( password="******", user_type=login_settings.user_type_registered).request( ).validate().assert_startswith( "body.code", login_v2_error_code.invalid_password)), Step( RunTestCase("使用 md5 加密后的密码登陆(登陆成功)").with_variables( password="******").call(LoginV2).export( "account_id", "token")), Step(RunTestCase("注销").call(DeleteUser)) ]
class TestDeleteAccountByEmailCodeSuccessfully(HttpRunner): config = (Config("P-使用邮箱验证码的形式注销用户").variables( **{ "client": "${get_client_from_orm_by_id(1)}", "token": None, "account_id": None, "email": None })) teststeps = [ Step( RunTestCase("调用sendVerifyEmailCode接口给验证邮箱发送验证码").call( SendAndGetVerifyCode).export("verify_code")), Step( RunTestCase("调用verifyEmailByCodeV2接口验证邮箱验证码").with_variables( code="$verify_code").call(VerifyEmailByCodeV2)), Step( RunTestCase("调用deleteUserV2接口,使用code注销用户").with_variables( code="$verify_code").call(DeleteUserByEmailCode)), Step( RunApiLoginV2("调用logInV2接口登录上述注销用户,返回用户不存在").with_variables( **{ "user_type": login_settings.user_type_registered }).request().validate().assert_startswith( "body.code", login_v2_error_code.account_not_exist)) ]
class TestSubstituteRegisterEmailWithVerifyEmail(HttpRunner): config = (Config("P-使用认证邮箱替换注册邮箱后,使用认证邮箱可以登陆成功").variables( **{ "client": "${get_client_from_orm_by_id(1)}", "register_email": "${generate_email()}", "verify_email": "${generate_email()}", "password": "******" })) teststeps = [ Step( RunTestCase("使用 V1 版本注册和认证,使注册邮箱和认证邮箱不一致").call( RegisterAndVerifyWithDiffEmails)), Step( RunTestCase("使用认证邮箱替换注册邮箱").with_variables( **{ "email": "$register_email" }).call(VerifyEmailToRegisterEmail)), Step( RunApiLoginV2("使用原注册邮箱登陆(失败)").with_variables( **{ "email": "$register_email", "user_type": login_settings.user_type_registered }).request().validate().assert_startswith( "body.code", login_v2_error_code.account_not_exist)), Step( RunTestCase("使用原认证邮箱(现注册邮箱)登陆(成功)").with_variables( **{ "email": "$verify_email", "user_type": login_settings.user_type_registered }).call(LoginV2).export("account_id", "token")), Step(RunTestCase("注销用户").call(DeleteUser)) ]
class TestVerifyWebUserViaApp(HttpRunner): config = ( Config("P-web 注册的用户,可以在 app 上登陆并完成认证邮箱") .variables(**{ "client": clients.ios, "email": "${generate_email()}", "password": "******" }) ) teststeps = [ Step( RunTestCase("在 web 注册新用户") .call(RegisterWebUser) ), Step( RunTestCase("在 app 上登陆") .call(LoginV2) .export("account_id", "token") ), Step( RunTestCase("获取验证码") .with_variables(**{ "type": "verifyEmail" }) .call(GetVerifyCodeApp) .export("verify_code") ), Step( RunTestCase("验证验证码") .with_variables(code="$verify_code") .call(VerifyEmailByCodeV2) ), Step( RunApiLoginV2("重新登陆 app 查看验证邮箱是否已更新") .with_variables(user_type=login_settings.user_type_registered) .request() .extract() .with_jmespath("body.result.accountID", "account_id") .with_jmespath("body.result.token", "token") .validate() .assert_equal("body.result.verifyEmail", "$email", "认证邮箱已更新") ), Step( RunTestCase("注销用户") .call(DeleteUser) ) ]
class TestDeleteAccountByPasswordSuccessfully(HttpRunner): config = (Config("P-使用密码注销成功").variables( **{ "client": "${get_client_from_orm_by_id(1)}", "token": None, "account_id": None })) teststeps = [ Step(RunTestCase("使用账户密码删除用户").call(DeleteUserByPassword)), Step( RunApiLoginV2("调用logInV2接口登录上述注销用户,返回用户不存在").with_variables( **{ "user_type": login_settings.user_type_registered }).request().validate().assert_startswith( "body.code", login_v2_error_code.account_not_exist)) ]
class TestLoginResponseVerifyEmailIsEmptyIfRegisterWithNoAuth(HttpRunner): config = ( Config("P-使用 registerWithNoAuth 接口注册后登陆,响应中 verifyEmail 为空").variables( **{ "client": clients.ios, "email": "${generate_email()}", "password": "******", })) teststeps = [ Step(RunTestCase("使用 registerWithNoAuth 注册").call(RegisterNewUser)), Step( RunApiLoginV2("登陆后查看 verifyEmail 字段的值").with_variables( user_type=login_settings.user_type_registered).request(). validate().assert_equal( "body.result.verifyEmail", "", "使用 registerWithNoAuth 注册后,verifyEmail 应该为空")), Step(RunTestCase("登陆").call(LoginV2).export("account_id", "token")), Step(RunTestCase("注销").call(DeleteUser)) ]
class TestRegisterVerifyAndLogin(HttpRunner): """ Register user with api 'registerWithNoAuth' and verify email. Config Vars: - client (Client): required - email (str): required - password (str): required Export Vars: - account_id (int) - token (str) """ config = (Config("P-使用 registerWithNoAuth 注册后认证邮箱").variables( **{ "client": "${get_client_from_orm_by_id(1)}", "email": "${generate_email()}", "password": "******" }).export("account_id", "token")) teststeps = [ Step(RunTestCase("注册新用户,不验证验证码").call(RegisterNewUser)), Step(RunTestCase("登陆").call(LoginV2).export("account_id", "token")), Step( RunTestCase("获取认证邮箱时发送的验证码").with_variables( type="verifyEmail").call(GetVerifyCode).export("verify_code")), Step( RunTestCase("验证邮箱验证码").with_variables(**{ "code": "$verify_code" }).call(VerifyEmailByCodeV2)), Step( RunApiLoginV2("登陆后查看 verifyEmail 是否已更新").with_variables( user_type=login_settings.user_type_registered).request(). extract().with_jmespath("body.result.accountID", "account_id").with_jmespath( "body.result.token", "token").validate().assert_equal( "body.result.verifyEmail", "$email")), ]