Repository navigation
Expand file tree
/
Copy pathtest_cli.py
More file actions
178 lines (158 loc) · 5.62 KB
/
Copy pathtest_cli.py
File metadata and controls
178 lines (158 loc) · 5.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env python3
"""
Test script for CLI functionality.
"""
import subprocess
import sys
import os
from pathlib import Path
def test_help():
"""Test help command."""
print("Testing help command...")
result = subprocess.run([sys.executable, "main.py", "--help"],
capture_output=True, text=True)
if result.returncode == 0:
print("✅ Help command works")
return True
else:
print("❌ Help command failed")
print(f"Error: {result.stderr}")
return False
def test_call_help():
"""Test call command help."""
print("Testing call command help...")
result = subprocess.run([sys.executable, "main.py", "call", "--help"],
capture_output=True, text=True)
if result.returncode == 0:
print("✅ Call command help works")
return True
else:
print("❌ Call command help failed")
print(f"Error: {result.stderr}")
return False
def test_missing_credentials():
"""Test error handling for missing VoIP credentials."""
print("Testing missing credentials error...")
result = subprocess.run([sys.executable, "main.py", "call", "+1234567890"],
capture_output=True, text=True)
if result.returncode == 1 and "VoIP credentials not provided" in result.stdout:
print("✅ Missing credentials error handled correctly")
return True
else:
print("❌ Missing credentials error not handled correctly")
print(f"Return code: {result.returncode}")
print(f"Output: {result.stdout}")
print(f"Error: {result.stderr}")
return False
def test_dry_run():
"""Test dry run mode."""
print("Testing dry run mode...")
# Set environment variables for testing
env = os.environ.copy()
env["VOIP_USERNAME"] = "test_user"
env["VOIP_PASSWORD"] = "test_pass"
env["VOIP_SERVER"] = "test.server.com"
result = subprocess.run([sys.executable, "main.py", "call", "+1234567890", "--dry-run"],
capture_output=True, text=True, env=env)
if result.returncode == 0 and "DRY RUN MODE" in result.stdout:
print("✅ Dry run mode works")
return True
else:
print("❌ Dry run mode failed")
print(f"Return code: {result.returncode}")
print(f"Output: {result.stdout}")
print(f"Error: {result.stderr}")
return False
def test_verbose_logging():
"""Test verbose logging."""
print("Testing verbose logging...")
env = os.environ.copy()
env["VOIP_USERNAME"] = "test_user"
env["VOIP_PASSWORD"] = "test_pass"
env["VOIP_SERVER"] = "test.server.com"
result = subprocess.run([sys.executable, "main.py", "call", "+1234567890", "--dry-run", "--verbose"],
capture_output=True, text=True, env=env)
if result.returncode == 0 and "DEBUG" in result.stdout:
print("✅ Verbose logging works")
return True
else:
print("❌ Verbose logging failed")
print(f"Return code: {result.returncode}")
print(f"Output: {result.stdout}")
return False
def test_config_commands():
"""Test config commands."""
print("Testing config commands...")
# Test config show
result = subprocess.run([sys.executable, "main.py", "config", "--show"],
capture_output=True, text=True)
if result.returncode == 0:
print("✅ Config show command works")
else:
print("❌ Config show command failed")
return False
# Test config set-voip
result = subprocess.run([sys.executable, "main.py", "config", "--set-voip"],
capture_output=True, text=True)
if result.returncode == 0:
print("✅ Config set-voip command works")
return True
else:
print("❌ Config set-voip command failed")
return False
def test_status_command():
"""Test status command."""
print("Testing status command...")
result = subprocess.run([sys.executable, "main.py", "status"],
capture_output=True, text=True)
if result.returncode == 0:
print("✅ Status command works")
return True
else:
print("❌ Status command failed")
print(f"Error: {result.stderr}")
return False
def test_logs_command():
"""Test logs command."""
print("Testing logs command...")
result = subprocess.run([sys.executable, "main.py", "logs"],
capture_output=True, text=True)
if result.returncode == 0:
print("✅ Logs command works")
return True
else:
print("❌ Logs command failed")
print(f"Error: {result.stderr}")
return False
def main():
"""Run all tests."""
print("🧪 Running CLI Tests\n")
tests = [
test_help,
test_call_help,
test_missing_credentials,
test_dry_run,
test_verbose_logging,
test_config_commands,
test_status_command,
test_logs_command
]
passed = 0
total = len(tests)
for test in tests:
try:
if test():
passed += 1
except Exception as e:
print(f"❌ Test {test.__name__} failed with exception: {e}")
print()
print(f"📊 Test Results: {passed}/{total} tests passed")
if passed == total:
print("🎉 All tests passed! CLI setup is working correctly.")
return True
else:
print("⚠️ Some tests failed. Please check the implementation.")
return False
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)