fix: resolve CI linting and code quality issues

- Remove unused imports across all generator files
- Remove unused variables (spec, url_params, query_params, test_name)
- Fix f-strings without placeholders in auth.py and go.py
- Fix duplicate BASIC auth handling with wrong indentation
- Add missing pytest fixtures (sample_openapi_spec, temp_spec_file, temp_json_spec_file)
- Add missing TemplateRenderError import to generator files
This commit is contained in:
CI Bot
2026-02-06 07:05:58 +00:00
parent 839317c44b
commit 123a4f7d1d
8 changed files with 211 additions and 29 deletions

View File

@@ -1,10 +1,6 @@
"""CLI interface for API TestGen."""
from pathlib import Path
from typing import Optional
import click
import yaml
from ..core import SpecParser, AuthConfig
from ..core.exceptions import InvalidOpenAPISpecError, UnsupportedVersionError
@@ -57,7 +53,7 @@ def parse_spec(ctx: click.Context):
try:
parser = SpecParser(spec_path)
spec = parser.load()
parser.load()
info = parser.get_info()
endpoints = parser.get_endpoints()

View File

@@ -1,6 +1,6 @@
"""Authentication configuration for API TestGen."""
from typing import Any, Dict, List, Optional, Union
from typing import Any, Dict, List, Optional
from enum import Enum
from .exceptions import AuthConfigError, MissingSecuritySchemeError
@@ -293,21 +293,21 @@ func getAPIKeyHeaders() map[string]string {{
}}
'''
elif method["type"] == AuthType.BEARER:
return f'''
func getBearerHeaders() map[string]string {{
return map[string]string{{
return '''
func getBearerHeaders() map[string]string {
return map[string]string{
"Authorization": fmt.Sprintf("%s %s", os.Getenv("TOKEN_PREFIX"), os.Getenv("TOKEN")),
}}
}}
}
}
'''
elif method["type"] == AuthType.BASIC:
return f'''
func getBasicHeaders(username, password string) map[string]string {{
return '''
func getBasicHeaders(username, password string) map[string]string {
auth := username + ":" + password
encoded := base64.StdEncoding.EncodeToString([]byte(auth))
return map[string]string{{
return map[string]string{
"Authorization": "Basic " + encoded,
}}
}}
}
}
'''
return ""

View File

@@ -6,7 +6,6 @@ from pathlib import Path
from typing import Any, Dict, List, Optional, Union
from openapi_spec_validator import validate
from openapi_spec_validator.versions import consts as validator_consts
from .exceptions import InvalidOpenAPISpecError, UnsupportedVersionError

View File

@@ -6,8 +6,8 @@ from typing import Any, Dict, List, Optional
from jinja2 import Environment, FileSystemLoader, TemplateSyntaxError, UndefinedError
from ..core import SpecParser, AuthConfig
from ..core.exceptions import GeneratorError, TemplateRenderError
from ..core import SpecParser
from ..core.exceptions import TemplateRenderError
class GoGenerator:
@@ -132,7 +132,6 @@ class GoGenerator:
"""
test_name = self._generate_test_name(endpoint)
params = self._generate_params(endpoint)
url_params = self._generate_url_params(endpoint)
test_code = f'''
func Test{test_name}(t *testing.T) {{
@@ -201,11 +200,11 @@ func Test{test_name}(t *testing.T) {{
if param["in"] == "path":
params.append(f'{param_name} := "test_{param_name}"')
params.append(f'url = strings.Replace(url, "{{'+param_name+'}}", {param_name}, 1)')
params.append('url = strings.Replace(url, "' + '{' + param_name + '}' + '", ' + param_name + ', 1)')
elif param["in"] == "query":
params.append(f'q := url.Values{{{param_name}: []string{{"test"}}}}')
params.append(f'url += "?" + q.Encode()')
params.append('url += "?" + q.Encode()')
return "\n ".join(params) if params else ""
@@ -219,11 +218,10 @@ func Test{test_name}(t *testing.T) {{
String containing URL parameter handling.
"""
path_params = [p for p in endpoint.get("parameters", []) if p["in"] == "path"]
query_params = [p for p in endpoint.get("parameters", []) if p["in"] == "query"]
parts = []
for param in path_params:
parts.append(f'strings.Replace(url, "{{'+param['name']+'}}", "test_' + param['name'] + '", 1)')
parts.append('strings.Replace(url, "' + '{' + param['name'] + '}' + '", "test_' + param['name'] + '", 1)')
return ""

View File

@@ -6,8 +6,8 @@ from typing import Any, Dict, List, Optional
from jinja2 import Environment, FileSystemLoader, TemplateSyntaxError, UndefinedError
from ..core import SpecParser, AuthConfig
from ..core.exceptions import GeneratorError, TemplateRenderError
from ..core import SpecParser
from ..core.exceptions import TemplateRenderError
class JestGenerator:
@@ -106,7 +106,6 @@ class JestGenerator:
Returns:
String containing the test code.
"""
test_name = self._generate_test_name(endpoint)
describe_name = endpoint["summary"] or endpoint["path"]
params = self._generate_params(endpoint)

View File

@@ -7,7 +7,7 @@ from typing import Any, Dict, List, Optional
from jinja2 import Environment, FileSystemLoader, TemplateSyntaxError, UndefinedError
from ..core import SpecParser, AuthConfig
from ..core.exceptions import GeneratorError, TemplateRenderError
from ..core.exceptions import TemplateRenderError
class PytestGenerator:

View File

@@ -2,7 +2,7 @@
import json
from pathlib import Path
from typing import Any, Dict, List, Optional
from typing import List, Optional
from ..core import SpecParser