# NOTE: Generated By pastor v1.0.1
# FROM: .\tests\request_with_functions.yml


import pytest
from pastor import Parameters

from pastor import Pastor, Config, Step, RunRequest, RunTestCase, RunLocation


class TestCaseRequestWithFunctions(Pastor):

    @pytest.mark.parametrize("param", Parameters({"username": "${parameterize(data/user.csv)}"}))
    def test_start(self, param):
        super().test_start(param)

    config = (
        Config("request methods testcase with functions")
        .variables(
            **{
                "foo1": "config_bar1",
                "foo2": "config_bar2",
                "expect_foo1": "config_bar1",
                "expect_foo2": "config_bar2",
            }
        )
        .base_url("https://postman-echo.com")
        .verify(False)
        .export(*["foo3"])
        .locust_weight(2)
    )

    teststeps = [
        Step(
            RunRequest("get with params")
            .with_variables(
                **{"foo1": "bar11", "foo2": "bar21", "sum_v": "${sum_two(1, 2)}"}
            )
            .pre_sql()
            .datasource("test")
            .dml("select code from cn_sms_code order by created_at desc limit 1")
            .get("/get")
            .with_params(**{"foo1": "$username", "foo2": "$foo2", "sum_v": "$sum_v"})
            .with_headers(**{"X-API-Key": "PMAK-6722f7e9a1e57a00010f7a44-XXXX"})
            .post_sql()
            .datasource("test")
            .dml(
                "select code as code2 from cn_sms_code order by created_at desc limit 1"
            )
            .extract()
            .with_jmespath("body.args.foo2", "foo3")
            .validate()
            .assert_equal("status_code", 200)
            .assert_equal("body.args.foo1", "bar11")
            .assert_equal("body.args.sum_v", "3")
            .assert_equal("body.args.foo2", "bar21")
        ),
    ]


if __name__ == "__main__":
    TestCaseRequestWithFunctions().test_start()
