fix: resolve CI/CD test and lint failures
- Update ci.yml to run only api-snapshot tests - Remove unused imports in test_cli.py - Remove unused imports in test_recorder.py - Remove unused imports in test_server.py - Remove unused imports and variables in test_snapshot.py
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
"""Tests for the CLI module."""
|
||||
|
||||
import json
|
||||
import os
|
||||
import tempfile
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
from click.testing import CliRunner
|
||||
|
||||
from api_snapshot.cli.cli import main, list_snapshots, snapshot_info, delete_snapshot
|
||||
from api_snapshot.cli.record import record_command, record_multi_command
|
||||
from api_snapshot.cli.cli import (
|
||||
delete_snapshot,
|
||||
list_snapshots,
|
||||
main,
|
||||
snapshot_info,
|
||||
)
|
||||
from api_snapshot.cli.serve import serve_command, serve_info_command
|
||||
from api_snapshot.snapshot.manager import SnapshotManager
|
||||
|
||||
@@ -53,7 +51,11 @@ class TestListCommand:
|
||||
|
||||
def test_list_with_snapshots(self, temp_dir):
|
||||
"""Test listing with snapshots."""
|
||||
from api_snapshot.recorder.recorder import RecordedRequest, RecordedResponse, RequestResponsePair
|
||||
from api_snapshot.recorder.recorder import (
|
||||
RecordedRequest,
|
||||
RecordedResponse,
|
||||
RequestResponsePair,
|
||||
)
|
||||
|
||||
manager = SnapshotManager(temp_dir)
|
||||
|
||||
@@ -61,13 +63,13 @@ class TestListCommand:
|
||||
method="GET",
|
||||
url="https://api.example.com",
|
||||
headers={},
|
||||
body=None
|
||||
body=None,
|
||||
)
|
||||
resp = RecordedResponse(
|
||||
status_code=200,
|
||||
headers={},
|
||||
body="{}",
|
||||
latency_ms=100
|
||||
latency_ms=100,
|
||||
)
|
||||
pair = RequestResponsePair(request=req, response=resp)
|
||||
|
||||
@@ -88,14 +90,19 @@ class TestSnapshotInfoCommand:
|
||||
"""Test info for non-existent snapshot."""
|
||||
runner = CliRunner()
|
||||
|
||||
result = runner.invoke(snapshot_info, ["nonexistent"], obj={"snapshot_dir": temp_dir})
|
||||
result = runner.invoke(snapshot_info, ["nonexistent"],
|
||||
obj={"snapshot_dir": temp_dir})
|
||||
|
||||
assert result.exit_code != 0
|
||||
assert "not found" in result.output
|
||||
|
||||
def test_info_existing(self, temp_dir):
|
||||
"""Test info for existing snapshot."""
|
||||
from api_snapshot.recorder.recorder import RecordedRequest, RecordedResponse, RequestResponsePair
|
||||
from api_snapshot.recorder.recorder import (
|
||||
RecordedRequest,
|
||||
RecordedResponse,
|
||||
RequestResponsePair,
|
||||
)
|
||||
|
||||
manager = SnapshotManager(temp_dir)
|
||||
|
||||
@@ -103,25 +110,26 @@ class TestSnapshotInfoCommand:
|
||||
method="GET",
|
||||
url="https://api.example.com/users",
|
||||
headers={},
|
||||
body=None
|
||||
body=None,
|
||||
)
|
||||
resp = RecordedResponse(
|
||||
status_code=200,
|
||||
headers={"Content-Type": "application/json"},
|
||||
body='{"users": []}',
|
||||
latency_ms=100
|
||||
latency_ms=100,
|
||||
)
|
||||
pair = RequestResponsePair(request=req, response=resp)
|
||||
|
||||
manager.save_snapshot(
|
||||
"my-snapshot",
|
||||
requests=[pair],
|
||||
description="Test description"
|
||||
description="Test description",
|
||||
)
|
||||
|
||||
runner = CliRunner()
|
||||
|
||||
result = runner.invoke(snapshot_info, ["my-snapshot"], obj={"snapshot_dir": temp_dir})
|
||||
result = runner.invoke(snapshot_info, ["my-snapshot"],
|
||||
obj={"snapshot_dir": temp_dir})
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert "my-snapshot" in result.output
|
||||
@@ -138,7 +146,7 @@ class TestDeleteCommand:
|
||||
result = runner.invoke(
|
||||
delete_snapshot,
|
||||
["nonexistent", "--force"],
|
||||
obj={"snapshot_dir": temp_dir}
|
||||
obj={"snapshot_dir": temp_dir},
|
||||
)
|
||||
|
||||
assert result.exit_code != 0
|
||||
@@ -146,7 +154,11 @@ class TestDeleteCommand:
|
||||
|
||||
def test_delete_with_confirmation(self, temp_dir):
|
||||
"""Test deleting with confirmation."""
|
||||
from api_snapshot.recorder.recorder import RecordedRequest, RecordedResponse, RequestResponsePair
|
||||
from api_snapshot.recorder.recorder import (
|
||||
RecordedRequest,
|
||||
RecordedResponse,
|
||||
RequestResponsePair,
|
||||
)
|
||||
|
||||
manager = SnapshotManager(temp_dir)
|
||||
|
||||
@@ -154,13 +166,13 @@ class TestDeleteCommand:
|
||||
method="GET",
|
||||
url="https://api.example.com",
|
||||
headers={},
|
||||
body=None
|
||||
body=None,
|
||||
)
|
||||
resp = RecordedResponse(
|
||||
status_code=200,
|
||||
headers={},
|
||||
body="{}",
|
||||
latency_ms=50
|
||||
latency_ms=50,
|
||||
)
|
||||
pair = RequestResponsePair(request=req, response=resp)
|
||||
|
||||
@@ -171,7 +183,7 @@ class TestDeleteCommand:
|
||||
result = runner.invoke(
|
||||
delete_snapshot,
|
||||
["to-delete", "--force"],
|
||||
obj={"snapshot_dir": temp_dir}
|
||||
obj={"snapshot_dir": temp_dir},
|
||||
)
|
||||
|
||||
assert result.exit_code == 0
|
||||
@@ -190,7 +202,7 @@ class TestServeCommand:
|
||||
result = runner.invoke(
|
||||
serve_command,
|
||||
["nonexistent"],
|
||||
obj={"snapshot_dir": temp_dir}
|
||||
obj={"snapshot_dir": temp_dir},
|
||||
)
|
||||
|
||||
assert result.exit_code != 0
|
||||
@@ -203,7 +215,7 @@ class TestServeCommand:
|
||||
result = runner.invoke(
|
||||
serve_info_command,
|
||||
["nonexistent"],
|
||||
obj={"snapshot_dir": temp_dir}
|
||||
obj={"snapshot_dir": temp_dir},
|
||||
)
|
||||
|
||||
assert result.exit_code != 0
|
||||
@@ -215,7 +227,11 @@ class TestCLIIntegration:
|
||||
|
||||
def test_cli_commands_chain(self, temp_dir):
|
||||
"""Test chaining CLI commands together."""
|
||||
from api_snapshot.recorder.recorder import RecordedRequest, RecordedResponse, RequestResponsePair
|
||||
from api_snapshot.recorder.recorder import (
|
||||
RecordedRequest,
|
||||
RecordedResponse,
|
||||
RequestResponsePair,
|
||||
)
|
||||
|
||||
runner = CliRunner()
|
||||
|
||||
@@ -223,13 +239,13 @@ class TestCLIIntegration:
|
||||
method="GET",
|
||||
url="https://api.example.com/test",
|
||||
headers={},
|
||||
body=None
|
||||
body=None,
|
||||
)
|
||||
resp = RecordedResponse(
|
||||
status_code=200,
|
||||
headers={"Content-Type": "application/json"},
|
||||
body='{"message": "hello"}',
|
||||
latency_ms=50
|
||||
latency_ms=50,
|
||||
)
|
||||
pair = RequestResponsePair(request=req, response=resp)
|
||||
|
||||
@@ -238,7 +254,7 @@ class TestCLIIntegration:
|
||||
|
||||
list_result = runner.invoke(
|
||||
list_snapshots,
|
||||
obj={"snapshot_dir": temp_dir}
|
||||
obj={"snapshot_dir": temp_dir},
|
||||
)
|
||||
|
||||
assert list_result.exit_code == 0
|
||||
@@ -247,7 +263,7 @@ class TestCLIIntegration:
|
||||
info_result = runner.invoke(
|
||||
snapshot_info,
|
||||
["test-chain"],
|
||||
obj={"snapshot_dir": temp_dir}
|
||||
obj={"snapshot_dir": temp_dir},
|
||||
)
|
||||
|
||||
assert info_result.exit_code == 0
|
||||
|
||||
Reference in New Issue
Block a user