Skip to content

Feature/allocation model get information tests #707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Eric-Butcher
Copy link
Contributor

No description provided.

@Eric-Butcher Eric-Butcher marked this pull request as draft June 26, 2025 16:36
@Eric-Butcher Eric-Butcher force-pushed the feature/allocation-model-get-information-tests branch from b427b6b to 5e8a5ae Compare June 26, 2025 16:40
@Eric-Butcher
Copy link
Contributor Author

Eric-Butcher commented Jun 26, 2025

The test cases where the ALLOCATION_ATTRIBUTE_VIEW_LIST are relevant just look a bit weird. See the case for test_attributes_with_names_in_view_list_included_in_information. Looking at the output and the function I am wondering if this is actually the behavior that is desired for get_information. I left some code commented out that will print the actual HTML being generated to a file so it can be more easily viewed but it seems kind of strange.

Also it seems like get_information would benefit from having its querysets having an explicit ordering applied. The default ordering for a queryset is database dependent so this might cause inconsistent behavior and have the current tests be inaccurate in some instances.

@Eric-Butcher Eric-Butcher force-pushed the feature/allocation-model-get-information-tests branch from 5e8a5ae to 82c8445 Compare June 30, 2025 14:45
@Eric-Butcher Eric-Butcher marked this pull request as ready for review June 30, 2025 14:45
@aebruno aebruno requested a review from ANekhai July 2, 2025 15:09
@Eric-Butcher Eric-Butcher force-pushed the feature/allocation-model-get-information-tests branch from 82c8445 to f8fddb7 Compare July 3, 2025 14:34
name_not_in_view_list_2 = "This Is Not In List"
sample_allocation_attribute_view_list = [name_in_view_list_1, name_in_view_list_2]

def find_percent(self, numerator, denominator):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a comment to explain the math here without having to dig into what is happening in models.py, especially the multiplication by 10000

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Kind of) done.

This rounding is actually a lot more troublesome than it might appear. I do not think the original function was written that soundly, probably could have just used a percent formatter instead. Because of floating point and rounding imprecision problems tiny deviations in how that percentage is obtained could alter results in some minor instances even though it probably does not matter

@override_settings(ALLOCATION_ATTRIBUTE_VIEW_LIST=sample_allocation_attribute_view_list)
def test_attribute_type_not_in_view_list_returns_without_type_substring_included(self):
"""Test that the get_information method returns a string without the attribute type substring when the type name is not in ALLOCATION_ATTRIBUTE_VIEW_LIST."""
allocation: Allocation = AllocationFactory()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we we move this allocation factory call to a test setup function if every test in this class runs the same setup step

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

# Allocation that we are testing, needed for creating AllocationAttributes
tested_allocation: Allocation = AllocationFactory()

# AllocationAttribute for each AllocationAttributeType
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have concerns about how maintainable this test will be, I think maybe adding some comments to provide more context for how you're constructing the test example might make it a little easier to parse and understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is too much I could reduce it down just just a single one which is in view and a single one which is not inside view, but the models are just so interdependent and necessary for the function that all of those steps have to be in there. I tried to give them variable names that were as descriptive as possible but if you have any suggestions on that front let me know

@Eric-Butcher Eric-Butcher force-pushed the feature/allocation-model-get-information-tests branch from f8fddb7 to 16577fb Compare July 16, 2025 17:22
@Eric-Butcher Eric-Butcher requested a review from ANekhai July 16, 2025 17:22
@Eric-Butcher Eric-Butcher force-pushed the feature/allocation-model-get-information-tests branch from 16577fb to 10214cd Compare July 17, 2025 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants