specmatic 0.9.0__py3-none-any.whl → 0.9.1__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.
Potentially problematic release.
This version of specmatic might be problematic. Click here for more details.
- specmatic/core/specmatic.py +66 -59
- specmatic/servers/asgi_app_server.py +3 -0
- specmatic/version.py +1 -1
- {specmatic-0.9.0.dist-info → specmatic-0.9.1.dist-info}/METADATA +7 -14
- {specmatic-0.9.0.dist-info → specmatic-0.9.1.dist-info}/RECORD +7 -7
- {specmatic-0.9.0.dist-info → specmatic-0.9.1.dist-info}/WHEEL +0 -0
- {specmatic-0.9.0.dist-info → specmatic-0.9.1.dist-info}/top_level.txt +0 -0
specmatic/core/specmatic.py
CHANGED
|
@@ -12,26 +12,31 @@ from specmatic.utils import get_junit_report_file_path
|
|
|
12
12
|
|
|
13
13
|
class Specmatic:
|
|
14
14
|
def __init__(self):
|
|
15
|
-
self.
|
|
16
|
-
self.
|
|
15
|
+
self.app = None
|
|
16
|
+
self.app_module = ''
|
|
17
17
|
self.app_host = '127.0.0.1'
|
|
18
18
|
self.app_port = 0
|
|
19
|
-
self.
|
|
20
|
-
self.
|
|
21
|
-
self.
|
|
19
|
+
self.reset_app_config_func = None
|
|
20
|
+
self.set_app_config_func = None
|
|
21
|
+
self.app_server = None
|
|
22
|
+
|
|
23
|
+
self.stub_host = None
|
|
24
|
+
self.stub_port = None
|
|
25
|
+
self.expectations = None
|
|
22
26
|
self.stub_args = None
|
|
27
|
+
self.stub = None
|
|
28
|
+
|
|
23
29
|
self.test_class = None
|
|
24
|
-
self.test_port = None
|
|
25
30
|
self.test_host = None
|
|
26
|
-
self.
|
|
27
|
-
self.
|
|
28
|
-
|
|
29
|
-
self.
|
|
31
|
+
self.test_port = None
|
|
32
|
+
self.test_args = None
|
|
33
|
+
|
|
34
|
+
self.project_root = ''
|
|
35
|
+
self.specmatic_json_file_path = ''
|
|
36
|
+
|
|
30
37
|
self.run_stub = False
|
|
31
38
|
self.run_app = False
|
|
32
39
|
self.run_tests = False
|
|
33
|
-
self.project_root = ''
|
|
34
|
-
self.specmatic_json_file_path = ''
|
|
35
40
|
|
|
36
41
|
def with_project_root(self, project_root):
|
|
37
42
|
self.project_root = project_root
|
|
@@ -54,30 +59,24 @@ class Specmatic:
|
|
|
54
59
|
self.run_app = True
|
|
55
60
|
return self
|
|
56
61
|
|
|
57
|
-
def
|
|
62
|
+
def with_wsgi_app(self, app, host: str = '127.0.0.1', port: int = 0, set_app_config_func=None,
|
|
63
|
+
reset_app_config_func=None):
|
|
58
64
|
self.app = app
|
|
65
|
+
self.app_host = host
|
|
66
|
+
self.app_port = port
|
|
67
|
+
self.set_app_config_func = set_app_config_func
|
|
68
|
+
self.reset_app_config_func = reset_app_config_func
|
|
59
69
|
self.run_app = True
|
|
60
70
|
return self
|
|
61
71
|
|
|
62
|
-
def
|
|
72
|
+
def with_asgi_app(self, app_module: str, host: str = '127.0.0.1', port: int = 0, set_app_config_func=None,
|
|
73
|
+
reset_app_config_func=None):
|
|
63
74
|
self.app_module = app_module
|
|
64
|
-
self.run_app = True
|
|
65
|
-
return self
|
|
66
|
-
|
|
67
|
-
def with_app_host(self, host: str):
|
|
68
75
|
self.app_host = host
|
|
69
|
-
return self
|
|
70
|
-
|
|
71
|
-
def with_app_port(self, port: int):
|
|
72
76
|
self.app_port = port
|
|
73
|
-
return self
|
|
74
|
-
|
|
75
|
-
def with_set_app_config_func(self, set_app_config_func):
|
|
76
77
|
self.set_app_config_func = set_app_config_func
|
|
77
|
-
return self
|
|
78
|
-
|
|
79
|
-
def with_reset_app_config_func(self, reset_app_config_func):
|
|
80
78
|
self.reset_app_config_func = reset_app_config_func
|
|
79
|
+
self.run_app = True
|
|
81
80
|
return self
|
|
82
81
|
|
|
83
82
|
def test(self, test_class, test_host: str = '127.0.0.1', test_port: int = 0, args=None):
|
|
@@ -88,38 +87,46 @@ class Specmatic:
|
|
|
88
87
|
self.run_tests = True
|
|
89
88
|
return self
|
|
90
89
|
|
|
90
|
+
def __init_app_server(self):
|
|
91
|
+
if self.run_app:
|
|
92
|
+
if self.app is None and self.app_module == '':
|
|
93
|
+
raise Exception('Please specify either an app or an app_module.')
|
|
94
|
+
if self.app is not None and self.app_module != '':
|
|
95
|
+
raise Exception('Please specify only one of app or app_module, and not both.')
|
|
96
|
+
if self.app is not None:
|
|
97
|
+
self.app_server = WSGIAppServer(self.app, self.app_host, self.app_port, self.set_app_config_func,
|
|
98
|
+
self.reset_app_config_func)
|
|
99
|
+
else:
|
|
100
|
+
self.app_server = ASGIAppServer(self.app_module, self.app_host, self.app_port, self.set_app_config_func,
|
|
101
|
+
self.reset_app_config_func)
|
|
102
|
+
|
|
103
|
+
def __start_stub(self):
|
|
104
|
+
if self.run_stub:
|
|
105
|
+
self.stub = SpecmaticStub(self.stub_host, self.stub_port, self.project_root, self.specmatic_json_file_path,
|
|
106
|
+
self.stub_args)
|
|
107
|
+
self.stub.set_expectations(self.expectations)
|
|
108
|
+
self.app_server.set_app_config(self.stub.host, self.stub.port)
|
|
109
|
+
|
|
110
|
+
def __execute_tests(self):
|
|
111
|
+
if self.run_tests:
|
|
112
|
+
if self.app_server is not None:
|
|
113
|
+
self.app_server.start()
|
|
114
|
+
self.test_host = self.app_server.host
|
|
115
|
+
self.test_port = self.app_server.port
|
|
116
|
+
SpecmaticTest(self.test_host, self.test_port, self.project_root,
|
|
117
|
+
self.specmatic_json_file_path, self.test_args).run()
|
|
118
|
+
if issubclass(self.test_class, unittest.TestCase):
|
|
119
|
+
print("Injecting unittest methods")
|
|
120
|
+
UnitTestGenerator(self.test_class, get_junit_report_file_path()).generate()
|
|
121
|
+
else:
|
|
122
|
+
print("Injecting pytest methods")
|
|
123
|
+
PyTestGenerator(self.test_class, get_junit_report_file_path()).generate()
|
|
124
|
+
|
|
91
125
|
def run(self):
|
|
92
|
-
stub = None
|
|
93
126
|
try:
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if self.app is not None and self.app_module != '':
|
|
98
|
-
raise Exception('Please specify only one of app or app_module, and not both.')
|
|
99
|
-
if self.app is not None:
|
|
100
|
-
self.app_server = WSGIAppServer(self.app, self.app_host, self.app_port, self.set_app_config_func,
|
|
101
|
-
self.reset_app_config_func)
|
|
102
|
-
else:
|
|
103
|
-
self.app_server = ASGIAppServer(self.app_module, self.app_host, self.app_port, self.set_app_config_func,
|
|
104
|
-
self.reset_app_config_func)
|
|
105
|
-
if self.run_stub:
|
|
106
|
-
stub = SpecmaticStub(self.stub_host, self.stub_port, self.project_root, self.specmatic_json_file_path,
|
|
107
|
-
self.stub_args)
|
|
108
|
-
stub.set_expectations(self.expectations)
|
|
109
|
-
self.app_server.set_app_config(stub.host, stub.port)
|
|
110
|
-
if self.run_tests:
|
|
111
|
-
if self.app_server is not None:
|
|
112
|
-
self.app_server.start()
|
|
113
|
-
self.test_host = self.app_server.host
|
|
114
|
-
self.test_port = self.app_server.port
|
|
115
|
-
SpecmaticTest(self.test_host, self.test_port, self.project_root,
|
|
116
|
-
self.specmatic_json_file_path, self.test_args).run()
|
|
117
|
-
if issubclass(self.test_class, unittest.TestCase):
|
|
118
|
-
print("Injecting unittest methods")
|
|
119
|
-
UnitTestGenerator(self.test_class, get_junit_report_file_path()).generate()
|
|
120
|
-
else:
|
|
121
|
-
print("Injecting pytest methods")
|
|
122
|
-
PyTestGenerator(self.test_class, get_junit_report_file_path()).generate()
|
|
127
|
+
self.__init_app_server()
|
|
128
|
+
self.__start_stub()
|
|
129
|
+
self.__execute_tests()
|
|
123
130
|
except Exception as e:
|
|
124
131
|
print(f"Error: {e}")
|
|
125
132
|
raise e
|
|
@@ -127,5 +134,5 @@ class Specmatic:
|
|
|
127
134
|
if self.app_server is not None:
|
|
128
135
|
self.app_server.stop()
|
|
129
136
|
self.app_server.reset_app_config()
|
|
130
|
-
if stub is not None:
|
|
131
|
-
stub.stop()
|
|
137
|
+
if self.stub is not None:
|
|
138
|
+
self.stub.stop()
|
|
@@ -43,6 +43,9 @@ class ASGIAppServer(AppServer):
|
|
|
43
43
|
def __read_process_output(self):
|
|
44
44
|
try:
|
|
45
45
|
for line in iter(self.__process.stdout.readline, ''):
|
|
46
|
+
if self.__process.poll() is not None:
|
|
47
|
+
line = line.decode()
|
|
48
|
+
raise Exception('App process terminated due to an error ' + line)
|
|
46
49
|
if line:
|
|
47
50
|
line = line.decode().rstrip()
|
|
48
51
|
print(line)
|
specmatic/version.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
__version__ = '0.9.
|
|
1
|
+
__version__ = '0.9.1'
|
|
2
2
|
__specmatic_version__ = '0.68.0'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: specmatic
|
|
3
|
-
Version: 0.9.
|
|
3
|
+
Version: 0.9.1
|
|
4
4
|
Summary: A Python module for using the Specmatic Library.
|
|
5
5
|
Home-page: https://github.com/znsio/specmatic-python-extensions
|
|
6
6
|
Author: Specmatic Builders
|
|
@@ -54,9 +54,7 @@ class TestContract:
|
|
|
54
54
|
Specmatic() \
|
|
55
55
|
.with_project_root(PROJECT_ROOT) \
|
|
56
56
|
.with_stub(stub_host, stub_port, [expectation_json_file]) \
|
|
57
|
-
.
|
|
58
|
-
.with_app_host(app_host)\
|
|
59
|
-
.with_app_port(app_port)\
|
|
57
|
+
.with_wsgi_app(app, app_host, app_port) \
|
|
60
58
|
.test(TestContract) \
|
|
61
59
|
.run()
|
|
62
60
|
``````
|
|
@@ -83,9 +81,7 @@ class TestContract:
|
|
|
83
81
|
|
|
84
82
|
Specmatic() \
|
|
85
83
|
.with_project_root(PROJECT_ROOT) \
|
|
86
|
-
.
|
|
87
|
-
.with_app_host(app_host)\
|
|
88
|
-
.with_app_port(app_port)\
|
|
84
|
+
.with_wsgi_app(app, app_host, app_port) \
|
|
89
85
|
.test(TestContract) \
|
|
90
86
|
.run()
|
|
91
87
|
``````
|
|
@@ -93,7 +89,7 @@ Specmatic() \
|
|
|
93
89
|
## ASGI Apps
|
|
94
90
|
|
|
95
91
|
#### To run contract tests with a stub for an asgi app (like sanic):
|
|
96
|
-
- If you are using an asgi app like sanic, fastapi, use the ``````
|
|
92
|
+
- If you are using an asgi app like sanic, fastapi, use the ``````with_asgi_app`````` function and pass it a string in the 'module:app' format.
|
|
97
93
|
``````
|
|
98
94
|
class TestContract:
|
|
99
95
|
pass
|
|
@@ -102,9 +98,7 @@ class TestContract:
|
|
|
102
98
|
Specmatic() \
|
|
103
99
|
.with_project_root(PROJECT_ROOT) \
|
|
104
100
|
.with_stub(stub_host, stub_port, [expectation_json_file]) \
|
|
105
|
-
.
|
|
106
|
-
.with_app_host(app_host) \
|
|
107
|
-
.with_app_port(app_port) \
|
|
101
|
+
.with_asgi_app('main:app', app_host, app_port) \
|
|
108
102
|
.test(TestContract) \
|
|
109
103
|
.run()
|
|
110
104
|
``````
|
|
@@ -119,15 +113,14 @@ class TestContract:
|
|
|
119
113
|
Specmatic() \
|
|
120
114
|
.with_project_root(PROJECT_ROOT) \
|
|
121
115
|
.with_stub(stub_host, stub_port, [expectation_json_file], ['--strict']) \
|
|
122
|
-
.
|
|
123
|
-
.with_app_port(app_port) \
|
|
116
|
+
.with_wsgi_app(app, port=app_port) \
|
|
124
117
|
.test(TestContract, args=['--testBaseURL=http://localhost:5000']) \
|
|
125
118
|
.run()
|
|
126
119
|
``````
|
|
127
120
|
|
|
128
121
|
## Common Issues
|
|
129
122
|
- **'Error loading ASGI app'**
|
|
130
|
-
This error occurs
|
|
123
|
+
This error occurs when an incorrect app module string is passed to the ``````with_asgi_app`````` function.
|
|
131
124
|
|
|
132
125
|
#### Solutions:
|
|
133
126
|
- Try to identify the correct module in which your app variable is instantiated/imported.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
specmatic/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
2
|
specmatic/utils.py,sha256=6JDPqpO51ykl0MWCOa32jkUOXZ-0RZ6N5Ng9_7r7XaU,519
|
|
3
|
-
specmatic/version.py,sha256=
|
|
3
|
+
specmatic/version.py,sha256=MpN_PFJMmvrp-2TOtwaw16FhamYEEkOXXdUWtIOP4YM,55
|
|
4
4
|
specmatic/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
5
|
specmatic/core/decorators.py,sha256=_TWZMbUyH4WFyYHzW0oBcuef-c6ktukJ9Av3iYrDkTY,2879
|
|
6
6
|
specmatic/core/specmatic.jar,sha256=LIHTAPFuGtfZ6zvcrwfVJ7luLAuSvMvDoalInN3pqUQ,87155557
|
|
7
|
-
specmatic/core/specmatic.py,sha256=
|
|
7
|
+
specmatic/core/specmatic.py,sha256=avagtEtRnfxUFqwHR3q-vIB0YdypJTsWEmQVA6DPXQQ,5361
|
|
8
8
|
specmatic/core/specmatic_base.py,sha256=sueXRmjXXLV8YC_3rsxGng2bPt2qWIsTWEO2A9MXMP0,1497
|
|
9
9
|
specmatic/core/specmatic_stub.py,sha256=_I6jc8oI7me6Q64gtPchRRqA-c8GGO5YTCIpw1nrwEo,4563
|
|
10
10
|
specmatic/core/specmatic_test.py,sha256=rZXCeTlH-3wkShJECL7VDN2hlkJgmuiKQYzVRwnLNok,994
|
|
@@ -14,10 +14,10 @@ specmatic/generators/test_generator_base.py,sha256=bCdJD9MOUX6FINPF2r06y9NQ5k10q
|
|
|
14
14
|
specmatic/generators/unittest_generator.py,sha256=Vkm8BP-_rZ-tFbLwUTNc90OgQCMJ4OHd8w5mShhcFyU,713
|
|
15
15
|
specmatic/servers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
16
|
specmatic/servers/app_server.py,sha256=kOZviJA7-F4kmMTLGiBln2oO5uYX28wKJM2xQJTOVQY,456
|
|
17
|
-
specmatic/servers/asgi_app_server.py,sha256=
|
|
17
|
+
specmatic/servers/asgi_app_server.py,sha256=yn3tpWoF-nP8labOJdn49UB85vKiqIELVXk-gAugcUc,2924
|
|
18
18
|
specmatic/servers/wsgi_app_server.py,sha256=3aU-o6Hh8FrnZlbjCLLpGY92HvJoU_rcqsZIb9TKVr8,1342
|
|
19
19
|
specmatic/servers/wsgi_server_thread.py,sha256=XUEYW7-FP1a-5EkQVGc3FI_jkDQBocArxHLiCn3JJvc,691
|
|
20
|
-
specmatic-0.9.
|
|
21
|
-
specmatic-0.9.
|
|
22
|
-
specmatic-0.9.
|
|
23
|
-
specmatic-0.9.
|
|
20
|
+
specmatic-0.9.1.dist-info/METADATA,sha256=OwazAuFZ4kT_CqWPPI914IixxOgtBreA9Ivspedn4d0,5717
|
|
21
|
+
specmatic-0.9.1.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
|
|
22
|
+
specmatic-0.9.1.dist-info/top_level.txt,sha256=E7kQ78YacKBoKKeKWR_N83exlG8r5J0wlzlGqFmvIfo,10
|
|
23
|
+
specmatic-0.9.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|