-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_crosschex_sync.py
More file actions
166 lines (130 loc) · 4.98 KB
/
Copy pathtest_crosschex_sync.py
File metadata and controls
166 lines (130 loc) · 4.98 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
#!/usr/bin/env python3
"""
Test CrossChex sync for specific API configuration
Run with: bench --site hrms.hamptons.om execute hamptons.test_crosschex_sync.test_sync
"""
import frappe
import json
def test_sync():
"""Test sync for HAMTONS 3 configuration"""
print("\n" + "="*80)
print("Testing CrossChex Sync - HAMTONS 3 (API Key: 853cfe14ff50623d550056a72f829036)")
print("="*80)
# Get the API configuration
config = frappe.db.get_value(
"CrossChex API Configuration",
{"api_key": "853cfe14ff50623d550056a72f829036"},
["name", "configuration_name", "api_url", "api_key", "connection_status", "last_sync_time"],
as_dict=True
)
if not config:
print("❌ Configuration not found!")
return
print(f"\n📋 Configuration Details:")
print(f" Name: {config['configuration_name']}")
print(f" API URL: {config['api_url']}")
print(f" API Key: {config['api_key']}")
print(f" Status: {config['connection_status']}")
print(f" Last Sync: {config['last_sync_time']}")
# Check current checkin count
before_count = frappe.db.count("Employee Checkin")
print(f"\n📊 Current Stats:")
print(f" Total Employee Checkins: {before_count}")
# Test the sync
print(f"\n🔄 Running sync...")
from hamptons.hamptons.doctype.crosschex_settings.crosschex_settings import sync_individual_device
result = sync_individual_device(
api_url=config['api_url'],
api_key=config['api_key'],
config_row_name=config['name'],
config_name=config['configuration_name']
)
print(f"\n📝 Sync Result:")
print(json.dumps(result, indent=2, default=str))
# Check new checkin count
after_count = frappe.db.count("Employee Checkin")
new_checkins = after_count - before_count
print(f"\n✅ Sync Complete:")
print(f" New Checkins Added: {new_checkins}")
print(f" Total Checkins Now: {after_count}")
# Show recent checkins
recent = frappe.db.sql("""
SELECT employee, employee_name, time, log_type, device_id
FROM `tabEmployee Checkin`
ORDER BY time DESC
LIMIT 5
""", as_dict=True)
print(f"\n📅 Most Recent Checkins:")
for r in recent:
print(f" • {r['time']} - {r['employee_name']} ({r['employee']}) - {r['log_type']}")
print("\n" + "="*80)
print("Test Complete")
print("="*80 + "\n")
return result
if __name__ == "__main__":
test_sync()
#!/usr/bin/env python3
"""
Test CrossChex sync for specific API configuration
Run with: bench --site hrms.hamptons.om execute hamptons.test_crosschex_sync.test_sync
"""
import frappe
import json
def test_sync():
"""Test sync for HAMTONS 3 configuration"""
print("\n" + "="*80)
print("Testing CrossChex Sync - HAMTONS 3 (API Key: 853cfe14ff50623d550056a72f829036)")
print("="*80)
# Get the API configuration
config = frappe.db.get_value(
"CrossChex API Configuration",
{"api_key": "853cfe14ff50623d550056a72f829036"},
["name", "configuration_name", "api_url", "api_key", "connection_status", "last_sync_time"],
as_dict=True
)
if not config:
print("❌ Configuration not found!")
return
print(f"\n📋 Configuration Details:")
print(f" Name: {config['configuration_name']}")
print(f" API URL: {config['api_url']}")
print(f" API Key: {config['api_key']}")
print(f" Status: {config['connection_status']}")
print(f" Last Sync: {config['last_sync_time']}")
# Check current checkin count
before_count = frappe.db.count("Employee Checkin")
print(f"\n📊 Current Stats:")
print(f" Total Employee Checkins: {before_count}")
# Test the sync
print(f"\n🔄 Running sync...")
from hamptons.hamptons.doctype.crosschex_settings.crosschex_settings import sync_individual_device
result = sync_individual_device(
api_url=config['api_url'],
api_key=config['api_key'],
config_row_name=config['name'],
config_name=config['configuration_name']
)
print(f"\n📝 Sync Result:")
print(json.dumps(result, indent=2, default=str))
# Check new checkin count
after_count = frappe.db.count("Employee Checkin")
new_checkins = after_count - before_count
print(f"\n✅ Sync Complete:")
print(f" New Checkins Added: {new_checkins}")
print(f" Total Checkins Now: {after_count}")
# Show recent checkins
recent = frappe.db.sql("""
SELECT employee, employee_name, time, log_type, device_id
FROM `tabEmployee Checkin`
ORDER BY time DESC
LIMIT 5
""", as_dict=True)
print(f"\n📅 Most Recent Checkins:")
for r in recent:
print(f" • {r['time']} - {r['employee_name']} ({r['employee']}) - {r['log_type']}")
print("\n" + "="*80)
print("Test Complete")
print("="*80 + "\n")
return result
if __name__ == "__main__":
test_sync()