Ejemplo n.º 1
0
class TestDeleteNoAuthUserByPasswordSuccessfully(HttpRunner):

    config = (
        Config("P-未验证的Vesync用户,使用密码正常注销")
        .variables(
            **{
                "client": "${get_client_from_orm_by_id(1)}",
                "email": "${generate_email()}",
                "password": "******",
                "user_country_code": "US",
                "password_md5": get_md5_hex_digest("123456")
            }
        )
        .export(*["account_id", "token"])
    )

    teststeps = [
        Step(
            RunTestCase("注册未验证的Vesync用户")
            .call(RegisterWithNoAuth)
        ),
        Step(
            RunTestCase("调用登录接口,使用 email 和密码登录")
            .call(LoginV2)
        ),
        Step(
            RunTestCase("使用账号密码删除用户")
            .call(DeleteAccountByPassword)
        )
    ]
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 TestDeleteAuthedUserByEmailCodeSuccessfully(HttpRunner):

    config = (
        Config("P-已验证的Vesync用户使用邮箱code注销,验证邮箱与登录邮箱一致")
        .variables(
            **{
                "client": "${get_client_from_orm_by_id(1)}",
                "email": "${generate_email()}",
                "password": "******",
                "user_country_code": "US",
                "password_md5": get_md5_hex_digest("123456")
            }
        )
        .export(*["account_id", "token"])
    )

    teststeps = [
        Step(
            RunTestCase("注册已验证的用户,验证邮箱和登录邮箱一致")
            .call(RegisterNewUserSuccessfully)
        ),
        Step(
            RunTestCase("调用登录接口,使用 email 和密码登录")
            .call(LoginV2)
        ),
        Step(
            RunTestCase("使用邮箱验证码删除用户")
            .call(DeleteAccountByEmailCode)
        )
    ]
Ejemplo n.º 4
0
class TestFailToDeleteAuthedUserByIncorrectEmailCode(HttpRunner):

    config = (Config("P-已验证的Vesync用户使用邮箱code注销,使用错误的邮箱验证码验证,注销失败").variables(
        **{
            "client": "${get_client_from_orm_by_id(1)}",
            "email": "${generate_email()}",
            "password": "******",
            "user_country_code": "US",
            "password_md5": get_md5_hex_digest("123456"),
            "err_code": 1234
        }).export(*["account_id", "token"]))

    teststeps = [
        Step(
            RunTestCase("注册已验证的用户,验证邮箱和登录邮箱一致").call(
                RegisterNewUserSuccessfully)),
        Step(RunTestCase("调用登录接口,使用 email 和密码登录").call(LoginV2)),
        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="$err_code",
                expected_value=-11212).call(DeleteUserByEmailCode)),
        Step(RunTestCase("调用登录接口,使用 email 和密码登录,登录成功").call(LoginV2))
    ]
Ejemplo n.º 5
0
class TestRegisterWithPlainPasswordAndLoginWithMD5Password(HttpRunner):

    config = (
        Config("P-使用明文密码注册后,使用该明文密码的 md5 加密值可以登陆成功")
        .variables(**{
            "client": "${get_client_from_orm_by_id(1)}",
            "email": "${generate_email()}",
            "register_password": "******",
            "login_password": get_md5_hex_digest("123456")
        })
    )

    teststeps = [
        Step(
            RunTestCase("在 web 注册")
            .with_variables(password="******")
            .call(RegisterNewUser)
        ),
        Step(
            RunTestCase("在 web 登陆")
            .with_variables(password="******")
            .call(Login)
        ),
        Step(
            RunTestCase("在 app 登陆")
            .with_variables(password="******")
            .call(LoginV2)
            .export("account_id", "token")
        ),
        Step(
            RunTestCase("注销")
            .call(DeleteUser)
        )
    ]
Ejemplo n.º 6
0
class TestFailToDeleteNoAuthUserByIncorrectPassword(HttpRunner):

    config = (Config("P-未验证的Vesync用户,使用错误的密码注销失败").variables(
        **{
            "client": "${get_client_from_orm_by_id(1)}",
            "email": "${generate_email()}",
            "password": "******",
            "user_country_code": "US",
            "password_md5": get_md5_hex_digest("123456"),
            "error_password": get_md5_hex_digest("254567")
        }).export(*["account_id", "token"]))

    teststeps = [
        Step(RunTestCase("注册未验证的Vesync用户").call(RegisterWithNoAuth)),
        Step(RunTestCase("调用登录接口,使用 email 和密码登录").call(LoginV2)),
        Step(
            RunTestCase("使用错误的密码注销用户,返回相应错误码").with_variables(
                password_md5="$error_password",
                expected_value=-11201).call(DeleteUserByPassword)),
        Step(RunTestCase("调用登录接口,使用 email 和密码登录,登录成功").call(LoginV2))
    ]
Ejemplo n.º 7
0
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 TestDeleteNoAuthYolandaByPasswordSuccessfully(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")
        }))

    teststeps = [
        Step(
            RunTestCase("注册新的Yolanda账户,并认证").call(
                RegisterAndVerifyYolandaAccount).export(
                    *["account_id", "token", "email", "password"])),
        Step(RunTestCase("使用账号密码删除用户").call(DeleteAccountByPassword))
    ]
import pytest
from httprunner import HttpRunner, Config, Step, RunTestCase

from runway.apis.iot.vesync.user import DeleteUser
from runway.apis.iot.vesync.user import LoginV2
from runway.apis.store.user import Login
from runway.builtin.email import generate_email
from runway.builtin.hash import get_md5_hex_digest
from runway.configs.client import clients
from .base_testcase_register_with_no_auth import TestRegisterWithNoAuth as RegisterNewUser

plain_password = "******"
hashed_password = get_md5_hex_digest(plain_password)

params = [
    # email, register password, login password
    (generate_email(), hashed_password, hashed_password),
    (generate_email(), plain_password, plain_password),
]


@pytest.fixture(autouse=True, params=params)
def setup(request):
    config: Config = request.cls.config
    email, register_password, login_password = request.param
    config.variables(email=email,
                     register_password=register_password,
                     login_password=login_password)


class TestLoginPasswordSameAsRegisterPassword(HttpRunner):
Ejemplo n.º 10
0
class YolandaRegister(HttpRunner):
    """
    call api 'registerInfo',注册一个Yolanda测试账号直接调用注册即可,所有基础信息都是自动生成

    Key-value pairs (optional):
        - accountId: $account_id (str), 默认使用时间戳组装
        - email: $email (str), 默认使用邮箱生成函数生成
        - password: $password (str), 默认123456的md5加密格式

    Export Variables:
        - email (str)
        - password (str)
    """
    timestamp = str(int(time.time()))
    config = (
        Config("注册Yolanda账号")
        .variables(
            timestamp=timestamp,
            account_id="${generate_yolanda_id()}",
            email="${generate_email()}",
            password=get_md5_hex_digest("123456"),
            register_time="20200202202012",
            nick_name="yolanda_test_name",
            avatar_icon="https://smartapi.vesync.com/v1/files/defaultImages/user/dfac72c18e598389b74b70e8ea21a84b.png",
            gender="Female",
            birthday="1990-01-01",
            height_in_cm=179,
            country="China",
            region="Shanghai",
            mobile="iphoneX",
            phone_os="ios",
            app_version="1.0",
            language="en",
            sign=generate_sign("yolanda001", "a3c4ce1f8bfa430db5f052f302bfbac3", timestamp),
        )
        .export("email", "password")
    )

    teststeps = [
        Step(
            RunRequest("调用Yolanda注册接口,注册Yolanda账号")
            .with_variables(**{"api": "${get_api_from_orm_by_name(yolandaRegister)}"})
            .post("${getattr($api, url)}")
            .with_params(**{
                "appid": "yolanda001",
                "sign": "$sign",
                "timestamp": "$timestamp"
            })
            .with_json({
                "accountId": "$account_id",
                "email": "$email",
                "password": "******",
                "registerTime": "$register_time",
                "nickName": "$nick_name",
                "avatarIcon": "$avatar_icon",
                "gender": "$gender",
                "birthday": "$birthday",
                "height": "$height_in_cm",
                "country": "$country",
                "region": "$region",
                "mobile": "$mobile",
                "os": "$phone_os",
                "appVersion": "$app_version",
                "language": "$language"
            })
            .export()
            .variable("email")
            .variable("password")
            .validate()
            .assert_equal("status_code", 200)
        )
    ]
Ejemplo n.º 11
0
def generate_sign(appid, secret, timestamp):
    sign = appid + secret + timestamp
    return get_md5_hex_digest(sign)