change: python testcase template

This commit is contained in:
debugtalk
2020-05-14 22:34:18 +08:00
parent ba0611a09a
commit f88845d9d4
13 changed files with 575 additions and 363 deletions

View File

@@ -1,83 +1,79 @@
# NOTICE: Generated By HttpRunner. DO'NOT EDIT!
import unittest
from httprunner.runner import TestCaseRunner
from httprunner.schema import TestsConfig, TestStep
class TestCaseRequestMethodsHardcode(TestCaseRunner):
config = TestsConfig(**{
"name": "request methods testcase in hardcode",
"base_url": "https://postman-echo.com",
"verify": False
})
class TestCaseHardcode(unittest.TestCase):
config = TestsConfig(
**{
"name": "request methods testcase in hardcode",
"base_url": "https://postman-echo.com",
"verify": False,
"path": "examples/postman_echo/request_methods/hardcode_test.py",
}
)
teststeps = [
TestStep(**{
"name": "get with params",
"request": {
"method": "GET",
"url": "/get",
"params": {
"foo1": "bar1",
"foo2": "bar2"
TestStep(
**{
"name": "get with params",
"request": {
"method": "GET",
"url": "/get",
"params": {"foo1": "bar1", "foo2": "bar2"},
"headers": {"User-Agent": "HttpRunner/3.0"},
},
"headers": {
"User-Agent": "HttpRunner/3.0"
}
},
"extract": {
"server": "headers.Server"
},
"validate": [
{"eq": ["status_code", 200]},
{"eq": ["headers.Server", "nginx"]}
]
}),
TestStep(**{
"name": "post raw text",
"request": {
"method": "POST",
"url": "/post",
"data": "This is expected to be sent back as part of response body.",
"headers": {
"User-Agent": "HttpRunner/3.0",
"Content-Type": "text/plain"
}
},
"validate": [
{"eq": ["status_code", 200]}
]
}),
TestStep(**{
"name": "post form data",
"request": {
"method": "POST",
"url": "/post",
"data": "foo1=bar1&foo2=bar2",
"headers": {
"User-Agent": "HttpRunner/3.0",
"Content-Type": "application/x-www-form-urlencoded"
}
},
"validate": [
{"eq": ["status_code", 200]}
]
}),
TestStep(**{
"name": "put request",
"request": {
"method": "PUT",
"url": "/put",
"data": "This is expected to be sent back as part of response body.",
"headers": {
"User-Agent": "HttpRunner/3.0",
"Content-Type": "text/plain"
}
},
"validate": [
{"eq": ["status_code", 200]}
]
})
"validate": [{"eq": ["status_code", 200]}],
}
),
TestStep(
**{
"name": "post raw text",
"request": {
"method": "POST",
"url": "/post",
"headers": {
"User-Agent": "HttpRunner/3.0",
"Content-Type": "text/plain",
},
"data": "This is expected to be sent back as part of response body.",
},
"validate": [{"eq": ["status_code", 200]}],
}
),
TestStep(
**{
"name": "post form data",
"request": {
"method": "POST",
"url": "/post",
"headers": {
"User-Agent": "HttpRunner/3.0",
"Content-Type": "application/x-www-form-urlencoded",
},
"data": "foo1=bar1&foo2=bar2",
},
"validate": [{"eq": ["status_code", 200]}],
}
),
TestStep(
**{
"name": "put request",
"request": {
"method": "PUT",
"url": "/put",
"headers": {
"User-Agent": "HttpRunner/3.0",
"Content-Type": "text/plain",
},
"data": "This is expected to be sent back as part of response body.",
},
"validate": [{"eq": ["status_code", 200]}],
}
),
]
if __name__ == '__main__':
TestCaseRequestMethodsHardcode().run()
def test_start(self):
TestCaseRunner(self.config, self.teststeps).run()

View File

@@ -1,98 +1,90 @@
# NOTICE: Generated By HttpRunner. DO'NOT EDIT!
import unittest
from httprunner.runner import TestCaseRunner
from httprunner.schema import TestsConfig, TestStep
from examples.postman_echo import debugtalk
class TestCaseRequestMethodsWithFunctions(TestCaseRunner):
config = TestsConfig(**{
"name": "request methods testcase with functions",
"variables": {
"foo1": "session_bar1"
},
"functions": {
"get_httprunner_version": debugtalk.get_httprunner_version,
"sum_two": debugtalk.sum_two
},
"base_url": "https://postman-echo.com",
"verify": False
})
class TestCaseRequestWithFunctions(unittest.TestCase):
config = TestsConfig(
**{
"name": "request methods testcase with functions",
"variables": {"foo1": "session_bar1"},
"base_url": "https://postman-echo.com",
"verify": False,
"path": "examples/postman_echo/request_methods/request_with_functions_test.py",
}
)
teststeps = [
TestStep(**{
"name": "get with params",
"variables": {
"foo1": "bar1",
"foo2": "session_bar2",
"sum_v": "${sum_two(1, 2)}"
},
"request": {
"method": "GET",
"url": "/get",
"params": {
"foo1": "$foo1",
"foo2": "$foo2",
"sum_v": "$sum_v"
TestStep(
**{
"name": "get with params",
"variables": {
"foo1": "bar1",
"foo2": "session_bar2",
"sum_v": "${sum_two(1, 2)}",
},
"headers": {
"User-Agent": "HttpRunner/${get_httprunner_version()}"
}
},
"extract": {
"session_foo2": "body.args.foo2"
},
"validate": [
{"eq": ["status_code", 200]},
{"eq": ["body.args.foo1", "session_bar1"]},
{"eq": ["body.args.foo2", "session_bar2"]},
{"eq": ["body.args.sum_v", 3]}
]
}),
TestStep(**{
"name": "post raw text",
"variables": {
"foo1": "hello world",
"foo3": "$session_foo2"
},
"request": {
"method": "POST",
"url": "/post",
"data": "This is expected to be sent back as part of response body: $foo1-$foo3.",
"headers": {
"User-Agent": "HttpRunner/${get_httprunner_version()}",
"Content-Type": "text/plain"
}
},
"validate": [
{"eq": ["status_code", 200]},
{"eq": [
"body.data",
"This is expected to be sent back as part of response body: session_bar1-session_bar2."
]},
]
}),
TestStep(**{
"name": "post form data",
"variables": {
"foo1": "session_bar1",
"foo2": "bar2"
},
"request": {
"method": "POST",
"url": "/post",
"data": "foo1=$foo1&foo2=$foo2",
"headers": {
"User-Agent": "HttpRunner/${get_httprunner_version()}",
"Content-Type": "application/x-www-form-urlencoded"
}
},
"validate": [
{"eq": ["status_code", 200]},
{"eq": ["body.form.foo1", "session_bar1"]},
{"eq": ["body.form.foo2", "bar2"]}
]
})
"request": {
"method": "GET",
"url": "/get",
"params": {"foo1": "$foo1", "foo2": "$foo2", "sum_v": "$sum_v"},
"headers": {"User-Agent": "HttpRunner/${get_httprunner_version()}"},
},
"extract": {"session_foo2": "body.args.foo2"},
"validate": [
{"eq": ["status_code", 200]},
{"eq": ["body.args.foo1", "session_bar1"]},
{"eq": ["body.args.sum_v", 3]},
{"eq": ["body.args.foo2", "session_bar2"]},
],
}
),
TestStep(
**{
"name": "post raw text",
"variables": {"foo1": "hello world", "foo3": "$session_foo2"},
"request": {
"method": "POST",
"url": "/post",
"headers": {
"User-Agent": "HttpRunner/${get_httprunner_version()}",
"Content-Type": "text/plain",
},
"data": "This is expected to be sent back as part of response body: $foo1-$foo3.",
},
"validate": [
{"eq": ["status_code", 200]},
{
"eq": [
"body.data",
"This is expected to be sent back as part of response body: session_bar1-session_bar2.",
]
},
],
}
),
TestStep(
**{
"name": "post form data",
"variables": {"foo1": "bar1", "foo2": "bar2"},
"request": {
"method": "POST",
"url": "/post",
"headers": {
"User-Agent": "HttpRunner/${get_httprunner_version()}",
"Content-Type": "application/x-www-form-urlencoded",
},
"data": "foo1=$foo1&foo2=$foo2",
},
"validate": [
{"eq": ["status_code", 200]},
{"eq": ["body.form.foo1", "session_bar1"]},
{"eq": ["body.form.foo2", "bar2"]},
],
}
),
]
if __name__ == '__main__':
TestCaseRequestMethodsWithFunctions().run()
def test_start(self):
TestCaseRunner(self.config, self.teststeps).run()

View File

@@ -1,34 +1,30 @@
from examples.postman_echo import debugtalk
from examples.postman_echo.request_methods.validate_with_variables_test \
import TestCaseRequestMethodsValidateWithVariables
# NOTICE: Generated By HttpRunner. DO'NOT EDIT!
import unittest
from httprunner.runner import TestCaseRunner
from httprunner.schema import TestsConfig, TestStep
class TestCaseRequestMethodsRefTestcase(TestCaseRunner):
config = TestsConfig(**{
"name": "request methods testcase: reference testcase",
"variables": {
"foo1": "session_bar1"
},
"functions": {
"get_httprunner_version": debugtalk.get_httprunner_version,
"sum_two": debugtalk.sum_two
},
"base_url": "https://postman-echo.com",
"verify": False
})
class TestCaseRequestWithTestcaseReference(unittest.TestCase):
config = TestsConfig(
**{
"name": "request methods testcase: reference testcase",
"variables": {"foo1": "session_bar1"},
"base_url": "https://postman-echo.com",
"verify": False,
"path": "examples/postman_echo/request_methods/request_with_testcase_reference_test.py",
}
)
teststeps = [
TestStep(**{
"name": "get with params",
"variables": {
"foo1": "override_bar1"
},
"testcase": TestCaseRequestMethodsValidateWithVariables
})
TestStep(
**{
"name": "request with variables",
"variables": {"foo1": "override_bar1"},
"testcase": "request_methods/request_with_variables.yml",
}
),
]
if __name__ == '__main__':
TestCaseRequestMethodsRefTestcase().run()
def test_start(self):
TestCaseRunner(self.config, self.teststeps).run()

View File

@@ -1,14 +1,18 @@
# NOTICE: Generated By HttpRunner. DO'NOT EDIT!
import unittest
from httprunner.runner import TestCaseRunner
from httprunner.schema import TestsConfig, TestStep
class TestCaseRequestWithVariables(TestCaseRunner):
class TestCaseRequestWithVariables(unittest.TestCase):
config = TestsConfig(
**{
"name": "request methods testcase with variables",
"variables": {"foo1": "session_bar1"},
"base_url": "https://postman-echo.com",
"verify": False,
"path": "examples/postman_echo/request_methods/request_with_variables_test.py",
}
)
@@ -77,6 +81,5 @@ class TestCaseRequestWithVariables(TestCaseRunner):
),
]
if __name__ == "__main__":
TestCaseRequestWithVariables().run()
def test_start(self):
TestCaseRunner(self.config, self.teststeps).run()

View File

@@ -1,53 +1,45 @@
# NOTICE: Generated By HttpRunner. DO'NOT EDIT!
import unittest
from httprunner.runner import TestCaseRunner
from httprunner.schema import TestsConfig, TestStep
from examples.postman_echo import debugtalk
class TestCaseRequestMethodsValidateWithFunctions(TestCaseRunner):
config = TestsConfig(**{
"name": "request methods testcase: validate with functions",
"variables": {
"foo1": "session_bar1"
},
"functions": {
"get_httprunner_version": debugtalk.get_httprunner_version,
"sum_two": debugtalk.sum_two
},
"base_url": "https://postman-echo.com",
"verify": False
})
class TestCaseValidateWithFunctions(unittest.TestCase):
config = TestsConfig(
**{
"name": "request methods testcase: validate with functions",
"variables": {"foo1": "session_bar1"},
"base_url": "https://postman-echo.com",
"verify": False,
"path": "examples/postman_echo/request_methods/validate_with_functions_test.py",
}
)
teststeps = [
TestStep(**{
"name": "get with params",
"variables": {
"foo1": "bar1",
"foo2": "session_bar2",
"sum_v": "${sum_two(1, 2)}"
},
"request": {
"method": "GET",
"url": "/get",
"params": {
"foo1": "$foo1",
"foo2": "$foo2",
"sum_v": "$sum_v"
TestStep(
**{
"name": "get with params",
"variables": {
"foo1": "bar1",
"foo2": "session_bar2",
"sum_v": "${sum_two(1, 2)}",
},
"headers": {
"User-Agent": "HttpRunner/${get_httprunner_version()}"
}
},
"extract": {
"session_foo2": "body.args.foo2"
},
"validate": [
{"eq": ["status_code", 200]},
{"eq": ["body.args.sum_v", 3]},
{"less_than": ["body.args.sum_v", "${sum_two(2, 2)}"]}
]
})
"request": {
"method": "GET",
"url": "/get",
"params": {"foo1": "$foo1", "foo2": "$foo2", "sum_v": "$sum_v"},
"headers": {"User-Agent": "HttpRunner/${get_httprunner_version()}"},
},
"extract": {"session_foo2": "body.args.foo2"},
"validate": [
{"eq": ["status_code", 200]},
{"eq": ["body.args.sum_v", 3]},
{"less_than": ["body.args.sum_v", "${sum_two(2, 2)}"]},
],
}
),
]
if __name__ == '__main__':
TestCaseRequestMethodsValidateWithFunctions().run()
def test_start(self):
TestCaseRunner(self.config, self.teststeps).run()

View File

@@ -1,99 +1,85 @@
# NOTICE: Generated By HttpRunner. DO'NOT EDIT!
import unittest
from httprunner.runner import TestCaseRunner
from httprunner.schema import TestsConfig, TestStep
class TestCaseRequestMethodsValidateWithVariables(TestCaseRunner):
config = TestsConfig(**{
"name": "request methods testcase: validate with variables",
"variables": {
"foo1": "session_bar1"
},
"base_url": "https://postman-echo.com",
"verify": False
})
class TestCaseValidateWithVariables(unittest.TestCase):
config = TestsConfig(
**{
"name": "request methods testcase: validate with variables",
"variables": {"foo1": "session_bar1"},
"base_url": "https://postman-echo.com",
"verify": False,
"path": "examples/postman_echo/request_methods/validate_with_variables_test.py",
}
)
teststeps = [
TestStep(**{
"name": "get with params",
"variables": {
"foo1": "bar1",
"foo2": "session_bar2"
},
"request": {
"method": "GET",
"url": "/get",
"params": {
"foo1": "$foo1",
"foo2": "$foo2"
TestStep(
**{
"name": "get with params",
"variables": {"foo1": "bar1", "foo2": "session_bar2"},
"request": {
"method": "GET",
"url": "/get",
"params": {"foo1": "$foo1", "foo2": "$foo2"},
"headers": {"User-Agent": "HttpRunner/3.0"},
},
"headers": {
"User-Agent": "HttpRunner/3.0"
}
},
"extract": {
"session_foo2": "body.args.foo2"
},
"validate": [
{"eq": ["status_code", 200]},
{"eq": ["body.args.foo1", "session_bar1"]},
{"eq": ["body.args.foo1", "$foo1"]},
{"eq": ["body.args.foo2", "session_bar2"]},
{"eq": ["body.args.foo2", "$foo2"]}
]
}),
TestStep(**{
"name": "post raw text",
"variables": {
"foo1": "hello world",
"foo3": "$session_foo2"
},
"request": {
"method": "POST",
"url": "/post",
"data": "This is expected to be sent back as part of response body: $foo1-$foo3.",
"headers": {
"User-Agent": "HttpRunner/3.0",
"Content-Type": "text/plain"
}
},
"validate": [
{"eq": ["status_code", 200]},
{"eq": [
"body.data",
"This is expected to be sent back as part of response body: session_bar1-session_bar2."
]},
{"eq": [
"body.data",
"This is expected to be sent back as part of response body: $foo1-$foo3."
]},
]
}),
TestStep(**{
"name": "post form data",
"variables": {
"foo1": "session_bar1",
"foo2": "bar2"
},
"request": {
"method": "POST",
"url": "/post",
"data": "foo1=$foo1&foo2=$foo2",
"headers": {
"User-Agent": "HttpRunner/3.0",
"Content-Type": "application/x-www-form-urlencoded"
}
},
"validate": [
{"eq": ["status_code", 200]},
{"eq": ["body.form.foo1", "session_bar1"]},
{"eq": ["body.form.foo1", "$foo1"]},
{"eq": ["body.form.foo2", "bar2"]},
{"eq": ["body.form.foo2", "$foo2"]}
]
})
"extract": {"session_foo2": "body.args.foo2"},
"validate": [
{"eq": ["status_code", 200]},
{"eq": ["body.args.foo1", "$foo1"]},
{"eq": ["body.args.foo2", "$foo2"]},
],
}
),
TestStep(
**{
"name": "post raw text",
"variables": {"foo1": "hello world", "foo3": "$session_foo2"},
"request": {
"method": "POST",
"url": "/post",
"headers": {
"User-Agent": "HttpRunner/3.0",
"Content-Type": "text/plain",
},
"data": "This is expected to be sent back as part of response body: $foo1-$foo3.",
},
"validate": [
{"eq": ["status_code", 200]},
{
"eq": [
"body.data",
"This is expected to be sent back as part of response body: session_bar1-$foo3.",
]
},
],
}
),
TestStep(
**{
"name": "post form data",
"variables": {"foo1": "bar1", "foo2": "bar2"},
"request": {
"method": "POST",
"url": "/post",
"headers": {
"User-Agent": "HttpRunner/3.0",
"Content-Type": "application/x-www-form-urlencoded",
},
"data": "foo1=$foo1&foo2=$foo2",
},
"validate": [
{"eq": ["status_code", 200]},
{"eq": ["body.form.foo1", "$foo1"]},
{"eq": ["body.form.foo2", "$foo2"]},
],
}
),
]
if __name__ == '__main__':
runner = TestCaseRequestMethodsValidateWithVariables().run()
print(runner.step_datas)
def test_start(self):
TestCaseRunner(self.config, self.teststeps).run()