# NOTE: Generated By HttpRunner v3.1.1
# FROM: 个人信息.yml

from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase
import pytest
from httprunner import Parameters


class TestCasepersonal(HttpRunner):

    @pytest.mark.parametrize(
        'param',
        Parameters(
            {
                "x_app_id": ["200"],
                "x_tenant_id": ['2'],
                "password": ["200622"],
                "regType": [4],
                "userName": ["15900980894"],
                "verifyCode": ["123456"],
            }
        ),
    )
    def test_start(self, param):
        super().test_start(param)

    config = (
        Config("个人信息修改")
        .base_url("${get_base_url()}")
        .variables(**{"storeCode": "STORE000086"})
        .verify(False)
        .export(*["token", "verifyId", "sessionId"])
    )
    teststeps = [
        Step(
            RunRequest("/mall/web/pcLogin")
            .get("/mall/web/pcLogin")
            .with_params(**{"phoneNumber": "$userName", "verifyCode": "$verifyCode"})
            .with_headers(
                **{
                    "sso_sessionid": "undefined",
                    "x-tenant-id": "$x_tenant_id",
                }
            )
            .extract()
            .with_jmespath('body.data.sessionId', 'sessionId')
            .with_jmespath('body.data.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")
        ),
        Step(
            RunRequest("/mall/user/getUserInfo")
            .get("/mall/user/getUserInfo")
            .with_params(
                **{"sessionId": "$sessionId"}
            )
            .with_headers(
                **{
                    "sso_sessionid": "$sessionId",
                    "x-tenant-id": "$x_tenant_id",
                }
            )
            .with_cookies(
                **{
                    "sessionId": "$sessionId",
                    "token": "$token",
                }
            )
            .extract()
            .with_jmespath('body.data.accountResDto.accountCode', "accountCode")
            .with_jmespath('body.data.accountResDto.personId', "personId")
            .with_jmespath('body.data.accountResDto.name', "name")
            .with_jmespath('body.data.accountResDto.nickname', "nickname")
            .with_jmespath('body.data.accountResDto.username', "username")
            .with_jmespath('body.data.accountResDto.phone', "phone")
            .with_jmespath('body.data.memberCardResDto.memberCode', "memberCode")
            .with_jmespath('body.data.accountResDto.id', "accountId")
            .with_jmespath('body.data.personResDto.userCode', "userCode")
            .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")
        ),
        Step(
            RunRequest("/mall/category/queryCategoryTree")
            .get("/mall/category/queryCategoryTree")
            .with_params(**{"status": "0"})
            .with_headers(
                **{
                    "sso_sessionid": "@sessionId",
                    "x-tenant-id": "$x_tenant_id",
                }
            )
            .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")
        ),
        Step(
            RunRequest("/mall/homeTemplate/selectDefaultStoreAndSort")
            .get("/mall/homeTemplate/selectDefaultStoreAndSort")
            .with_params(**{"businessType": "phonix", "type": "pc"})
            .with_headers(
                **{
                    "sso_sessionid": "$sessionId",
                    "x-tenant-id": "$x_tenant_id",
                }
            )
            .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")
        ),
        Step(
            RunRequest("/mall/homeTemplate/selectDefaultStoreCode")
            .get("/mall/homeTemplate/selectDefaultStoreCode")
            .with_params(**{"businessType": "phonix", "type": "pc"})
            .with_headers(
                **{
                    "sso_sessionid": "$sessionId",
                    "x-tenant-id": "$x_tenant_id",
                }
            )
            .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")
        ),
        Step(
            RunRequest("/mall/cart/cartTotalNum")
            .get("/mall/cart/cartTotalNum")
            .with_params(
                **{
                    "cartType": "1",
                    "channel": "1",
                    "pageSize": "50",
                    "qp-buyerCode-eq": "$accountCode",
                    "qp-cartType-eq": "0",
                    "qp-channelId-eq": "1",
                    "qp-storeCode-eq": "$storeCode",
                }
            )
            .with_headers(
                **{
                    "sso_sessionid": "$sessionId",
                    "x-tenant-id": "$x_tenant_id",
                }
            )
            .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")
        ),
        Step(
            RunRequest("/mall/cmsTemplate/getTemplateByStoreCode")
            .get("/mall/cmsTemplate/getTemplateByStoreCode")
            .with_params(
                **{
                    "qp-bg-eq": "1",
                    "qp-platform-eq": "2",
                    "qp-storeCode-eq": "$storeCode",
                }
            )
            .with_headers(
                **{
                    "sso_sessionid": "$sessionId",
                    "x-tenant-id": "$x_tenant_id",
                }
            )
            .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")
        ),
        Step(
            RunRequest("/mall/homeTemplate/getItemPagerByYourLike")
            .get("/mall/homeTemplate/getItemPagerByYourLike")
            .with_params(**{"pageSize": "12", "qp-storeCode-eq": "$storeCode"})
            .with_headers(
                **{
                    "sso_sessionid": "$sessionId",
                    "x-tenant-id": "$x_tenant_id",
                }
            )
            .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")
        ),
        Step(
            RunRequest("/mall/cart/cartTotalNum")
            .get("/mall/cart/cartTotalNum")
            .with_params(
                **{
                    "cartType": "1",
                    "channel": "1",
                    "pageSize": "50",
                    "qp-buyerCode-eq": "$accountCode",
                    "qp-cartType-eq": "0",
                    "qp-channelId-eq": "1",
                    "qp-storeCode-eq": "$storeCode",
                }
            )
            .with_headers(
                **{
                    "sso_sessionid": "$sessionId",
                    "x-tenant-id": "$x_tenant_id",
                }
            )
            .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")
        ),
        Step(
            RunRequest("/mall/category/queryCategoryTree")
            .get("/mall/category/queryCategoryTree")
            .with_params(**{"status": "0"})
            .with_headers(
                **{
                    "sso_sessionid": "$sessionId",
                    "x-tenant-id": "$x_tenant_id",
                }
            )
            .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")
        ),
        Step(
            RunRequest("/mall/homeTemplate/selectDefaultStoreAndSort")
            .get(
                "/mall/homeTemplate/selectDefaultStoreAndSort"
            )
            .with_params(**{"businessType": "phonix", "type": "pc"})
            .with_headers(
                **{
                    "sso_sessionid": "$sessionId",
                    "x-tenant-id": "$x_tenant_id",
                }
            )
            .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")
        ),
        Step(
            RunRequest("/mall/user/getUserInfo")
            .get("/mall/user/getUserInfo")
            .with_params(
                **{"sessionId": "$sessionId"}
            )
            .with_headers(
                **{
                    "sso_sessionid": "$sessionId",
                    "x-tenant-id": "$x_tenant_id",
                }
            )
            .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")
        ),
        Step(
            RunRequest("/mall/cart/cartTotalNum")
            .get("/mall/cart/cartTotalNum")
            .with_params(
                **{
                    "cartType": "1",
                    "channel": "1",
                    "pageSize": "50",
                    "qp-buyerCode-eq": "$accountCode",
                    "qp-cartType-eq": "0",
                    "qp-channelId-eq": "1",
                    "qp-storeCode-eq": "$storeCode",
                }
            )
            .with_headers(
                **{
                    "sso_sessionid": "$sessionId",
                    "x-tenant-id": "$x_tenant_id",
                }
            )
            .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")
        ),
        Step(
            RunRequest("/mall/upload/oss")
            .with_variables(
                **{
                    "file_path": "image/special.jpg",
                    "m_encoder": "${multipart_encoder(file=$file_path)}",
                }
            )
            .post("/mall/upload/oss")
            .with_headers(
                **{
                    "Content-Type": "${multipart_content_type($m_encoder)}",
                    "sso_sessionid": "$sessionId",
                    "x-tenant-id": "$x_tenant_id",
                }
            )
            .with_cookies(
                **{
                    "sessionId": "$sessionId",
                    "token": "$token",
                }
            )
            .with_data("$m_encoder")
            .extract()
            .with_jmespath('body.data','img')
            .validate()
            .assert_equal("status_code", 200)
            .assert_equal('headers."Content-Type"', "application/json;charset=UTF-8")
            .assert_equal("body.code", "000000")
        ),
        Step(
            RunRequest("/mall/user/patchMyselfInfo")
            .put("/mall/user/patchMyselfInfo")
            .with_headers(
                **{
                    "sso_sessionid": "$sessionId",
                    "x-tenant-id": "$x_tenant_id",
                }
            )
            .with_cookies(
                **{
                    "sessionId": "$sessionId",
                    "token": "$token",
                }
            )
            .with_json(
                {
                    "accountCode": "$accountCode",
                    "accountId": "$accountId",
                    "imgUrl": "$img",
                    "nickname": "修改后的昵称",
                    "occupation": "修改后的职业",
                    "personId": "$personId",
                    "phone": "$phone",
                    "sex": 1,
                }
            )
            .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")
        ),
        Step(
            RunRequest("/mall/user/getUserInfo")
            .get("/mall/user/getUserInfo")
            .with_params(
                **{"sessionId": "$sessionId"}
            )
            .with_headers(
                **{
                    "sso_sessionid": "$sessionId",
                    "x-tenant-id": "$x_tenant_id",
                }
            )
            .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")
        ),
    ]
