pytest-api-framework-alpha 0.2.10__tar.gz → 0.3.1__tar.gz

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.
Files changed (35) hide show
  1. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/PKG-INFO +1 -1
  2. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/framework/base_class.py +51 -20
  3. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/framework/conftest.py +333 -259
  4. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/framework/db/mysql_db.py +23 -13
  5. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/framework/db/redis_db.py +23 -21
  6. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/framework/exceptions.py +9 -0
  7. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/framework/exit_code.py +7 -3
  8. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/framework/extract.py +11 -11
  9. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/framework/global_attribute.py +2 -2
  10. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/framework/http_client.py +31 -6
  11. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/framework/render_data.py +3 -3
  12. pytest_api_framework_alpha-0.3.1/framework/script.py +3 -0
  13. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/framework/startapp.py +23 -21
  14. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/framework/utils/common.py +10 -9
  15. pytest_api_framework_alpha-0.3.1/framework/utils/date_util.py +204 -0
  16. pytest_api_framework_alpha-0.3.1/framework/utils/yaml_util.py +96 -0
  17. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/pytest_api_framework_alpha.egg-info/PKG-INFO +1 -1
  18. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/pytest_api_framework_alpha.egg-info/SOURCES.txt +2 -2
  19. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/setup.py +1 -1
  20. pytest_api_framework_alpha-0.2.10/framework/allure_report.py +0 -35
  21. pytest_api_framework_alpha-0.2.10/framework/settings.py +0 -30
  22. pytest_api_framework_alpha-0.2.10/framework/utils/yaml_util.py +0 -25
  23. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/framework/__init__.py +0 -0
  24. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/framework/db/__init__.py +0 -0
  25. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/framework/report.py +0 -0
  26. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/framework/utils/__init__.py +0 -0
  27. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/framework/utils/encrypt.py +0 -0
  28. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/framework/utils/log_util.py +0 -0
  29. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/framework/utils/mock_util.py +0 -0
  30. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/framework/utils/teams_util.py +0 -0
  31. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/framework/validate.py +0 -0
  32. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/pytest_api_framework_alpha.egg-info/dependency_links.txt +0 -0
  33. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/pytest_api_framework_alpha.egg-info/requires.txt +0 -0
  34. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/pytest_api_framework_alpha.egg-info/top_level.txt +0 -0
  35. {pytest_api_framework_alpha-0.2.10 → pytest_api_framework_alpha-0.3.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pytest-api-framework-alpha
3
- Version: 0.2.10
3
+ Version: 0.3.1
4
4
  Author: alpha
5
5
  Author-email:
6
6
  Requires-Python: >=3.6
@@ -1,30 +1,41 @@
1
1
  import traceback
2
2
  import importlib
3
+ from dataclasses import dataclass
3
4
  from datetime import datetime, timedelta
4
5
  from urllib.parse import urlparse, urlunparse, urljoin
5
6
 
6
7
  import pytest
7
8
  from box import Box
9
+ from faker import Faker
8
10
 
9
- from framework.exit_code import ExitCode
10
11
  from framework.db.redis_db import RedisDB
11
12
  from framework.db.mysql_db import MysqlDB
12
13
  from framework.utils.log_util import logger
13
14
  from framework.render_data import RenderData
14
15
  from framework.http_client import ResponseUtil
15
- from config.settings import UNAUTHORIZED_CODE, FAKER_LANGUAGE
16
+ from framework.utils.date_util import DateUtil
16
17
  from framework.utils.common import snake_to_pascal, SingletonFaker
17
- from framework.global_attribute import CONFIG, GlobalAttribute, _FRAMEWORK_CONTEXT
18
- from framework.exceptions import ValidateException, RenderException, RequestException, ResponseException
18
+ from framework.global_attribute import GlobalAttribute, _FRAMEWORK_CONTEXT,CONTEXT
19
+ from framework.exceptions import ValidateException, RenderException, RequestException, ResponseException, \
20
+ GetAccountError, GetAppHttpError
19
21
  from framework.utils.mock_util import get_customized_kytmock, set_customized_kytmock, PaymentType, RiskLevel, IsDelayed
20
22
 
23
+ from handlers.extend_base_test_case_attr import ExtendBaseTestCase
24
+ from config.settings import UNAUTHORIZED_CODE, FAKER_LANGUAGE
25
+
21
26
  module = importlib.import_module("test_case.conftest")
22
27
 
28
+ @dataclass
29
+ class Scenario:
30
+ describe: str
31
+ level: str
32
+ data: str
33
+ expect: str
23
34
 
24
- class BaseTestCase(object):
35
+ class BaseTestCase(ExtendBaseTestCase):
25
36
  http = None
26
37
  data: Box = None
27
- scenario: Box = None
38
+ scenario: Scenario = None
28
39
  belong_app = None
29
40
  response: ResponseUtil = None
30
41
  context: GlobalAttribute = None
@@ -32,17 +43,26 @@ class BaseTestCase(object):
32
43
  payment_type: PaymentType = PaymentType
33
44
  risk_level: RiskLevel = RiskLevel
34
45
  is_delayed: IsDelayed = IsDelayed
46
+ date_util: DateUtil = DateUtil
47
+ logger: logger = logger
35
48
  # faker方法文档 https://blog.csdn.net/m0_60052979/article/details/126368024
36
- faker = SingletonFaker(locale=FAKER_LANGUAGE).faker
49
+ faker: Faker = SingletonFaker(locale=FAKER_LANGUAGE).faker
50
+ env = CONTEXT.get("env")
37
51
 
38
- def request(self, app=None, *, account, data, **kwargs):
52
+ def request(self, app=None, *, account, data, **kwargs) -> ResponseUtil:
39
53
  try:
40
54
  app = self.default_app(app)
41
- app_http = getattr(self.http, app)
55
+ try:
56
+ app_http = getattr(self.http, app)
57
+ except AttributeError as e:
58
+ raise GetAppHttpError(e)
42
59
  domain = self.context.get(app).get("domain")
43
60
  data = RenderData(data).render()
44
61
  data.request.url = self.replace_domain(data.request.url, domain)
45
- self.response = getattr(app_http, account).request(data=data, kwargs=kwargs)
62
+ try:
63
+ self.response = getattr(app_http, account).request(data=data, kwargs=kwargs)
64
+ except AttributeError as e:
65
+ raise GetAccountError(e)
46
66
  if self.response.status_code in UNAUTHORIZED_CODE:
47
67
  _http = _FRAMEWORK_CONTEXT.get(key="_http")
48
68
  setattr(_http, app, getattr(module, f"{snake_to_pascal(app)}Login")(app))
@@ -56,11 +76,21 @@ class BaseTestCase(object):
56
76
  traceback.print_exc()
57
77
  pytest.fail(str(e))
58
78
 
79
+ except GetAccountError as e:
80
+ logger.error(f"获取账号{account}异常: {e}")
81
+ traceback.print_exc()
82
+ pytest.fail(str(e))
83
+
84
+ except GetAppHttpError as e:
85
+ logger.error(f"获取{app} http对象异常: {e}")
86
+ traceback.print_exc()
87
+ pytest.fail(str(e))
88
+
59
89
  except RequestException as e:
60
90
  logger.error(f"请求异常: {e}")
61
91
  traceback.print_exc()
62
92
  pytest.fail(str(e))
63
-
93
+
64
94
  except ResponseException as e:
65
95
  logger.error(f"响应异常: {e}")
66
96
  traceback.print_exc()
@@ -72,30 +102,29 @@ class BaseTestCase(object):
72
102
  pytest.fail(str(e))
73
103
 
74
104
  except Exception as e:
75
- # logger.error(e)
105
+ logger.error(e)
76
106
  traceback.print_exc()
77
- # pytest.exit(e)
78
- return None
107
+ pytest.fail(str(e))
79
108
 
80
- def post(self, app, account, url, data=None, json=None, **kwargs):
109
+ def post(self, app, account, url, data=None, json=None, **kwargs) -> ResponseUtil:
81
110
  domain = self.context.get(app).get("domain")
82
111
  request = {"url": urljoin(domain, url), "data": data, "json": json}
83
112
  request.update({"method": "post", "headers": {}, **kwargs})
84
113
  return self.request(app=app, account=account, data=Box({"request": request}))
85
114
 
86
- def get(self, app, account, url, params=None, **kwargs):
115
+ def get(self, app, account, url, params=None, **kwargs) -> ResponseUtil:
87
116
  domain = self.context.get(app).get("domain")
88
117
  request = {"url": urljoin(domain, url), "params": params}
89
118
  request.update({"method": "get", "headers": {}, **kwargs})
90
119
  return self.request(app=app, account=account, data=Box({"request": request}))
91
120
 
92
- def put(self, app, account, url, data=None, json=None, **kwargs):
121
+ def put(self, app, account, url, data=None, json=None, **kwargs) -> ResponseUtil:
93
122
  domain = self.context.get(app).get("domain")
94
123
  request = {"url": urljoin(domain, url), "data": data, "json": json}
95
124
  request.update({"method": "put", "headers": {}, **kwargs})
96
125
  return self.request(app=app, account=account, data=Box({"request": request}))
97
126
 
98
- def delete(self, app, account, url, **kwargs):
127
+ def delete(self, app, account, url, **kwargs) -> ResponseUtil:
99
128
  domain = self.context.get(app).get("domain")
100
129
  request = {"url": urljoin(domain, url)}
101
130
  request.update({"method": "delete", "headers": {}, **kwargs})
@@ -105,15 +134,17 @@ class BaseTestCase(object):
105
134
  try:
106
135
  return _FRAMEWORK_CONTEXT.get(app=self.default_app(app), key="mysql").get(db)
107
136
  except AttributeError as e:
137
+ logger.error(f"获取mysql连接异常: {e} {self.default_app(app)} {app} {db} ")
108
138
  traceback.print_exc()
109
- pytest.exit(ExitCode.LOAD_DATABASE_INFO_ERROR)
139
+ # pytest.exit(ExitCode.LOAD_DATABASE_INFO_ERROR)
110
140
 
111
141
  def redis_conn(self, db, index=0, app=None) -> RedisDB:
112
142
  try:
113
143
  return _FRAMEWORK_CONTEXT.get(app=self.default_app(app), key="redis").get(db)[index]
114
144
  except AttributeError as e:
145
+ logger.error(f"获取redis连接异常: {e}")
115
146
  traceback.print_exc()
116
- pytest.exit(ExitCode.LOAD_DATABASE_INFO_ERROR)
147
+ # pytest.exit(ExitCode.LOAD_DATABASE_INFO_ERROR)
117
148
 
118
149
  def context_set(self, key, value):
119
150
  self.context.set(app=self.belong_app, key=key, value=value)