Skip to content
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

Refactor: choices for EnrollmentFlow.system_name #2698

Merged
merged 5 commits into from
Feb 21, 2025

Conversation

angela-tran
Copy link
Member

@angela-tran angela-tran commented Feb 20, 2025

Needed by #2689 for #2632

This PR introduces a SystemName choices enum to be used as the possible values for EnrollmentFlow.system_name. This will be useful for defining flow-specific context dicts .

It's helpful to split this out from #2689 so that I can fix unit tests that are broken by the introduction of choices to EnrollmentFlow.system_name.

Benefits Admin user-facing change

The System name field on EnrollmentFlows now is a dropdown with these values:

System name dropdown in Benefits Admin

System name dropdown with helper text in Benefits Admin

@angela-tran angela-tran requested a review from a team as a code owner February 20, 2025 01:52
@angela-tran angela-tran self-assigned this Feb 20, 2025
@angela-tran angela-tran marked this pull request as draft February 20, 2025 01:52
@github-actions github-actions bot added migrations [auto] Review for potential model changes/needed data migrations updates back-end Django views, sessions, middleware, models, migrations etc. labels Feb 20, 2025
@angela-tran angela-tran force-pushed the refactor/context-module branch from b3df575 to 007d906 Compare February 20, 2025 01:57
@angela-tran angela-tran force-pushed the feat/system-name-choices branch from 12d5324 to af6e848 Compare February 20, 2025 01:59
@angela-tran angela-tran changed the title Refactor: system_name choices Refactor: EnrollmentFlow.system_name choices Feb 20, 2025
@angela-tran angela-tran changed the title Refactor: EnrollmentFlow.system_name choices Refactor: choices for EnrollmentFlow.system_name Feb 20, 2025
Copy link

github-actions bot commented Feb 20, 2025

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  benefits/core/context
  __init__.py
  flow.py
  benefits/core/models
  enrollment.py
Project Total  

This report was generated by python-coverage-comment-action

@angela-tran angela-tran force-pushed the feat/system-name-choices branch 2 times, most recently from 8149f4e to a42d90b Compare February 20, 2025 16:45
@angela-tran angela-tran mentioned this pull request Feb 20, 2025
3 tasks
Base automatically changed from refactor/context-module to main February 20, 2025 17:05
@angela-tran angela-tran marked this pull request as ready for review February 20, 2025 17:05
this test didn't break with the introduction of system_name choices,
but it's still good practice to use a valid system name.
similar to the previous commit, it's best if our test objects align with
the actual objects in our app.

fix a test that needs the verified type to match the fixture's
system_name.
@angela-tran angela-tran force-pushed the feat/system-name-choices branch from 8149f4e to 588fffe Compare February 20, 2025 17:06
@angela-tran
Copy link
Member Author

Added a screenshot above of user-facing change. (Also, Kegan was correct that Django uses the enum name to generate the display value.)

@lalver1
Copy link
Member

lalver1 commented Feb 20, 2025

I don't think we need to do anything here, but in our local_fixtures we use agency_card as the system name for the Agency Cardholder EnrollmentFlow. This name isn't in the SystemName enum but this doesn't cause any trouble when you run bin/reset_db.sh, for example. The database still populates with agency_card as the system name even though the admin shows dashed lines:

image

I was thinking about when this gets deployed to prod but since there is no agency_card in prod this isn't an issue, it only affects the local dev environment.

@thekaveman
Copy link
Member

@lalver1

I don't think we need to do anything here, in our local_fixtures we use agency_card as the system name

Wouldn't this cause an exception when that slug is looked up in the context dictionary?

@angela-tran
Copy link
Member Author

... in our local_fixtures we use agency_card as the system name for the Agency Cardholder EnrollmentFlow.

Ahh, that's a good catch @lalver1

This name isn't in the SystemName enum but this doesn't cause any trouble when you run bin/reset_db.sh, for example. The database still populates with agency_card as the system name even though the admin shows dashed lines:

What you're pointing out here is that Django only enforces the choices when saving via a ModelForm (see django.forms.ChoiceField's validate). I think it would be best practice to create objects in the same way that ModelForms would, so that means our sample fixtures should abide by what the model's fields say. Same goes for the objects and fixtures we create in our pytests.

I suppose we could add logic to the model's clean method to mirror the validation that Django does with ModelForms, but not sure if that's actually worth our time and maintenance.

@angela-tran
Copy link
Member Author

angela-tran commented Feb 20, 2025

@thekaveman

Wouldn't this cause an exception when that slug is looked up in the context dictionary?

It would depend on how the look-up is written.

For example, in my WIP PR, the look-up of in_person_eligibility_context is defensive and will return an empty dictionary if the key was not found.

However, the look-up of agency_index assumes that every slug will have an entry, so that would throw an exception. I think that's desired because we would want to be alerted that we forgot to add copy for an agency index (I mean, hopefully we would've caught it earlier than that, but still).

Definitely open to a differing opinion on how this should work.

@angela-tran
Copy link
Member Author

I'm going to add agency_card to our SystemName choice enum.

@thekaveman
Copy link
Member

I think my initial take was, an exception should be thrown because we have a mismatch / invalid config in this case. E.g. a non-defensive lookup.

@lalver1
Copy link
Member

lalver1 commented Feb 20, 2025

Thanks @angela-tran and @thekaveman for elaborating on this.

I agree about adding agency_card to the SystemName enum, so that

... sample fixtures should abide by what the model's fields say

@angela-tran
Copy link
Member Author

Ready for review again

Copy link
Member

@lalver1 lalver1 left a comment

Choose a reason for hiding this comment

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

Looks good to me! 👍

@angela-tran
Copy link
Member Author

I think my initial take was, an exception should be thrown because we have a mismatch / invalid config in this case. E.g. a non-defensive lookup.

Makes sense. I'll think about this more in #2689

@angela-tran angela-tran merged commit 216fe98 into main Feb 21, 2025
14 checks passed
@angela-tran angela-tran deleted the feat/system-name-choices branch February 21, 2025 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
back-end Django views, sessions, middleware, models, migrations etc. migrations [auto] Review for potential model changes/needed data migrations updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants