You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
3.4 KiB
73 lines
3.4 KiB
import unittest
|
|
from pathlib import Path
|
|
from re import Pattern, compile
|
|
from .context import src
|
|
from src import config
|
|
from src import ReportSource
|
|
|
|
class TestReportConfig(unittest.TestCase):
|
|
|
|
def test_from_file(self):
|
|
# Provide the path to your config file
|
|
config_file = Path(r"tests\test_inputs\TEST_reports_config.toml")
|
|
|
|
# Call the static method from_file to create an instance of ReportConfig
|
|
report_config = config.ReportConfig.from_file(config_file)
|
|
|
|
# Assert the values of the attributes in the created instance
|
|
self.assertEqual(report_config.paths.input_directory, Path(r"tests\test_inputs"))
|
|
self.assertEqual(report_config.paths.gp_glob, r'*GP*.xlsx')
|
|
self.assertEqual(report_config.paths.ob_glob, r"*OB*.xlsx")
|
|
self.assertEqual(report_config.paths.output_directory, Path(r"tests\test_outputs"))
|
|
self.assertEqual(report_config.use_mssql, False)
|
|
self.assertEqual(report_config.paths.db_path, Path("./onhold_reconciliation.db"))
|
|
self.assertEqual(report_config.work_columns, ["HideNextMonth", "Resolution"])
|
|
self.assertEqual(report_config.finished_columns, [
|
|
"contract_number",
|
|
"vendor_name",
|
|
"AppNum",
|
|
"Document Number",
|
|
"DateBooked",
|
|
"Document Date",
|
|
])
|
|
self.assertEqual(report_config.filters["doc_num_filters"], [
|
|
compile(r"p(oin)?ts",),
|
|
compile(r"pool",),
|
|
compile(r"promo",),
|
|
compile(r"o(ver)?f(und)?",),
|
|
compile(r"m(ar)?ke?t",),
|
|
compile(r"title",),
|
|
compile(r"adj",),
|
|
compile(r"reg fee",),
|
|
compile(r"rent",),
|
|
compile(r"cma",),
|
|
])
|
|
self.assertEqual(report_config.filters["po_filter"], [compile(r"^(?!.*cma(\s|\d)).*$")])
|
|
self.assertEqual(report_config.shared_columns[0]["standardized_name"], "contract_number")
|
|
self.assertEqual(report_config.shared_columns[0]["GP"], "Transaction Description")
|
|
self.assertEqual(report_config.shared_columns[0]["OB"], "Contract")
|
|
self.assertEqual(report_config.shared_columns[1]["standardized_name"], "onhold_amount")
|
|
self.assertEqual(report_config.shared_columns[1]["GP"], "Current Trx Amount")
|
|
self.assertEqual(report_config.shared_columns[1]["OB"], "CurrentOnHold")
|
|
self.assertEqual(report_config.shared_columns[2]["standardized_name"], "vendor_name")
|
|
self.assertEqual(report_config.shared_columns[2]["GP"], "Vendor Name")
|
|
self.assertEqual(report_config.shared_columns[2]["OB"], "DealerName")
|
|
|
|
def test_get_newest(self):
|
|
# Provide the path to your config file
|
|
config_file = Path(r"tests\test_inputs\TEST_reports_config.toml")
|
|
|
|
# Call the static method from_file to create an instance of ReportConfig
|
|
report_config = config.ReportConfig.from_file(config_file)
|
|
|
|
newest_ob: Path = report_config.paths.get_most_recent(report_type=ReportSource.OB)
|
|
self.assertEqual(newest_ob.name, "April 2023 OB.xlsx")
|
|
newest_gp: Path = report_config.paths.get_most_recent(report_type=ReportSource.GP)
|
|
self.assertEqual(newest_gp.name, "April GP.xlsx")
|
|
|
|
nob, ngp = report_config.paths.get_most_recent()
|
|
self.assertEqual(nob.name, "April 2023 OB.xlsx")
|
|
self.assertEqual(ngp.name, "April GP.xlsx")
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main() |