From d94d964c2761e0e9b39fea91184da69c25877ac1 Mon Sep 17 00:00:00 2001 From: Evan Sims Date: Mon, 27 Jan 2025 19:22:02 -0600 Subject: [PATCH] chore: add ruff linter and code formatter --- Makefile | 8 +- .../clients/python/.openapi-generator-ignore | 1 + config/clients/python/config.overrides.json | 1 + .../example/example1/example1.py.mustache | 4 + .../example/example1/setup.py.mustache | 12 +-- .../example/opentelemetry/main.py.mustache | 15 ++-- .../example/opentelemetry/setup.py.mustache | 12 +-- .../asynchronous.py.mustache | 8 +- .../streamed-list-objects/setup.py.mustache | 12 +-- .../synchronous.py.mustache | 8 +- .../python/template/gitignore_custom.mustache | 1 + config/clients/python/template/model.mustache | 1 - config/clients/python/template/pyproject.toml | 76 +++++++++++++++++++ .../python/template/setup_cfg.mustache | 20 ----- .../python/template/src/__init__.py.mustache | 23 ++++++ .../python/template/src/api.py.mustache | 1 - .../template/src/api/__init__.py.mustache | 7 ++ .../template/src/api_client.py.mustache | 13 ++-- .../template/src/client/__init__.py.mustache | 7 ++ .../template/src/client/client.py.mustache | 3 +- .../src/client/models/__init__.py.mustache | 19 +++++ .../models/batch_check_item.py.mustache | 2 + .../models/batch_check_request.py.mustache | 1 + .../models/batch_check_response.py.mustache | 1 + .../batch_check_single_response.py.mustache | 2 +- .../client/models/check_request.py.mustache | 1 + .../client_batch_check_response.py.mustache | 1 + .../models/list_objects_request.py.mustache | 1 + .../models/list_relations_request.py.mustache | 1 + .../src/client/models/tuple.py.mustache | 1 + .../client/models/write_request.py.mustache | 1 + .../client/models/write_response.py.mustache | 1 + .../models/write_single_response.py.mustache | 2 + .../models/write_transaction_opts.py.mustache | 1 - .../template/src/configuration.py.mustache | 2 +- .../template/src/credentials.py.mustache | 4 +- .../python/template/src/help.py.mustache | 3 + .../template/src/models/__init__.py.mustache | 5 ++ .../python/template/src/oauth2.py.mustache | 2 +- .../template/src/sync/__init__.py.mustache | 6 ++ .../python/template/src/sync/api.py.mustache | 2 - .../template/src/sync/api_client.py.mustache | 13 ++-- .../template/src/sync/oauth2.py.mustache | 2 +- .../src/telemetry/__init__.py.mustache | 17 +++++ .../src/telemetry/attributes.py.mustache | 3 + .../src/telemetry/configuration.py.mustache | 3 + .../src/telemetry/counters.py.mustache | 2 + .../src/telemetry/histograms.py.mustache | 2 + .../src/telemetry/metrics.py.mustache | 2 + .../src/telemetry/telemetry.py.mustache | 2 + .../src/telemetry/utilities.py.mustache | 4 +- .../template/test-requirements.mustache | 10 +-- .../python/template/test/__init__.py.mustache | 1 + .../template/test/api/__init__.py.mustache | 1 + .../python/template/test/api_test.py.mustache | 2 +- .../template/test/client/__init__.py.mustache | 1 + .../test/configuration_test.py.mustache | 8 -- .../template/test/oauth2_test.py.mustache | 2 - .../template/test/sync/__init__.py.mustache | 1 + .../template/test/sync/api_test.py.mustache | 4 +- .../test/sync/client/__init__.py.mustache | 1 + .../telemetry/attributes_test.py.mustache | 6 +- .../telemetry/configuration_test.py.mustache | 4 +- .../test/telemetry/counters_test.py.mustache | 4 +- .../telemetry/histograms_test.py.mustache | 4 +- .../test/telemetry/metrics_test.py.mustache | 15 +--- .../test/telemetry/telemetry_test.py.mustache | 4 +- .../test/telemetry/utilities_test.py.mustache | 4 +- 68 files changed, 283 insertions(+), 131 deletions(-) create mode 100644 config/clients/python/template/pyproject.toml delete mode 100644 config/clients/python/template/setup_cfg.mustache diff --git a/Makefile b/Makefile index 824d1237..014ebb9d 100644 --- a/Makefile +++ b/Makefile @@ -125,17 +125,15 @@ build-client-python: make run-in-docker sdk_language=python image=python:${PYTHON_DOCKER_TAG} command="/bin/sh -c 'python -m pip install --upgrade pip && \ python -m pip install --upgrade setuptools wheel && \ python -m pip install -r test-requirements.txt && \ - python -m pyupgrade \`find . -name *.py -type f\` --py310-plus --keep-runtime-typing && \ - python -m isort . --profile black && \ - python -m autoflake --exclude=__init__.py --in-place --remove-unused-variables --remove-all-unused-imports -r . && \ - python -m black . && \ + python -m ruff check --select I --fix . && \ + python -m ruff format . && \ python setup.py sdist bdist_wheel'" .PHONY: test-client-python test-client-python: build-client-python make run-in-docker sdk_language=python image=python:${PYTHON_DOCKER_TAG} command="/bin/sh -c 'python -m pip install -r test-requirements.txt && \ pytest --cov-report term-missing --cov=openfga_sdk test/ && \ - flake8 . --count --show-source --statistics'" + ruff check .'" ### Java .PHONY: tag-client-java diff --git a/config/clients/python/.openapi-generator-ignore b/config/clients/python/.openapi-generator-ignore index 2e6a0ecd..56a5dff4 100644 --- a/config/clients/python/.openapi-generator-ignore +++ b/config/clients/python/.openapi-generator-ignore @@ -14,3 +14,4 @@ test/* .gitlab-ci.yml .travis.yml tox.ini +setup.cfg diff --git a/config/clients/python/config.overrides.json b/config/clients/python/config.overrides.json index 3fe89010..13e71723 100644 --- a/config/clients/python/config.overrides.json +++ b/config/clients/python/config.overrides.json @@ -14,6 +14,7 @@ "supportsStreamedListObjects": "streamed_list_objects", "files": { ".snyk": {}, + "pyproject.toml": {}, "api_sync.mustache": { "folder": "openfga_sdk/sync", diff --git a/config/clients/python/template/example/example1/example1.py.mustache b/config/clients/python/template/example/example1/example1.py.mustache index dd924a15..cc72fb4d 100644 --- a/config/clients/python/template/example/example1/example1.py.mustache +++ b/config/clients/python/template/example/example1/example1.py.mustache @@ -1,3 +1,7 @@ +# ruff: noqa: E402 + +{{>partial_header}} + import asyncio import os import sys diff --git a/config/clients/python/template/example/example1/setup.py.mustache b/config/clients/python/template/example/example1/setup.py.mustache index 0008c28b..4b25531d 100644 --- a/config/clients/python/template/example/example1/setup.py.mustache +++ b/config/clients/python/template/example/example1/setup.py.mustache @@ -1,14 +1,4 @@ -""" - Python SDK for OpenFGA - - API version: 0.1 - Website: https://openfga.dev - Documentation: https://openfga.dev/docs - Support: https://discord.gg/8naAwJfWN6 - License: [Apache-2.0](https://github.com/openfga/python-sdk/blob/main/LICENSE) - - NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. -""" +{{>partial_header}} from setuptools import find_packages, setup diff --git a/config/clients/python/template/example/opentelemetry/main.py.mustache b/config/clients/python/template/example/opentelemetry/main.py.mustache index 63c34678..5483c5a4 100644 --- a/config/clients/python/template/example/opentelemetry/main.py.mustache +++ b/config/clients/python/template/example/opentelemetry/main.py.mustache @@ -1,3 +1,7 @@ +# ruff: noqa: E402 + +{{>partial_header}} + import asyncio import os import sys @@ -198,16 +202,15 @@ async def main(): print(f"Making {checks_requests} checks ...", end=" ") for _ in range(checks_requests): try: - allowed = app().unpack( - await fga_client.check( - body=ClientCheckRequest( - user="user:anne", relation="owner", object="folder:foo" - ), + await fga_client.check( + body=ClientCheckRequest( + user="user:anne", relation="owner", object="folder:foo" ), - "allowed", ) + except FgaValidationException as error: print(f"Checked failed due to validation exception: {error}") + print("Done!") diff --git a/config/clients/python/template/example/opentelemetry/setup.py.mustache b/config/clients/python/template/example/opentelemetry/setup.py.mustache index ddeb10fc..fb220881 100644 --- a/config/clients/python/template/example/opentelemetry/setup.py.mustache +++ b/config/clients/python/template/example/opentelemetry/setup.py.mustache @@ -1,14 +1,4 @@ -""" - Python SDK for OpenFGA - - API version: 0.1 - Website: https://openfga.dev - Documentation: https://openfga.dev/docs - Support: https://discord.gg/8naAwJfWN6 - License: [Apache-2.0](https://github.com/openfga/python-sdk/blob/main/LICENSE) - - NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. -""" +{{>partial_header}} from setuptools import find_packages, setup diff --git a/config/clients/python/template/example/streamed-list-objects/asynchronous.py.mustache b/config/clients/python/template/example/streamed-list-objects/asynchronous.py.mustache index 2968454e..19cb0b7e 100644 --- a/config/clients/python/template/example/streamed-list-objects/asynchronous.py.mustache +++ b/config/clients/python/template/example/streamed-list-objects/asynchronous.py.mustache @@ -1,3 +1,7 @@ +# ruff: noqa: E402 + +{{>partial_header}} + import asyncio import json import os @@ -72,7 +76,7 @@ async def main(): ) print(f"Created temporary authorization model ({model})") - print(f"Writing 100 mock tuples to store.") + print("Writing 100 mock tuples to store.") # Write mock data writes = [] @@ -111,7 +115,7 @@ async def main(): try: await fga_client.delete_store() print(f"Deleted temporary store ({store})") - except: + except Exception: pass print("Finished.") diff --git a/config/clients/python/template/example/streamed-list-objects/setup.py.mustache b/config/clients/python/template/example/streamed-list-objects/setup.py.mustache index 7a381fff..68b2ace3 100644 --- a/config/clients/python/template/example/streamed-list-objects/setup.py.mustache +++ b/config/clients/python/template/example/streamed-list-objects/setup.py.mustache @@ -1,14 +1,4 @@ -""" - Python SDK for OpenFGA - - API version: 0.1 - Website: https://openfga.dev - Documentation: https://openfga.dev/docs - Support: https://discord.gg/8naAwJfWN6 - License: [Apache-2.0](https://github.com/openfga/python-sdk/blob/main/LICENSE) - - NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. -""" +{{>partial_header}} from setuptools import find_packages, setup diff --git a/config/clients/python/template/example/streamed-list-objects/synchronous.py.mustache b/config/clients/python/template/example/streamed-list-objects/synchronous.py.mustache index d3db0d29..e6bc688f 100644 --- a/config/clients/python/template/example/streamed-list-objects/synchronous.py.mustache +++ b/config/clients/python/template/example/streamed-list-objects/synchronous.py.mustache @@ -1,3 +1,7 @@ +# ruff: noqa: E402 + +{{>partial_header}} + import json import os import sys @@ -69,7 +73,7 @@ def main(): ) print(f"Created temporary authorization model ({model})") - print(f"Writing 100 mock tuples to store.") + print("Writing 100 mock tuples to store.") # Write mock data writes = [] @@ -108,7 +112,7 @@ def main(): try: fga_client.delete_store() print(f"Deleted temporary store ({store})") - except: + except Exception: pass print("Finished.") diff --git a/config/clients/python/template/gitignore_custom.mustache b/config/clients/python/template/gitignore_custom.mustache index ae5ff0ce..1657fc69 100644 --- a/config/clients/python/template/gitignore_custom.mustache +++ b/config/clients/python/template/gitignore_custom.mustache @@ -50,6 +50,7 @@ venv/ .venv/ .python-version .pytest_cache +.ruff_cache test/__pycache__/ # Translations diff --git a/config/clients/python/template/model.mustache b/config/clients/python/template/model.mustache index d620f96f..7a01ae67 100644 --- a/config/clients/python/template/model.mustache +++ b/config/clients/python/template/model.mustache @@ -5,7 +5,6 @@ try: except ImportError: from inspect import getargspec as getfullargspec import pprint -import re from {{packageName}}.configuration import Configuration diff --git a/config/clients/python/template/pyproject.toml b/config/clients/python/template/pyproject.toml new file mode 100644 index 00000000..52f77385 --- /dev/null +++ b/config/clients/python/template/pyproject.toml @@ -0,0 +1,76 @@ +[tool.ruff] +exclude = [ + ".bzr", + ".direnv", + ".eggs", + ".git", + ".git-rewrite", + ".hg", + ".ipynb_checkpoints", + ".mypy_cache", + ".nox", + ".pants.d", + ".pyenv", + ".pytest_cache", + ".pytype", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + ".vscode", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "node_modules", + "site-packages", + "venv", +] + +line-length = 88 +indent-width = 4 + +target-version = "py310" + +[tool.ruff.lint] +extend-select = [ + #"B", # flake8-bugbear + #"C4", # flake8-comprehensions + #"C9", # mccabe + "I", # isort + #"PGH", # pygrep-hooks + #"RUF", # ruff + #"UP", # pyupgrade + #"W", # pycodestyle + #"YTT", # flake8-2020 + #"TRY", # tryceratops + #"EM", # flake8-errmsg +] +ignore = [] + +fixable = ["ALL"] +unfixable = [] + +dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" + +[tool.ruff.lint.isort] +lines-between-types = 1 +lines-after-imports = 2 + +[tool.ruff.format] +quote-style = "double" +indent-style = "space" +skip-magic-trailing-comma = false +line-ending = "auto" + +[tool.pytest.ini_options] +testpaths = [ + "test", + "integration", +] + +addopts = "--cov=openfga_sdk --cov-report term-missing --cov-report xml --cov-report html" + +asyncio_mode = "strict" +asyncio_default_fixture_loop_scope = "function" diff --git a/config/clients/python/template/setup_cfg.mustache b/config/clients/python/template/setup_cfg.mustache deleted file mode 100644 index 719e295b..00000000 --- a/config/clients/python/template/setup_cfg.mustache +++ /dev/null @@ -1,20 +0,0 @@ -[flake8] -ignore=F401,E203,E402,E501,E722,W291,W503 -exclude=.pytest_cache,build,docs,example,test -max-line-length=88 -extend-select = B950 -extend-ignore = E203,E501,E701 - -[isort] -profile=black -multi_line_output = 3 -include_trailing_comma = True -force_grid_wrap = 0 -use_parentheses = True -ensure_newline_before_comments = True -line_length = 88 -split_on_trailing_comma = True - -[tool:pytest] -testpaths=test -addopts=--cov=openfga_sdk --cov-report term-missing --cov-report xml --cov-report html diff --git a/config/clients/python/template/src/__init__.py.mustache b/config/clients/python/template/src/__init__.py.mustache index 13699158..f7b0141c 100644 --- a/config/clients/python/template/src/__init__.py.mustache +++ b/config/clients/python/template/src/__init__.py.mustache @@ -1,4 +1,5 @@ {{>partial_header}} + __version__ = "{{packageVersion}}" from {{packageName}}.client.client import OpenFgaClient @@ -29,3 +30,25 @@ from {{packageName}}.telemetry.configuration import ( __import__('sys').setrecursionlimit({{{.}}}) {{/recursionLimit}} + +__all__ = [ + "OpenFgaClient", + "ClientConfiguration", + {{#apiInfo}}{{#apis}}"{{classname}}", + {{/apis}}{{/apiInfo}} + "ApiClient", + "Configuration", + "OpenApiException", + "FgaValidationException", + "ApiValueError", + "ApiKeyError", + "ApiAttributeError", + "ApiException", + {{#models}}{{#model}}"{{classname}}", + {{/model}}{{/models}} + "TelemetryConfiguration", + "TelemetryConfigurations", + "TelemetryConfigurationType", + "TelemetryMetricConfiguration", + "TelemetryMetricsConfiguration", +] diff --git a/config/clients/python/template/src/api.py.mustache b/config/clients/python/template/src/api.py.mustache index fba48d63..7bb4fa76 100644 --- a/config/clients/python/template/src/api.py.mustache +++ b/config/clients/python/template/src/api.py.mustache @@ -1,6 +1,5 @@ {{>partial_header}} - from {{packageName}}.api_client import ApiClient from {{packageName}}.exceptions import ApiValueError, FgaValidationException from {{packageName}}.oauth2 import OAuth2Client diff --git a/config/clients/python/template/src/api/__init__.py.mustache b/config/clients/python/template/src/api/__init__.py.mustache index e134de02..f6dd869f 100644 --- a/config/clients/python/template/src/api/__init__.py.mustache +++ b/config/clients/python/template/src/api/__init__.py.mustache @@ -1,2 +1,9 @@ +{{>partial_header}} + {{#apiInfo}}{{#apis}}from {{apiPackage}}.{{classFilename}} import {{classname}} {{/apis}}{{/apiInfo}} + +__all__ = [ + {{#apiInfo}}{{#apis}}"{{classname}}", + {{/apis}}{{/apiInfo}} +] diff --git a/config/clients/python/template/src/api_client.py.mustache b/config/clients/python/template/src/api_client.py.mustache index 2e9413ea..391a6b5d 100644 --- a/config/clients/python/template/src/api_client.py.mustache +++ b/config/clients/python/template/src/api_client.py.mustache @@ -481,14 +481,17 @@ class ApiClient: if klass in self.PRIMITIVE_TYPES: return self.__deserialize_primitive(data, klass) - elif klass == object: + + if klass is object: return self.__deserialize_object(data) - elif klass == datetime.date: + + if klass is datetime.date: return self.__deserialize_date(data) - elif klass == datetime.datetime: + + if klass is datetime.datetime: return self.__deserialize_datetime(data) - else: - return self.__deserialize_model(data, klass) + + return self.__deserialize_model(data, klass) {{#asyncio}}async {{/asyncio}}def call_api( self, diff --git a/config/clients/python/template/src/client/__init__.py.mustache b/config/clients/python/template/src/client/__init__.py.mustache index 1e85e02c..7e2ef67b 100644 --- a/config/clients/python/template/src/client/__init__.py.mustache +++ b/config/clients/python/template/src/client/__init__.py.mustache @@ -1,4 +1,11 @@ {{>partial_header}} + from {{packageName}}.client.client import OpenFgaClient from {{packageName}}.client.configuration import ClientConfiguration from {{packageName}}.client.models.check_request import ClientCheckRequest + +__all__ = [ + "OpenFgaClient", + "ClientConfiguration", + "ClientCheckRequest", +] diff --git a/config/clients/python/template/src/client/client.py.mustache b/config/clients/python/template/src/client/client.py.mustache index 0747639b..55795fbe 100644 --- a/config/clients/python/template/src/client/client.py.mustache +++ b/config/clients/python/template/src/client/client.py.mustache @@ -14,11 +14,10 @@ from {{packageName}}.client.configuration import ClientConfiguration from {{packageName}}.client.models.assertion import ClientAssertion from {{packageName}}.client.models.batch_check_item import ClientBatchCheckItem, construct_batch_item from {{packageName}}.client.models.batch_check_request import ClientBatchCheckRequest -from {{packageName}}.client.models.batch_check_response import BatchCheckResponse, ClientBatchCheckResponse +from {{packageName}}.client.models.batch_check_response import ClientBatchCheckResponse from {{packageName}}.client.models.batch_check_single_response import ClientBatchCheckSingleResponse from {{packageName}}.client.models.client_batch_check_response import ClientBatchCheckClientResponse from {{packageName}}.client.models.check_request import ClientCheckRequest, construct_check_request -from {{packageName}}.client.models.batch_check_response import BatchCheckResponse from {{packageName}}.client.models.tuple import ClientTuple, convert_tuple_keys from {{packageName}}.client.models.write_request import ClientWriteRequest from {{packageName}}.client.models.write_response import ClientWriteResponse diff --git a/config/clients/python/template/src/client/models/__init__.py.mustache b/config/clients/python/template/src/client/models/__init__.py.mustache index 5f61f417..7edc3e50 100644 --- a/config/clients/python/template/src/client/models/__init__.py.mustache +++ b/config/clients/python/template/src/client/models/__init__.py.mustache @@ -1,4 +1,5 @@ {{>partial_header}} + from {{packageName}}.client.models.assertion import ClientAssertion from {{packageName}}.client.models.batch_check_item import ClientBatchCheckItem from {{packageName}}.client.models.batch_check_request import ClientBatchCheckRequest @@ -14,3 +15,21 @@ from {{packageName}}.client.models.tuple import ClientTuple from {{packageName}}.client.models.write_request import ClientWriteRequest from {{packageName}}.client.models.write_response import ClientWriteResponse from {{packageName}}.client.models.write_transaction_opts import WriteTransactionOpts + +__all__ = [ + "ClientAssertion", + "ClientBatchCheckItem", + "ClientBatchCheckRequest", + "ClientBatchCheckResponse", + "ClientBatchCheckSingleResponse", + "ClientCheckRequest", + "ClientBatchCheckClientResponse", + "ClientExpandRequest", + "ClientListObjectsRequest", + "ClientListRelationsRequest", + "ClientReadChangesRequest", + "ClientTuple", + "ClientWriteRequest", + "ClientWriteResponse", + "WriteTransactionOpts", +] diff --git a/config/clients/python/template/src/client/models/batch_check_item.py.mustache b/config/clients/python/template/src/client/models/batch_check_item.py.mustache index 139767cb..6229ab62 100644 --- a/config/clients/python/template/src/client/models/batch_check_item.py.mustache +++ b/config/clients/python/template/src/client/models/batch_check_item.py.mustache @@ -5,6 +5,7 @@ from {{packageName}}.models.batch_check_item import BatchCheckItem from {{packageName}}.models.check_request_tuple_key import CheckRequestTupleKey from {{packageName}}.models.contextual_tuple_keys import ContextualTupleKeys + def construct_batch_item(check): batch_item = BatchCheckItem( tuple_key=CheckRequestTupleKey( @@ -23,6 +24,7 @@ def construct_batch_item(check): return batch_item + class ClientBatchCheckItem: def __init__( self, diff --git a/config/clients/python/template/src/client/models/batch_check_request.py.mustache b/config/clients/python/template/src/client/models/batch_check_request.py.mustache index 4c1572df..efe9b321 100644 --- a/config/clients/python/template/src/client/models/batch_check_request.py.mustache +++ b/config/clients/python/template/src/client/models/batch_check_request.py.mustache @@ -2,6 +2,7 @@ from {{packageName}}.client.models.batch_check_item import ClientBatchCheckItem + class ClientBatchCheckRequest: """ ClientBatchCheckRequest encapsulates the parameters for a BatchCheck request diff --git a/config/clients/python/template/src/client/models/batch_check_response.py.mustache b/config/clients/python/template/src/client/models/batch_check_response.py.mustache index 532c4588..018f288a 100644 --- a/config/clients/python/template/src/client/models/batch_check_response.py.mustache +++ b/config/clients/python/template/src/client/models/batch_check_response.py.mustache @@ -2,6 +2,7 @@ from {{packageName}}.client.models.batch_check_single_response import ClientBatchCheckSingleResponse + class ClientBatchCheckResponse: def __init__(self, result: list[ClientBatchCheckSingleResponse]): self._result = result diff --git a/config/clients/python/template/src/client/models/batch_check_single_response.py.mustache b/config/clients/python/template/src/client/models/batch_check_single_response.py.mustache index 3fe78d32..3a46eb29 100644 --- a/config/clients/python/template/src/client/models/batch_check_single_response.py.mustache +++ b/config/clients/python/template/src/client/models/batch_check_single_response.py.mustache @@ -1,9 +1,9 @@ {{>partial_header}} from {{packageName}}.client.models.tuple import ClientTuple -from {{packageName}}.models.batch_check_single_result import BatchCheckSingleResult from {{packageName}}.models.check_error import CheckError + class ClientBatchCheckSingleResponse: def __init__( self, diff --git a/config/clients/python/template/src/client/models/check_request.py.mustache b/config/clients/python/template/src/client/models/check_request.py.mustache index 7a0dce90..8f9dc0a7 100644 --- a/config/clients/python/template/src/client/models/check_request.py.mustache +++ b/config/clients/python/template/src/client/models/check_request.py.mustache @@ -2,6 +2,7 @@ from {{packageName}}.client.models.tuple import ClientTuple + def construct_check_request(user: str, relation: str, object: str, contextual_tuples: list[ClientTuple] = None, context: object = None): """ helper function to construct the check request body diff --git a/config/clients/python/template/src/client/models/client_batch_check_response.py.mustache b/config/clients/python/template/src/client/models/client_batch_check_response.py.mustache index 52c9765c..33c72e25 100644 --- a/config/clients/python/template/src/client/models/client_batch_check_response.py.mustache +++ b/config/clients/python/template/src/client/models/client_batch_check_response.py.mustache @@ -3,6 +3,7 @@ from {{packageName}}.client.models.check_request import ClientCheckRequest from {{packageName}}.models.check_response import CheckResponse + class ClientBatchCheckClientResponse: """ ClientBatchCheckClientResponse encapsulates the response for a single batch check diff --git a/config/clients/python/template/src/client/models/list_objects_request.py.mustache b/config/clients/python/template/src/client/models/list_objects_request.py.mustache index 748eeb46..674d5b9f 100644 --- a/config/clients/python/template/src/client/models/list_objects_request.py.mustache +++ b/config/clients/python/template/src/client/models/list_objects_request.py.mustache @@ -2,6 +2,7 @@ from {{packageName}}.client.models.tuple import ClientTuple + class ClientListObjectsRequest: """ ClientListObjectsRequest encapsulates the parameters required for list objects diff --git a/config/clients/python/template/src/client/models/list_relations_request.py.mustache b/config/clients/python/template/src/client/models/list_relations_request.py.mustache index 02a9650c..eb668d30 100644 --- a/config/clients/python/template/src/client/models/list_relations_request.py.mustache +++ b/config/clients/python/template/src/client/models/list_relations_request.py.mustache @@ -2,6 +2,7 @@ from {{packageName}}.client.models.tuple import ClientTuple + class ClientListRelationsRequest: """ ClientListRelationsRequest encapsulates the parameters required for list all relations user have with object diff --git a/config/clients/python/template/src/client/models/tuple.py.mustache b/config/clients/python/template/src/client/models/tuple.py.mustache index d5e75def..823c706b 100644 --- a/config/clients/python/template/src/client/models/tuple.py.mustache +++ b/config/clients/python/template/src/client/models/tuple.py.mustache @@ -3,6 +3,7 @@ from {{packageName}}.models.relationship_condition import RelationshipCondition from {{packageName}}.models.tuple_key import TupleKey + class ClientTuple: """ ClientTuple encapsulates the client tuple diff --git a/config/clients/python/template/src/client/models/write_request.py.mustache b/config/clients/python/template/src/client/models/write_request.py.mustache index 2ffa0fbd..56335d15 100644 --- a/config/clients/python/template/src/client/models/write_request.py.mustache +++ b/config/clients/python/template/src/client/models/write_request.py.mustache @@ -4,6 +4,7 @@ from {{packageName}}.client.models.tuple import ClientTuple, convert_tuple_keys from {{packageName}}.models.write_request_writes import WriteRequestWrites from {{packageName}}.models.write_request_deletes import WriteRequestDeletes + class ClientWriteRequest: """ ClientWriteRequest encapsulates the parameters required to write diff --git a/config/clients/python/template/src/client/models/write_response.py.mustache b/config/clients/python/template/src/client/models/write_response.py.mustache index e8979971..7302bf17 100644 --- a/config/clients/python/template/src/client/models/write_response.py.mustache +++ b/config/clients/python/template/src/client/models/write_response.py.mustache @@ -2,6 +2,7 @@ from {{packageName}}.client.models.write_single_response import ClientWriteSingleResponse + class ClientWriteResponse: """ ClientWriteResponse returns the set of responses and their statuses diff --git a/config/clients/python/template/src/client/models/write_single_response.py.mustache b/config/clients/python/template/src/client/models/write_single_response.py.mustache index c79e8ed9..dcf76956 100644 --- a/config/clients/python/template/src/client/models/write_single_response.py.mustache +++ b/config/clients/python/template/src/client/models/write_single_response.py.mustache @@ -2,12 +2,14 @@ from {{packageName}}.client.models.tuple import ClientTuple + def construct_write_single_response(tuple_key: ClientTuple, success: bool, error: Exception=None): """ Helper function to return a single write response """ return ClientWriteSingleResponse(tuple_key, success, error) + class ClientWriteSingleResponse: """ ClientWriteSingleResponse encapsulates the response of a single write diff --git a/config/clients/python/template/src/client/models/write_transaction_opts.py.mustache b/config/clients/python/template/src/client/models/write_transaction_opts.py.mustache index 4777b063..b74f493b 100644 --- a/config/clients/python/template/src/client/models/write_transaction_opts.py.mustache +++ b/config/clients/python/template/src/client/models/write_transaction_opts.py.mustache @@ -1,6 +1,5 @@ {{>partial_header}} - class WriteTransactionOpts: """ OpenFGA client write transaction info diff --git a/config/clients/python/template/src/configuration.py.mustache b/config/clients/python/template/src/configuration.py.mustache index 910ecccc..c8d4e993 100644 --- a/config/clients/python/template/src/configuration.py.mustache +++ b/config/clients/python/template/src/configuration.py.mustache @@ -22,6 +22,7 @@ from {{packageName}}.telemetry.counters import TelemetryCounter from {{packageName}}.telemetry.histograms import TelemetryHistogram from {{packageName}}.validation import is_well_formed_ulid_string + class RetryParams: """NOTE: This class is auto generated by OpenAPI Generator @@ -617,7 +618,6 @@ class Configuration: raise FgaValidationException(f"timeout_millisec not within reasonable range (0,60000), {self._timeout_millisec}") - @property def api_scheme(self): """Return connection is https or http.""" diff --git a/config/clients/python/template/src/credentials.py.mustache b/config/clients/python/template/src/credentials.py.mustache index d8d4df22..e0440a8e 100644 --- a/config/clients/python/template/src/credentials.py.mustache +++ b/config/clients/python/template/src/credentials.py.mustache @@ -188,7 +188,7 @@ class Credentials: if self.method == 'client_credentials': if self.configuration is None or none_or_empty(self.configuration.client_id) or none_or_empty(self.configuration.client_secret) or none_or_empty(self.configuration.api_audience) or none_or_empty(self.configuration.api_issuer): raise ApiValueError('configuration `{}` requires client_id, client_secret, api_audience and api_issuer defined for client_credentials method.') - # validate token issuer - parsed_issuer_url = self._parse_issuer(self.configuration.api_issuer) + # validate token issuer + self._parse_issuer(self.configuration.api_issuer) diff --git a/config/clients/python/template/src/help.py.mustache b/config/clients/python/template/src/help.py.mustache index c6017efa..659398f4 100644 --- a/config/clients/python/template/src/help.py.mustache +++ b/config/clients/python/template/src/help.py.mustache @@ -1,3 +1,5 @@ +{{>partial_header}} + import json import platform import sys @@ -7,6 +9,7 @@ import opentelemetry.version from . import __version__ as openfga_sdk_version + try: import urllib3 diff --git a/config/clients/python/template/src/models/__init__.py.mustache b/config/clients/python/template/src/models/__init__.py.mustache index c9c421a2..8de0949d 100644 --- a/config/clients/python/template/src/models/__init__.py.mustache +++ b/config/clients/python/template/src/models/__init__.py.mustache @@ -1,3 +1,8 @@ {{>partial_header}} {{#models}}{{#model}}from {{modelPackage}}.{{classFilename}} import {{classname}}{{/model}} {{/models}} + +__all__ = [ +{{#models}}{{#model}}"{{classname}}", +{{/model}}{{/models}} +] diff --git a/config/clients/python/template/src/oauth2.py.mustache b/config/clients/python/template/src/oauth2.py.mustache index 03356e25..9a8ffd52 100644 --- a/config/clients/python/template/src/oauth2.py.mustache +++ b/config/clients/python/template/src/oauth2.py.mustache @@ -109,7 +109,7 @@ class OAuth2Client: if 200 <= raw_response.status <= 299: try: api_response = json.loads(raw_response.data) - except: + except Exception: raise AuthenticationError(http_resp=raw_response) if api_response.get("expires_in") and api_response.get("access_token"): diff --git a/config/clients/python/template/src/sync/__init__.py.mustache b/config/clients/python/template/src/sync/__init__.py.mustache index 09cad624..e4bd82fa 100644 --- a/config/clients/python/template/src/sync/__init__.py.mustache +++ b/config/clients/python/template/src/sync/__init__.py.mustache @@ -2,3 +2,9 @@ from {{packageName}}.sync.client.client import OpenFgaClient from {{packageName}}.sync.api_client import ApiClient + + +__all__ = [ + "ApiClient", + "OpenFgaClient", +] diff --git a/config/clients/python/template/src/sync/api.py.mustache b/config/clients/python/template/src/sync/api.py.mustache index 23e25544..5feedbb6 100644 --- a/config/clients/python/template/src/sync/api.py.mustache +++ b/config/clients/python/template/src/sync/api.py.mustache @@ -1,7 +1,5 @@ {{>partial_header}} -import re - from {{packageName}}.exceptions import ApiValueError, FgaValidationException from {{packageName}}.sync.api_client import ApiClient from {{packageName}}.sync.oauth2 import OAuth2Client diff --git a/config/clients/python/template/src/sync/api_client.py.mustache b/config/clients/python/template/src/sync/api_client.py.mustache index 68171661..cc455a50 100644 --- a/config/clients/python/template/src/sync/api_client.py.mustache +++ b/config/clients/python/template/src/sync/api_client.py.mustache @@ -464,14 +464,17 @@ class ApiClient: if klass in self.PRIMITIVE_TYPES: return self.__deserialize_primitive(data, klass) - elif klass == object: + + if klass is object: return self.__deserialize_object(data) - elif klass == datetime.date: + + if klass is datetime.date: return self.__deserialize_date(data) - elif klass == datetime.datetime: + + if klass is datetime.datetime: return self.__deserialize_datetime(data) - else: - return self.__deserialize_model(data, klass) + + return self.__deserialize_model(data, klass) def call_api( self, diff --git a/config/clients/python/template/src/sync/oauth2.py.mustache b/config/clients/python/template/src/sync/oauth2.py.mustache index 032a9c96..e4a39dec 100644 --- a/config/clients/python/template/src/sync/oauth2.py.mustache +++ b/config/clients/python/template/src/sync/oauth2.py.mustache @@ -109,7 +109,7 @@ class OAuth2Client: if 200 <= raw_response.status <= 299: try: api_response = json.loads(raw_response.data) - except: + except Exception: raise AuthenticationError(http_resp=raw_response) if api_response.get("expires_in") and api_response.get("access_token"): diff --git a/config/clients/python/template/src/telemetry/__init__.py.mustache b/config/clients/python/template/src/telemetry/__init__.py.mustache index 73c1c462..b7df2c2e 100644 --- a/config/clients/python/template/src/telemetry/__init__.py.mustache +++ b/config/clients/python/template/src/telemetry/__init__.py.mustache @@ -1,3 +1,5 @@ +{{>partial_header}} + from {{packageName}}.telemetry.attributes import TelemetryAttribute, TelemetryAttributes from {{packageName}}.telemetry.configuration import ( TelemetryConfiguration, @@ -9,3 +11,18 @@ from {{packageName}}.telemetry.configuration import ( from {{packageName}}.telemetry.histograms import TelemetryHistogram, TelemetryHistograms from {{packageName}}.telemetry.metrics import TelemetryMetrics from {{packageName}}.telemetry.telemetry import Telemetry + + +__all__ = [ + "Telemetry", + "TelemetryAttribute", + "TelemetryAttributes", + "TelemetryConfiguration", + "TelemetryConfigurations", + "TelemetryConfigurationType", + "TelemetryMetricConfiguration", + "TelemetryMetricsConfiguration", + "TelemetryHistogram", + "TelemetryHistograms", + "TelemetryMetrics", +] diff --git a/config/clients/python/template/src/telemetry/attributes.py.mustache b/config/clients/python/template/src/telemetry/attributes.py.mustache index 9cd697c2..ff35b006 100644 --- a/config/clients/python/template/src/telemetry/attributes.py.mustache +++ b/config/clients/python/template/src/telemetry/attributes.py.mustache @@ -1,3 +1,5 @@ +{{>partial_header}} + import time import urllib from typing import Any, NamedTuple @@ -12,6 +14,7 @@ from {{packageName}}.telemetry.utilities import ( doesInstanceHaveCallable, ) + class TelemetryAttribute(NamedTuple): name: str format: str = "string" diff --git a/config/clients/python/template/src/telemetry/configuration.py.mustache b/config/clients/python/template/src/telemetry/configuration.py.mustache index 9ba43cdf..5cb354e8 100644 --- a/config/clients/python/template/src/telemetry/configuration.py.mustache +++ b/config/clients/python/template/src/telemetry/configuration.py.mustache @@ -1,9 +1,12 @@ +{{>partial_header}} + from typing import NamedTuple from {{packageName}}.telemetry.attributes import TelemetryAttribute, TelemetryAttributes from {{packageName}}.telemetry.counters import TelemetryCounter, TelemetryCounters from {{packageName}}.telemetry.histograms import TelemetryHistogram, TelemetryHistograms + class TelemetryMetricConfiguration: """ Telemetry configuration for an individual histogram or counter. When instantiated directly, all attributes are disabled by default. diff --git a/config/clients/python/template/src/telemetry/counters.py.mustache b/config/clients/python/template/src/telemetry/counters.py.mustache index 3e16ce49..96bbe8a1 100644 --- a/config/clients/python/template/src/telemetry/counters.py.mustache +++ b/config/clients/python/template/src/telemetry/counters.py.mustache @@ -1,3 +1,5 @@ +{{>partial_header}} + from typing import NamedTuple diff --git a/config/clients/python/template/src/telemetry/histograms.py.mustache b/config/clients/python/template/src/telemetry/histograms.py.mustache index 482fd3ae..26a1ca78 100644 --- a/config/clients/python/template/src/telemetry/histograms.py.mustache +++ b/config/clients/python/template/src/telemetry/histograms.py.mustache @@ -1,3 +1,5 @@ +{{>partial_header}} + from typing import NamedTuple diff --git a/config/clients/python/template/src/telemetry/metrics.py.mustache b/config/clients/python/template/src/telemetry/metrics.py.mustache index 865b7dd0..3aecae99 100644 --- a/config/clients/python/template/src/telemetry/metrics.py.mustache +++ b/config/clients/python/template/src/telemetry/metrics.py.mustache @@ -1,3 +1,5 @@ +{{>partial_header}} + from opentelemetry.metrics import Counter, Histogram, Meter, get_meter from {{packageName}}.telemetry.attributes import ( diff --git a/config/clients/python/template/src/telemetry/telemetry.py.mustache b/config/clients/python/template/src/telemetry/telemetry.py.mustache index 25d78cfb..bb1e5b1b 100644 --- a/config/clients/python/template/src/telemetry/telemetry.py.mustache +++ b/config/clients/python/template/src/telemetry/telemetry.py.mustache @@ -1,3 +1,5 @@ +{{>partial_header}} + from {{packageName}}.telemetry.metrics import TelemetryMetrics diff --git a/config/clients/python/template/src/telemetry/utilities.py.mustache b/config/clients/python/template/src/telemetry/utilities.py.mustache index de52ec7c..69204c35 100644 --- a/config/clients/python/template/src/telemetry/utilities.py.mustache +++ b/config/clients/python/template/src/telemetry/utilities.py.mustache @@ -1,7 +1,9 @@ +{{>partial_header}} + def doesInstanceHaveCallable(instance: object, callableName: str) -> bool: instanceCallable = getattr(instance, callableName, None) if instanceCallable is None: return False - return callable(instanceCallable) \ No newline at end of file + return callable(instanceCallable) diff --git a/config/clients/python/template/test-requirements.mustache b/config/clients/python/template/test-requirements.mustache index aae4461c..27570111 100644 --- a/config/clients/python/template/test-requirements.mustache +++ b/config/clients/python/template/test-requirements.mustache @@ -1,11 +1,7 @@ -r requirements.txt -mock >= 5.1.0, < 6 -autoflake==2.3.1 -black==24.10.0 -flake8 >= 7.0.0, < 8 griffe >= 0.41.2, < 2 -isort==5.13.2 -pytest-cov >= 5, < 7 -pyupgrade==3.19.1 +mock >= 5.1.0, < 6 pytest-asyncio >= 0.25, < 1 +pytest-cov >= 5, < 7 +ruff >= 0.9, < 1 diff --git a/config/clients/python/template/test/__init__.py.mustache b/config/clients/python/template/test/__init__.py.mustache index e69de29b..96e69920 100644 --- a/config/clients/python/template/test/__init__.py.mustache +++ b/config/clients/python/template/test/__init__.py.mustache @@ -0,0 +1 @@ +{{>partial_header}} diff --git a/config/clients/python/template/test/api/__init__.py.mustache b/config/clients/python/template/test/api/__init__.py.mustache index e69de29b..96e69920 100644 --- a/config/clients/python/template/test/api/__init__.py.mustache +++ b/config/clients/python/template/test/api/__init__.py.mustache @@ -0,0 +1 @@ +{{>partial_header}} diff --git a/config/clients/python/template/test/api_test.py.mustache b/config/clients/python/template/test/api_test.py.mustache index a620ca7e..b017face 100644 --- a/config/clients/python/template/test/api_test.py.mustache +++ b/config/clients/python/template/test/api_test.py.mustache @@ -1491,7 +1491,7 @@ class TestOpenFgaApi(IsolatedAsyncioTestCase): user="user:81684243-9356-4421-8fbf-a4f8d36aa31b", ), ) - with self.assertRaises(ServiceException) as api_exception: + with self.assertRaises(ServiceException): {{#asyncio}}await {{/asyncio}}api_instance.check( body=body, ) diff --git a/config/clients/python/template/test/client/__init__.py.mustache b/config/clients/python/template/test/client/__init__.py.mustache index e69de29b..96e69920 100644 --- a/config/clients/python/template/test/client/__init__.py.mustache +++ b/config/clients/python/template/test/client/__init__.py.mustache @@ -0,0 +1 @@ +{{>partial_header}} diff --git a/config/clients/python/template/test/configuration_test.py.mustache b/config/clients/python/template/test/configuration_test.py.mustache index 751c820d..d0352ee3 100644 --- a/config/clients/python/template/test/configuration_test.py.mustache +++ b/config/clients/python/template/test/configuration_test.py.mustache @@ -271,14 +271,6 @@ class TestConfigurationHostSettings: ) def test_configuration_get_host_from_settings_invalid_value(self, configuration): - servers = [ - { - "url": "https://{region}.{{sampleApiDomain}}", - "description": "Example", - "variables": {"region": {"default_value": "us"}}, - } - ] - variables = {"region": "invalid"} with pytest.raises(ValueError): configuration.get_host_from_settings(999, variables={"var": "value"}) diff --git a/config/clients/python/template/test/oauth2_test.py.mustache b/config/clients/python/template/test/oauth2_test.py.mustache index fcd0be87..51062700 100644 --- a/config/clients/python/template/test/oauth2_test.py.mustache +++ b/config/clients/python/template/test/oauth2_test.py.mustache @@ -1,7 +1,5 @@ {{>partial_header}} -import urllib3 - from datetime import datetime, timedelta from unittest import IsolatedAsyncioTestCase from unittest.mock import patch diff --git a/config/clients/python/template/test/sync/__init__.py.mustache b/config/clients/python/template/test/sync/__init__.py.mustache index e69de29b..96e69920 100644 --- a/config/clients/python/template/test/sync/__init__.py.mustache +++ b/config/clients/python/template/test/sync/__init__.py.mustache @@ -0,0 +1 @@ +{{>partial_header}} diff --git a/config/clients/python/template/test/sync/api_test.py.mustache b/config/clients/python/template/test/sync/api_test.py.mustache index a8d0dc7f..96df6f15 100644 --- a/config/clients/python/template/test/sync/api_test.py.mustache +++ b/config/clients/python/template/test/sync/api_test.py.mustache @@ -1418,7 +1418,7 @@ class TestOpenFgaApiSync(IsolatedAsyncioTestCase): self.assertEqual(mock_request.call_count, 1) @patch.object(rest.RESTClientObject, "request") - async def test_500_error(self, mock_request): + async def test_500_error_retry(self, mock_request): """ Test to ensure 5xx retries are handled properly """ @@ -1491,7 +1491,7 @@ class TestOpenFgaApiSync(IsolatedAsyncioTestCase): user="user:81684243-9356-4421-8fbf-a4f8d36aa31b", ), ) - with self.assertRaises(ServiceException) as api_exception: + with self.assertRaises(ServiceException): api_instance.check( body=body, ) diff --git a/config/clients/python/template/test/sync/client/__init__.py.mustache b/config/clients/python/template/test/sync/client/__init__.py.mustache index e69de29b..96e69920 100644 --- a/config/clients/python/template/test/sync/client/__init__.py.mustache +++ b/config/clients/python/template/test/sync/client/__init__.py.mustache @@ -0,0 +1 @@ +{{>partial_header}} diff --git a/config/clients/python/template/test/telemetry/attributes_test.py.mustache b/config/clients/python/template/test/telemetry/attributes_test.py.mustache index 28086afa..9a4783e7 100644 --- a/config/clients/python/template/test/telemetry/attributes_test.py.mustache +++ b/config/clients/python/template/test/telemetry/attributes_test.py.mustache @@ -1,3 +1,5 @@ +{{>partial_header}} + import time from unittest.mock import MagicMock @@ -8,7 +10,7 @@ from {{packageName}}.credentials import CredentialConfiguration, Credentials from {{packageName}}.models.batch_check_request import BatchCheckRequest from {{packageName}}.models.check_request import CheckRequest from {{packageName}}.rest import RESTResponse -from {{packageName}}.rest import RESTResponse + from {{packageName}}.telemetry.attributes import ( TelemetryAttributes, ) @@ -168,4 +170,4 @@ def test_from_body_with_other_body(telemetry_attributes): attributes = telemetry_attributes.fromBody(body=body) - assert attributes == {} \ No newline at end of file + assert attributes == {} diff --git a/config/clients/python/template/test/telemetry/configuration_test.py.mustache b/config/clients/python/template/test/telemetry/configuration_test.py.mustache index 2607c433..74b384ba 100644 --- a/config/clients/python/template/test/telemetry/configuration_test.py.mustache +++ b/config/clients/python/template/test/telemetry/configuration_test.py.mustache @@ -1,3 +1,5 @@ +{{>partial_header}} + from {{packageName}}.telemetry.attributes import TelemetryAttributes from {{packageName}}.telemetry.configuration import ( TelemetryConfiguration, @@ -312,4 +314,4 @@ def test_default_telemetry_metric_configuration(): assert metric_config[TelemetryAttributes.http_server_request_duration] is False assert metric_config[TelemetryAttributes.url_scheme] is True assert metric_config[TelemetryAttributes.url_full] is True - assert metric_config[TelemetryAttributes.user_agent_original] is True \ No newline at end of file + assert metric_config[TelemetryAttributes.user_agent_original] is True diff --git a/config/clients/python/template/test/telemetry/counters_test.py.mustache b/config/clients/python/template/test/telemetry/counters_test.py.mustache index 1dff0f33..34707495 100644 --- a/config/clients/python/template/test/telemetry/counters_test.py.mustache +++ b/config/clients/python/template/test/telemetry/counters_test.py.mustache @@ -1,3 +1,5 @@ +{{>partial_header}} + from {{packageName}}.telemetry.counters import TelemetryCounter, TelemetryCounters @@ -32,4 +34,4 @@ def test_telemetry_counters_custom_counter(): assert custom_counter.name == "fga-client.custom.counter" assert custom_counter.unit == "operations" - assert custom_counter.description == "A custom counter for specific operations." \ No newline at end of file + assert custom_counter.description == "A custom counter for specific operations." diff --git a/config/clients/python/template/test/telemetry/histograms_test.py.mustache b/config/clients/python/template/test/telemetry/histograms_test.py.mustache index df700568..4f0f614a 100644 --- a/config/clients/python/template/test/telemetry/histograms_test.py.mustache +++ b/config/clients/python/template/test/telemetry/histograms_test.py.mustache @@ -1,3 +1,5 @@ +{{>partial_header}} + from {{packageName}}.telemetry.histograms import TelemetryHistogram, TelemetryHistograms @@ -40,4 +42,4 @@ def test_telemetry_histograms_custom_histogram(): assert custom_histogram.name == "fga-client.custom.histogram" assert custom_histogram.unit == "operations" - assert custom_histogram.description == "A custom histogram for specific operations." \ No newline at end of file + assert custom_histogram.description == "A custom histogram for specific operations." diff --git a/config/clients/python/template/test/telemetry/metrics_test.py.mustache b/config/clients/python/template/test/telemetry/metrics_test.py.mustache index aa4d2b24..79f6719b 100644 --- a/config/clients/python/template/test/telemetry/metrics_test.py.mustache +++ b/config/clients/python/template/test/telemetry/metrics_test.py.mustache @@ -1,9 +1,10 @@ +{{>partial_header}} + from unittest.mock import MagicMock, patch import pytest from opentelemetry.metrics import Counter, Histogram, Meter -from {{packageName}}.telemetry.attributes import TelemetryAttributes from {{packageName}}.telemetry.counters import TelemetryCounters from {{packageName}}.telemetry.histograms import TelemetryHistograms from {{packageName}}.telemetry.metrics import TelemetryMetrics @@ -39,11 +40,6 @@ def test_counter_creation(mock_get_meter): telemetry = TelemetryMetrics() - attributes = { - TelemetryAttributes.fga_client_request_model_id.name: "model_123", - "custom_attribute": "custom_value", - } - counter = telemetry.counter(TelemetryCounters.fga_client_credentials_request) assert counter == mock_counter @@ -64,11 +60,6 @@ def test_histogram_creation(mock_get_meter): telemetry = TelemetryMetrics() - attributes = { - TelemetryAttributes.fga_client_request_model_id.name: "model_123", - "custom_attribute": "custom_value", - } - histogram = telemetry.histogram(TelemetryHistograms.fga_client_request_duration) assert histogram == mock_histogram @@ -89,4 +80,4 @@ def test_invalid_counter_key(): def test_invalid_histogram_key(): telemetry = TelemetryMetrics() with pytest.raises(ValueError): - telemetry.histogram("invalid_histogram_key") \ No newline at end of file + telemetry.histogram("invalid_histogram_key") diff --git a/config/clients/python/template/test/telemetry/telemetry_test.py.mustache b/config/clients/python/template/test/telemetry/telemetry_test.py.mustache index 3a3122a1..508e9ce3 100644 --- a/config/clients/python/template/test/telemetry/telemetry_test.py.mustache +++ b/config/clients/python/template/test/telemetry/telemetry_test.py.mustache @@ -1,3 +1,5 @@ +{{>partial_header}} + from unittest.mock import patch from {{packageName}}.telemetry.metrics import ( @@ -42,4 +44,4 @@ def test_metrics_initialization_without_patch(): # Access the metrics property again, no new instance should be created metrics_again = telemetry.metrics - assert metrics_again == metrics \ No newline at end of file + assert metrics_again == metrics diff --git a/config/clients/python/template/test/telemetry/utilities_test.py.mustache b/config/clients/python/template/test/telemetry/utilities_test.py.mustache index 7a3a23df..79a34fd0 100644 --- a/config/clients/python/template/test/telemetry/utilities_test.py.mustache +++ b/config/clients/python/template/test/telemetry/utilities_test.py.mustache @@ -1,4 +1,6 @@ -from mock import MagicMock +{{>partial_header}} + +from unittest.mock import MagicMock from {{packageName}}.telemetry.utilities import doesInstanceHaveCallable