surety-api 0.0.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 (38) hide show
  1. surety_api-0.0.1/.github/workflows/publish.yml +30 -0
  2. surety_api-0.0.1/.github/workflows/pylint.yml +24 -0
  3. surety_api-0.0.1/.github/workflows/release.yml +41 -0
  4. surety_api-0.0.1/.github/workflows/test.yml +53 -0
  5. surety_api-0.0.1/.gitignore +210 -0
  6. surety_api-0.0.1/.pylintrc +48 -0
  7. surety_api-0.0.1/LICENSE +21 -0
  8. surety_api-0.0.1/PKG-INFO +37 -0
  9. surety_api-0.0.1/README.md +15 -0
  10. surety_api-0.0.1/etc/config.yaml +5 -0
  11. surety_api-0.0.1/pyproject.toml +44 -0
  12. surety_api-0.0.1/requirements/common.txt +7 -0
  13. surety_api-0.0.1/requirements/test.txt +7 -0
  14. surety_api-0.0.1/setup.cfg +4 -0
  15. surety_api-0.0.1/surety/api/__init__.py +4 -0
  16. surety_api-0.0.1/surety/api/caller.py +85 -0
  17. surety_api-0.0.1/surety/api/method.py +175 -0
  18. surety_api-0.0.1/surety/api/mock/__init__.py +0 -0
  19. surety_api-0.0.1/surety/api/mock/data.py +95 -0
  20. surety_api-0.0.1/surety/api/mock/service.py +179 -0
  21. surety_api-0.0.1/surety/api/schema.py +79 -0
  22. surety_api-0.0.1/surety_api.egg-info/PKG-INFO +37 -0
  23. surety_api-0.0.1/surety_api.egg-info/SOURCES.txt +36 -0
  24. surety_api-0.0.1/surety_api.egg-info/dependency_links.txt +1 -0
  25. surety_api-0.0.1/surety_api.egg-info/requires.txt +7 -0
  26. surety_api-0.0.1/surety_api.egg-info/top_level.txt +1 -0
  27. surety_api-0.0.1/tests/__init__.py +0 -0
  28. surety_api-0.0.1/tests/conftest.py +0 -0
  29. surety_api-0.0.1/tests/data/__init__.py +0 -0
  30. surety_api-0.0.1/tests/data/dummy_api.py +31 -0
  31. surety_api-0.0.1/tests/etc/config.yaml +9 -0
  32. surety_api-0.0.1/tests/etc/config_no_app.yaml +2 -0
  33. surety_api-0.0.1/tests/etc/config_no_mock.yaml +2 -0
  34. surety_api-0.0.1/tests/test_api_method.py +295 -0
  35. surety_api-0.0.1/tests/test_app_url.py +20 -0
  36. surety_api-0.0.1/tests/test_caller.py +54 -0
  37. surety_api-0.0.1/tests/test_mock_service.py +91 -0
  38. surety_api-0.0.1/tests/test_schema.py +50 -0
@@ -0,0 +1,30 @@
1
+ name: Publish
2
+
3
+ on:
4
+ workflow_run:
5
+ workflows: ["Create Release"]
6
+ types: [completed]
7
+
8
+ jobs:
9
+ deploy:
10
+
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+ with:
16
+ fetch-depth: 0
17
+ - name: Set up Python
18
+ uses: actions/setup-python@v2
19
+ with:
20
+ python-version: '3.x'
21
+ - name: Install dependencies
22
+ run: |
23
+ python -m pip install --upgrade pip
24
+ pip install build
25
+ - name: Build package
26
+ run: python -m build
27
+ - name: Publish package
28
+ uses: pypa/gh-action-pypi-publish@release/v1
29
+ with:
30
+ password: ${{ secrets.PYPI_API_TOKEN }}
@@ -0,0 +1,24 @@
1
+ name: Pylint
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ lint:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ matrix:
10
+ python-version: ["3.9", "3.10", "3.11"]
11
+ steps:
12
+ - uses: actions/checkout@v3
13
+ - name: Set up Python ${{ matrix.python-version }}
14
+ uses: actions/setup-python@v3
15
+ with:
16
+ python-version: ${{ matrix.python-version }}
17
+ - name: Install dependencies
18
+ run: |
19
+ python -m pip install --upgrade pip
20
+ pip install -r requirements/test.txt
21
+ pip install -e .
22
+ - name: Analysing the code with pylint
23
+ run:
24
+ python -m pylint surety/api tests
@@ -0,0 +1,41 @@
1
+ name: Create Release
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ permissions:
9
+ contents: write
10
+
11
+ jobs:
12
+ tag-and-release:
13
+ runs-on: ubuntu-latest
14
+
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ with:
18
+ fetch-depth: 0
19
+
20
+ - uses: actions/setup-python@v5
21
+ with:
22
+ python-version: "3.12"
23
+
24
+ - run: pip install build setuptools-scm
25
+
26
+ - name: Build package
27
+ run: python -m build
28
+
29
+ - name: Create tag
30
+ id: tag
31
+ uses: anothrNick/github-tag-action@1.67.0
32
+ env:
33
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34
+ DEFAULT_BUMP: patch
35
+ WITH_V: true
36
+
37
+ - name: Create GitHub Release
38
+ uses: softprops/action-gh-release@v2
39
+ with:
40
+ tag_name: ${{ steps.tag.outputs.new_tag }}
41
+ files: dist/*
@@ -0,0 +1,53 @@
1
+ name: Tests
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ test:
11
+ permissions: write-all
12
+ runs-on: ubuntu-latest
13
+
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+
17
+ - name: Set up Python
18
+ uses: actions/setup-python@v5
19
+ with:
20
+ python-version: "3.10"
21
+ cache: "pip"
22
+ cache-dependency-path: |
23
+ requirements/test.txt
24
+ pyproject.toml
25
+
26
+ - name: Install dependencies
27
+ run: |
28
+ python -m pip install --upgrade pip
29
+ pip install -r requirements/test.txt
30
+ pip install -e .
31
+
32
+ - name: Run tests
33
+ run: |
34
+ pytest \
35
+ --cache-clear \
36
+ --junitxml=test-report.xml \
37
+ --cov=surety/api \
38
+ --cov-report=term-missing:skip-covered \
39
+ --cov-report=xml \
40
+ > pytest-coverage.txt
41
+
42
+ - name: Pytest coverage comment
43
+ if: always()
44
+ uses: MishaKav/pytest-coverage-comment@main
45
+ with:
46
+ pytest-coverage-path: pytest-coverage.txt
47
+ junitxml-path: test-report.xml
48
+
49
+ - name: Publish test report
50
+ if: always()
51
+ uses: elenakulgavaya/pytest-report-action@v1.3
52
+ with:
53
+ path: test-report.xml
@@ -0,0 +1,210 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # packaging fixes
7
+ */__init__.pyi
8
+
9
+ # C extensions
10
+ *.so
11
+
12
+ # Distribution / packaging
13
+ .Python
14
+ build/
15
+ develop-eggs/
16
+ dist/
17
+ downloads/
18
+ eggs/
19
+ .eggs/
20
+ lib/
21
+ lib64/
22
+ parts/
23
+ sdist/
24
+ var/
25
+ wheels/
26
+ share/python-wheels/
27
+ *.egg-info/
28
+ .installed.cfg
29
+ *.egg
30
+ MANIFEST
31
+
32
+ # PyInstaller
33
+ # Usually these files are written by a python script from a template
34
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
35
+ *.manifest
36
+ *.spec
37
+
38
+ # Installer logs
39
+ pip-log.txt
40
+ pip-delete-this-directory.txt
41
+
42
+ # Unit test / coverage reports
43
+ htmlcov/
44
+ .tox/
45
+ .nox/
46
+ .coverage
47
+ .coverage.*
48
+ .cache
49
+ nosetests.xml
50
+ coverage.xml
51
+ *.cover
52
+ *.py.cover
53
+ .hypothesis/
54
+ .pytest_cache/
55
+ cover/
56
+
57
+ # Translations
58
+ *.mo
59
+ *.pot
60
+
61
+ # Django stuff:
62
+ *.log
63
+ local_settings.py
64
+ db.sqlite3
65
+ db.sqlite3-journal
66
+
67
+ # Flask stuff:
68
+ instance/
69
+ .webassets-cache
70
+
71
+ # Scrapy stuff:
72
+ .scrapy
73
+
74
+ # Sphinx documentation
75
+ docs/_build/
76
+
77
+ # PyBuilder
78
+ .pybuilder/
79
+ target/
80
+
81
+ # Jupyter Notebook
82
+ .ipynb_checkpoints
83
+
84
+ # IPython
85
+ profile_default/
86
+ ipython_config.py
87
+
88
+ # pyenv
89
+ # For a library or package, you might want to ignore these files since the code is
90
+ # intended to run in multiple environments; otherwise, check them in:
91
+ # .python-version
92
+
93
+ # pipenv
94
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
95
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
96
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
97
+ # install all needed dependencies.
98
+ #Pipfile.lock
99
+
100
+ # UV
101
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
102
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
103
+ # commonly ignored for libraries.
104
+ #uv.lock
105
+
106
+ # poetry
107
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
108
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
109
+ # commonly ignored for libraries.
110
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
111
+ #poetry.lock
112
+ #poetry.toml
113
+
114
+ # pdm
115
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
116
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
117
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
118
+ #pdm.lock
119
+ #pdm.toml
120
+ .pdm-python
121
+ .pdm-build/
122
+
123
+ # pixi
124
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
125
+ #pixi.lock
126
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
127
+ # in the .venv directory. It is recommended not to include this directory in version control.
128
+ .pixi
129
+
130
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
131
+ __pypackages__/
132
+
133
+ # Celery stuff
134
+ celerybeat-schedule
135
+ celerybeat.pid
136
+
137
+ # SageMath parsed files
138
+ *.sage.py
139
+
140
+ # Environments
141
+ .env
142
+ .envrc
143
+ .venv
144
+ env/
145
+ venv/
146
+ ENV/
147
+ env.bak/
148
+ venv.bak/
149
+
150
+ # Spyder project settings
151
+ .spyderproject
152
+ .spyproject
153
+
154
+ # Rope project settings
155
+ .ropeproject
156
+
157
+ # mkdocs documentation
158
+ /site
159
+
160
+ # mypy
161
+ .mypy_cache/
162
+ .dmypy.json
163
+ dmypy.json
164
+
165
+ # Pyre type checker
166
+ .pyre/
167
+
168
+ # pytype static type analyzer
169
+ .pytype/
170
+
171
+ # Cython debug symbols
172
+ cython_debug/
173
+
174
+ # PyCharm
175
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
176
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
177
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
178
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
179
+ #.idea/
180
+
181
+ # Abstra
182
+ # Abstra is an AI-powered process automation framework.
183
+ # Ignore directories containing user credentials, local state, and settings.
184
+ # Learn more at https://abstra.io/docs
185
+ .abstra/
186
+
187
+ # Visual Studio Code
188
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
189
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
190
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
191
+ # you could uncomment the following to ignore the entire vscode folder
192
+ # .vscode/
193
+
194
+ # Ruff stuff:
195
+ .ruff_cache/
196
+
197
+ # PyPI configuration file
198
+ .pypirc
199
+
200
+ # Cursor
201
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
202
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
203
+ # refer to https://docs.cursor.com/context/ignore-files
204
+ .cursorignore
205
+ .cursorindexingignore
206
+
207
+ # Marimo
208
+ marimo/_static/
209
+ marimo/_lsp/
210
+ __marimo__/
@@ -0,0 +1,48 @@
1
+ [MASTER]
2
+ init-hook='import sys; sys.path.append("./src")'
3
+ ignore=LICENSE,
4
+ pyproject.toml,
5
+ README.md,
6
+ requirements/,
7
+ pytest.ini,
8
+ setup.cfg,
9
+ pytest-coverage.txt,
10
+ test-report.xml
11
+ ignore-paths=dist,
12
+ fild-api-hug.egg-info
13
+
14
+ py-version=3.11
15
+ suggestion-mode=yes
16
+
17
+ [MESSAGES CONTROL]
18
+ disable=missing-function-docstring,
19
+ missing-class-docstring,
20
+ missing-module-docstring,
21
+ import-outside-toplevel,
22
+ attribute-defined-outside-init,
23
+ fixme
24
+
25
+
26
+ [TYPECHECK]
27
+ ignored-modules=surety
28
+
29
+ [BASIC]
30
+ good-names=i,
31
+ j,
32
+ k,
33
+ ex,
34
+ tz,
35
+ Run,
36
+ _
37
+
38
+ [DESIGN]
39
+ max-args=14
40
+ max-attributes=7
41
+ max-bool-expr=5
42
+ max-branches=19
43
+ max-locals=19
44
+ max-parents=7
45
+ max-public-methods=20
46
+ max-returns=6
47
+ max-statements=50
48
+ min-public-methods=0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Elena Kulgavaya
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,37 @@
1
+ Metadata-Version: 2.4
2
+ Name: surety-api
3
+ Version: 0.0.1
4
+ Summary: Contract-aware API interaction layer for the Surety ecosystem.
5
+ Author-email: Elena Kulgavaya <elena.kulgavaya@gmail.com>
6
+ License: MIT
7
+ Keywords: api,contract-testing,automation,integration-testing,surety
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: deepdiff==8.0.1
15
+ Requires-Dist: surety<1.0,>=0.0.4
16
+ Requires-Dist: surety-config>=0.0.3
17
+ Requires-Dist: surety-diff>=0.0.1
18
+ Requires-Dist: requests
19
+ Requires-Dist: pyyaml
20
+ Requires-Dist: waiting
21
+ Dynamic: license-file
22
+
23
+ # Surety API
24
+
25
+ Contract-aware API interaction layer for the Surety ecosystem.
26
+
27
+ `surety-api` enables structured API testing, mocking, and
28
+ interaction based on Surety contracts.
29
+
30
+ It bridges declarative contracts and real HTTP communication.
31
+
32
+ ---
33
+
34
+ ## Installation
35
+
36
+ ```bash
37
+ pip install surety-api
@@ -0,0 +1,15 @@
1
+ # Surety API
2
+
3
+ Contract-aware API interaction layer for the Surety ecosystem.
4
+
5
+ `surety-api` enables structured API testing, mocking, and
6
+ interaction based on Surety contracts.
7
+
8
+ It bridges declarative contracts and real HTTP communication.
9
+
10
+ ---
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ pip install surety-api
@@ -0,0 +1,5 @@
1
+ App:
2
+ url: http://localhost:9000
3
+ MockServer:
4
+ host: localhost
5
+ port: 8088
@@ -0,0 +1,44 @@
1
+ [build-system]
2
+ requires = ["setuptools>=64", "setuptools-scm"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "surety-api"
7
+ description = "Contract-aware API interaction layer for the Surety ecosystem."
8
+ readme = "README.md"
9
+ requires-python = ">=3.8"
10
+ license = { text = "MIT" }
11
+ authors = [
12
+ { name = "Elena Kulgavaya", email = "elena.kulgavaya@gmail.com" }
13
+ ]
14
+ dynamic = ["version"]
15
+ dependencies = [
16
+ "deepdiff==8.0.1",
17
+ "surety>=0.0.4,<1.0",
18
+ "surety-config>=0.0.3",
19
+ "surety-diff>=0.0.1",
20
+ "requests",
21
+ "pyyaml",
22
+ "waiting"
23
+ ]
24
+ keywords = [
25
+ "api",
26
+ "contract-testing",
27
+ "automation",
28
+ "integration-testing",
29
+ "surety"
30
+ ]
31
+
32
+ classifiers = [
33
+ "Programming Language :: Python :: 3",
34
+ "License :: OSI Approved :: MIT License",
35
+ "Operating System :: OS Independent",
36
+ ]
37
+
38
+ [tool.setuptools.packages.find]
39
+ where = ["."]
40
+ include = ["surety*"]
41
+
42
+ [tool.setuptools_scm]
43
+ version_scheme = "guess-next-dev"
44
+ local_scheme = "no-local-version"
@@ -0,0 +1,7 @@
1
+ deepdiff==8.0.1
2
+ surety==0.0.4
3
+ surety-config==0.0.3
4
+ surety-diff==0.0.1
5
+ requests==2.32.3
6
+ pyyaml==6.0.2
7
+ waiting==1.5.0
@@ -0,0 +1,7 @@
1
+ -r common.txt
2
+
3
+ pylint==3.2.7
4
+ pytest==8.3.3
5
+ pytest-cov==5.0.0
6
+ pytest-mock==3.14.0
7
+ requests-mock==1.12.1
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,4 @@
1
+ from .caller import ApiCaller
2
+ from .mock.service import MockServer
3
+ from .method import ApiMethod
4
+ from .schema import HttpMethod
@@ -0,0 +1,85 @@
1
+ from surety.process import dictionary
2
+ from surety.sdk import Field
3
+ from surety.diff import compare
4
+
5
+ from surety.api.method import ApiMethod
6
+
7
+
8
+ class ApiCaller:
9
+ method: ApiMethod
10
+
11
+ def __init__(self, req_body=None, path_params=None, headers=None,
12
+ params=None, cookies=None, updates=None):
13
+ self.req_body = req_body
14
+ self.response = None
15
+ self.path_params = path_params
16
+ self.headers = headers
17
+ self.params = params
18
+ self.cookies = cookies
19
+ self.updates = updates
20
+
21
+ def request(self):
22
+ req_body = self.req_body
23
+ params = self.params
24
+
25
+ if req_body is None:
26
+ pass
27
+ elif isinstance(self.req_body, Field):
28
+ req_body = self.req_body.value
29
+
30
+ if self.updates:
31
+ req_body = dictionary.merge_with_updates(req_body, self.updates)
32
+
33
+ if params is None:
34
+ pass
35
+ elif isinstance(self.params, Field):
36
+ params = self.params.value
37
+
38
+ self.response = self.method.call(
39
+ req_body=req_body,
40
+ path_params=self.path_params,
41
+ headers=self.headers,
42
+ params=params,
43
+ cookies=self.cookies
44
+ )
45
+
46
+ return self
47
+
48
+ def verify_response(self, error_code=None, resp_body=None, normalize=False,
49
+ normalize_keys=None, parse_response=None, rules=None):
50
+ if error_code:
51
+ assert self.response.status_code == error_code, (
52
+ f'Unexpected code: {self.response.status_code}\n'
53
+ f'Response text: {self.response.text}'
54
+ )
55
+ else:
56
+ assert self.response.status_code == 200, (
57
+ f'Unexpected response code: {self.response.status_code}'
58
+ f'\nResponse text: {self.response.text}'
59
+ )
60
+
61
+ if resp_body is not None or isinstance(resp_body, Field):
62
+ content_type = self.response.headers.get('Content-Type')
63
+
64
+ if content_type == 'text/csv':
65
+ result_data = self.response.text
66
+
67
+ if parse_response and callable(parse_response):
68
+ result_data = parse_response(result_data)
69
+ else:
70
+ result_data = self.response.text and self.response.json()
71
+
72
+ if isinstance(resp_body, Field):
73
+ resp_body = resp_body.value
74
+
75
+ if normalize or normalize_keys:
76
+ resp_body = dictionary.normalize(resp_body, result_data, keys=normalize_keys)
77
+
78
+ compare(
79
+ expected=resp_body,
80
+ actual=result_data,
81
+ rules=rules,
82
+ target_name='api response'
83
+ )
84
+
85
+ return self