stackConsult commited on
Commit
bf1af21
·
verified ·
1 Parent(s): cc10b69

Add atomic activity ingestion validation script

Browse files

Validates core ingestion with four test scenarios:
- Valid insert (should succeed)
- Invalid status value (should fail)
- Missing required field (should fail)
- Confirm atomic insert (should always succeed if schema-valid)
Each test outputs PASS/FAIL and error details for review.

Files changed (1) hide show
  1. test_validation.py +56 -0
test_validation.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Validation script: Runs schema-compliant inserts, error cases, and prints results for atomic activity ingestion function.
3
+ """
4
+ from activity_ingestion import atomic_append_activity
5
+ import os
6
+
7
+ def print_test_result(test_name, result):
8
+ status = 'PASS' if result['success'] else 'FAIL'
9
+ print(f'[{status}] {test_name}')
10
+ if result['error']:
11
+ print(f' Error: {result["error"]}')
12
+ else:
13
+ print(f' Commit Hash: {result.get("commit_hash")}, Request ID: {result.get("request_id")}')
14
+
15
+ def test_all():
16
+ # Clean up before test for atomicity validation
17
+ if os.path.exists('activity_log.csv'):
18
+ os.rename('activity_log.csv', 'activity_log.csv.bak')
19
+
20
+ valid_rec = {
21
+ 'agent_id': 'validation_agent',
22
+ 'activity_type': 'ingest',
23
+ 'entity_id': 'entity_001',
24
+ 'status': 'success',
25
+ 'notes': 'Valid activity example',
26
+ 'context': 'Validation test - success'
27
+ }
28
+ invalid_rec = {
29
+ 'agent_id': 'validation_agent',
30
+ 'activity_type': 'ingest',
31
+ 'entity_id': 'entity_002',
32
+ 'status': 'not_valid', # invalid
33
+ 'notes': 'Should fail',
34
+ 'context': 'Validation test - error'
35
+ }
36
+ missing_field = {
37
+ 'agent_id': 'validation_agent',
38
+ 'activity_type': 'ingest',
39
+ # 'entity_id' missing
40
+ 'status': 'success',
41
+ 'notes': 'Missing field',
42
+ 'context': 'Validation test - missing'
43
+ }
44
+ print('Running validation tests...')
45
+ print_test_result('Valid record insert', atomic_append_activity('activity_log.csv', valid_rec))
46
+ print_test_result('Invalid status value', atomic_append_activity('activity_log.csv', invalid_rec))
47
+ print_test_result('Missing required field', atomic_append_activity('activity_log.csv', missing_field))
48
+ print('Re-inserting valid to confirm atomicity:')
49
+ print_test_result('Second valid insert', atomic_append_activity('activity_log.csv', valid_rec))
50
+
51
+ if os.path.exists('activity_log.csv.bak'):
52
+ os.remove('activity_log.csv')
53
+ os.rename('activity_log.csv.bak', 'activity_log.csv')
54
+
55
+ if __name__ == '__main__':
56
+ test_all()