Пример #1
0
 def test_determine_tier_program_improper_setup(self):
     """
     Tests that determine_tier_program() raises ImproperlyConfigured if no $0-discount TierProgram
     has been created and income supplied is too low.
     """
     program = ProgramFactory.create()
     with self.assertRaises(ImproperlyConfigured):
         determine_tier_program(program, 0)
Пример #2
0
 def test_determine_tier_program_improper_setup(self):
     """
     Tests that determine_tier_program() raises ImproperlyConfigured if no $0-discount TierProgram
     has been created and income supplied is too low.
     """
     program = ProgramFactory.create()
     with self.assertRaises(ImproperlyConfigured):
         determine_tier_program(program, 0)
Пример #3
0
    def save(self):
        """
        Override save method
        """
        if self.validated_data["original_currency"] != "USD":
            raise ValidationError("Only USD supported currently")
        user = self.context["request"].user
        tier_program = determine_tier_program(self.validated_data["program"], self.validated_data["original_income"])

        financial_aid = FinancialAid.objects.create(
            original_income=self.validated_data["original_income"],
            original_currency=self.validated_data["original_currency"],
            tier_program=tier_program,
            user=user,
            income_usd=self.validated_data["original_income"],
            country_of_income=user.profile.country,
            date_exchange_rate=datetime.datetime.now()
        )

        if determine_auto_approval(financial_aid) is True:
            financial_aid.status = FinancialAidStatus.AUTO_APPROVED
        else:
            financial_aid.status = FinancialAidStatus.PENDING_DOCS
        financial_aid.save()

        # Add auditing here

        return financial_aid
Пример #4
0
 def test_income_validation(self, original_income, original_currency, income_threshold, auto_approved):
     """
     Tests FinancialAidRequestView post endpoint
     """
     CountryIncomeThreshold.objects.filter(country_code=self.profile.country).update(
         income_threshold=income_threshold
     )
     data = {
         "original_income": original_income,
         "original_currency": original_currency,
         "program_id": self.program.id,
     }
     assert FinancialAid.objects.exclude(status=FinancialAidStatus.RESET).count() == 0
     assert FinancialAidAudit.objects.count() == 0
     self.make_http_request(self.client.post, self.request_url, status.HTTP_201_CREATED, data=data)
     assert FinancialAid.objects.exclude(status=FinancialAidStatus.RESET).count() == 1
     assert FinancialAidAudit.objects.count() == 1
     financial_aid = FinancialAid.objects.exclude(status=FinancialAidStatus.RESET).first()
     income_usd = determine_income_usd(original_income, original_currency)
     assert financial_aid.tier_program == determine_tier_program(self.program, income_usd)
     if not auto_approved:
         assert financial_aid.status == FinancialAidStatus.PENDING_DOCS
     else:
         assert financial_aid.status == FinancialAidStatus.AUTO_APPROVED
     self.assertAlmostEqual(financial_aid.income_usd, income_usd)
     assert financial_aid.user == self.profile.user
     self.assertAlmostEqual(financial_aid.original_income, original_income)
     assert financial_aid.original_currency == original_currency
     assert financial_aid.country_of_income == self.profile.country
     assert financial_aid.country_of_residence == self.profile.country
     assert is_near_now(financial_aid.date_exchange_rate)
Пример #5
0
    def save(self, **kwargs):
        """
        Override save method
        """
        try:
            income_usd = determine_income_usd(
                self.validated_data["original_income"],
                self.validated_data["original_currency"]
            )
        except NotSupportedException:
            raise ValidationError("Currency not supported")
        user = self.context["request"].user
        tier_program = determine_tier_program(self.validated_data["program"], income_usd)

        financial_aid = FinancialAid.objects.create(
            original_income=self.validated_data["original_income"],
            original_currency=self.validated_data["original_currency"],
            tier_program=tier_program,
            user=user,
            income_usd=income_usd,
            country_of_income=user.profile.country,
            date_exchange_rate=now_in_utc(),
            country_of_residence=user.profile.country,
        )

        if determine_auto_approval(financial_aid, tier_program) is True:
            financial_aid.status = FinancialAidStatus.AUTO_APPROVED
        else:
            financial_aid.status = FinancialAidStatus.PENDING_DOCS
        financial_aid.save_and_log(user)

        return financial_aid
Пример #6
0
 def test_determine_tier_program(self, income, expected_tier_key):
     """
     Tests determine_tier_program() assigning the correct tiers. This should assign the tier where the tier's
     income threshold is equal to or less than income.
     """
     assert determine_tier_program(
         self.program, income) == self.tier_programs[expected_tier_key]
Пример #7
0
    def save(self, **kwargs):
        """
        Override save method
        """
        try:
            income_usd = determine_income_usd(
                self.validated_data["original_income"],
                self.validated_data["original_currency"])
        except NotSupportedException:
            raise ValidationError("Currency not supported")
        user = self.context["request"].user
        tier_program = determine_tier_program(self.validated_data["program"],
                                              income_usd)

        financial_aid = FinancialAid.objects.create(
            original_income=self.validated_data["original_income"],
            original_currency=self.validated_data["original_currency"],
            tier_program=tier_program,
            user=user,
            income_usd=income_usd,
            country_of_income=user.profile.country,
            date_exchange_rate=now_in_utc(),
            country_of_residence=user.profile.country,
        )

        if determine_auto_approval(financial_aid, tier_program) is True:
            financial_aid.status = FinancialAidStatus.AUTO_APPROVED
        else:
            financial_aid.status = FinancialAidStatus.PENDING_DOCS
        financial_aid.save_and_log(user)

        return financial_aid
Пример #8
0
 def test_determine_tier_program_not_current(self):
     """
     A current=False tier should be ignored
     """
     not_current = TierProgramFactory.create(program=self.program,
                                             income_threshold=75000,
                                             current=False)
     assert determine_tier_program(self.program, 34938234) != not_current
Пример #9
0
 def test_determine_tier_program(self):
     """
     Tests determine_tier_program()
     """
     assert determine_tier_program(self.program, 0) == self.tiers["0k"]
     assert determine_tier_program(self.program, 1000) == self.tiers["0k"]
     assert determine_tier_program(self.program, 15000) == self.tiers["15k"]
     assert determine_tier_program(self.program, 23500) == self.tiers["15k"]
     assert determine_tier_program(self.program, 50000) == self.tiers["50k"]
     assert determine_tier_program(self.program, 72800) == self.tiers["50k"]
     assert determine_tier_program(self.program,
                                   100000) == self.tiers["100k"]
     assert determine_tier_program(self.program,
                                   34938234) == self.tiers["100k"]
     assert determine_tier_program(
         self.program, 34938234) != self.tiers["150k_not_current"]
Пример #10
0
 def test_determine_auto_approval(self, income_usd, country_code, expected):
     """
     Tests determine_auto_approval() assigning the correct auto-approval status. This should return True
     if income is strictly greater than the threshold (or if the threshold is 0, which is inclusive of 0).
     """
     financial_aid = FinancialAidFactory.create(
         income_usd=income_usd,
         country_of_income=country_code,
     )
     tier_program = determine_tier_program(self.program, income_usd)
     assert determine_auto_approval(financial_aid, tier_program) is expected
Пример #11
0
 def test_determine_auto_approval(self, income_usd, country_code, expected):
     """
     Tests determine_auto_approval() assigning the correct auto-approval status. This should return True
     if income is strictly greater than the threshold (or if the threshold is 0, which is inclusive of 0).
     """
     financial_aid = FinancialAidFactory.create(
         income_usd=income_usd,
         country_of_income=country_code,
     )
     tier_program = determine_tier_program(self.program, income_usd)
     assert determine_auto_approval(financial_aid, tier_program) is expected
Пример #12
0
 def test_determine_tier_program_not_current(self):
     """
     A current=False tier should be ignored
     """
     not_current = TierProgramFactory.create(program=self.program, income_threshold=75000, current=False)
     assert determine_tier_program(self.program, 34938234) != not_current
Пример #13
0
 def test_determine_tier_program(self, income, expected_tier_key):
     """
     Tests determine_tier_program() assigning the correct tiers. This should assign the tier where the tier's
     income threshold is equal to or less than income.
     """
     assert determine_tier_program(self.program, income) == self.tier_programs[expected_tier_key]