Skip to content

Commit 016238b

Browse files
committed
test_application_csv_small
1 parent ff742c7 commit 016238b

File tree

7 files changed

+107
-2
lines changed

7 files changed

+107
-2
lines changed

lambdas/shared/src/common/validator/parsers/csv_parser.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ def __init__(self):
1212
# parse the CSV into a Dictionary
1313
def parse_csv_file(self, csv_filename):
1414
input_file = csv.DictReader(open(csv_filename))
15+
input_file = csv.DictReader(open(csv_filename), delimiter="|")
1516
self.csv_file_data = {elem: [] for elem in input_file.fieldnames}
17+
keys = self.csv_file_data.keys()
1618
for row in input_file:
17-
for key in self.csv_file_data.keys():
19+
for key in keys:
1820
self.csv_file_data[key].append(row[key])
1921

2022
# ---------------------------------------------

lambdas/shared/tests/test_common/validator/test_application_csv.py renamed to lambdas/shared/tests/test_common/validator/Xtest_application_csv_old.py

File renamed without changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
NHS_NUMBER|PERSON_FORENAME|PERSON_SURNAME|PERSON_DOB
2+
"9674963871"|"SABINA"|"GREIR"|"20190131"
3+
"9454195417"|"SHAQUILLE"|"KOLBERG"|"30110513"
4+
"9730117489"||"RUDD"|"20011114"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
NHS_NUMBER|PERSON_FORENAME|PERSON_SURNAME|PERSON_DOB
2+
"9674963871"|"SABINA"|"GREIR"|"20190131"
3+
"9454195417"|"SHAQUILLE"|"KOLBERG"|"20110513"
4+
"9730117489"|"STUART"|"RUDD"|"20011114"
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"id": "No 2",
3+
"schemaName": "Small Test Validation",
4+
"version": 1.0,
5+
"releaseDate": "2024-07-17T00:00:00.000Z",
6+
"expressions": [
7+
{ "expressionId" : "check_1",
8+
"fieldNameCSV": "NHS_NUMBER",
9+
"fieldNameFlat": "NHS_NUMBER",
10+
"errorLevel" : 0,
11+
"expression": {
12+
"expressionName": "NHS Number Not Empty Check",
13+
"expressionType": "NOTEMPTY",
14+
"expressionRule": ""
15+
},
16+
"errorGroup": "validity"
17+
},
18+
{
19+
"expressionId" : "check_2",
20+
"fieldNameCSV": "PERSON_FORENAME",
21+
"fieldNameFlat": "PERSON_FORENAME",
22+
"errorLevel" : 0,
23+
"expression": {
24+
"expressionName": "Person Forname Not Empty Check",
25+
"expressionType": "NOTEMPTY",
26+
"expressionRule": ""
27+
},
28+
"errorGroup": "completeness"
29+
},
30+
{
31+
"expressionId" : "check_3",
32+
"fieldNameCSV": "PERSON_SURNAME",
33+
"fieldNameFlat": "PERSON_SURNAME",
34+
"errorLevel" : 0,
35+
"parentExpression": "check_1",
36+
"expression": {
37+
"expressionName": "Person Surname Not Empty Check",
38+
"expressionType": "NOTEMPTY",
39+
"expressionRule": ""
40+
},
41+
"errorGroup": "completeness"
42+
},
43+
{
44+
"expressionId" : "check_3",
45+
"fieldNameCSV": "PERSON_DOB",
46+
"fieldNameFlat": "PERSON_DOB",
47+
"errorLevel" : 0,
48+
"parentExpression": "check_1",
49+
"expression": {
50+
"expressionName": "Person DOB Not Empty Check",
51+
"expressionType": "NOTEMPTY",
52+
"expressionRule": ""
53+
},
54+
"errorGroup": "completeness"
55+
},
56+
{
57+
"expressionId" : "check_4",
58+
"fieldNameCSV": "PERSON_DOB",
59+
"fieldNameFlat": "PERSON_DOB",
60+
"errorLevel" : 0,
61+
"parentExpression": "check_1",
62+
"expression": {
63+
"expressionName": "Person DOB Valid Date Check",
64+
"expressionType": "DATE",
65+
"expressionRule": ""
66+
},
67+
"errorGroup": "completeness"
68+
}
69+
]
70+
}

lambdas/shared/tests/test_common/validator/test_application_csv_row.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
'approved_educational_activity,overall_absence,authorised_absence,unauthorised_absence,' \
1212
'late_sessions,possible_sessions,reason_present_am,reason_present_pm,reason_present,' \
1313
'reason_l_present_late_before_registers_closed'
14-
DATA_TYPE = 'CSVROW'
1514

1615
schema_data_folder = Path(__file__).parent / "schemas"
1716
schemaFilePath = schema_data_folder / "test_school_schema.json"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Test application file
2+
import json
3+
import unittest
4+
from pathlib import Path
5+
6+
from common.validator.validator import Validator
7+
8+
9+
class TestValidator(unittest.TestCase):
10+
def setUp(self):
11+
self.parent_folder = Path(__file__).parent
12+
schema_file_path = self.parent_folder / "schemas/test_small_schema.json"
13+
with open(schema_file_path) as JSON:
14+
self.schema = json.load(JSON)
15+
16+
def test_run_validation_csv_success(self):
17+
good_file_path = self.parent_folder / "data/test_small_ok.csv"
18+
validator = Validator(self.schema)
19+
error_report = validator.validate_csv(good_file_path, False, True, True)
20+
self.assertTrue(error_report == [])
21+
22+
def test_run_validation_csv_fails(self):
23+
bad_file_path = self.parent_folder / "data/test_small_nok.csv"
24+
validator = Validator(self.schema)
25+
error_report = validator.validate_csv(bad_file_path, False, True, True)
26+
self.assertTrue(error_report != [])

0 commit comments

Comments
 (0)