#!/usr/bin/env python3
"""
Auto-generated CLI tests for apikey commands

Generated by: tests/generators/test_generator.py
DO NOT EDIT MANUALLY - Regenerate with: python tests/generators/test_generator.py

This file provides comprehensive coverage of apikey CLI commands, options,
and parameter combinations. Tests are automatically generated by introspecting
the Click command structure.
"""

import subprocess
import os

# Set testing environment variable
os.environ["N8N_DEPLOY_TESTING"] = "1"

CLI_COMMAND = ["./n8n-deploy"]


def test_apikey_activate_help():
    """Test apikey  activate --help"""
    result = subprocess.run(CLI_COMMAND + ["apikey", "activate", "--help"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey activate --help\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )
    assert "Usage:" in result.stdout or "Usage:" in result.stderr, (
        f"Expected 'Usage:' in output\n" f"stdout: {result.stdout[:500]}\n" f"stderr: {result.stderr[:500]}"
    )


def test_apikey_activate_data_dir_valid_path():
    """Test apikey  activate with valid --data-dir"""
    result = subprocess.run(
        CLI_COMMAND + ["apikey", "activate", "--data-dir", "/tmp"], capture_output=True, text=True, timeout=60
    )
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey activate --data-dir /tmp\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_apikey_activate_with_positional_args():
    """Test apikey  activate with positional arguments"""
    result = subprocess.run(CLI_COMMAND + ["apikey", "activate", "test_key_name"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey activate test_key_name\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_apikey_activate_missing_required_args():
    """Test apikey  activate with missing required arguments"""
    result = subprocess.run(CLI_COMMAND + ["apikey", "activate"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey activate\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )
    assert "Error:" in result.stdout or "Error:" in result.stderr, (
        f"Expected 'Error:' in output\n" f"stdout: {result.stdout[:500]}\n" f"stderr: {result.stderr[:500]}"
    )


def test_apikey_add_help():
    """Test apikey  add --help"""
    result = subprocess.run(CLI_COMMAND + ["apikey", "add", "--help"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey add --help\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )
    assert "Usage:" in result.stdout or "Usage:" in result.stderr, (
        f"Expected 'Usage:' in output\n" f"stdout: {result.stdout[:500]}\n" f"stderr: {result.stderr[:500]}"
    )


def test_apikey_add_data_dir_valid_path():
    """Test apikey  add with valid --data-dir"""
    result = subprocess.run(CLI_COMMAND + ["apikey", "add", "--data-dir", "/tmp"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey add --data-dir /tmp\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_apikey_add_with_positional_args():
    """Test apikey  add with positional arguments"""
    result = subprocess.run(CLI_COMMAND + ["apikey", "add", "test_key"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey add test_key\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_apikey_deactivate_help():
    """Test apikey  deactivate --help"""
    result = subprocess.run(CLI_COMMAND + ["apikey", "deactivate", "--help"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey deactivate --help\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )
    assert "Usage:" in result.stdout or "Usage:" in result.stderr, (
        f"Expected 'Usage:' in output\n" f"stdout: {result.stdout[:500]}\n" f"stderr: {result.stderr[:500]}"
    )


def test_apikey_deactivate_data_dir_valid_path():
    """Test apikey  deactivate with valid --data-dir"""
    result = subprocess.run(
        CLI_COMMAND + ["apikey", "deactivate", "--data-dir", "/tmp"], capture_output=True, text=True, timeout=60
    )
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey deactivate --data-dir /tmp\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_apikey_deactivate_with_positional_args():
    """Test apikey  deactivate with positional arguments"""
    result = subprocess.run(
        CLI_COMMAND + ["apikey", "deactivate", "test_key_name"], capture_output=True, text=True, timeout=60
    )
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey deactivate test_key_name\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_apikey_deactivate_missing_required_args():
    """Test apikey  deactivate with missing required arguments"""
    result = subprocess.run(CLI_COMMAND + ["apikey", "deactivate"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey deactivate\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )
    assert "Error:" in result.stdout or "Error:" in result.stderr, (
        f"Expected 'Error:' in output\n" f"stdout: {result.stdout[:500]}\n" f"stderr: {result.stderr[:500]}"
    )


def test_apikey_delete_help():
    """Test apikey  delete --help"""
    result = subprocess.run(CLI_COMMAND + ["apikey", "delete", "--help"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey delete --help\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )
    assert "Usage:" in result.stdout or "Usage:" in result.stderr, (
        f"Expected 'Usage:' in output\n" f"stdout: {result.stdout[:500]}\n" f"stderr: {result.stderr[:500]}"
    )


def test_apikey_delete_force_flag():
    """Test apikey  delete with --force flag"""
    result = subprocess.run(CLI_COMMAND + ["apikey", "delete", "--force"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey delete --force\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_apikey_delete_data_dir_valid_path():
    """Test apikey  delete with valid --data-dir"""
    result = subprocess.run(
        CLI_COMMAND + ["apikey", "delete", "--data-dir", "/tmp"], capture_output=True, text=True, timeout=60
    )
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey delete --data-dir /tmp\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_apikey_delete_with_positional_args():
    """Test apikey  delete with positional arguments"""
    result = subprocess.run(CLI_COMMAND + ["apikey", "delete", "test_key_name"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey delete test_key_name\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_apikey_delete_missing_required_args():
    """Test apikey  delete with missing required arguments"""
    result = subprocess.run(CLI_COMMAND + ["apikey", "delete"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey delete\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )
    assert "Error:" in result.stdout or "Error:" in result.stderr, (
        f"Expected 'Error:' in output\n" f"stdout: {result.stdout[:500]}\n" f"stderr: {result.stderr[:500]}"
    )


def test_apikey_list_help():
    """Test apikey  list --help"""
    result = subprocess.run(CLI_COMMAND + ["apikey", "list", "--help"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey list --help\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )
    assert "Usage:" in result.stdout or "Usage:" in result.stderr, (
        f"Expected 'Usage:' in output\n" f"stdout: {result.stdout[:500]}\n" f"stderr: {result.stderr[:500]}"
    )


def test_apikey_list_no_args():
    """Test apikey  list with no arguments"""
    result = subprocess.run(CLI_COMMAND + ["apikey", "list"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey list\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_apikey_list_unmask_flag():
    """Test apikey  list with --unmask flag"""
    result = subprocess.run(CLI_COMMAND + ["apikey", "list", "--unmask"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey list --unmask\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_apikey_list_output_json_flag():
    """Test apikey  list with --output-json flag"""
    result = subprocess.run(CLI_COMMAND + ["apikey", "list", "--output-json"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey list --output-json\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_apikey_list_data_dir_valid_path():
    """Test apikey  list with valid --data-dir"""
    result = subprocess.run(CLI_COMMAND + ["apikey", "list", "--data-dir", "/tmp"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey list --data-dir /tmp\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_apikey_test_help():
    """Test apikey  test --help"""
    result = subprocess.run(CLI_COMMAND + ["apikey", "test", "--help"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey test --help\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )
    assert "Usage:" in result.stdout or "Usage:" in result.stderr, (
        f"Expected 'Usage:' in output\n" f"stdout: {result.stdout[:500]}\n" f"stderr: {result.stderr[:500]}"
    )


def test_apikey_test_skip_ssl_verify_flag():
    """Test apikey  test with --skip-ssl-verify flag"""
    result = subprocess.run(CLI_COMMAND + ["apikey", "test", "--skip-ssl-verify"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey test --skip-ssl-verify\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_apikey_test_data_dir_valid_path():
    """Test apikey  test with valid --data-dir"""
    result = subprocess.run(CLI_COMMAND + ["apikey", "test", "--data-dir", "/tmp"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey test --data-dir /tmp\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_apikey_test_with_positional_args():
    """Test apikey  test with positional arguments"""
    result = subprocess.run(CLI_COMMAND + ["apikey", "test", "test_key_name"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [0, 1, 2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey test test_key_name\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )


def test_apikey_test_missing_required_args():
    """Test apikey  test with missing required arguments"""
    result = subprocess.run(CLI_COMMAND + ["apikey", "test"], capture_output=True, text=True, timeout=60)
    assert result.returncode in [2], (
        f"Command failed with exit code {result.returncode}\n"
        f"Command: apikey test\n"
        f"stdout: {result.stdout[:500]}\n"
        f"stderr: {result.stderr[:500]}"
    )
    assert "Error:" in result.stdout or "Error:" in result.stderr, (
        f"Expected 'Error:' in output\n" f"stdout: {result.stdout[:500]}\n" f"stderr: {result.stderr[:500]}"
    )
