Skip to content

Commit

Permalink
Task 42, creating tests for SampleData GoodFile and BadFile (#56)
Browse files Browse the repository at this point in the history
Closes #52 

I misunderstood the requirements first. I thought we had to create tests
to make sure the GoodFile had the correct data for each field. I
understood the requirements later.

---------

Co-authored-by: Nargis Sultani <[email protected]>
  • Loading branch information
nargis-sultani and Nargis Sultani authored Sep 28, 2023
1 parent 31803cc commit 98da8ef
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 6 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,24 @@ There are few files in `src/validator` that will be of interest.
- The repo also includes 2 test datasets for manual testing, one with all valid data, and one where each line
represents a different failed validation, or different permutation of of the same
failed validation.
- [`SBL_Validations_SampleData_GoodFile_03312023.csv`](SBL_Validations_SampleData_GoodFile_03312023.csv)
- [`SBL_Validations_SampleData_BadFile_03312023.csv`](SBL_Validations_SampleData_BadFile_03312023.csv)
- [`sbl-validations-pass.csv`](src/tests/data/sbl-validations-pass.csv)
- [`sbl-validations-fail.csv`](src/tests/data/sbl-validations-fail.csv)

### Manual Test
```sh
# Test validating the "good" file
# If passing lei value, pass lei as first arg and csv_path as second arg
python src/validator/main.py 000TESTFIUIDDONOTUSE SBL_Validations_SampleData_GoodFile_03312023.csv
python src/validator/main.py 000TESTFIUIDDONOTUSE src/tests/data/sbl-validations-pass.csv
# else just pass the csv_path as arg
python src/validator/main.py SBL_Validations_SampleData_GoodFile_03312023.csv
python src/validator/main.py src/tests/data/sbl-validations-pass.csv

# Test validating the "bad" file
python src/validator/main.py 000TESTFIUIDDONOTUSE SBL_Validations_SampleData_BadFile_03312023.csv
python src/validator/main.py 000TESTFIUIDDONOTUSE src/tests/data/sbl-validations-fail.csv
# or
python src/validator/main.py SBL_Validations_SampleData_BadFile_03312023.csv
python src/validator/main.py src/tests/data/sbl-validations-fail.csv
```


## Development

Development Process
Expand Down
Binary file removed example_sblar.xlsx
Binary file not shown.
File renamed without changes.
File renamed without changes.
54 changes: 54 additions & 0 deletions src/tests/test_sample_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import os
import sys

import pandas as pd
import pytest

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 = "./src/tests/data/sbl-validations-pass.csv"
BAD_FILE_PATH = "./src/tests/data/sbl-validations-fail.csv"


class TestValidatingSampleData:
valid_response = {"response": "No validations errors or warnings"}

good_file_df = pd.read_csv(GOOD_FILE_PATH, dtype=str, na_filter=False)
bad_file_df = pd.read_csv(BAD_FILE_PATH, dtype=str, na_filter=False)

def test_invalid_data_file(self):
failed_fpath = "./file-does-not-exist.csv"
with pytest.raises(Exception) as exc:
pd.read_csv(failed_fpath, dtype=str, na_filter=False)
assert exc.type == FileNotFoundError

def test_run_validation_on_good_data_invalid_lei(self):
lei = "000TESTFIUIDDONOTUS1"
validation_result = validate_phases(self.good_file_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"
validation_result = validate_phases(self.good_file_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"
validation_result = validate_phases(self.bad_file_df, lei)

assert len(validation_result) >= 1
assert validation_result[0] != self.valid_response

def test_run_validation_on_bad_data_valid_lei(self):
lei = "000TESTFIUIDDONOTUSE"
validation_result = validate_phases(self.bad_file_df, lei)

assert len(validation_result) >= 1
assert validation_result[0] != self.valid_response

0 comments on commit 98da8ef

Please sign in to comment.