class TestRegisterWithUppercaseEmail(HttpRunner): config = (Config("P-使用大写字母邮箱注册成功后,使用大写或小写的形式均能登陆成功").variables( **{ "client": "${get_client_from_orm_by_id(1)}", "password": "******" })) teststeps = [ Step( RunApiIsAccountExist("调用 isAccountExist 时传入大写的邮箱 (但使用小写邮箱获取验证码)"). with_variables(**{ "email": uppercase_email, "lowercase_email": lowercase_email }).request().teardown_hook( "${get_verify_code_from_redis($lowercase_email)}", "verify_code").export().variable( "verify_code").validate().assert_equal("body.code", 0)), Step( RunTestCase("调用注册接口时传入大写邮箱").with_variables( **{ "email": uppercase_email, "verify_email": "$email" }).call(RegisterV2)), Step( RunTestCase("登陆时使用大写邮箱(登陆成功)").with_variables( email=uppercase_email).call(LoginV2)), Step( RunTestCase("登陆时使用小写邮箱(登陆成功)").with_variables( email=lowercase_email).call(LoginV2).export( "account_id", "token")), Step(RunTestCase("注销").call(DeleteUser)) ]
class TestRegisterWithNoAuth(HttpRunner): """ Generate an email and register with the new generated one. Config Variables: - client (Client): optional, set as default with '${get_client_from_orm_by_id(1)}' - email (str): optional, default to "${generate_email()}" - password (str): optional, default to '123456' - user_country_code (str): optional, default to 'US' """ config = ( Config("P-注册邮箱和收取验证码的邮箱一致,可以注册成功").variables( **{ "client": "${get_client_from_orm_by_id(1)}", # type: Client "email": "${generate_email()}", # type: str "password": "******", # type: str "user_country_code": "US" })) teststeps = [ Step( RunApiIsAccountExist("判断用户是否不存在").request().update_json_object({ "type": "registerWithNoAuth" }).validate().assert_equal("body.code", 0)), Step(RunTestCase("调用注册接口").with_variables().call(RegisterWithNoAuth)) ]
class TestFailToRegisterWhenEmailAlreadyVerified(HttpRunner): config = (Config("N-认证邮箱已作为其他用户的认证邮箱被占用,注册失败").variables( **{ "client": "${get_client_from_orm_by_id(1)}", "email": None, "password": "******", "verify_email": "$email" })) teststeps = [ Step( RunApiIsAccountExist( "检测邮箱时指定邮箱已被占用(作为其他用户的认证邮箱)").request().update_json_object({ "type": "registerWithNoAuth" }).validate().assert_startswith( "to_string(body.code)", is_account_exist_error_code.email_already_verified)), Step( RunApiRegisterWithNoAuth("注册时指定的邮箱已被占用(作为其他用户的认证邮箱)"). with_variables( **{ "user_country_code": "US", "accept_marketing_email": "1", "register_app_version": "${getattr($client, client_version)}" }).request().validate().assert_startswith( "to_string(body.code)", register_with_no_auth_error_code.email_already_verified)), ]
class TestEmailOccupiedByVerifiedUserWithRegister(HttpRunner): config = (Config( "N-指定的新邮箱已经被占用,且作为其他已认证用户(注册邮箱和认证邮箱不一致)的注册邮箱或认证邮箱,更换失败").variables( **{ "client": clients.ios, "register_email": None, "verify_email": None, "email": "${generate_email()}", "password": "******" })) teststeps = [ Step(RunTestCase("注册一个新邮箱").call(RegisterNewUserWithNoAuth)), Step(RunTestCase("登陆").call(LoginV2).export("account_id", "token")), Step( RunApiIsAccountExist( "isAccountExist type 传入 verifyEmail, email 传入已认证用户的注册邮箱"). with_variables(**{ "email": "$register_email" }).request().update_json_object({ "accountID": "$account_id", "token": "$token", "type": "verifyEmail", }).validate().assert_startswith( "body.code", is_account_exist_error_code.account_already_exist)), Step( RunApiIsAccountExist( "isAccountExist type 传入 verifyEmail,email 传入已认证用户的认证邮箱"). with_variables(**{ "email": "$verify_email" }).request().update_json_object({ "accountID": "$account_id", "token": "$token", "type": "verifyEmail", }).validate().assert_startswith( "body.code", is_account_exist_error_code.email_already_verified)) ]
class TestFailToRegisterWithInvalidPassword(HttpRunner): config = (Config("N-密码不合法,注册失败").variables( **{ "client": "${get_client_from_orm_by_id(1)}", "email": None, "password": None, "error_code": None })) teststeps = [ Step( RunApiIsAccountExist( "使用不合法的密码注册").request().validate().assert_startswith( "to_string(body.code)", "$error_code")), ]
class TestFailToRegisterWithTemporaryEmail(HttpRunner): config = (Config("N-使用临时邮箱后缀注册,注册失败").variables( **{ "client": "${get_client_from_orm_by_id(1)}", "email": None, "password": "******", "error_code": None })) teststeps = [ Step( RunApiIsAccountExist( "使用临时邮箱注册").request().validate().assert_regex_match( "to_string(body.code)", "$error_code[0-9]+")), ]
class TestNewEmailOccupiedAsOtherUserVerifyEmail(HttpRunner): config = ( Config("N-isAccountExist type 为 changeAccount,指定的新邮箱已被其他用户作为认证邮箱占用,对应用户已存在的错误码") .variables(**{ "client": "${get_client_from_orm_by_id(1)}", "init_email": "${generate_email()}", "new_email": "${generate_email()}", "password": "******" }) ) teststeps = [ Step( RunTestCase("注册用户(不认证邮箱)") .with_variables(**{ "email": "$init_email" }) .call(RegisterUserNoAuth) ), Step( RunTestCase("使用原注册邮箱登陆") .with_variables(**{ "email": "$init_email" }) .call(LoginV2) .export("account_id", "token") ), Step( RunTestCase("校验密码") .call(VerifyPassword) ), Step( RunApiIsAccountExist("给新邮箱发送验证码时新邮箱已被注册") .with_variables(email="$new_email") .request() .update_json_object({ "type": "changeAccount" }) .validate() .assert_startswith("body.code", is_account_exist_error_code.email_already_verified) ), Step( RunTestCase("注销用户") .call(DeleteUser) ) ]
class TestErrorCodeAccountAlreadyExist(HttpRunner): config = (Config("N-调用 /cloud/v1/user/isAccountExist 时指定的邮箱已注册过,错误码对应用户已存在" ).variables(**{ "client": None, "email": None, "type": None, })) teststeps = [ Step( RunApiIsAccountExist( "调用接口 isAccountExist").request().update_json_object({ "type": "$type" }).validate().assert_startswith( "to_string(body.code)", is_account_exist_error_code.account_already_exist)), ]
class TestFailToRegisterWhenEmailWasVerifyEmail(HttpRunner): config = ( Config("N-认证邮箱已作为其他用户的认证邮箱被占用,注册失败") .variables(**{ "client": "${get_client_from_orm_by_id(1)}", "email": None, "password": "******", "verify_email": "$email", }) ) teststeps = [ Step( RunApiIsAccountExist("检测邮箱时指定邮箱已被占用(作为其他用户的认证邮箱)") .request() .validate() .assert_startswith("to_string(body.code)", is_account_exist_error_code.email_already_verified) ), ]
class TestFailToUpgradeWhenEmailAsOtherUserVerifyEmail(HttpRunner): config = ( Config("N-指定邮箱已被其他用户作为认证邮箱被占用,注册失败") .variables(**{ "client": "${get_client_from_orm_by_id(1)}", "verify_email": None, "account_id": None, "token": None }) ) teststeps = [ Step( RunApiIsAccountExist("/cloud/v1/user/isAccountExist 指定的邮箱已被占用") .with_variables(**{ "email": "$verify_email" }) .request() .update_json_object({ "type": "upgradeGuest", }) .validate() .assert_startswith("body.code", is_account_exist_error_code.email_already_verified) ), Step( RunApiGuestUpgrade("/cloud/v1/user/guestUpgrade 指定的邮箱已被占用") .with_variables(**{ "email": "$verify_email", "verify_code": "0000", "password": "******" }) .request() .validate() .assert_startswith("body.code", guest_upgrade_error_code.email_already_verified) ), Step( RunTestCase("注销用户") .call(DeleteUser) ) ]
class TestFailToUpgradeWhenEmailAlreadyRegistered(HttpRunner): config = ( Config("N-游客升级时使用的邮箱已注册过,注册失败") .variables(**{ "client": "${get_client_from_orm_by_id(1)}", "exist_user_email": None, "account_id": None, "token": None }) ) teststeps = [ Step( RunApiIsAccountExist("调用接口 isAccountExist 时指定邮箱已被注册过") .with_variables(**{ "email": "$exist_user_email" }) .request() .update_json_object({ "type": "upgradeGuest", }) .validate() .assert_startswith("body.code", is_account_exist_error_code.account_already_exist) ), Step( RunApiGuestUpgrade("调用接口 guestUpgrade 时指定的邮箱已被注册过") .with_variables(**{ "email": "$exist_user_email", "verify_code": "0000", "password": "******" }) .request() .validate() .assert_startswith("body.code", guest_upgrade_error_code.account_already_exist) ), Step( RunTestCase("注销用户") .call(DeleteUser) ) ]
class TestVerifyEmailAfterEmailVerified(HttpRunner): config = (Config("N-邮箱已认证过,再次认证失败").variables( **{ "client": None, "email": None, "password": None, "account_id": None, "token": None })) teststeps = [ Step( RunTestCase("获取认证邮箱时发送的验证码").with_variables( type="verifyEmail").call(GetVerifyCode).export("verify_code")), Step( RunTestCase("第一次验证邮箱验证码").with_variables(**{ "code": "$verify_code" }).call(VerifyEmailByCodeV2)), Step( RunApiIsAccountExist( "调用 isAccountExist 再次认证邮箱").request().update_json_object({ "accountID": "$account_id", "token": "$token", "type": "verifyEmail" }).validate().assert_startswith( "body.code", is_account_exist_error_code.email_already_verified)), Step( RunApiVerifyEmailByCodeV2("调用 VerifyEmailByCodeV2 再次验证邮箱验证码"). with_variables(**{ "verify_email": "$email", "code": "$verify_code" }).request().validate().assert_equal( "body.code", 0, "verifyEmailByCodeV2 接口再次认证时可以认证成功")) ]
class TestEmailOccupiedByVerifiedUserWithRegisterV2(HttpRunner): config = ( Config("N-指定的新邮箱已经被占用,且作为其他已认证用户(注册邮箱和认证邮箱一致)的注册邮箱,更换失败").variables( **{ "client": None, "email": None, "client_id": None, "token": None })) teststeps = [ Step( RunApiIsAccountExist("isAccountExist type 传入 verifyEmail").request( ).update_json_object({ "type": "verifyEmail", "accountID": "$account_id", "token": "$token" }).validate().assert_startswith( "body.code", is_account_exist_error_code.email_already_verified)) ]
class TestEmailOccupiedByUnverifiedUser(HttpRunner): config = (Config("N-指定的新邮箱已经被占用,且作为其他未认证用户的注册邮箱,更换失败").variables( **{ "client": clients.ios, "email": "${generate_email()}", "other_user_email": None, "password": "******" })) teststeps = [ Step( RunTestCase("使用 registerWithNoAuth 注册用户").call( RegisterNewUserWithNoAuth)), Step(RunTestCase("登陆").call(LoginV2).export("account_id", "token")), Step( RunApiIsAccountExist( "isAccountExist,type 传入 verifyEmail,account 传入其他用户的注册邮箱"). with_variables(**{ "email": "$other_user_email" }).request().update_json_object({ "accountID": "$account_id", "token": "$token", "type": "verifyEmail", }).validate().assert_startswith( "body.code", is_account_exist_error_code.account_already_exist)), Step( RunApiVerifyEmailByCodeV2( "verifyEmailByCodeV2 接口 verifyEmail 传入其他未认证用户的注册邮箱"). with_variables(**{ "code": "0000", "verify_email": "$other_user_email" }).request().validate().assert_startswith( "body.code", verify_email_by_code_v2_error_code.verify_code_expired)) ]
class TestNewEmailIsOccupiedAsOtherUserVerifyEmailError(HttpRunner): config = (Config( "N-isAccountExist type 为 changeAccount,指定的新邮箱被其他用户作为认证邮箱占用,对应用户已存在的错误码" ).variables( **{ "client": "${get_client_from_orm_by_id(1)}", "init_email": "${generate_email()}", "new_email": None, "password": "******" })) teststeps = [ Step( RunTestCase("使用初始邮箱注册用户").with_variables( email="$init_email").call(RegisterNewUser)), Step( RunTestCase("使用初始邮箱登陆").with_variables( email="$init_email").call(LoginV2).export( "account_id", "token")), Step( RunTestCase("给初始邮箱发送并获取验证码").with_variables(email="$init_email"). call(SendAndGetVerifyCode).export("verify_code")), Step( RunTestCase("验证从初始邮箱获取的验证码").with_variables( email="$init_email", code="$verify_code").call(VerifyEmailByCodeV2)), Step( RunApiIsAccountExist("给新邮箱发送验证码 (新邮箱已注册过用户)").with_variables( email="$new_email").request().update_json_object({ "type": "changeAccount" }).validate().assert_startswith( "body.code", is_account_exist_error_code.email_already_verified)), Step(RunTestCase("注销用户").call(DeleteUser)) ]
class TestLoginWithLowercaseEmail(HttpRunner): config = (Config("P-使用大写字母邮箱注册成功后,使用大写或小写的形式均能登陆成功").variables( **{ "client": "${get_client_from_orm_by_id(1)}", "email": lowercase_email, "password": "******", "account_id": None, "token": None })) teststeps = [ Step( RunApiIsAccountExist("调用 isAccountExist 时传入大写的邮箱").with_variables( **{ "email": uppercase_email, "lowercase_email": lowercase_email, }).request().update_json_object({ "accountID": "$account_id", "token": "$token", "type": "upgradeGuest" }).teardown_hook( "${get_verify_code_from_redis($lowercase_email)}", "verify_code").export().variable( "verify_code").validate().assert_equal("body.code", 0)), Step( RunTestCase("升级游客为正式用户").with_variables( email=uppercase_email).call(UpgradeGuest)), Step(RunTestCase("使用小写形式登陆(成功)").call(LoginV2)), Step( RunTestCase("使用大写形式登陆(失败)").with_variables( email=uppercase_email).call(LoginV2).export( "account_id", "token")), Step(RunTestCase("注销").call(DeleteUser)) ]