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 Nov 19, 2024
1 parent cee0534 commit 35a4da5
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 26 deletions.
106 changes: 101 additions & 5 deletions benefits/core/migrations/0032_optionalfields.py
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,102 @@ 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="logo_large",
field=models.ImageField(
blank=True,
default="agencies/cst-lg.png",
help_text="The large version of the transit agency's logo.",
null=True,
upload_to=benefits.core.models.agency_logo_large,
),
),
migrations.AlterField(
model_name="transitagency",
name="logo_small",
field=models.ImageField(
blank=True,
default="agencies/cst-sm.png",
help_text="The small version of the transit agency's logo.",
null=True,
upload_to=benefits.core.models.agency_logo_small,
),
),
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
6 changes: 1 addition & 5 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 All @@ -67,9 +65,7 @@
"transit_processor_client_id": "",
"transit_processor_client_secret_name": "cst-transit-processor-client-secret",
"staff_group": 2,
"customer_service_group": 2,
"logo_large": "agencies/cst-lg.png",
"logo_small": "agencies/cst-sm.png"
"customer_service_group": 2
}
},
{
Expand Down
35 changes: 23 additions & 12 deletions benefits/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,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 @@ -164,7 +170,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 @@ -188,20 +193,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 @@ -213,7 +225,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 All @@ -228,14 +239,14 @@ class TransitAgency(models.Model):
related_name="+",
)
logo_large = models.ImageField(
default=None,
default="agencies/cst-lg.png",
null=True,
blank=True,
upload_to=agency_logo_large,
help_text="The large version of the transit agency's logo.",
)
logo_small = models.ImageField(
default=None,
default="agencies/cst-sm.png",
null=True,
blank=True,
upload_to=agency_logo_small,
Expand Down
19 changes: 15 additions & 4 deletions tests/pytest/core/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,19 @@ def test_TransitProcessor_str(model_TransitProcessor):
assert str(model_TransitProcessor) == model_TransitProcessor.name


@pytest.mark.django_db
def test_TransitAgency_defaults():
agency = TransitAgency.objects.create(slug="test")

assert agency.slug == "test"
assert agency.short_name == "CST"
assert agency.long_name == "California State Transit"
assert agency.phone == "1-800-555-5555"
assert agency.info_url == "https://www.agency-website.com"
assert agency.logo_large.url.endswith("agencies/cst-lg.png")
assert agency.logo_small.url.endswith("agencies/cst-sm.png")


@pytest.mark.django_db
def test_TransitAgency_str(model_TransitAgency):
assert str(model_TransitAgency) == model_TransitAgency.long_name
Expand All @@ -415,8 +428,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 Expand Up @@ -517,13 +530,11 @@ def test_TransitAgency_for_user_in_group_not_linked_to_any_agency():

@pytest.mark.django_db
def test_agency_logo_small(model_TransitAgency):

assert agency_logo_small(model_TransitAgency, "local_filename.png") == "agencies/test-sm.png"


@pytest.mark.django_db
def test_agency_logo_large(model_TransitAgency):

assert agency_logo_large(model_TransitAgency, "local_filename.png") == "agencies/test-lg.png"


Expand Down

0 comments on commit 35a4da5

Please sign in to comment.