-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_copy_functionality.py
More file actions
84 lines (68 loc) · 2.58 KB
/
Copy pathtest_copy_functionality.py
File metadata and controls
84 lines (68 loc) · 2.58 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
#!/usr/bin/env python3
"""
Test script to verify the copy API request functionality works correctly
"""
import json
from mockachu.generators.generator import Generators, GeneratorActions
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '.'))
def test_copy_functionality():
"""Test the core logic used in copy_api_request_to_clipboard"""
print("Testing copy to clipboard functionality...")
# Simulate field configuration like in the UI
field_config = {
"name": "test_field",
"generator": Generators.PERSON_GENERATOR,
"action": GeneratorActions.RANDOM_PERSON_FIRST_NAME,
"nullable_percentage": 0,
"parameters": None
}
# Build API request like the UI does
api_request = {
"fields": [],
"rows": 10,
"format": "JSON"
}
# Handle generator name (could be enum or string)
generator = field_config["generator"]
generator_name = generator.name if hasattr(
generator, 'name') else str(generator)
# Handle action name (could be enum or string)
action = field_config["action"]
action_name = action.name if hasattr(action, 'name') else str(action)
api_field = {
"name": field_config["name"],
"generator": generator_name,
"action": action_name
}
# Add nullable percentage if not zero
if field_config.get("nullable_percentage", 0) > 0:
api_field["nullable_percentage"] = field_config["nullable_percentage"]
# Add parameters if present
if field_config.get("parameters"):
api_field["parameters"] = field_config["parameters"]
api_request["fields"].append(api_field)
# Convert to JSON
json_request = json.dumps(api_request, indent=2)
print("Generated API request:")
print(json_request)
print("\n✅ Copy functionality logic is working correctly!")
# Validate that the JSON is valid and can be used with the API
try:
parsed = json.loads(json_request)
assert "fields" in parsed
assert "rows" in parsed
assert "format" in parsed
assert len(parsed["fields"]) == 1
assert parsed["fields"][0]["name"] == "test_field"
assert parsed["fields"][0]["generator"] == "PERSON_GENERATOR"
assert parsed["fields"][0]["action"] == "RANDOM_PERSON_FIRST_NAME"
print("✅ Generated JSON is valid and properly structured!")
return True
except Exception as e:
print(f"❌ JSON validation failed: {e}")
return False
if __name__ == "__main__":
success = test_copy_functionality()
sys.exit(0 if success else 1)