Skip to content

Commit 2348b97

Browse files
committed
Setup JSON tester class with basic unitest setup - no mocks. Next add mocks.
1 parent 5e8cd93 commit 2348b97

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

‎ETL/FileParsers/fileparser.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def file(self, file: str):
1717

1818
@property
1919
def directory(self):
20-
return self.__data_dir.toString()
20+
return self.__data_dir
2121

2222
@directory.setter
2323
def directory(self, directory: str):

‎ETL/FileParsers/jsonparser.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ class JSONParser(FileParser):
66

77
def parse_file(self):
88
with open(self.file, "r") as jd:
9+
# Add call to validator here
910
self.responses = json.loads(jd.read())
1011

12+
def get_responses(self):
13+
return self.responses
14+
1115
def print_json(self):
1216
for i in self.responses:
13-
print(f"\nWe are on {i} iteration\n")
17+
print("\n")
1418
for k in i.keys():
1519
print(f"The key is {k} with value(s): {i[k]}")

‎ETL/test_loadJSON.py‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
import pytest
1+
import unittest
22
from ETL.FileParsers.jsonparser import JSONParser
33

4-
# This will be replaced by specific fileParser unit tests (as it will be the abstract)
5-
def test_check_file():
4+
# TODO: Add mock of json.loads & open
5+
6+
class TestJSONParser(unittest.TestCase):
67
jp = JSONParser()
7-
jp.file = "student_poll.json"
8-
assert jp.check_file() is True
8+
9+
def test_check_file(self):
10+
self.jp.file = "student_poll.json"
11+
assert self.jp.check_file() is True
12+
13+
def test_get_responses(self):
14+
test_dict = {'grade': 'freshman', 'TA': False}
15+
self.jp.responses = [{'grade': 'freshman', 'TA': False}, {'grade': 'sophomore', 'TA': False}]
16+
self.assertDictEqual(self.jp.get_responses()[0], test_dict)

0 commit comments

Comments
 (0)