specmatic 0.7.7__tar.gz → 0.7.9__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.

Files changed (36) hide show
  1. {specmatic-0.7.7/specmatic.egg-info → specmatic-0.7.9}/PKG-INFO +44 -2
  2. {specmatic-0.7.7 → specmatic-0.7.9}/README.md +43 -1
  3. {specmatic-0.7.7 → specmatic-0.7.9}/setup.py +6 -20
  4. {specmatic-0.7.7 → specmatic-0.7.9}/specmatic/version.py +1 -1
  5. {specmatic-0.7.7 → specmatic-0.7.9/specmatic.egg-info}/PKG-INFO +44 -2
  6. {specmatic-0.7.7 → specmatic-0.7.9}/specmatic.egg-info/SOURCES.txt +1 -8
  7. specmatic-0.7.7/test/test_contract_using_api.py +0 -32
  8. specmatic-0.7.7/test/test_contract_using_api_with_autowiring.py +0 -38
  9. specmatic-0.7.7/test/test_contract_using_api_with_central_repo.py +0 -27
  10. specmatic-0.7.7/test/test_contract_using_decorators.py +0 -25
  11. specmatic-0.7.7/test/test_contract_using_decorators_with_central_repo.py +0 -24
  12. specmatic-0.7.7/test/test_contract_with_sanic_app.py +0 -34
  13. specmatic-0.7.7/test/test_contract_with_sanic_app_with_autowiring.py +0 -51
  14. {specmatic-0.7.7 → specmatic-0.7.9}/MANIFEST.in +0 -0
  15. {specmatic-0.7.7 → specmatic-0.7.9}/setup.cfg +0 -0
  16. {specmatic-0.7.7 → specmatic-0.7.9}/specmatic/__init__.py +0 -0
  17. {specmatic-0.7.7 → specmatic-0.7.9}/specmatic/core/__init__.py +0 -0
  18. {specmatic-0.7.7 → specmatic-0.7.9}/specmatic/core/decorators.py +0 -0
  19. {specmatic-0.7.7 → specmatic-0.7.9}/specmatic/core/specmatic.jar +0 -0
  20. {specmatic-0.7.7 → specmatic-0.7.9}/specmatic/core/specmatic.py +0 -0
  21. {specmatic-0.7.7 → specmatic-0.7.9}/specmatic/core/specmatic_base.py +0 -0
  22. {specmatic-0.7.7 → specmatic-0.7.9}/specmatic/core/specmatic_stub.py +0 -0
  23. {specmatic-0.7.7 → specmatic-0.7.9}/specmatic/core/specmatic_test.py +0 -0
  24. {specmatic-0.7.7 → specmatic-0.7.9}/specmatic/generators/__init__.py +0 -0
  25. {specmatic-0.7.7 → specmatic-0.7.9}/specmatic/generators/pytest_generator.py +0 -0
  26. {specmatic-0.7.7 → specmatic-0.7.9}/specmatic/generators/test_generator_base.py +0 -0
  27. {specmatic-0.7.7 → specmatic-0.7.9}/specmatic/generators/unittest_generator.py +0 -0
  28. {specmatic-0.7.7 → specmatic-0.7.9}/specmatic/servers/__init__.py +0 -0
  29. {specmatic-0.7.7 → specmatic-0.7.9}/specmatic/servers/app_server.py +0 -0
  30. {specmatic-0.7.7 → specmatic-0.7.9}/specmatic/servers/asgi_server_thread.py +0 -0
  31. {specmatic-0.7.7 → specmatic-0.7.9}/specmatic/servers/wsgi_server.py +0 -0
  32. {specmatic-0.7.7 → specmatic-0.7.9}/specmatic/servers/wsgi_server_thread.py +0 -0
  33. {specmatic-0.7.7 → specmatic-0.7.9}/specmatic/utils.py +0 -0
  34. {specmatic-0.7.7 → specmatic-0.7.9}/specmatic.egg-info/dependency_links.txt +0 -0
  35. {specmatic-0.7.7 → specmatic-0.7.9}/specmatic.egg-info/requires.txt +0 -0
  36. {specmatic-0.7.7 → specmatic-0.7.9}/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.7.7
3
+ Version: 0.7.9
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
@@ -28,6 +28,8 @@ The open api specification can be present either locally or in a [Central Contra
28
28
  - Declare an empty class in it called 'TestContract'.
29
29
  Specmatic will use this class to inject tests dynamically into it when you run it via say PyTest.
30
30
 
31
+ ## WSGI Apps
32
+
31
33
  #### To run contract tests with a stub for a wsgi app (like Flask):
32
34
  ``````
33
35
  class TestContract:
@@ -55,6 +57,35 @@ Specmatic.test_wsgi_app(app,
55
57
  - You can run this test from either your IDE or command line by pointing pytest to your test folder:
56
58
  ``````pytest test -v -s``````
57
59
  - NOTE: Please ensure that you set the '-v' and '-s' flags while running pytest as otherwise pytest may swallow up the console output.
60
+ - [Click here](https://specmatic.in/documentation/service_virtualization_tutorial.html) to learn more about stubbing/service virtualization.
61
+
62
+ #### To run contract tests using a central contract repository:
63
+
64
+ ``````
65
+ Specmatic.test_wsgi_app(app,
66
+ TestContract,
67
+ project_root=PROJECT_ROOT,
68
+ stub_host=stub_host,
69
+ stub_port=stub_port,
70
+ expectation_files=[expectation_json_file])
71
+ ``````
72
+
73
+ - When using a [central contract repository](https://specmatic.in/documentation/central_contract_repository.html), provide the absolute path to the root folder
74
+ of your application in the 'project_root' parameter.
75
+ - You would need to have a specmatic.json file in your project root directory. [Click here](https://specmatic.in/documentation/central_contract_repository.html#specmaticjson) to learn
76
+ more about the specmatic.json file.
77
+
78
+
79
+ #### To run contract tests without a stub, set the 'with_stub' parameter as False:
80
+
81
+ ``````
82
+ Specmatic.test_wsgi_app(app,
83
+ TestContract,
84
+ with_stub=False,
85
+ project_root=ROOT_DIR)
86
+ ``````
87
+
88
+ ## ASGI Apps
58
89
 
59
90
  #### To run contract tests with a stub for an asgi app (like sanic):
60
91
  ``````
@@ -73,7 +104,18 @@ Specmatic.test_asgi_app('main:app',
73
104
  - the rest of the arguments are similar to that of the ``````Specmatic.test_wsgi_app()`````` method.
74
105
 
75
106
 
76
- - [Click here](https://specmatic.in/documentation/service_virtualization_tutorial.html) to learn more about stubbing/service virtualization.
107
+ ## Common Issues
108
+ - **'Error loading ASGI app'** error when running Specmatic.test_asgi_app()
109
+ This error occurs due to incorrect module being specified in the app module parameter 'module:app' string.
110
+
111
+ #### Solutions:
112
+ - Try to identify the correct module in which your app variable is instantiated/imported.
113
+ For example if your 'app' variable is declared in main.py, try passing 'main:app'.
114
+ - Try running the app using uvicorn directly:
115
+ `````` uvciron 'main:app' ``````
116
+ If you are able to get the app started using uvicorn, it will work with specmatic too.
117
+
118
+ ## Sample Projects
77
119
  - [Check out the Specmatic Order BFF Python repo](https://github.com/znsio/specmatic-order-bff-python/) to see more examples of how to use specmatic with a Flask app.
78
120
  - [Check out the Specmatic Order BFF Python Sanic repo](https://github.com/znsio/specmatic-order-bff-python-sanic/) to see more examples of how to use specmatic with a Sanic app.
79
121
  - [Check out the Specmatic Order API Python repo](https://github.com/znsio/specmatic-order-api-python/) to see an examples of how to just run tests without using a stub.
@@ -19,6 +19,8 @@ The open api specification can be present either locally or in a [Central Contra
19
19
  - Declare an empty class in it called 'TestContract'.
20
20
  Specmatic will use this class to inject tests dynamically into it when you run it via say PyTest.
21
21
 
22
+ ## WSGI Apps
23
+
22
24
  #### To run contract tests with a stub for a wsgi app (like Flask):
23
25
  ``````
24
26
  class TestContract:
@@ -46,6 +48,35 @@ Specmatic.test_wsgi_app(app,
46
48
  - You can run this test from either your IDE or command line by pointing pytest to your test folder:
47
49
  ``````pytest test -v -s``````
48
50
  - NOTE: Please ensure that you set the '-v' and '-s' flags while running pytest as otherwise pytest may swallow up the console output.
51
+ - [Click here](https://specmatic.in/documentation/service_virtualization_tutorial.html) to learn more about stubbing/service virtualization.
52
+
53
+ #### To run contract tests using a central contract repository:
54
+
55
+ ``````
56
+ Specmatic.test_wsgi_app(app,
57
+ TestContract,
58
+ project_root=PROJECT_ROOT,
59
+ stub_host=stub_host,
60
+ stub_port=stub_port,
61
+ expectation_files=[expectation_json_file])
62
+ ``````
63
+
64
+ - When using a [central contract repository](https://specmatic.in/documentation/central_contract_repository.html), provide the absolute path to the root folder
65
+ of your application in the 'project_root' parameter.
66
+ - You would need to have a specmatic.json file in your project root directory. [Click here](https://specmatic.in/documentation/central_contract_repository.html#specmaticjson) to learn
67
+ more about the specmatic.json file.
68
+
69
+
70
+ #### To run contract tests without a stub, set the 'with_stub' parameter as False:
71
+
72
+ ``````
73
+ Specmatic.test_wsgi_app(app,
74
+ TestContract,
75
+ with_stub=False,
76
+ project_root=ROOT_DIR)
77
+ ``````
78
+
79
+ ## ASGI Apps
49
80
 
50
81
  #### To run contract tests with a stub for an asgi app (like sanic):
51
82
  ``````
@@ -64,7 +95,18 @@ Specmatic.test_asgi_app('main:app',
64
95
  - the rest of the arguments are similar to that of the ``````Specmatic.test_wsgi_app()`````` method.
65
96
 
66
97
 
67
- - [Click here](https://specmatic.in/documentation/service_virtualization_tutorial.html) to learn more about stubbing/service virtualization.
98
+ ## Common Issues
99
+ - **'Error loading ASGI app'** error when running Specmatic.test_asgi_app()
100
+ This error occurs due to incorrect module being specified in the app module parameter 'module:app' string.
101
+
102
+ #### Solutions:
103
+ - Try to identify the correct module in which your app variable is instantiated/imported.
104
+ For example if your 'app' variable is declared in main.py, try passing 'main:app'.
105
+ - Try running the app using uvicorn directly:
106
+ `````` uvciron 'main:app' ``````
107
+ If you are able to get the app started using uvicorn, it will work with specmatic too.
108
+
109
+ ## Sample Projects
68
110
  - [Check out the Specmatic Order BFF Python repo](https://github.com/znsio/specmatic-order-bff-python/) to see more examples of how to use specmatic with a Flask app.
69
111
  - [Check out the Specmatic Order BFF Python Sanic repo](https://github.com/znsio/specmatic-order-bff-python-sanic/) to see more examples of how to use specmatic with a Sanic app.
70
112
  - [Check out the Specmatic Order API Python repo](https://github.com/znsio/specmatic-order-api-python/) to see an examples of how to just run tests without using a stub.
@@ -2,24 +2,10 @@ import os
2
2
  from pathlib import Path
3
3
 
4
4
  from setuptools import setup, find_packages
5
- import urllib.request
6
5
 
6
+ from build_utils import get_version, download_specmatic_jar
7
7
 
8
- def download_specmatic_jar(version):
9
- file_url = f'https://github.com/znsio/specmatic/releases/download/{version}/specmatic.jar'
10
- file_path = 'specmatic/core/specmatic.jar'
11
- print(f"Downloading core jar from: {file_url}")
12
- urllib.request.urlretrieve(file_url, file_path)
13
-
14
-
15
- def get_version():
16
- version = {}
17
- with open(os.path.join('specmatic', 'version.py')) as file:
18
- exec(file.read(), version)
19
- return version
20
-
21
-
22
- version = get_version()
8
+ version = get_version(os.path.join('specmatic', 'version.py'))
23
9
 
24
10
  download_specmatic_jar(version['__specmatic_version__'])
25
11
 
@@ -38,9 +24,9 @@ setup(
38
24
  packages=find_packages(exclude=['test', 'test.*']),
39
25
  include_package_data=True,
40
26
  install_requires=[
41
- 'pytest==7.3.1',
42
- 'requests>=2.0.0',
43
- 'Werkzeug==2.3.3',
44
- 'uvicorn>=0.18.0'
27
+ 'pytest==7.3.1',
28
+ 'requests>=2.0.0',
29
+ 'Werkzeug==2.3.3',
30
+ 'uvicorn>=0.18.0'
45
31
  ]
46
32
  )
@@ -1,2 +1,2 @@
1
- __version__ = '0.7.7'
1
+ __version__ = '0.7.9'
2
2
  __specmatic_version__ = '0.67.0'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: specmatic
3
- Version: 0.7.7
3
+ Version: 0.7.9
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
@@ -28,6 +28,8 @@ The open api specification can be present either locally or in a [Central Contra
28
28
  - Declare an empty class in it called 'TestContract'.
29
29
  Specmatic will use this class to inject tests dynamically into it when you run it via say PyTest.
30
30
 
31
+ ## WSGI Apps
32
+
31
33
  #### To run contract tests with a stub for a wsgi app (like Flask):
32
34
  ``````
33
35
  class TestContract:
@@ -55,6 +57,35 @@ Specmatic.test_wsgi_app(app,
55
57
  - You can run this test from either your IDE or command line by pointing pytest to your test folder:
56
58
  ``````pytest test -v -s``````
57
59
  - NOTE: Please ensure that you set the '-v' and '-s' flags while running pytest as otherwise pytest may swallow up the console output.
60
+ - [Click here](https://specmatic.in/documentation/service_virtualization_tutorial.html) to learn more about stubbing/service virtualization.
61
+
62
+ #### To run contract tests using a central contract repository:
63
+
64
+ ``````
65
+ Specmatic.test_wsgi_app(app,
66
+ TestContract,
67
+ project_root=PROJECT_ROOT,
68
+ stub_host=stub_host,
69
+ stub_port=stub_port,
70
+ expectation_files=[expectation_json_file])
71
+ ``````
72
+
73
+ - When using a [central contract repository](https://specmatic.in/documentation/central_contract_repository.html), provide the absolute path to the root folder
74
+ of your application in the 'project_root' parameter.
75
+ - You would need to have a specmatic.json file in your project root directory. [Click here](https://specmatic.in/documentation/central_contract_repository.html#specmaticjson) to learn
76
+ more about the specmatic.json file.
77
+
78
+
79
+ #### To run contract tests without a stub, set the 'with_stub' parameter as False:
80
+
81
+ ``````
82
+ Specmatic.test_wsgi_app(app,
83
+ TestContract,
84
+ with_stub=False,
85
+ project_root=ROOT_DIR)
86
+ ``````
87
+
88
+ ## ASGI Apps
58
89
 
59
90
  #### To run contract tests with a stub for an asgi app (like sanic):
60
91
  ``````
@@ -73,7 +104,18 @@ Specmatic.test_asgi_app('main:app',
73
104
  - the rest of the arguments are similar to that of the ``````Specmatic.test_wsgi_app()`````` method.
74
105
 
75
106
 
76
- - [Click here](https://specmatic.in/documentation/service_virtualization_tutorial.html) to learn more about stubbing/service virtualization.
107
+ ## Common Issues
108
+ - **'Error loading ASGI app'** error when running Specmatic.test_asgi_app()
109
+ This error occurs due to incorrect module being specified in the app module parameter 'module:app' string.
110
+
111
+ #### Solutions:
112
+ - Try to identify the correct module in which your app variable is instantiated/imported.
113
+ For example if your 'app' variable is declared in main.py, try passing 'main:app'.
114
+ - Try running the app using uvicorn directly:
115
+ `````` uvciron 'main:app' ``````
116
+ If you are able to get the app started using uvicorn, it will work with specmatic too.
117
+
118
+ ## Sample Projects
77
119
  - [Check out the Specmatic Order BFF Python repo](https://github.com/znsio/specmatic-order-bff-python/) to see more examples of how to use specmatic with a Flask app.
78
120
  - [Check out the Specmatic Order BFF Python Sanic repo](https://github.com/znsio/specmatic-order-bff-python-sanic/) to see more examples of how to use specmatic with a Sanic app.
79
121
  - [Check out the Specmatic Order API Python repo](https://github.com/znsio/specmatic-order-api-python/) to see an examples of how to just run tests without using a stub.
@@ -24,11 +24,4 @@ specmatic/servers/__init__.py
24
24
  specmatic/servers/app_server.py
25
25
  specmatic/servers/asgi_server_thread.py
26
26
  specmatic/servers/wsgi_server.py
27
- specmatic/servers/wsgi_server_thread.py
28
- test/test_contract_using_api.py
29
- test/test_contract_using_api_with_autowiring.py
30
- test/test_contract_using_api_with_central_repo.py
31
- test/test_contract_using_decorators.py
32
- test/test_contract_using_decorators_with_central_repo.py
33
- test/test_contract_with_sanic_app.py
34
- test/test_contract_with_sanic_app_with_autowiring.py
27
+ specmatic/servers/wsgi_server_thread.py
@@ -1,32 +0,0 @@
1
- import pytest
2
-
3
- from specmatic.core.specmatic import Specmatic
4
- from specmatic.utils import get_project_root
5
- from test.flask_app import app
6
-
7
- app_host = "127.0.0.1"
8
- app_port = 5000
9
- stub_host = "127.0.0.1"
10
- stub_port = 8080
11
- PROJECT_ROOT = get_project_root()
12
- expectation_json_file = PROJECT_ROOT + '/test/data/expectation.json'
13
- app_contract_file = PROJECT_ROOT + '/test/spec/product-search-bff-api.yaml'
14
- stub_contract_file = PROJECT_ROOT + '/test/spec/api_order_v1.yaml'
15
-
16
-
17
- class TestContract:
18
- pass
19
-
20
-
21
- Specmatic.test_wsgi_app(app,
22
- TestContract,
23
- app_contracts=[app_contract_file],
24
- stub_contracts=[stub_contract_file],
25
- app_host=app_host,
26
- app_port=app_port,
27
- stub_host=stub_host,
28
- stub_port=stub_port,
29
- expectation_files=[expectation_json_file])
30
-
31
- if __name__ == '__main__':
32
- pytest.main()
@@ -1,38 +0,0 @@
1
- import os
2
-
3
- import pytest
4
-
5
- from specmatic.core.specmatic import Specmatic
6
- from specmatic.utils import get_project_root
7
- from test.flask_app import app
8
-
9
- stub_host = "127.0.0.1"
10
- stub_port = 8080
11
- PROJECT_ROOT = get_project_root()
12
- expectation_json_file = PROJECT_ROOT + '/test/data/expectation.json'
13
-
14
-
15
- class TestContract:
16
- pass
17
-
18
-
19
- def update_app_config_with_stub_info(app, host: str, port: int):
20
- app.config['ORDER_API_HOST'] = host
21
- app.config['ORDER_API_PORT'] = str(port)
22
-
23
-
24
- def reset_app_config(app):
25
- app.config["ORDER_API_HOST"] = os.getenv("ORDER_API_HOST")
26
- app.config["ORDER_API_PORT"] = os.getenv("ORDER_API_PORT")
27
-
28
-
29
- Specmatic.test_wsgi_app(app,
30
- TestContract,
31
- project_root=PROJECT_ROOT,
32
- expectation_files=[expectation_json_file],
33
- app_config_update_func=update_app_config_with_stub_info)
34
-
35
- reset_app_config(app)
36
-
37
- if __name__ == '__main__':
38
- pytest.main()
@@ -1,27 +0,0 @@
1
- import pytest
2
-
3
- from specmatic.core.specmatic import Specmatic
4
- from specmatic.utils import get_project_root
5
- from test.flask_app import app
6
-
7
- app_host = "127.0.0.1"
8
- app_port = 5000
9
- stub_host = "127.0.0.1"
10
- stub_port = 8080
11
- PROJECT_ROOT = get_project_root()
12
- expectation_json_file = PROJECT_ROOT + '/test/data/expectation.json'
13
-
14
-
15
- class TestContract:
16
- pass
17
-
18
-
19
- Specmatic.test_wsgi_app(app,
20
- TestContract,
21
- project_root=PROJECT_ROOT,
22
- stub_host=stub_host,
23
- stub_port=stub_port,
24
- expectation_files=[expectation_json_file])
25
-
26
- if __name__ == '__main__':
27
- pytest.main()
@@ -1,25 +0,0 @@
1
- import pytest
2
-
3
- from specmatic.core.decorators import specmatic_contract_test, specmatic_stub, start_wsgi_app
4
- from specmatic.utils import get_project_root
5
- from test.flask_app import app
6
-
7
- app_host = "127.0.0.1"
8
- app_port = 5000
9
- stub_host = "127.0.0.1"
10
- stub_port = 8080
11
- PROJECT_ROOT = get_project_root()
12
- expectation_json_file = PROJECT_ROOT + '/test/data/expectation.json'
13
- service_contract_file = PROJECT_ROOT + '/test/spec/product-search-bff-api.yaml'
14
- stub_contract_file = PROJECT_ROOT + '/test/spec/api_order_v1.yaml'
15
-
16
-
17
- @specmatic_contract_test(app_host, app_port, contract_files=[service_contract_file])
18
- @start_wsgi_app(app, app_host, app_port)
19
- @specmatic_stub(stub_host, stub_port, expectations=[expectation_json_file], contract_files=[stub_contract_file])
20
- class TestContractWithLocalSpecs:
21
- pass
22
-
23
-
24
- if __name__ == '__main__':
25
- pytest.main()
@@ -1,24 +0,0 @@
1
- import pytest
2
-
3
- from specmatic.core.decorators import specmatic_contract_test, specmatic_stub, start_wsgi_app
4
- from specmatic.utils import get_project_root
5
- from test.flask_app import app
6
-
7
- app_host = "127.0.0.1"
8
- app_port = 5000
9
- stub_host = "127.0.0.1"
10
- stub_port = 8080
11
- PROJECT_ROOT = get_project_root()
12
- APP_ROOT = PROJECT_ROOT + '/test'
13
- expectation_json_file = PROJECT_ROOT + '/test/data/expectation.json'
14
-
15
-
16
- @specmatic_contract_test(project_root=PROJECT_ROOT)
17
- @start_wsgi_app(app)
18
- @specmatic_stub(stub_host, stub_port, PROJECT_ROOT, [expectation_json_file])
19
- class TestContract:
20
- pass
21
-
22
-
23
- if __name__ == '__main__':
24
- pytest.main()
@@ -1,34 +0,0 @@
1
- import pytest
2
-
3
- from specmatic.core.specmatic import Specmatic
4
- from specmatic.utils import get_project_root
5
-
6
- PROJECT_ROOT = get_project_root()
7
-
8
- app_host = "127.0.0.1"
9
- app_port = 8000
10
- stub_host = "127.0.0.1"
11
- stub_port = 8080
12
-
13
- expectation_json_file = PROJECT_ROOT + '/test/data/expectation.json'
14
- app_contract_file = PROJECT_ROOT + '/test/spec/product-search-bff-api.yaml'
15
- stub_contract_file = PROJECT_ROOT + '/test/spec/api_order_v1.yaml'
16
- app_module = PROJECT_ROOT + '/test/sanic_app'
17
-
18
-
19
- class TestContract:
20
- pass
21
-
22
-
23
- Specmatic.test_asgi_app('test.sanic_app:app',
24
- TestContract,
25
- app_contracts=[app_contract_file],
26
- stub_contracts=[stub_contract_file],
27
- app_host=app_host,
28
- app_port=app_port,
29
- stub_host=stub_host,
30
- stub_port=stub_port,
31
- expectation_files=[expectation_json_file])
32
-
33
- if __name__ == '__main__':
34
- pytest.main()
@@ -1,51 +0,0 @@
1
- import pytest
2
- import configparser
3
-
4
- from specmatic.core.specmatic import Specmatic
5
- from specmatic.utils import get_project_root
6
-
7
- PROJECT_ROOT = get_project_root()
8
-
9
- app_host = "127.0.0.1"
10
- app_port = 8000
11
- stub_host = "127.0.0.1"
12
- stub_port = 8080
13
-
14
- expectation_json_file = PROJECT_ROOT + '/test/data/expectation.json'
15
- app_contract_file = PROJECT_ROOT + '/test/spec/product-search-bff-api.yaml'
16
- stub_contract_file = PROJECT_ROOT + '/test/spec/api_order_v1.yaml'
17
- app_module = PROJECT_ROOT + '/test/sanic_app'
18
-
19
-
20
- class TestContract:
21
- pass
22
-
23
-
24
- def update_app_config_with_stub_info(host: str, port: int):
25
- config = configparser.ConfigParser()
26
- config.read('config.ini')
27
- config['dev']['ORDER_API_HOST'] = host
28
- config['dev']['ORDER_API_PORT'] = str(port)
29
- with open('./../config.ini', 'w') as configfile:
30
- config.write(configfile)
31
-
32
-
33
- def reset_app_config():
34
- config = configparser.ConfigParser()
35
- config.read('config.ini')
36
- config['dev']['ORDER_API_HOST'] = '127.0.0.1'
37
- config['dev']['ORDER_API_PORT'] = '8080'
38
- with open('./../config.ini', 'w') as configfile:
39
- config.write(configfile)
40
-
41
-
42
- Specmatic.test_asgi_app('test.sanic_app:app',
43
- TestContract,
44
- project_root=PROJECT_ROOT,
45
- expectation_files=[expectation_json_file],
46
- app_config_update_func=update_app_config_with_stub_info)
47
-
48
- reset_app_config()
49
-
50
- if __name__ == '__main__':
51
- pytest.main()
File without changes
File without changes
File without changes