Skip to content

Commit

Permalink
refactor(models): more field defaults for TransitAgency
Browse files Browse the repository at this point in the history
- use CST defaults for user-facing fields
- allow blanks for config fields
- remove null from TextField, not needed when blank=True
  • Loading branch information
thekaveman committed Oct 31, 2024
1 parent 0e4c913 commit dd0eb4e
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import django.db.models.deletion
from django.db import migrations, models

import benefits.core.models
import benefits.secrets


class Migration(migrations.Migration):

Expand Down Expand Up @@ -35,17 +38,14 @@ class Migration(migrations.Migration):
model_name="transitagency",
name="eligibility_api_id",
field=models.TextField(
blank=True, default="", help_text="The identifier for this agency used in Eligibility API calls.", null=True
blank=True, default="", help_text="The identifier for this agency used in Eligibility API calls."
),
),
migrations.AlterField(
model_name="transitagency",
name="eligibility_api_jws_signing_alg",
field=models.TextField(
blank=True,
default="",
help_text="The JWS-compatible signing algorithm used in Eligibility API calls.",
null=True,
blank=True, default="", help_text="The JWS-compatible signing algorithm used in Eligibility API calls."
),
),
migrations.AlterField(
Expand Down Expand Up @@ -81,6 +81,80 @@ class Migration(migrations.Migration):
help_text="Used for URL navigation for this agency, e.g. the agency homepage url is /{slug}"
),
),
migrations.AlterField(
model_name="transitagency",
name="info_url",
field=models.URLField(
default="https://www.agency-website.com",
help_text="URL of a website/page with more information about the agency's discounts",
),
),
migrations.AlterField(
model_name="transitagency",
name="long_name",
field=models.TextField(
default="California State Transit",
help_text="The user-facing long name for this agency. Often the short_name acronym, spelled out.",
),
),
migrations.AlterField(
model_name="transitagency",
name="phone",
field=models.TextField(default="1-800-555-5555", help_text="Agency customer support phone number"),
),
migrations.AlterField(
model_name="transitagency",
name="short_name",
field=models.TextField(
default="CST", help_text="The user-facing short name for this agency. Often an uppercase acronym."
),
),
migrations.AlterField(
model_name="transitagency",
name="sso_domain",
field=models.TextField(
blank=True,
default="",
help_text="The email domain of users to automatically add to this agency's staff group upon login.",
),
),
migrations.AlterField(
model_name="transitagency",
name="transit_processor",
field=models.ForeignKey(
blank=True,
default=None,
help_text="This agency's TransitProcessor.",
null=True,
on_delete=django.db.models.deletion.PROTECT,
to="core.transitprocessor",
),
),
migrations.AlterField(
model_name="transitagency",
name="transit_processor_audience",
field=models.TextField(
blank=True, default="", help_text="This agency's audience value used to access the TransitProcessor's API."
),
),
migrations.AlterField(
model_name="transitagency",
name="transit_processor_client_id",
field=models.TextField(
blank=True, default="", help_text="This agency's client_id value used to access the TransitProcessor's API."
),
),
migrations.AlterField(
model_name="transitagency",
name="transit_processor_client_secret_name",
field=benefits.core.models.SecretNameField(
blank=True,
default="",
help_text="The name of the secret containing this agency's client_secret value used to access the TransitProcessor's API.", # noqa: E501
max_length=127,
validators=[benefits.secrets.SecretNameValidator()],
),
),
migrations.RenameField(
model_name="enrollmentflow",
old_name="eligibility_start_template",
Expand Down
2 changes: 0 additions & 2 deletions benefits/core/migrations/local_fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@
"slug": "cst",
"short_name": "CST (local)",
"long_name": "California State Transit (local)",
"info_url": "https://www.agency-website.com",
"phone": "1-800-555-5555",
"eligibility_api_id": "cst",
"eligibility_api_private_key": 2,
"eligibility_api_public_key": 3,
Expand Down
31 changes: 21 additions & 10 deletions benefits/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,18 @@ class TransitAgency(models.Model):
id = models.AutoField(primary_key=True)
active = models.BooleanField(default=False, help_text="Determines if this Agency is enabled for users")
slug = models.SlugField(help_text="Used for URL navigation for this agency, e.g. the agency homepage url is /{slug}")
short_name = models.TextField(help_text="The user-facing short name for this agency. Often an uppercase acronym.")
short_name = models.TextField(
default="CST", help_text="The user-facing short name for this agency. Often an uppercase acronym."
)
long_name = models.TextField(
help_text="The user-facing long name for this agency. Often the short_name acronym, spelled out."
default="California State Transit",
help_text="The user-facing long name for this agency. Often the short_name acronym, spelled out.",
)
info_url = models.URLField(
default="https://www.agency-website.com",
help_text="URL of a website/page with more information about the agency's discounts",
)
info_url = models.URLField(help_text="URL of a website/page with more information about the agency's discounts")
phone = models.TextField(help_text="Agency customer support phone number")
phone = models.TextField(default="1-800-555-5555", help_text="Agency customer support phone number")
index_template_override = models.TextField(
help_text="Override the default template used for this agency's landing page",
blank=True,
Expand All @@ -150,7 +156,6 @@ class TransitAgency(models.Model):
)
eligibility_api_id = models.TextField(
help_text="The identifier for this agency used in Eligibility API calls.",
null=True,
blank=True,
default="",
)
Expand All @@ -174,20 +179,27 @@ class TransitAgency(models.Model):
)
eligibility_api_jws_signing_alg = models.TextField(
help_text="The JWS-compatible signing algorithm used in Eligibility API calls.",
null=True,
blank=True,
default="",
)
transit_processor = models.ForeignKey(TransitProcessor, on_delete=models.PROTECT)
transit_processor = models.ForeignKey(
TransitProcessor,
on_delete=models.PROTECT,
null=True,
blank=True,
default=None,
help_text="This agency's TransitProcessor.",
)
transit_processor_audience = models.TextField(
help_text="This agency's audience value used to access the TransitProcessor's API.", default=""
help_text="This agency's audience value used to access the TransitProcessor's API.", default="", blank=True
)
transit_processor_client_id = models.TextField(
help_text="This agency's client_id value used to access the TransitProcessor's API.", default=""
help_text="This agency's client_id value used to access the TransitProcessor's API.", default="", blank=True
)
transit_processor_client_secret_name = SecretNameField(
help_text="The name of the secret containing this agency's client_secret value used to access the TransitProcessor's API.", # noqa: E501
default="",
blank=True,
)
staff_group = models.OneToOneField(
Group,
Expand All @@ -199,7 +211,6 @@ class TransitAgency(models.Model):
related_name="transit_agency",
)
sso_domain = models.TextField(
null=True,
blank=True,
default="",
help_text="The email domain of users to automatically add to this agency's staff group upon login.",
Expand Down
4 changes: 2 additions & 2 deletions tests/pytest/core/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@ def test_TransitAgency_template_overrides(model_TransitAgency):
assert model_TransitAgency.index_template == model_TransitAgency.index_template_override
assert model_TransitAgency.eligibility_index_template == model_TransitAgency.eligibility_index_template_override

model_TransitAgency.index_template_override = None
model_TransitAgency.eligibility_index_template_override = None
model_TransitAgency.index_template_override = ""
model_TransitAgency.eligibility_index_template_override = ""
model_TransitAgency.save()

assert model_TransitAgency.index_template == f"core/index--{model_TransitAgency.slug}.html"
Expand Down

0 comments on commit dd0eb4e

Please sign in to comment.