Move nonbillable pydantic models from invoicing-private-data#291
Move nonbillable pydantic models from invoicing-private-data#291marcoagonzales007 wants to merge 4 commits into
Conversation
QuanMPhm
left a comment
There was a problem hiding this comment.
A few structural comments
| data = yaml.safe_load(file) | ||
| projects = ExcludedProjectList.model_validate(data) | ||
| for project in projects.root: | ||
| project_name = project.name | ||
| cluster_list = project.clusters.root | ||
| is_billable = project.is_billable | ||
|
|
||
| if project.start: | ||
| if not _is_in_time_range(project.start, project.end): |
There was a problem hiding this comment.
Could you move all the parsing logic here into the ExcludedProjectList models? Same goes for the PI-list parsing logic as well. They should have a function such that given the invoice month, returns both the list of timed, and non-timed projects. It makes the most sense for the models to have the parsing/validation logic, and for loader.py to only handle "loading".
Afterwards, can you move the test cases for the models over here as well? Place them in a unit test file
QuanMPhm
left a comment
There was a problem hiding this comment.
Looking better. A few comments
There was a problem hiding this comment.
Follow-up on the comment about some functions that should be moved in the pydantic models themselves, this file should now contain test cases for the nonbillable list that has been sitting in test_util.py.
When you move the test cases over here, you should be able to use pytest.parametrize to help you create test data for the nonbillable list, and pytest-mock to mock get_allowed_clusters()
7a58604 to
422cd01
Compare
| def _load_pi_config(self, filepath: str) -> PIList: | ||
| with open(filepath) as file: | ||
| pi_list = yaml.safe_load(file) |
There was a problem hiding this comment.
Since _load_pi_config will only ever receive invoice_settings.nonbillable_pis_filepath as the file to load, could you do this instead?
def _load_pi_config(self) -> PIList:
with open(filepath) as file:
pi_list = yaml.safe_load(invoice_settings.nonbillable_pis_filepath)
return PIList.model_validate(pi_list)
def get_nonbillable_pis(self) -> list[str]:
return self._load_pi_config().get_nonbillable_pis()
def get_pi_non_billed_su_types(self) -> dict[str, list[str]]:
"""PI usernames -> list of SU types that receive credit (zeroed out)."""
eturn self._load_pi_config().get_pi_non_billed_su_types()
QuanMPhm
left a comment
There was a problem hiding this comment.
The code changes looks good. Can you squash all your commits into one, and write a concise commit message?
107f3fe to
79190e1
Compare
| validators | ||
| python-dateutil | ||
| pydantic-settings | ||
| pytest-mock |
There was a problem hiding this comment.
I just realized, can you put this into the test-requirement.txt file, as this is a dependancy for tests?
79190e1 to
f2bdb8d
Compare
…illable-pydantic-models
QuanMPhm
left a comment
There was a problem hiding this comment.
It seems the recently merged PR introduced some merge conflicts. Please resolve them
-Copied the pydantic models from
invoicing-private-data/validate_projects/models.pyinto a newprocess_report/nonbillable_models.pyin this repo.-Updated loader.py to validate the YAML through the pydantic models instead of using raw dicts
Closes #287