-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task 42, creating tests for SampleData GoodFile and BadFile
- Loading branch information
Nargis Sultani
committed
Sep 27, 2023
1 parent
bff77c6
commit 271c7fb
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import pandas as pd | ||
import pytest | ||
|
||
from validator import main | ||
from validator.create_schemas import validate_phases | ||
from validator.sample_data import read_bad_data, read_good_data | ||
|
||
|
||
class TestValidatingSampleData: | ||
valid_response = {"response": "No validations errors or warnings"} | ||
|
||
def test_invalid_good_data_file(self): | ||
failed_fpath = "./SBL_Validations_SampleData_GoodFile_03312023_1.csv" | ||
with pytest.raises(Exception) as exc: | ||
read_good_data(failed_fpath) | ||
assert exc.type == FileNotFoundError | ||
|
||
def test_invalid_bad_data_file(self): | ||
failed_fpath = "./SBL_Validations_SampleData_BadFile_03312023_1.csv" | ||
with pytest.raises(Exception) as exc: | ||
read_bad_data(failed_fpath) | ||
assert exc.type == FileNotFoundError | ||
|
||
def test_run_validation_on_good_data_invalid_lei(self): | ||
lei = "000TESTFIUIDDONOTUS1" | ||
good_data_df = read_good_data() | ||
validation_result = validate_phases(good_data_df, lei) | ||
|
||
assert len(validation_result) == 1 | ||
assert validation_result[0] != self.valid_response | ||
|
||
def test_run_validation_on_good_data_valid_lei(self): | ||
lei = "000TESTFIUIDDONOTUSE" | ||
good_data_df = read_good_data() | ||
validation_result = validate_phases(good_data_df, lei) | ||
|
||
assert len(validation_result) == 1 | ||
assert validation_result[0] == self.valid_response | ||
|
||
def test_run_validation_on_bad_data_invalid_lei(self): | ||
lei = "000TESTFIUIDDONOTUS1" | ||
bad_data_df = read_bad_data() | ||
validation_result = validate_phases(bad_data_df, lei) | ||
|
||
print(validation_result) | ||
assert len(validation_result) >= 1 | ||
assert validation_result[0] != self.valid_response | ||
|
||
def test_run_validation_on_bad_data_valid_lei(self): | ||
lei = "000TESTFIUIDDONOTUSE" | ||
bad_data_df = read_bad_data() | ||
# print(bad_data_df) | ||
validation_result = validate_phases(bad_data_df, lei) | ||
|
||
assert len(validation_result) >= 1 | ||
assert validation_result[0] != self.valid_response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import os | ||
import sys | ||
|
||
import pandas as pd | ||
|
||
from validator.create_schemas import validate_phases | ||
|
||
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) # noqa: E402 | ||
sys.path.append(ROOT_DIR) # noqa: E402 | ||
|
||
GOOD_FILE_PATH = "./SBL_Validations_SampleData_GoodFile_03312023.csv" | ||
BAD_FILE_PATH = "./SBL_Validations_SampleData_BadFile_03312023.csv" | ||
|
||
|
||
def read_good_data(csv_path: str = GOOD_FILE_PATH): | ||
"""reads SampleData GoodFile csv file and returns a dataframe. | ||
Args: | ||
csv_path (str, optional): _description_. Defaults to GOOD_FILE_PATH. | ||
Returns: | ||
dataframe : return csv rows as dataframe | ||
""" | ||
|
||
good_data_df = pd.read_csv(csv_path, dtype=str, na_filter=False) | ||
return good_data_df | ||
|
||
|
||
def read_bad_data(csv_path: str = BAD_FILE_PATH): | ||
"""reads SampleData BadFile csv file and returns a dataframe. | ||
Args: | ||
csv_path (str, optional): _description_. Defaults to BAD_FILE_PATH. | ||
Returns: | ||
dataframe : return csv rows as dataframe | ||
""" | ||
|
||
bad_data_df = pd.read_csv(csv_path, dtype=str, na_filter=False) | ||
return bad_data_df |