|
1 | 1 | #!/usr/bin/env python3 |
2 | | -"""Test script for VoiceIt3 Python SDK — exercises all API endpoints against voiceitapi3""" |
3 | | - |
4 | | -import os |
5 | | -import sys |
| 2 | +"""Full API test: create user, video enroll x3, video verify, cleanup""" |
| 3 | +import os, sys |
6 | 4 | from voiceit3 import VoiceIt3 |
7 | 5 |
|
8 | 6 | api_key = os.environ.get("VOICEIT_API_KEY", "") |
9 | 7 | api_token = os.environ.get("VOICEIT_API_TOKEN", "") |
10 | | - |
11 | 8 | if not api_key or not api_token: |
12 | | - print("Set VOICEIT_API_KEY and VOICEIT_API_TOKEN environment variables") |
13 | | - sys.exit(1) |
| 9 | + print("Set VOICEIT_API_KEY and VOICEIT_API_TOKEN"); sys.exit(1) |
14 | 10 |
|
15 | 11 | vi = VoiceIt3(api_key, api_token) |
16 | | - |
17 | | -# Users |
18 | | -print("CreateUser:", vi.create_user()) |
19 | | -print("GetAllUsers:", vi.get_all_users()) |
20 | | - |
21 | | -# Groups |
22 | | -print("CreateGroup:", vi.create_group("Test Group")) |
23 | | -print("GetAllGroups:", vi.get_all_groups()) |
24 | | - |
25 | | -# Phrases |
26 | | -print("GetPhrases:", vi.get_phrases("en-US")) |
27 | | - |
28 | | -print("\nAll API calls completed successfully!") |
| 12 | +phrase = "never forget tomorrow is a new day" |
| 13 | +td = "test-data" |
| 14 | +errors = 0 |
| 15 | + |
| 16 | +def check(step, r, expected="SUCC"): |
| 17 | + global errors |
| 18 | + code = r.get("responseCode", "?") |
| 19 | + ok = code == expected |
| 20 | + print(f"{'PASS' if ok else 'FAIL'}: {step} ({code})") |
| 21 | + if not ok: errors += 1 |
| 22 | + return r |
| 23 | + |
| 24 | +# 1. Create user |
| 25 | +r = check("CreateUser", vi.create_user()) |
| 26 | +user_id = r.get("userId", "") |
| 27 | + |
| 28 | +# 2. Video enrollment x3 |
| 29 | +for i in range(1, 4): |
| 30 | + check(f"VideoEnrollment{i}", vi.create_video_enrollment(user_id, "en-US", phrase, f"{td}/videoEnrollmentA{i}.mov")) |
| 31 | + |
| 32 | +# 3. Video verification (tests both voice + face) |
| 33 | +r = check("VideoVerification", vi.video_verification(user_id, "en-US", phrase, f"{td}/videoVerificationA1.mov")) |
| 34 | +print(f" Voice confidence: {r.get('voiceConfidence', 0)}, Face confidence: {r.get('faceConfidence', 0)}") |
| 35 | + |
| 36 | +# 4. Cleanup |
| 37 | +check("DeleteEnrollments", vi.delete_all_enrollments(user_id)) |
| 38 | +check("DeleteUser", vi.delete_user(user_id)) |
| 39 | + |
| 40 | +if errors > 0: |
| 41 | + print(f"\n{errors} FAILURES"); sys.exit(1) |
| 42 | +print("\nAll tests passed!") |
0 commit comments