# NOTE: Generated By HttpRunner v3.1.4
# FROM: entercart.har

"""
@author :springfall
"""

from httprunner import HttpRunner, Config, Step, RunRequest, RunTestCase, Parameters
import pytest
from testcases.login_test.login_test import TestCaseLogin as Login


class TestCaseEntercart(HttpRunner):
    @pytest.mark.parametrize(
        'param',
        Parameters(
            {
                "phoneNumber-verifyCode": "${parameterize(common.csv)}",
            }
        ),
    )
    def test_start(self, param):
        super().test_start(param)

    config = (
        Config("进入购物车模块")
        .base_url("${get_base_url()}")
        .variables(**{
            "x_tenant_id": "2"
        })
        .verify(False)
        .export(
            *['sessionId', 'token', 'accountCode', 'personId', "name", "nickname", "username", "phone", "memberCode",
              "userCode", "account_id", "storeCode"])
    )

    teststeps = [
        Step(
            RunTestCase("Login")
            .call(Login)
            .export(*['sessionId', 'token', 'accountCode', 'personId', "name", "nickname", "username", "phone", "memberCode",
                    "userCode", "account_id", "storeCode"])
        ),
        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(
                **{
                    "x-tenant-id": "$x_tenant_id",
                    "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")
        ),
        Step(
            RunRequest("/mall/cart/selectCartList")
            .get("/mall/cart/selectCartList")
            .with_params(
                **{
                    "cartType": "1",
                    "channel": "1",
                    "pageSize": "50",
                    "memberCode": "$memberCode",
                    "qp-buyerCode-eq": "$accountCode",
                    "qp-cartType-eq": "0",
                    "qp-channelId-eq": "1",
                    "qp-storeCode-eq": "$storeCode",
                }
            )
            .with_headers(
                **{
                    "x-tenant-id": "$x_tenant_id",
                    "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")
        ),
        Step(
            RunRequest("/mall/cart/cartTotalPrice")
            .post("/mall/cart/cartTotalPrice")
            .with_headers(
                **{
                    "x-tenant-id": "$x_tenant_id",
                    "sso_sessionid": "$sessionId",
                }
            )
            .with_cookies(
                **{
                    "sessionId": "$sessionId",
                    "token": "$token",
                }
            )
            .with_json(
                {
                    "orderLineList": [],
                    "buyerCode": "$accountCode",
                    "cartType": 0,
                    "channel": 1,
                    "memberCardCode": "$memberCode",
                    "orderSource": 1,
                    "selectedOrderTicketId": 0,
                    "sellerCode": "SJ001",
                    "storeCode": "$storeCode",
                    "tradeType": 8,
                    "calStep": 1,
                    "selectedOrderTicketIds": [0],
                }
            )
            .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/web/getVerificationCode")
            .get("/mall/web/getVerificationCode")
            .with_params(**{"page": "1"})
            .with_headers(
                **{
                    "x-tenant-id": "$x_tenant_id",
                    "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")
        ),
    ]