pytest-dsl 0.1.1__py3-none-any.whl → 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pytest_dsl/cli.py +42 -6
- pytest_dsl/core/__init__.py +7 -0
- pytest_dsl/core/custom_keyword_manager.py +213 -0
- pytest_dsl/core/dsl_executor.py +171 -3
- pytest_dsl/core/http_request.py +163 -54
- pytest_dsl/core/lexer.py +36 -1
- pytest_dsl/core/parser.py +155 -13
- pytest_dsl/core/parsetab.py +82 -49
- pytest_dsl/core/variable_utils.py +1 -1
- pytest_dsl/examples/custom/test_advanced_keywords.auto +31 -0
- pytest_dsl/examples/custom/test_custom_keywords.auto +37 -0
- pytest_dsl/examples/custom/test_default_values.auto +34 -0
- pytest_dsl/examples/http/http_retry_assertions.auto +2 -2
- pytest_dsl/examples/http/http_retry_assertions_enhanced.auto +2 -2
- pytest_dsl/examples/test_custom_keyword.py +9 -0
- pytest_dsl/examples/test_http.py +0 -139
- pytest_dsl/keywords/http_keywords.py +290 -102
- pytest_dsl/parsetab.py +69 -0
- pytest_dsl-0.3.0.dist-info/METADATA +448 -0
- {pytest_dsl-0.1.1.dist-info → pytest_dsl-0.3.0.dist-info}/RECORD +24 -24
- {pytest_dsl-0.1.1.dist-info → pytest_dsl-0.3.0.dist-info}/WHEEL +1 -1
- pytest_dsl/core/custom_auth_example.py +0 -425
- pytest_dsl/examples/csrf_auth_provider.py +0 -232
- pytest_dsl/examples/http/csrf_auth_test.auto +0 -64
- pytest_dsl/examples/http/custom_auth_test.auto +0 -76
- pytest_dsl/examples/http_clients.yaml +0 -48
- pytest_dsl/examples/keyword_example.py +0 -70
- pytest_dsl-0.1.1.dist-info/METADATA +0 -504
- {pytest_dsl-0.1.1.dist-info → pytest_dsl-0.3.0.dist-info}/entry_points.txt +0 -0
- {pytest_dsl-0.1.1.dist-info → pytest_dsl-0.3.0.dist-info}/licenses/LICENSE +0 -0
- {pytest_dsl-0.1.1.dist-info → pytest_dsl-0.3.0.dist-info}/top_level.txt +0 -0
@@ -1,64 +0,0 @@
|
|
1
|
-
@name: CSRF登录授权测试
|
2
|
-
@description: 演示CSRF登录授权提供者的使用
|
3
|
-
@tags: [HTTP, API, 授权, CSRF, 示例]
|
4
|
-
@author: Felix
|
5
|
-
@date: 2024-05-20
|
6
|
-
|
7
|
-
# CSRF登录授权测试示例
|
8
|
-
# 演示CSRF登录授权提供者的使用
|
9
|
-
|
10
|
-
# 测试CSRF登录认证
|
11
|
-
[HTTP请求],客户端:'csrf_auth',配置:'''
|
12
|
-
method: GET
|
13
|
-
url: /headers
|
14
|
-
captures:
|
15
|
-
csrf_token: ["jsonpath", "$.headers.X-Csrf-Token"]
|
16
|
-
asserts:
|
17
|
-
- ["status", "eq", 200]
|
18
|
-
- ["jsonpath", "$.headers.X-Csrf-Token", "exists"]
|
19
|
-
'''
|
20
|
-
|
21
|
-
[打印],内容:'CSRF令牌: ${csrf_token}'
|
22
|
-
|
23
|
-
# 测试CSRF令牌过期后自动重新登录
|
24
|
-
[HTTP请求],客户端:'csrf_auth',配置:'''
|
25
|
-
method: GET
|
26
|
-
url: /headers
|
27
|
-
headers:
|
28
|
-
X-Csrf-Token: expired_token # 模拟过期令牌
|
29
|
-
captures:
|
30
|
-
csrf_token: ["jsonpath", "$.headers.X-Csrf-Token"]
|
31
|
-
asserts:
|
32
|
-
- ["status", "eq", 200]
|
33
|
-
- ["jsonpath", "$.headers.X-Csrf-Token", "exists"]
|
34
|
-
'''
|
35
|
-
|
36
|
-
[打印],内容:'新的CSRF令牌: ${csrf_token}'
|
37
|
-
|
38
|
-
# 测试需要CSRF令牌的POST请求
|
39
|
-
[HTTP请求],客户端:'csrf_auth',配置:'''
|
40
|
-
method: POST
|
41
|
-
url: /anything
|
42
|
-
json:
|
43
|
-
test: "data"
|
44
|
-
captures:
|
45
|
-
headers: ["jsonpath", "$.headers"]
|
46
|
-
json: ["jsonpath", "$.json"]
|
47
|
-
asserts:
|
48
|
-
- ["status", "eq", 200]
|
49
|
-
- ["jsonpath", "$.headers.X-Csrf-Token", "exists"]
|
50
|
-
'''
|
51
|
-
|
52
|
-
[打印],内容:'请求头: ${headers}'
|
53
|
-
[打印],内容:'请求体: ${json}'
|
54
|
-
|
55
|
-
# 测试禁用CSRF认证
|
56
|
-
[HTTP请求],客户端:'csrf_auth',配置:'''
|
57
|
-
method: GET
|
58
|
-
url: /headers
|
59
|
-
disable_auth: true
|
60
|
-
asserts:
|
61
|
-
- ["status", "eq", 200]
|
62
|
-
'''
|
63
|
-
|
64
|
-
[打印],内容:'CSRF登录授权测试完成'
|
@@ -1,76 +0,0 @@
|
|
1
|
-
@name: 自定义授权测试
|
2
|
-
@description: 演示自定义授权提供者的使用
|
3
|
-
@tags: [HTTP, API, 授权, 示例]
|
4
|
-
@author: Felix
|
5
|
-
@date: 2024-05-01
|
6
|
-
|
7
|
-
# 自定义授权测试示例
|
8
|
-
# 演示自定义授权提供者的使用
|
9
|
-
|
10
|
-
# 测试HMAC签名授权
|
11
|
-
[HTTP请求],客户端:'hmac_auth',配置:'''
|
12
|
-
method: GET
|
13
|
-
url: /headers
|
14
|
-
captures:
|
15
|
-
auth_header: ["jsonpath", "$.headers.Authorization"]
|
16
|
-
asserts:
|
17
|
-
- ["status", "eq", 200]
|
18
|
-
- ["jsonpath", "$.headers.Authorization", "exists"]
|
19
|
-
- ["jsonpath", "$.headers.X-Amz-Date", "exists"]
|
20
|
-
'''
|
21
|
-
|
22
|
-
[打印],内容:'HMAC授权头: ${auth_header}'
|
23
|
-
|
24
|
-
# 测试JWT刷新令牌授权
|
25
|
-
[HTTP请求],客户端:'jwt_auth',配置:'''
|
26
|
-
method: GET
|
27
|
-
url: /headers
|
28
|
-
captures:
|
29
|
-
auth_header: ["jsonpath", "$.headers.Authorization"]
|
30
|
-
asserts:
|
31
|
-
- ["status", "eq", 200]
|
32
|
-
- ["jsonpath", "$.headers.Authorization", "startswith", "Bearer "]
|
33
|
-
'''
|
34
|
-
|
35
|
-
[打印],内容:'JWT授权头: ${auth_header}'
|
36
|
-
|
37
|
-
# 测试微信小程序授权
|
38
|
-
[HTTP请求],客户端:'wechat_auth',配置:'''
|
39
|
-
method: GET
|
40
|
-
url: /headers
|
41
|
-
captures:
|
42
|
-
openid: ["jsonpath", "$.headers.X-Wx-Openid"]
|
43
|
-
session_key: ["jsonpath", "$.headers.X-Wx-Session-Key"]
|
44
|
-
asserts:
|
45
|
-
- ["status", "eq", 200]
|
46
|
-
- ["jsonpath", "$.headers.X-Wx-Openid", "exists"]
|
47
|
-
- ["jsonpath", "$.headers.X-Wx-Session-Key", "exists"]
|
48
|
-
'''
|
49
|
-
|
50
|
-
[打印],内容:'微信OpenID: ${openid}'
|
51
|
-
[打印],内容:'微信Session Key: ${session_key}'
|
52
|
-
|
53
|
-
# 测试多步骤授权
|
54
|
-
[HTTP请求],客户端:'multi_step_auth',配置:'''
|
55
|
-
method: GET
|
56
|
-
url: /headers
|
57
|
-
captures:
|
58
|
-
auth_header: ["jsonpath", "$.headers.Authorization"]
|
59
|
-
asserts:
|
60
|
-
- ["status", "eq", 200]
|
61
|
-
- ["jsonpath", "$.headers.Authorization", "startswith", "Bearer "]
|
62
|
-
'''
|
63
|
-
|
64
|
-
[打印],内容:'多步骤授权头: ${auth_header}'
|
65
|
-
|
66
|
-
# 测试禁用授权
|
67
|
-
[HTTP请求],客户端:'multi_step_auth',配置:'''
|
68
|
-
method: GET
|
69
|
-
url: /headers
|
70
|
-
disable_auth: true
|
71
|
-
asserts:
|
72
|
-
- ["status", "eq", 200]
|
73
|
-
- ["jsonpath", "$.headers.Authorization", "not_exists"]
|
74
|
-
'''
|
75
|
-
|
76
|
-
[打印],内容:'自定义授权测试完成'
|
@@ -1,48 +0,0 @@
|
|
1
|
-
http_clients:
|
2
|
-
hmac_auth:
|
3
|
-
base_url: https://httpbin.org
|
4
|
-
headers:
|
5
|
-
User-Agent: pytest-dsl-client/1.0
|
6
|
-
Accept: application/json
|
7
|
-
timeout: 30
|
8
|
-
verify_ssl: true
|
9
|
-
session: true
|
10
|
-
auth:
|
11
|
-
type: custom
|
12
|
-
provider_name: hmac_aws_auth
|
13
|
-
|
14
|
-
jwt_auth:
|
15
|
-
base_url: https://httpbin.org
|
16
|
-
headers:
|
17
|
-
User-Agent: pytest-dsl-client/1.0
|
18
|
-
Accept: application/json
|
19
|
-
timeout: 30
|
20
|
-
verify_ssl: true
|
21
|
-
session: true
|
22
|
-
auth:
|
23
|
-
type: custom
|
24
|
-
provider_name: jwt_refresh_auth
|
25
|
-
|
26
|
-
wechat_auth:
|
27
|
-
base_url: https://httpbin.org
|
28
|
-
headers:
|
29
|
-
User-Agent: pytest-dsl-client/1.0
|
30
|
-
Accept: application/json
|
31
|
-
timeout: 30
|
32
|
-
verify_ssl: true
|
33
|
-
session: true
|
34
|
-
auth:
|
35
|
-
type: custom
|
36
|
-
provider_name: wechat_miniapp_auth
|
37
|
-
|
38
|
-
multi_step_auth:
|
39
|
-
base_url: https://httpbin.org
|
40
|
-
headers:
|
41
|
-
User-Agent: pytest-dsl-client/1.0
|
42
|
-
Accept: application/json
|
43
|
-
timeout: 30
|
44
|
-
verify_ssl: true
|
45
|
-
session: true
|
46
|
-
auth:
|
47
|
-
type: custom
|
48
|
-
provider_name: multi_step_auth
|
@@ -1,70 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
示例: 如何在您的项目中创建自定义关键字
|
3
|
-
|
4
|
-
将该文件放在您项目的 keywords 目录下,
|
5
|
-
例如: my_project/keywords/my_keywords.py
|
6
|
-
|
7
|
-
pytest-dsl 会自动导入这些关键字。
|
8
|
-
"""
|
9
|
-
|
10
|
-
from pytest_dsl.core.keyword_manager import keyword_manager
|
11
|
-
|
12
|
-
# 示例1: 简单关键字
|
13
|
-
@keyword_manager.register('打印消息', [
|
14
|
-
{'name': '消息', 'mapping': 'message', 'description': '要打印的消息内容'},
|
15
|
-
])
|
16
|
-
def print_message(**kwargs):
|
17
|
-
"""打印一条消息到控制台
|
18
|
-
|
19
|
-
Args:
|
20
|
-
message: 要打印的消息
|
21
|
-
context: 测试上下文 (自动传入)
|
22
|
-
"""
|
23
|
-
message = kwargs.get('message', '')
|
24
|
-
print(f"自定义关键字消息: {message}")
|
25
|
-
return True
|
26
|
-
|
27
|
-
# 示例2: 带返回值的关键字
|
28
|
-
@keyword_manager.register('生成随机数', [
|
29
|
-
{'name': '最小值', 'mapping': 'min_value', 'description': '随机数范围最小值'},
|
30
|
-
{'name': '最大值', 'mapping': 'max_value', 'description': '随机数范围最大值'},
|
31
|
-
])
|
32
|
-
def generate_random(**kwargs):
|
33
|
-
"""生成指定范围内的随机整数
|
34
|
-
|
35
|
-
Args:
|
36
|
-
min_value: 最小值
|
37
|
-
max_value: 最大值
|
38
|
-
context: 测试上下文 (自动传入)
|
39
|
-
|
40
|
-
Returns:
|
41
|
-
随机整数
|
42
|
-
"""
|
43
|
-
import random
|
44
|
-
min_value = int(kwargs.get('min_value', 1))
|
45
|
-
max_value = int(kwargs.get('max_value', 100))
|
46
|
-
|
47
|
-
result = random.randint(min_value, max_value)
|
48
|
-
return result
|
49
|
-
|
50
|
-
# 示例3: 操作上下文的关键字
|
51
|
-
@keyword_manager.register('保存到上下文', [
|
52
|
-
{'name': '键名', 'mapping': 'key', 'description': '保存在上下文中的键名'},
|
53
|
-
{'name': '值', 'mapping': 'value', 'description': '要保存的值'},
|
54
|
-
])
|
55
|
-
def save_to_context(**kwargs):
|
56
|
-
"""将值保存到测试上下文中
|
57
|
-
|
58
|
-
Args:
|
59
|
-
key: 键名
|
60
|
-
value: 要保存的值
|
61
|
-
context: 测试上下文 (自动传入)
|
62
|
-
"""
|
63
|
-
key = kwargs.get('key')
|
64
|
-
value = kwargs.get('value')
|
65
|
-
context = kwargs.get('context')
|
66
|
-
|
67
|
-
if key and context:
|
68
|
-
context.set(key, value)
|
69
|
-
return True
|
70
|
-
return False
|