Skip to content

Commit

Permalink
TCCP: Exclude non-targeted cards
Browse files Browse the repository at this point in the history
Some credit cards offer a purchase APR for a specific credit tier but
are not marked as being "specifically targeted" to that credit tier,
recorded in the TCCP survey under the "Targeted credit tiers" column.

Previously TCCP filter results would include these cards, so if a user
marked their credit tier as 620-719, they might see cards that, while
they offer a purchase APR for this range, are not marked as being
"specifically targeted" to this range.

This change removes those cards from the results.
  • Loading branch information
chosak committed Mar 21, 2024
1 parent 5652238 commit fb8697a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
4 changes: 4 additions & 0 deletions cfgov/tccp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ def for_credit_tier(self, credit_tier, summary_stats=None):
# We exclude cards that don't have a purchase APR for this tier.
qs = qs.exclude(purchase_apr_for_tier__isnull=True)

# We also exclude those cards that aren't "specifically targeted" for
# this tier.
qs = qs.filter(targeted_credit_tiers__contains=credit_tier)

# Finally, we want to annotate each card with a rating based on how
# its purchase APR compares with other cards within the same tier.
#
Expand Down
8 changes: 7 additions & 1 deletion cfgov/tccp/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def test_ordering_by_purchase_apr(self):
for apr in [2.9, 0.9, 99.9, 0]:
baker.make(
CardSurveyData,
targeted_credit_tiers=["Credit score 619 or less"],
purchase_apr_poor=apr,
)

Expand All @@ -31,6 +32,7 @@ def test_ordering_by_transfer_apr(self):
]:
baker.make(
CardSurveyData,
targeted_credit_tiers=["Credit score 619 or less"],
purchase_apr_poor=purchase_apr,
transfer_apr_poor=transfer_apr,
)
Expand All @@ -45,7 +47,11 @@ def test_ordering_by_transfer_apr(self):

def test_ordering_by_product_name(self):
for product_name in ["e", "a", "b", "d", "c"]:
baker.make(CardSurveyData, product_name=product_name)
baker.make(
CardSurveyData,
targeted_credit_tiers=["Credit scores from 620 to 719"],
product_name=product_name,
)

qs = CardSurveyData.objects.all()
self.assertQuerysetEqual(
Expand Down
10 changes: 9 additions & 1 deletion cfgov/tccp/tests/test_filterset.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ def test_field_value_used_if_specified(self):
self.assertEqual(CardSurveyDataFilterSet(data).data, data)

def test_filter_by_situations_noop(self):
baker.make(CardSurveyData, purchase_apr_good=0.99, _quantity=10)
baker.make(
CardSurveyData,
targeted_credit_tiers=["Credit scores from 620 to 719"],
purchase_apr_good=0.99,
_quantity=10,
)

qs = CardSurveyData.objects.all()
self.assertEqual(qs.count(), 10)
Expand All @@ -40,6 +45,7 @@ def test_filter_by_location(self):
CardSurveyData,
availability_of_credit_card_plan="One State/Territory",
state=state,
targeted_credit_tiers=["Credit scores from 620 to 719"],
purchase_apr_good=0.99,
_quantity=3,
)
Expand All @@ -53,6 +59,7 @@ def test_filter_by_location(self):
def test_filter_by_no_account_fee(self):
baker.make(
CardSurveyData,
targeted_credit_tiers=["Credit scores from 620 to 719"],
purchase_apr_good=0.99,
periodic_fee_type=["Annual"],
)
Expand All @@ -69,6 +76,7 @@ def test_filter_by_no_account_fee(self):
def test_filter_by_rewards(self):
baker.make(
CardSurveyData,
targeted_credit_tiers=["Credit scores from 620 to 719"],
purchase_apr_good=0.99,
rewards=["Cashback rewards"],
)
Expand Down
17 changes: 17 additions & 0 deletions cfgov/tccp/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def test_available_in(self):
def test_for_credit_tier(self):
baker.make(
CardSurveyData,
targeted_credit_tiers=["Credit score 619 or less"],
purchase_apr_poor=9.99,
transfer_apr_poor=8.88,
transfer_apr_min=7.77,
Expand All @@ -73,6 +74,7 @@ def test_for_credit_tier(self):

baker.make(
CardSurveyData,
targeted_credit_tiers=["Credit score of 720 or greater"],
purchase_apr_great=9.99,
transfer_apr_great=None,
transfer_apr_min=7.77,
Expand Down Expand Up @@ -113,6 +115,11 @@ def test_get_summary_statistics(self):
baker.make(
CardSurveyData,
report_date=today,
targeted_credit_tiers=[
"Credit score 619 or less",
"Credit scores from 620 to 719",
"Credit score of 720 or greater",
],
purchase_apr_poor=3,
purchase_apr_good=2,
purchase_apr_great=1,
Expand All @@ -121,6 +128,11 @@ def test_get_summary_statistics(self):
baker.make(
CardSurveyData,
report_date=today,
targeted_credit_tiers=[
"Credit score 619 or less",
"Credit scores from 620 to 719",
"Credit score of 720 or greater",
],
purchase_apr_poor=9,
purchase_apr_good=6,
purchase_apr_great=3,
Expand All @@ -129,6 +141,11 @@ def test_get_summary_statistics(self):
baker.make(
CardSurveyData,
report_date=today,
targeted_credit_tiers=[
"Credit score 619 or less",
"Credit scores from 620 to 719",
"Credit score of 720 or greater",
],
purchase_apr_great=0,
)

Expand Down
1 change: 1 addition & 0 deletions cfgov/tccp/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class CardListViewTests(TestCase):
def setUpTestData(cls):
baker.make(
CardSurveyData,
targeted_credit_tiers=["Credit score of 720 or greater"],
purchase_apr_great=0.99,
_quantity=5,
)
Expand Down

0 comments on commit fb8697a

Please sign in to comment.