-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(context): use the user's transit agency if they are logged in
this is needed by templates in the in_person app
- Loading branch information
1 parent
1f37452
commit dec3d6c
Showing
2 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
from datetime import datetime, timedelta, timezone | ||
from django.contrib.auth.models import Group, User | ||
import pytest | ||
|
||
from benefits.core import session | ||
from benefits.core.context_processors import unique_values, enrollment | ||
from benefits.core import session, models | ||
from benefits.core.context_processors import unique_values, enrollment, agency | ||
|
||
|
||
def test_unique_values(): | ||
|
@@ -39,3 +40,48 @@ def test_enrollment_expiration(app_request, model_EligibilityType_supports_expir | |
context = enrollment(app_request) | ||
|
||
assert context["enrollment"] == {"expires": expiry, "reenrollment": reenrollment, "supports_expiration": True} | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_agency_unauthenticated_user(app_request, model_TransitAgency): | ||
session.update(app_request, agency=model_TransitAgency) | ||
|
||
context = agency(app_request) | ||
|
||
assert context["agency"] == { | ||
"eligibility_index_url": model_TransitAgency.eligibility_index_url, | ||
"help_templates": unique_values( | ||
[f.help_template for f in model_TransitAgency.enrollment_flows.all() if f.help_template] | ||
), | ||
"info_url": model_TransitAgency.info_url, | ||
"long_name": model_TransitAgency.long_name, | ||
"phone": model_TransitAgency.phone, | ||
"short_name": model_TransitAgency.short_name, | ||
"slug": model_TransitAgency.slug, | ||
} | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_agency_authenticated_user(app_request, model_TransitAgency): | ||
group = Group.objects.create(name="test_group") | ||
|
||
agency_for_user = models.TransitAgency.by_id(model_TransitAgency.id) | ||
agency_for_user.pk = None | ||
agency_for_user.group = group | ||
agency_for_user.save() | ||
|
||
user = User.objects.create_user(username="test_user", email="[email protected]", password="test", is_staff=True) | ||
user.groups.add(group) | ||
|
||
app_request.user = user | ||
context = agency(app_request) | ||
|
||
assert context["agency"] == { | ||
"eligibility_index_url": agency_for_user.eligibility_index_url, | ||
"help_templates": unique_values([f.help_template for f in agency_for_user.enrollment_flows.all() if f.help_template]), | ||
"info_url": agency_for_user.info_url, | ||
"long_name": agency_for_user.long_name, | ||
"phone": agency_for_user.phone, | ||
"short_name": agency_for_user.short_name, | ||
"slug": agency_for_user.slug, | ||
} |