11# Test application file
2+ import time
23import unittest
34from pathlib import Path
5+ from unittest .mock import Mock
46
7+ from common .validator .error_report .error_reporter import build_error_report
58from common .validator .validator import Validator
69from test_common .validator .testing_utils .constants import CSV_HEADER , CSV_VALUES
710from tests .test_common .validator .testing_utils .csv_fhir_utils import build_row , parse_test_file
@@ -21,23 +24,42 @@ def setUp(self):
2124
2225 def test_run_validation_on_valid_csv_row (self ):
2326 valid_rows = build_row (CSV_HEADER , CSV_VALUES )
24- error_report = self .validator .validate_csv_row (valid_rows , CSV_HEADER , True , True , True )
25- print (f"Error Report: { error_report } " )
26- self .assertEqual (error_report , [])
27+ error_list = self .validator .validate_csv_row (valid_rows , CSV_HEADER , True , True , True )
28+ self .assertEqual (error_list , [])
2729
2830 def test_run_validation_on_invalid_csv_row (self ):
2931 invalid_rows = build_row (CSV_HEADER , {** CSV_VALUES , "NHS_NUMBER" : "" })
30- error_report = self .validator .validate_csv_row (invalid_rows , CSV_HEADER , True , True , True )
31- print ( f"Error Report: { error_report } " )
32- self .assertTrue (len (error_report ) > 0 )
33- messages = [(e .name , e .message , e .details ) for e in error_report ]
32+ error_list = self .validator .validate_csv_row (invalid_rows , CSV_HEADER , True , True , True )
33+
34+ self .assertTrue (len (error_list ) > 0 )
35+ messages = [(e .name , e .message , e .details ) for e in error_list ]
3436 expected_error = (
3537 "NHS Number Not Empty Check" ,
3638 "Value not empty failure" ,
3739 "Value is empty, not as expected" ,
3840 )
39- self .maxDiff = None
40- print (f"Error Report: { error_report } " )
41- print (f"Messages: { messages } " )
42- print (f"Expected Error: { expected_error } " )
4341 self .assertIn (expected_error , messages )
42+
43+ csv_parser = Mock ()
44+ csv_parser .extract_field_value .return_value = "2025-11-06T12:00:00Z"
45+ error_report = build_error_report ("25a8cc4d-1875-4191-ac6d-2d63a0ebc64b" , csv_parser , error_list )
46+
47+ failed_validation = self .validator .has_validation_failed (error_list )
48+
49+ if len (error_list ) > 0 :
50+ start = time .time ()
51+
52+ if len (error_list ) > 0 :
53+ print (error_list )
54+ else :
55+ print ("Validated CSV Successfully" )
56+ print (error_report )
57+
58+ if failed_validation :
59+ print ("CSV Validation failed due to a critical validation failure..." )
60+ else :
61+ print ("CSV Validation Successful, see reports for details" )
62+
63+ end = time .time ()
64+ print ("Time Taken : " )
65+ print (end - start )
0 commit comments