def test_transaction_fields(): """Are the USAA columns mapped to the TransactionColumns? This is done to standardize the final parsed history. """ standard_col_headers = [c.name for c in TransactionColumns] for usaa, ours in Usaa.field_2_transaction().items(): assert usaa in Usaa.field_names() assert ours in standard_col_headers
def test_get_field_amount(): """Is an amount parsed correctly for a line? NB the 'amount' column is used to validate an input file, so it should be tested """ # MAGIC should match the fake value expected = Decimal('123.45') assert expected == Usaa.get_field(FAKE_USAA_GOOD_LINE_PLUS, Usaa._AMOUNT_COL_NAME)
def test_get_field_date(): """Is a date parsed correctly for a line? NB the 'date' column is used to validate an input file, so it should be tested """ # MAGIC should match the fake value expected = datetime.datetime.strptime("01/11/2020", "%m/%d/%Y").date() assert expected == Usaa.get_field(FAKE_USAA_GOOD_LINE_PLUS, Usaa._DATE_COL_NAME)
def test_init_fixture(usaa_file_fixture): """Does initialization with the fixture succeed?""" Usaa(usaa_file_fixture)
def test_init(): """Does initialization succeed?""" with usaa_file() as path: Usaa(path)
def usaa_instance(usaa_file_fixture): """An instance of Usaa.""" yield Usaa(usaa_file_fixture)
def test_run_parse_checks_amount_col(): """Does a bad debit/credit value get rejected?""" path = "FAKE_PATH_FOR_TESTING" assert not Usaa._run_parse_checks(FAKE_USAA_BAD_AMOUNT, path, LOGGER)
def test_run_parse_checks_date_col(): """Does a bad date value get rejected?""" path = "FAKE_PATH_FOR_TESTING" assert not Usaa._run_parse_checks(FAKE_USAA_BAD_DATE, path, LOGGER)
def test_run_parse_checks_col_count(): """Does a bad column count get rejected?""" path = "FAKE_PATH_FOR_TESTING" assert not Usaa._run_parse_checks(FAKE_USAA_EXTRA_COL, path, LOGGER) assert not Usaa._run_parse_checks(FAKE_USAA_MISSING_COL, path, LOGGER)
def test_is_file_parsable_reject(): """Does a file with bad contents get rejected?""" data = FAKE_USAA_BAD_LINE with temp_data(prefix=None, suffix=".csv", data=data) as path: assert not Usaa.is_file_parsable(path)
def test_is_file_parsable_bbt(bbt_file_fixture): """Does a file meant for another parser get rejected?""" assert not Usaa.is_file_parsable(bbt_file_fixture)
def test_is_file_parsable(usaa_file_fixture): """Does a good file pass the check?""" assert Usaa.is_file_parsable(usaa_file_fixture)
def test_check_date_reject(): """Does a bad date value fail?""" assert not Usaa.check_date_column(FAKE_USAA_BAD_LINE)
def test_check_date(): """Does a good date pass?""" assert Usaa.check_date_column(FAKE_USAA_GOOD_LINE_PLUS)
def test_check_amount_reject(): """Does a bad amount value fail?""" assert not Usaa.check_amount_column(FAKE_USAA_BAD_LINE)
def test_check_amount(): """Does a good amount value pass?""" assert Usaa.check_amount_column(FAKE_USAA_GOOD_LINE_PLUS) assert Usaa.check_amount_column(FAKE_USAA_GOOD_LINE_MINUS)