specmatic 0.9.0__tar.gz → 0.9.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.
Potentially problematic release.
This version of specmatic might be problematic. Click here for more details.
- {specmatic-0.9.0/specmatic.egg-info → specmatic-0.9.1}/PKG-INFO +7 -14
- {specmatic-0.9.0 → specmatic-0.9.1}/README.md +6 -13
- {specmatic-0.9.0 → specmatic-0.9.1}/specmatic/core/specmatic.py +66 -59
- {specmatic-0.9.0 → specmatic-0.9.1}/specmatic/servers/asgi_app_server.py +3 -0
- {specmatic-0.9.0 → specmatic-0.9.1}/specmatic/version.py +1 -1
- {specmatic-0.9.0 → specmatic-0.9.1/specmatic.egg-info}/PKG-INFO +7 -14
- {specmatic-0.9.0 → specmatic-0.9.1}/MANIFEST.in +0 -0
- {specmatic-0.9.0 → specmatic-0.9.1}/setup.cfg +0 -0
- {specmatic-0.9.0 → specmatic-0.9.1}/setup.py +0 -0
- {specmatic-0.9.0 → specmatic-0.9.1}/specmatic/__init__.py +0 -0
- {specmatic-0.9.0 → specmatic-0.9.1}/specmatic/core/__init__.py +0 -0
- {specmatic-0.9.0 → specmatic-0.9.1}/specmatic/core/decorators.py +0 -0
- {specmatic-0.9.0 → specmatic-0.9.1}/specmatic/core/specmatic.jar +0 -0
- {specmatic-0.9.0 → specmatic-0.9.1}/specmatic/core/specmatic_base.py +0 -0
- {specmatic-0.9.0 → specmatic-0.9.1}/specmatic/core/specmatic_stub.py +0 -0
- {specmatic-0.9.0 → specmatic-0.9.1}/specmatic/core/specmatic_test.py +0 -0
- {specmatic-0.9.0 → specmatic-0.9.1}/specmatic/generators/__init__.py +0 -0
- {specmatic-0.9.0 → specmatic-0.9.1}/specmatic/generators/pytest_generator.py +0 -0
- {specmatic-0.9.0 → specmatic-0.9.1}/specmatic/generators/test_generator_base.py +0 -0
- {specmatic-0.9.0 → specmatic-0.9.1}/specmatic/generators/unittest_generator.py +0 -0
- {specmatic-0.9.0 → specmatic-0.9.1}/specmatic/servers/__init__.py +0 -0
- {specmatic-0.9.0 → specmatic-0.9.1}/specmatic/servers/app_server.py +0 -0
- {specmatic-0.9.0 → specmatic-0.9.1}/specmatic/servers/wsgi_app_server.py +0 -0
- {specmatic-0.9.0 → specmatic-0.9.1}/specmatic/servers/wsgi_server_thread.py +0 -0
- {specmatic-0.9.0 → specmatic-0.9.1}/specmatic/utils.py +0 -0
- {specmatic-0.9.0 → specmatic-0.9.1}/specmatic.egg-info/SOURCES.txt +0 -0
- {specmatic-0.9.0 → specmatic-0.9.1}/specmatic.egg-info/dependency_links.txt +0 -0
- {specmatic-0.9.0 → specmatic-0.9.1}/specmatic.egg-info/requires.txt +0 -0
- {specmatic-0.9.0 → specmatic-0.9.1}/specmatic.egg-info/top_level.txt +0 -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
|
|
@@ -50,9 +50,7 @@ class TestContract:
|
|
|
50
50
|
Specmatic() \
|
|
51
51
|
.with_project_root(PROJECT_ROOT) \
|
|
52
52
|
.with_stub(stub_host, stub_port, [expectation_json_file]) \
|
|
53
|
-
.
|
|
54
|
-
.with_app_host(app_host)\
|
|
55
|
-
.with_app_port(app_port)\
|
|
53
|
+
.with_wsgi_app(app, app_host, app_port) \
|
|
56
54
|
.test(TestContract) \
|
|
57
55
|
.run()
|
|
58
56
|
``````
|
|
@@ -79,9 +77,7 @@ class TestContract:
|
|
|
79
77
|
|
|
80
78
|
Specmatic() \
|
|
81
79
|
.with_project_root(PROJECT_ROOT) \
|
|
82
|
-
.
|
|
83
|
-
.with_app_host(app_host)\
|
|
84
|
-
.with_app_port(app_port)\
|
|
80
|
+
.with_wsgi_app(app, app_host, app_port) \
|
|
85
81
|
.test(TestContract) \
|
|
86
82
|
.run()
|
|
87
83
|
``````
|
|
@@ -89,7 +85,7 @@ Specmatic() \
|
|
|
89
85
|
## ASGI Apps
|
|
90
86
|
|
|
91
87
|
#### To run contract tests with a stub for an asgi app (like sanic):
|
|
92
|
-
- If you are using an asgi app like sanic, fastapi, use the ``````
|
|
88
|
+
- 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.
|
|
93
89
|
``````
|
|
94
90
|
class TestContract:
|
|
95
91
|
pass
|
|
@@ -98,9 +94,7 @@ class TestContract:
|
|
|
98
94
|
Specmatic() \
|
|
99
95
|
.with_project_root(PROJECT_ROOT) \
|
|
100
96
|
.with_stub(stub_host, stub_port, [expectation_json_file]) \
|
|
101
|
-
.
|
|
102
|
-
.with_app_host(app_host) \
|
|
103
|
-
.with_app_port(app_port) \
|
|
97
|
+
.with_asgi_app('main:app', app_host, app_port) \
|
|
104
98
|
.test(TestContract) \
|
|
105
99
|
.run()
|
|
106
100
|
``````
|
|
@@ -115,15 +109,14 @@ class TestContract:
|
|
|
115
109
|
Specmatic() \
|
|
116
110
|
.with_project_root(PROJECT_ROOT) \
|
|
117
111
|
.with_stub(stub_host, stub_port, [expectation_json_file], ['--strict']) \
|
|
118
|
-
.
|
|
119
|
-
.with_app_port(app_port) \
|
|
112
|
+
.with_wsgi_app(app, port=app_port) \
|
|
120
113
|
.test(TestContract, args=['--testBaseURL=http://localhost:5000']) \
|
|
121
114
|
.run()
|
|
122
115
|
``````
|
|
123
116
|
|
|
124
117
|
## Common Issues
|
|
125
118
|
- **'Error loading ASGI app'**
|
|
126
|
-
This error occurs
|
|
119
|
+
This error occurs when an incorrect app module string is passed to the ``````with_asgi_app`````` function.
|
|
127
120
|
|
|
128
121
|
#### Solutions:
|
|
129
122
|
- Try to identify the correct module in which your app variable is instantiated/imported.
|
|
@@ -41,9 +41,7 @@ class TestContract:
|
|
|
41
41
|
Specmatic() \
|
|
42
42
|
.with_project_root(PROJECT_ROOT) \
|
|
43
43
|
.with_stub(stub_host, stub_port, [expectation_json_file]) \
|
|
44
|
-
.
|
|
45
|
-
.with_app_host(app_host)\
|
|
46
|
-
.with_app_port(app_port)\
|
|
44
|
+
.with_wsgi_app(app, app_host, app_port) \
|
|
47
45
|
.test(TestContract) \
|
|
48
46
|
.run()
|
|
49
47
|
``````
|
|
@@ -70,9 +68,7 @@ class TestContract:
|
|
|
70
68
|
|
|
71
69
|
Specmatic() \
|
|
72
70
|
.with_project_root(PROJECT_ROOT) \
|
|
73
|
-
.
|
|
74
|
-
.with_app_host(app_host)\
|
|
75
|
-
.with_app_port(app_port)\
|
|
71
|
+
.with_wsgi_app(app, app_host, app_port) \
|
|
76
72
|
.test(TestContract) \
|
|
77
73
|
.run()
|
|
78
74
|
``````
|
|
@@ -80,7 +76,7 @@ Specmatic() \
|
|
|
80
76
|
## ASGI Apps
|
|
81
77
|
|
|
82
78
|
#### To run contract tests with a stub for an asgi app (like sanic):
|
|
83
|
-
- If you are using an asgi app like sanic, fastapi, use the ``````
|
|
79
|
+
- 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.
|
|
84
80
|
``````
|
|
85
81
|
class TestContract:
|
|
86
82
|
pass
|
|
@@ -89,9 +85,7 @@ class TestContract:
|
|
|
89
85
|
Specmatic() \
|
|
90
86
|
.with_project_root(PROJECT_ROOT) \
|
|
91
87
|
.with_stub(stub_host, stub_port, [expectation_json_file]) \
|
|
92
|
-
.
|
|
93
|
-
.with_app_host(app_host) \
|
|
94
|
-
.with_app_port(app_port) \
|
|
88
|
+
.with_asgi_app('main:app', app_host, app_port) \
|
|
95
89
|
.test(TestContract) \
|
|
96
90
|
.run()
|
|
97
91
|
``````
|
|
@@ -106,15 +100,14 @@ class TestContract:
|
|
|
106
100
|
Specmatic() \
|
|
107
101
|
.with_project_root(PROJECT_ROOT) \
|
|
108
102
|
.with_stub(stub_host, stub_port, [expectation_json_file], ['--strict']) \
|
|
109
|
-
.
|
|
110
|
-
.with_app_port(app_port) \
|
|
103
|
+
.with_wsgi_app(app, port=app_port) \
|
|
111
104
|
.test(TestContract, args=['--testBaseURL=http://localhost:5000']) \
|
|
112
105
|
.run()
|
|
113
106
|
``````
|
|
114
107
|
|
|
115
108
|
## Common Issues
|
|
116
109
|
- **'Error loading ASGI app'**
|
|
117
|
-
This error occurs
|
|
110
|
+
This error occurs when an incorrect app module string is passed to the ``````with_asgi_app`````` function.
|
|
118
111
|
|
|
119
112
|
#### Solutions:
|
|
120
113
|
- Try to identify the correct module in which your app variable is instantiated/imported.
|
|
@@ -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)
|
|
@@ -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
|
|
@@ -50,9 +50,7 @@ class TestContract:
|
|
|
50
50
|
Specmatic() \
|
|
51
51
|
.with_project_root(PROJECT_ROOT) \
|
|
52
52
|
.with_stub(stub_host, stub_port, [expectation_json_file]) \
|
|
53
|
-
.
|
|
54
|
-
.with_app_host(app_host)\
|
|
55
|
-
.with_app_port(app_port)\
|
|
53
|
+
.with_wsgi_app(app, app_host, app_port) \
|
|
56
54
|
.test(TestContract) \
|
|
57
55
|
.run()
|
|
58
56
|
``````
|
|
@@ -79,9 +77,7 @@ class TestContract:
|
|
|
79
77
|
|
|
80
78
|
Specmatic() \
|
|
81
79
|
.with_project_root(PROJECT_ROOT) \
|
|
82
|
-
.
|
|
83
|
-
.with_app_host(app_host)\
|
|
84
|
-
.with_app_port(app_port)\
|
|
80
|
+
.with_wsgi_app(app, app_host, app_port) \
|
|
85
81
|
.test(TestContract) \
|
|
86
82
|
.run()
|
|
87
83
|
``````
|
|
@@ -89,7 +85,7 @@ Specmatic() \
|
|
|
89
85
|
## ASGI Apps
|
|
90
86
|
|
|
91
87
|
#### To run contract tests with a stub for an asgi app (like sanic):
|
|
92
|
-
- If you are using an asgi app like sanic, fastapi, use the ``````
|
|
88
|
+
- 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.
|
|
93
89
|
``````
|
|
94
90
|
class TestContract:
|
|
95
91
|
pass
|
|
@@ -98,9 +94,7 @@ class TestContract:
|
|
|
98
94
|
Specmatic() \
|
|
99
95
|
.with_project_root(PROJECT_ROOT) \
|
|
100
96
|
.with_stub(stub_host, stub_port, [expectation_json_file]) \
|
|
101
|
-
.
|
|
102
|
-
.with_app_host(app_host) \
|
|
103
|
-
.with_app_port(app_port) \
|
|
97
|
+
.with_asgi_app('main:app', app_host, app_port) \
|
|
104
98
|
.test(TestContract) \
|
|
105
99
|
.run()
|
|
106
100
|
``````
|
|
@@ -115,15 +109,14 @@ class TestContract:
|
|
|
115
109
|
Specmatic() \
|
|
116
110
|
.with_project_root(PROJECT_ROOT) \
|
|
117
111
|
.with_stub(stub_host, stub_port, [expectation_json_file], ['--strict']) \
|
|
118
|
-
.
|
|
119
|
-
.with_app_port(app_port) \
|
|
112
|
+
.with_wsgi_app(app, port=app_port) \
|
|
120
113
|
.test(TestContract, args=['--testBaseURL=http://localhost:5000']) \
|
|
121
114
|
.run()
|
|
122
115
|
``````
|
|
123
116
|
|
|
124
117
|
## Common Issues
|
|
125
118
|
- **'Error loading ASGI app'**
|
|
126
|
-
This error occurs
|
|
119
|
+
This error occurs when an incorrect app module string is passed to the ``````with_asgi_app`````` function.
|
|
127
120
|
|
|
128
121
|
#### Solutions:
|
|
129
122
|
- Try to identify the correct module in which your app variable is instantiated/imported.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|