Example #1
0
    def form_valid(self, form):
        benefits_form = SponsorshipsBenefitsForm(data=self.benefits_data)
        if not benefits_form.is_valid():
            return self._redirect_back_to_benefits()

        sponsor = form.save()

        uc = use_cases.CreateSponsorshipApplicationUseCase.build()
        sponsorship = uc.execute(
            self.request.user,
            sponsor,
            benefits_form.get_benefits(include_add_ons=True,
                                       include_a_la_carte=True),
            benefits_form.get_package(),
            request=self.request,
        )
        notified = uc.notifications[1].get_recipient_list({
            "user":
            self.request.user,
            "sponsorship":
            sponsorship
        })

        response = render(
            self.request,
            "sponsors/sponsorship_application_finished.html",
            context={
                "sponsorship": sponsorship,
                "notified": notified
            },
        )
        cookies.delete_sponsorship_selected_benefits(response)
        return response
Example #2
0
    def test_get_package_get_or_create_a_la_carte_only_package(self):
        data = {"a_la_carte_benefits": [self.a_la_carte[0].id]}
        form = SponsorshipsBenefitsForm(data=data)
        self.assertTrue(form.is_valid())
        self.assertEqual(1, SponsorshipPackage.objects.count())

        # should create package if it doesn't exist yet
        package = form.get_package()
        self.assertEqual("A La Carte Only", package.name)
        self.assertEqual("a-la-carte-only", package.slug)
        self.assertEqual(175, package.logo_dimension)
        self.assertEqual(0, package.sponsorship_amount)
        self.assertFalse(package.advertise)
        self.assertEqual(2, SponsorshipPackage.objects.count())

        # re-use previously created package for subsequent applications
        data = {"a_la_carte_benefits": [self.a_la_carte[0].id]}
        form = SponsorshipsBenefitsForm(data=data)
        self.assertTrue(form.is_valid())
        self.assertEqual(package, form.get_package())
        self.assertEqual(2, SponsorshipPackage.objects.count())
Example #3
0
 def test_get_package_return_selected_package(self):
     data = {"benefits_psf": [self.program_1_benefits[0]], "package": self.package.id}
     form = SponsorshipsBenefitsForm(data=data)
     self.assertTrue(form.is_valid())
     self.assertEqual(self.package, form.get_package())