コード例 #1
0
ファイル: login_test.py プロジェクト: duanmuqianqian/apitest
class TestCaseLogin(HttpRunner):
    @classmethod
    def setup_class(cls):
        print("运行于测试用例之前")

    @classmethod
    def teardown_class(cls):
        print("运行于测试用例之后")

    @pytest.mark.parametrize(
        "param",
        Parameters({
            "title-username-password-isLogin-status_code-content-contain_msg":
            "${get_userinfo()}"
        }),
    )
    def test_start(self, param):
        super().test_start(param)

    config = Config("testcase description").base_url(
        "${ENV(BASE_URL_PRE)}").verify(False)

    teststeps = [
        Step(
            RunRequest("$title").setup_hook("${hook_up($request)}").post(
                "/3/7.5.26/bplapi/user/v1/loginByEmailPassword").
            with_params(**{
                "client": "3102879F-6EE8-41D4-BCD0-4A95BCE06D06"
            }).with_headers(
                **{
                    "Content-Type":
                    "application/x-www-form-urlencoded; charset=utf-8",
                    "User-Agent":
                    "Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 isp/unknown network/WIFI prokanqiu/7.5.26 iPhone13,2",
                }).with_data({
                    "clientId": "88505902",
                    "password": "******",
                    "username": "******",
                    "client": "3102879F-6EE8-41D4-BCD0-4A95BCE06D06",
                }).teardown_hook(
                    "${hook_down($response)}").validate().assert_equal(
                        "status_code",
                        "$status_code").assert_equal("body.isLogin",
                                                     "$isLogin")
            # .assert_string_equals("body.error.text", "$text")
            # .assert_contains("body.error.text", "$text")
            # .assert_contains("body.result","$contain_msg")
            .assert_contains("$content", "$contain_msg").assert_contains(
                "$content", "$contain_msg")),
    ]
コード例 #2
0
class TestCaseValidateWithVariables(HttpRunner):

    config = (
        Config("request methods testcase: validate with variables").variables(
            **{
                "foo1": "session_bar1"
            }).base_url("https://postman-echo.com").verify(False))

    teststeps = [
        Step(
            RunRequest("get with params").with_variables(**{
                "foo1": "bar1",
                "foo2": "session_bar2"
            }).get("/get").with_params(**{
                "foo1": "$foo1",
                "foo2": "$foo2"
            }).with_headers(**{
                "User-Agent": "HttpRunner/3.0"
            }).extract().with_jmespath("body.args.foo2",
                                       "session_foo2").validate().assert_equal(
                                           "status_code", 200).assert_equal(
                                               "body.args.foo1",
                                               "$foo1").assert_equal(
                                                   "body.args.foo2", "$foo2")),
        Step(
            RunRequest("post raw text").with_variables(**{
                "foo1": "hello world",
                "foo3": "$session_foo2"
            }).post("/post").with_headers(**{
                "User-Agent": "HttpRunner/3.0",
                "Content-Type": "text/plain"
            }).with_data(
                "This is expected to be sent back as part of response body: $foo1-$foo3."
            ).validate().assert_equal("status_code", 200).assert_equal(
                "body.data",
                "This is expected to be sent back as part of response body: hello world-$foo3.",
            )),
        Step(
            RunRequest("post form data").with_variables(**{
                "foo1": "bar1",
                "foo2": "bar2"
            }).post("/post").with_headers(
                **{
                    "User-Agent": "HttpRunner/3.0",
                    "Content-Type": "application/x-www-form-urlencoded",
                }).with_data("foo1=$foo1&foo2=$foo2").validate().assert_equal(
                    "status_code",
                    200).assert_equal("body.form.foo1", "$foo1").assert_equal(
                        "body.form.foo2", "$foo2")),
    ]
コード例 #3
0
class TestCaseGettimeline(HttpRunner):
    @classmethod
    def setup_class(cls):
        print("运行于测试用例之前")

    @classmethod
    def teardown_class(cls):
        print("运行于测试用例之后")

    @pytest.mark.parametrize("param", Parameters(
        {"title-page-puid-type-lastCommentTime-status-msg": "${get_timeline()}"}
    ), )
    def test_start(self, param):
        super().test_start(param)

    config = Config("获取动态列表").base_url("${ENV(BASE_URL)}").verify(False)

    teststeps = [
        Step(
            RunTestCase("登录")
            .call(TestCaseLoginbyemailpassword)

        ),
        Step(
            RunRequest("$title")
            .get(
                "/3/7.5.26/bplapi/timeline/v1/getTimeline"
            )
            .with_params(
                **{
                    "page": "$page",
                    "type": "$type",
                    "puid": "$puid",
                    "lastCommentTime": "$lastCommentTime",

                }
            )
            .with_headers(
                **{
                    "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 isp/unknown network/WIFI prokanqiu/7.5.26 iPhone13,2",

                }
            )

            .validate()
            .assert_equal("body.status", "$status")
            .assert_equal("body.msg", "$msg")
        ),
    ]
コード例 #4
0
class TestCaseVideoShareVideoListByGameId(
        HttpRunner):  #更改为与接口相关的名字,方便以后引用(例如引用login接口需要先导入类名)
    @pytest.mark.parametrize(
        "param",
        Parameters({
            "username-password":
            "******"  #取excel表格中的数据做数据驱动
        }))
    def test_start(self, param):
        super().test_start(param)

    config = (
        Config("share_video_list_by_game_id").variables(
            **{
                "username": "******",  #在此文件中引用其他测试用例,需要定义本次用例中引用的参数
                "password": "******"
            }))

    teststeps = [
        Step(
            RunTestCase("login function").call(TestCasesLogin)  #调用login接口
            .export(*["token"])),
        Step(
            RunRequest("share_video_list_by_game_id").with_variables(
                **{}).get("${ENV(url)}").with_params(
                    **{
                        "deviceid": "${ENV(deviceid)}",
                        "ver": "${ENV(ver)}",
                        "pid": "${ENV(pid)}",
                        "logintoken": "$token",
                        "account_id": "$username",
                        "mode": "${ENV(mode)}",
                        "language": "${ENV(language)}",
                        "lz": "${ENV(lz)}",
                        "hwdeviceid": "${ENV(hwdeviceid)}",
                        "TimeZoneName": "${ENV(TimeZoneName)}",
                        "TimeZoneId": "${ENV(TimeZoneId)}",
                        "version": "${ENV(version)}",
                        "brand": "${ENV(brand)}",
                        "Sint": "29",
                        "page": "1",
                        "rows": "10",
                        "game_id": "10841",
                        "m": "video",
                        "a": "share_video_list_by_game_id"
                    }).validate().assert_equal(
                        "status_code",
                        200).assert_equal("${judgment_ret($response)}", 0))
    ]
コード例 #5
0
class TestVerifyEmailAfterEmailVerified(HttpRunner):

    config = (
        Config("N-邮箱已认证过,再次认证失败")
        .variables(**{
            "client": clients.web,
            "email": "${generate_email()}",
            "password": "******",
        })
    )

    teststeps = [
        Step(
            RunTestCase("注册、认证、登陆")
            .call(RegisterVerifyLogin)
            .export("verify_code", "account_id", "token")
        ),
        Step(
            RunApiIsAccountExist("调用 isAccountExist 再次认证邮箱")
            .with_variables(**{
                "type": "verifyEmail"
            })
            .request()
            .update_json_object({
                "context": {
                    "accountID": "$account_id",
                    "token": "$token"
                }
            })
            .validate()
            .assert_startswith("body.code", is_account_exist_error_code.email_already_verified)
        ),
        Step(
            RunApiVerifyEmailByCode("调用 VerifyEmailByCode 再次验证邮箱验证码")
            .with_variables(**{"code": "$verify_code"})
            .request()
            .validate()
            .assert_equal("body.code", 0)
        ),
        Step(
            RunTestCase("在手机 app 登陆")
            .call(LoginV2)
            .export("account_id", "token")
        ),
        Step(
            RunTestCase("注销")
            .call(DeleteUser)
        )
    ]
コード例 #6
0
class TestCaseCmstemplatepageQuerytemplatebyid(HttpRunner):

    @pytest.mark.parametrize(
        "param",
        Parameters({
            "business_userName-business_password-business_verifyCode-business_regType": "${parameterize(common.csv)}",
            "store_code-templateId": "${parameterize(testcases/api/business/cmsTemplate/cmsTemplatePage_queryTemplateById.csv)}"
        })
    )
    def test_start(self, param) -> "HttpRunner":
        super().test_start(param)

    config = (
        Config("计算购物车中选中商品的价格")
        .base_url("${get_base_url()}")
        .variables(**{
            "x_tenant_id": "2",  # tenant Default value : 2     必填选项  header部分
        })
        .export(*["sessionId", "token", "employeeName", "employeeId", "accountName", "accountId", "accountCode"])
        .verify(False)
    )

    teststeps = [
        Step(
            RunTestCase("商家后台登录")
            .call(Login)
            .export(*["sessionId", "token", "employeeName", "employeeId", "accountName", "accountId", "accountCode"])
        ),
        Step(
            RunRequest("查询页面基础数据")
            .get("/business/api/cmsTemplatePage/queryTemplateById")
            .with_params(**{"templateId": "741364749471719424"})
            .with_headers(
                **{
                    "x-tenant-id": "$x_tenant_id",
                    "sso_sessionid": "$sessionId",
                    "store-code": "$store_code",
                    "business-code": "$accountCode",
                    "token": "$token",
                }
            )
            .validate()
            .assert_equal("status_code", 200)
            .assert_equal('headers."Content-Type"', "application/json;charset=UTF-8")
            .assert_equal("body.code", "000000")
            .assert_equal("body.msg", "Success")
            .assert_equal("body.traceId", "")
        ),
    ]
コード例 #7
0
class TestOperateAfterLogOut(HttpRunner):

    config = (
        Config("P-用户登出后,使用登出前 token 调用 getProductConfigList 接口,调用失败")
        .variables(**{
            "client": "${web()}",
            "username": "******",
            "password": "******",
            "superuser_account_id": None,
            "superuser_token": None
        })
    )

    teststeps = [
        Step(
            RunTestCase("创建一个工厂用户")
            .with_variables(**{
                "account_id": "$superuser_account_id",
                "token": "$superuser_token"
            })
            .call(CreateUser)
        ),
        Step(
            RunTestCase("新工厂用户登陆")
            .call(Login)
            .export("account_id", "token", "factory_id")
        ),
        Step(
            RunTestCase("新工厂用户登出")
            .call(LogOut)
        ),
        Step(
            RunApiGetProductConfigList("登出后调用 getProductConfigList 接口")
            .with_variables(**{
                "get_all": True
            })
            .request()
            .validate()
            .assert_startswith("body.code", production_test_shared_error_codes.token_expired)
        ),
        Step(
            RunTestCase("删除新增的用户")
            .with_variables(**{
                "account_id": "$superuser_account_id",
                "token": "$superuser_token"
            })
            .call(DeleteUser)
        )
    ]
コード例 #8
0
class TestCaseBrandGetbrandlist(HttpRunner):
    @pytest.mark.parametrize(
        "param",
        Parameters({
            "userName-password-verifyCode1-regType":
            "${parameterize(common.csv)}",
            "currentPage-pageSize-qp_name_eq-qp_showType_eq-qp_status_eq-sorter":
            "${parameterize(testcases/api/ops/brand/brand_getBrandList.csv)}",
        }))
    def test_start(self, param) -> "HttpRunner":
        super().test_start(param)

    config = (
        Config("登录ops环境").base_url("${get_base_url()}").variables(
            **{
                "x_tenant_id":
                "2",  # tenant Default value : 2     必填选项  header部分
                "x_app_id": "200",
            }).export(*["token", "sessionId"]).verify(False))

    teststeps = [
        Step(RunTestCase("登录").call(Login).export(*["sessionId", "token"])),
        Step(
            RunRequest("查询品牌对象,也就是列表").get(
                "/ops/api/brand/getBrandList").with_params(
                    **{
                        "qp-status-eq": "$qp_status_eq",
                        "currentPage": "$currentPage",
                        "pageSize": "$pageSize",
                        "qp-name-eq": "$qp_name_eq",
                        "qp-showType-eq": "$qp_showType_eq",
                        "sorter": "$sorter"
                    }).with_headers(
                        **{
                            "x-app-id": "$x_app_id",
                            "x-tenant-id": "$x_tenant_id",
                            "sso_sessionid": "$sessionId",
                            "Token": "$token",
                        }).with_cookies(**{
                            "sessionId": "$sessionId",
                            "token": "$token",
                        }).validate().assert_equal(
                            "status_code", 200).assert_equal(
                                'headers."Content-Type"',
                                "application/json;charset=UTF-8").assert_equal(
                                    "body.code", "000000").assert_equal(
                                        "body.msg", "Success").assert_equal(
                                            "body.traceId", "")),
    ]
コード例 #9
0
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)
        )
    ]
コード例 #10
0
class TestCaseDemoApi(HttpRunner):

    config = Config("demo api")

    teststeps = [
        Step(
            RunRequest("demo api")
            .with_variables(**{"var1": "login", "var2": "test"})
            .post("/api/uavcontrol/user/$var1")
            .with_headers(**{"Content-Type": "application/json"})
            .with_json({"key": "$var2"})
            .validate()
            .assert_equal("status_code", 200)
        ),
    ]
コード例 #11
0
class TestConfigModelSentAsIs(HttpRunner):

    config = (Config(
        "P-feedbackType 为 FeedbackDeviceErr 或 FeedbackUser,邮件中显示的 configModel 和传入的一致"
    ).variables(
        **{
            "email": "*****@*****.**",
            "account_id": None,
            "token": None,
            "client": None,
            "feedback_type": None,
            "config_model": None,
        }))

    teststeps = [Step(RunTestCase("调用 feedbackV2 接口发送反馈").call(FeedbackV2))]
コード例 #12
0
class TestCaseClloectlist(HttpRunner):
    config = Config("testcase description").base_url(
        "${ENV(BASE_URL_PRE)}").verify(False)

    teststeps = [
        Step(RunTestCase("登录").call(TestCaseLoginbyemailpassword)),
        Step(
            RunRequest("/3/7.5.26/collect/getThreadsCollectList").
            get("/3/7.5.26/collect/getThreadsCollectList").with_headers(
                **{
                    "User-Agent":
                    "Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 isp/unknown network/WIFI prokanqiu/7.5.26 iPhone13,2",
                }).validate().assert_equal("status_code", 200).assert_equal(
                    "body.is_login", 1)),
    ]
コード例 #13
0
class TestDraw3Successfully(HttpRunner):

    config = (Config("P-用户2进行所有抽奖,且结果正确").variables(
        **{
            "client": None,
            "account_id": None,
            "token": None,
            "award_pool_name": anniversary_draw_settings.award_pool_name,
            "trigger_source": "$award_pool_name",
            "remaining_points": 20
        }))

    teststeps = [
        Step(RunTestCase("用户3抽奖").call(TestDrawSuccessfully)),
    ]
コード例 #14
0
class TestRegisterWithCorrectVerifyCode(HttpRunner):

    config = (Config("P-使用正确的验证码,可以注册成功").variables(
        **{
            "client": "${get_client_from_orm_by_id(1)}",
            "email": "${generate_email()}",
            "password": "******",
            "user_country_code": "US"
        }))

    teststeps = [
        Step(RunTestCase("使用正确的验证码注册").call(RegisterNewUser)),
        Step(RunTestCase("登陆").call(LoginV2).export("account_id", "token")),
        Step(RunTestCase("注销用户").call(DeleteUser))
    ]
class TestCaseRequestWithTestcaseReference(HttpRunner):
    config = (
        Config("request with referenced testcase")
        .variables(**{"foo1": "session_bar1", "var2": "testsuite_val2"})
        .base_url("https://postman-echo.com")
        .verify(False)
    )

    teststeps = [
        Step(
            RunTestCase("request with functions")
            .with_variables(**{"foo1": "override_bar1"})
            .call(RequestWithFunctions)
        ),
    ]
コード例 #16
0
class VerifyEmailByCode(HttpRunner):
    """
    Call api 'verifyEmailByCode' to verify email.

    Config Variables:
        - client (Client): required
        - code (str): required
        - email (str): required
    """
    config = (Config("调用 verifyEmailByCode 接口验证邮箱"))

    teststeps = [
        Step(RunApiVerifyEmailByCode().request().validate().assert_equal(
            "body.code", 0))
    ]
コード例 #17
0
class Report(HttpRunner):
    """
    Call api 'report' to report.

    Config Variables:
        - client (Client), required
        - account_om (Client), required
        - token_om (Client), required
    """

    config = (Config("举报内容").variables(reason_id=1))

    teststeps = [
        Step(RunApiReport().request().validate().assert_equal("body.code", 0))
    ]
コード例 #18
0
class TestRegisterWithValidEmail(HttpRunner):

    config = (Config("P-使用满足正则表达式的邮箱注册,可以注册成功").variables(**{
        "client": clients.web,
        "email": None,
        "password": "******"
    }))

    teststeps = [
        Step(RunTestCase("使用满足正则的邮箱注册").call(RegisterNewUser)),
        Step(
            RunTestCase("在 app 登陆").call(LoginV2).export(
                "account_id", "token")),
        Step(RunTestCase("注销").call(DeleteUser))
    ]
コード例 #19
0
ファイル: logout.py プロジェクト: kakaaaluote/runway
class LogOut(HttpRunner):
    """
    Call api 'logout' successfully.

     Config Variables:
        - client (Client): optional, default to '${web()}'
        - account_id (int): required
        - token (str): required
    """

    config = (Config("工厂用户管理-后台用户登出成功").variables(**{"client": "${web()}"}))

    teststeps = [
        Step(RunApiLogout().request().validate().assert_equal("body.code", 0)),
    ]
コード例 #20
0
class DeleteContentTag(HttpRunner):
    """
    Call api 'deleteContentTag' to delete tag

    Config Variables:
        - id (int): required
        - type (int): required
    """

    config = (Config("根据id删除tag数据"))

    teststeps = [
        Step(RunApiDeleteContentTag().request().validate().assert_equal(
            "body.code", 0)),
    ]
コード例 #21
0
class DeleteContent(HttpRunner):
    """
    Call api 'deleteContent' to delete content

    Config Variables:
        - id (int): required
        - type (int): required
    """

    config = (Config("用户删除自己发布的内容"))

    teststeps = [
        Step(RunApiDeleteContent().request().validate().assert_equal(
            "body.code", 0)),
    ]
コード例 #22
0
class TestSuperuserGetUsers(HttpRunner):

    config = (Config("P-拥有用户管理权限的用户获取工厂用户列表,可以获取成功").variables(**{
        "client": "${web()}",
        "account_id": None,
        "token": None,
    }))

    teststeps = [
        Step(
            RunTestCase("获取用户列表").with_variables(**{
                "page_no": 1,
                "page_size": 10,
            }).call(GetUserInfoList))
    ]
コード例 #23
0
class TestRegisterWithValidCountryCode(HttpRunner):

    config = (Config("P-国家码为 ISO3166 中的国家码,可以注册成功").variables(
        **{
            "client": "${get_client_from_orm_by_id(1)}",
            "email": None,
            "user_country_code": None,
            "password": "******"
        }))

    teststeps = [
        Step(RunTestCase("使用 ISO3166 中的国家码注册").call(RegisterNewUser)),
        Step(RunTestCase("登陆").call(LoginV2).export("account_id", "token")),
        Step(RunTestCase("注销").call(DeleteUser))
    ]
コード例 #24
0
class TestDeviceTypeSentAsIs(HttpRunner):

    config = (Config(
        "P-feedbackType 为 FeedbackUser/FeedbackDeviceErr/Feedback158 任意一个,"
        "邮件中显示的 deviceType 和参数 deviceType 传入的值一致").variables(
            **{
                "email": "*****@*****.**",
                "account_id": None,
                "token": None,
                "client": None,
                "feedback_type": None,
                "device_type": None,
            }))

    teststeps = [Step(RunTestCase("调用 feedbackV2 接口发送反馈").call(FeedbackV2))]
コード例 #25
0
class TestGetCidByMac(HttpRunner):

    config = (Config("P-mac 地址存在或不存在对应的 cid,均会返回一个 cid"))

    teststeps = [
        Step(RunApiGetCidByMac().with_variables(
            mac=search_test_records_settings.mac).request().validate().
             assert_equal("body.code", 0).assert_not_equal(
                 "body.data.cid", None, "此 mac 有对应的 cid,应该返回该 cid 但没有返回")),
        Step(RunApiGetCidByMac().with_variables(
            mac="${gen_mac()}").request().validate().assert_equal(
                "body.code",
                0).assert_not_equal("body.data.cid", None,
                                    "此 mac 无对应的 cid,应该返回一个新的 cid 但没有返回")),
    ]
コード例 #26
0
class TestAllOptionalParamsNull(HttpRunner):

    config = (Config("P-所有非必须参数均不传入,可反馈成功").variables(
        **{
            "account_id": None,
            "token": None,
            "client": None,
            "email": "*****@*****.**",
            "feedback_msg": "I am feedback message",
        }))

    teststeps = [
        Step(RunApiFeedbackV2().request().validate().assert_equal(
            "body.code", 0))
    ]
コード例 #27
0
class DeleteCommunityData(HttpRunner):
    """
    Call api 'deleteCommunityData' to delete club content

    Config Variables:
        - id (int): required
        - type (int): required
    """

    config = (Config("根据id删除社区数据").variables(**{"id": "$id", "type": "$type"}))

    teststeps = [
        Step(RunApiDeleteCommunityData().request().validate().assert_equal(
            "body.code", 0)),
    ]
コード例 #28
0
class TestCaseItemSelectActivityAndTicket(HttpRunner):
    @pytest.mark.parametrize(
        "param",
        Parameters({
            "phoneNumber-verifyCode":
            "${parameterize(common.csv)}",
            "qp_memberCardCode_eq-qp_skuCode_in-qp_storeCode_eq-qp_userCode_eq":
            "${parameterize(testcases/api/mall/item/item_selectActivityAndTicket.csv)}"
        }))
    def test_start(self, param) -> "HttpRunner":
        super().test_start(param)

    config = (
        Config("查询商品参与的活动和优惠券").base_url("${get_base_url()}").variables(**{
            "x_tenant_id":
            "2",  #tenant Default value : 2     必填选项  header部分
        }).verify(False))

    teststeps = [
        Step(
            RunTestCase("登录").with_variables(**{
                "x_tenant_id": "2",
            }).call(Login).export(*[
                'sessionId', 'token', 'accountCode', 'personId', "name",
                "nickname", "username", "phone", "memberCode", "userCode",
                "account_id", "storeCode", "member_id"
            ])),
        Step(
            RunRequest("查询商品参与的活动和优惠券").get(
                "/mall/item/selectActivityAndTicket").with_params(
                    **{
                        "qp-skuCode-in": "$qp_skuCode_in",
                        "qp-storeCode-eq": "$qp_storeCode_eq",
                        "qp-memberCardCode-eq": "$qp_memberCardCode_eq",
                        "qp-userCode-eq": "$qp_userCode_eq",
                    }).with_headers(**{
                        "x-tenant-id": "2",
                        "sso_sessionid": "$sessionId",
                    }).with_cookies(**{
                        "sessionId": "$sessionId",
                        "token": "$token",
                    }).validate().assert_equal(
                        "status_code", 200).assert_equal(
                            'headers."Content-Type"',
                            "application/json;charset=UTF-8").assert_equal(
                                "body.code",
                                "000000").assert_equal("body.msg", "Success")),
    ]
コード例 #29
0
ファイル: upload_test.py プロジェクト: jeffery13790/sjp
class TestCaseUpload(HttpRunner):
    @pytest.mark.parametrize(
        "param",
        Parameters({
            "business_userName-business_password-business_verifyCode-business_regType":
            "${parameterize(common.csv)}",
            "file_path":
            "${parameterize(testcases/api/business/upload/upload.csv)}"
        }))
    def test_start(self, param) -> "HttpRunner":
        super().test_start(param)

    config = (
        Config("计算购物车中选中商品的价格").base_url("${get_base_url()}").variables(**{
            "x_tenant_id":
            "2",  # tenant Default value : 2     必填选项  header部分
        }).export(*[
            "sessionId", "token", "employeeName", "employeeId", "accountName",
            "accountId", "accountCode"
        ]).verify(False))

    teststeps = [
        Step(
            RunTestCase("商家后台登录").call(Login).export(*[
                "sessionId", "token", "employeeName", "employeeId",
                "accountName", "accountId", "accountCode"
            ])),
        Step(
            RunRequest("图片上传").with_variables(
                **{
                    "file_path": "$file_path",
                    "m_encoder": "${multipart_encoder(file=$file_path)}",
                }).post("/business/api/upload").with_headers(
                    **{
                        "Content-Type":
                        "${multipart_content_type($m_encoder)}",
                        "Token": "$token",
                        "sso_sessionid": "$sessionId",
                        "x-tenant-id": "$x_tenant_id",
                    }).with_data("$m_encoder").validate().assert_equal(
                        "status_code", 200).assert_equal(
                            'headers."Content-Type"',
                            "application/json;charset=UTF-8").assert_equal(
                                "body.code",
                                "000000").assert_equal("body.msg", "Success")
            # .assert_contains("body.data", "$file_path")
        ),
    ]
class TestCaseAppUserQueryAlarmMsg(HttpRunner):
    @pytest.mark.parametrize(
        "param",
        Parameters({
            "message_type":
            "${parameterize(test_data/message_type_data.csv)}",
            "username-pwd-platform-pkgname-push_id-push_channel-version-language":
            "${parameterize(test_data/normal_device_bind_data.csv)}",
            "status_code-ok-status-code-ids-token":
            [[200, 1, "ok", 200, 0, "_app"]],
        }),
    )
    def test_start(self, param):
        super().test_start(param)

    config = Config("告警消息页").base_url("${ENV(api_url)}").export(
        *["token", "msg_id"])

    teststeps = [
        Step(
            RunTestCase("获取登录token").call(AppUserLogin).export(
                *["id", "token"])),
        Step(
            RunRequest("告警消息页").post("app/user/query/alarm_msg").with_headers(
                **{
                    "Content-Type": "application/json"
                }).with_json({
                    "end_timestamp": 1616465128,
                    "language": "$language",
                    "limit": 30,
                    "message_type": ["$message_type"],
                    "page": 1,
                    "pkgname": "$pkgname",
                    "platform": "$platform",
                    "start_timestamp": 1616428800,
                    "token": "$token",
                    "version": "$version",
                }).extract().with_jmespath(
                    "body.data.items[0].msg_id",
                    "msg_id").validate().assert_equal(
                        "status_code", "$status_code").assert_equal(
                            'headers."Content-Type"',
                            "application/json;charset=UTF-8").assert_equal(
                                "body.ok",
                                "$ok").assert_equal("body.status",
                                                    "$status").assert_equal(
                                                        "body.code", "$code")),
    ]