Skip to content

Commit 53dab2a

Browse files
authored
All methods return a request Response (#4)
1 parent f4bb71c commit 53dab2a

File tree

12 files changed

+189
-408
lines changed

12 files changed

+189
-408
lines changed

.github/workflows/coverage.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Post coverage comment
2+
3+
on:
4+
workflow_run:
5+
workflows: ["automated-tests"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
test:
11+
name: Run tests & display coverage
12+
runs-on: ubuntu-latest
13+
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
14+
permissions:
15+
# Gives the action the necessary permissions for publishing new
16+
# comments in pull requests.
17+
pull-requests: write
18+
# Gives the action the necessary permissions for editing existing
19+
# comments (to avoid publishing multiple comments in the same PR)
20+
contents: write
21+
# Gives the action the necessary permissions for looking up the
22+
# workflow that launched this workflow, and download the related
23+
# artifact that contains the comment to be published
24+
actions: read
25+
steps:
26+
27+
- name: Post comment
28+
uses: py-cov-action/python-coverage-comment-action@v3
29+
with:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }}

.github/workflows/tests.yml

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,31 @@ jobs:
77
pytest:
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/checkout@v4
11-
- uses: actions/setup-python@v4
12-
with:
13-
python-version: '3.10'
10+
- uses: actions/checkout@v4
11+
- uses: actions/setup-python@v4
12+
with:
13+
python-version: '3.10'
1414

15-
- name: Install dependencies
16-
run: |
17-
python -m pip install pip -U; python -m pip install poetry; poetry install
18-
- name: Run tests
19-
run: |
20-
pytest -svx
15+
- name: Install dependencies
16+
run: |
17+
python -m pip install pip -U; python -m pip install poetry; poetry install
18+
19+
- name: Run tests
20+
run: |
21+
poetry run coverage run --source kafka_schema_registry_admin -m pytest --verbose
22+
poetry run coverage report -m
23+
24+
- name: Coverage comment
25+
id: coverage_comment
26+
uses: py-cov-action/python-coverage-comment-action@v3
27+
with:
28+
GITHUB_TOKEN: ${{ github.token }}
29+
30+
- name: Store Pull Request comment to be posted
31+
uses: actions/upload-artifact@v3
32+
if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true'
33+
with:
34+
# If you use a different name, update COMMENT_ARTIFACT_NAME accordingly
35+
name: python-coverage-comment-action
36+
# If you use a different name, update COMMENT_FILENAME accordingly
37+
path: python-coverage-comment-action.txt

.isort.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[settings]
2-
known_third_party = pydantic,pytest,requests,testcontainers
2+
known_third_party = pytest,requests,testcontainers

.pre-commit-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ repos:
1212
- id: trailing-whitespace
1313
- id: mixed-line-ending
1414
- id: detect-aws-credentials
15+
args:
16+
- "--allow-missing-credentials"
1517
- id: detect-private-key
1618
- id: fix-byte-order-marker
1719

docs/conf.py

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
#
2020
import os
2121
import sys
22-
sys.path.insert(0, os.path.abspath('..'))
22+
23+
sys.path.insert(0, os.path.abspath(".."))
2324

2425
import kafka_schema_registry_admin
2526

@@ -31,22 +32,22 @@
3132

3233
# Add any Sphinx extension module names here, as strings. They can be
3334
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
34-
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode']
35+
extensions = ["sphinx.ext.autodoc", "sphinx.ext.viewcode"]
3536

3637
# Add any paths that contain templates here, relative to this directory.
37-
templates_path = ['_templates']
38+
templates_path = ["_templates"]
3839

3940
# The suffix(es) of source filenames.
4041
# You can specify multiple suffix as a list of string:
4142
#
4243
# source_suffix = ['.rst', '.md']
43-
source_suffix = '.rst'
44+
source_suffix = ".rst"
4445

4546
# The master toctree document.
46-
master_doc = 'index'
47+
master_doc = "index"
4748

4849
# General information about the project.
49-
project = 'Kafka schema registry admin'
50+
project = "Kafka schema registry admin"
5051
copyright = "2021, JohnPreston"
5152
author = "JohnPreston"
5253

@@ -69,10 +70,10 @@
6970
# List of patterns, relative to source directory, that match files and
7071
# directories to ignore when looking for source files.
7172
# This patterns also effect to html_static_path and html_extra_path
72-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
73+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
7374

7475
# The name of the Pygments (syntax highlighting) style to use.
75-
pygments_style = 'sphinx'
76+
pygments_style = "sphinx"
7677

7778
# If true, `todo` and `todoList` produce output, else they produce nothing.
7879
todo_include_todos = False
@@ -83,7 +84,7 @@
8384
# The theme to use for HTML and HTML Help pages. See the documentation for
8485
# a list of builtin themes.
8586
#
86-
html_theme = 'alabaster'
87+
html_theme = "alabaster"
8788

8889
# Theme options are theme-specific and customize the look and feel of a
8990
# theme further. For a list of options available for each theme, see the
@@ -94,13 +95,13 @@
9495
# Add any paths that contain custom static files (such as style sheets) here,
9596
# relative to this directory. They are copied after the builtin static files,
9697
# so a file named "default.css" will overwrite the builtin "default.css".
97-
html_static_path = ['_static']
98+
html_static_path = ["_static"]
9899

99100

100101
# -- Options for HTMLHelp output ---------------------------------------
101102

102103
# Output file base name for HTML help builder.
103-
htmlhelp_basename = 'kafka_schema_registry_admindoc'
104+
htmlhelp_basename = "kafka_schema_registry_admindoc"
104105

105106

106107
# -- Options for LaTeX output ------------------------------------------
@@ -109,15 +110,12 @@
109110
# The paper size ('letterpaper' or 'a4paper').
110111
#
111112
# 'papersize': 'letterpaper',
112-
113113
# The font size ('10pt', '11pt' or '12pt').
114114
#
115115
# 'pointsize': '10pt',
116-
117116
# Additional stuff for the LaTeX preamble.
118117
#
119118
# 'preamble': '',
120-
121119
# Latex figure (float) alignment
122120
#
123121
# 'figure_align': 'htbp',
@@ -127,9 +125,13 @@
127125
# (source start file, target name, title, author, documentclass
128126
# [howto, manual, or own class]).
129127
latex_documents = [
130-
(master_doc, 'kafka_schema_registry_admin.tex',
131-
'Kafka schema registry admin Documentation',
132-
'JohnPreston', 'manual'),
128+
(
129+
master_doc,
130+
"kafka_schema_registry_admin.tex",
131+
"Kafka schema registry admin Documentation",
132+
"JohnPreston",
133+
"manual",
134+
),
133135
]
134136

135137

@@ -138,9 +140,13 @@
138140
# One entry per manual page. List of tuples
139141
# (source start file, name, description, authors, manual section).
140142
man_pages = [
141-
(master_doc, 'kafka_schema_registry_admin',
142-
'Kafka schema registry admin Documentation',
143-
[author], 1)
143+
(
144+
master_doc,
145+
"kafka_schema_registry_admin",
146+
"Kafka schema registry admin Documentation",
147+
[author],
148+
1,
149+
)
144150
]
145151

146152

@@ -150,13 +156,13 @@
150156
# (source start file, target name, title, author,
151157
# dir menu entry, description, category)
152158
texinfo_documents = [
153-
(master_doc, 'kafka_schema_registry_admin',
154-
'Kafka schema registry admin Documentation',
155-
author,
156-
'kafka_schema_registry_admin',
157-
'One line description of project.',
158-
'Miscellaneous'),
159+
(
160+
master_doc,
161+
"kafka_schema_registry_admin",
162+
"Kafka schema registry admin Documentation",
163+
author,
164+
"kafka_schema_registry_admin",
165+
"One line description of project.",
166+
"Miscellaneous",
167+
),
159168
]
160-
161-
162-

kafka_schema_registry_admin/client_wrapper/__init__.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class Client:
1919
"""API Client wrapper around the requests"""
2020

21-
def __init__(self, base_url: str):
21+
def __init__(self, base_url: str, basic_auth: dict = None):
2222
self._base_url = base_url
2323

2424
self._default_headers: dict = {
@@ -28,6 +28,12 @@ def __init__(self, base_url: str):
2828
"Accept": "application/json",
2929
"Content-Type": "application/vnd.schemaregistry.v1+json",
3030
}
31+
self.auth = None
32+
if basic_auth:
33+
self.auth = (
34+
basic_auth["basic_auth.username"],
35+
basic_auth["basic_auth.password"],
36+
)
3137

3238
@evaluate_api_return
3339
def get(self, api_path: str, *args, **kwargs) -> Response:
@@ -38,7 +44,7 @@ def get(self, api_path: str, *args, **kwargs) -> Response:
3844
headers.update(self._default_headers)
3945
url: str = urlparse(self._base_url + api_path).geturl()
4046

41-
response = requests.get(url, *args, **kwargs)
47+
response = requests.get(url, auth=self.auth, *args, **kwargs)
4248
return response
4349

4450
@evaluate_api_return
@@ -50,8 +56,7 @@ def post(self, api_path: str, *args, **kwargs) -> Response:
5056
headers.update(self._default_headers)
5157
headers.update(self._post_headers)
5258
url: str = urlparse(self._base_url + api_path).geturl()
53-
print("URL??", url)
54-
response = requests.post(url, *args, **kwargs)
59+
response = requests.post(url, auth=self.auth, *args, **kwargs)
5560
return response
5661

5762
@evaluate_api_return
@@ -63,7 +68,7 @@ def put(self, api_path: str, *args, **kwargs) -> Response:
6368
headers.update(self._default_headers)
6469
url: str = urlparse(self._base_url + api_path).geturl()
6570

66-
response = requests.put(url, *args, **kwargs)
71+
response = requests.put(url, auth=self.auth, *args, **kwargs)
6772
return response
6873

6974
@evaluate_api_return
@@ -75,5 +80,5 @@ def delete(self, api_path: str, *args, **kwargs) -> Response:
7580
headers.update(self._default_headers)
7681

7782
url: str = urlparse(self._base_url + api_path).geturl()
78-
response = requests.delete(url, *args, **kwargs)
83+
response = requests.delete(url, auth=self.auth, *args, **kwargs)
7984
return response

0 commit comments

Comments
 (0)