Example #1
0
 def _create_contributions(self, flagged=True):
     status = ContributionStatus.FLAGGED if flagged else ContributionStatus.PAID
     expiring_flagged_data = timezone.now(
     ) - settings.FLAGGED_PAYMENT_AUTO_ACCEPT_DELTA - timedelta(days=1)
     non_expiring_flagged_date = timezone.now() - timedelta(days=1)
     ContributionFactory.create_batch(self.expired_contrib_count,
                                      status=status,
                                      flagged_date=expiring_flagged_data)
     ContributionFactory.create_batch(
         self.non_expired_contrib_count,
         status=status,
         flagged_date=non_expiring_flagged_date)
Example #2
0
 def setUp(self):
     self.subscription_id = "test-subscription-id"
     self.stripe_account_id = "testing-stripe-account-id"
     self.org = OrganizationFactory(
         stripe_account_id=self.stripe_account_id)
     self.contributor = ContributorFactory()
     self.contribution = ContributionFactory(
         contributor=self.contributor,
         organization=self.org,
         provider_subscription_id=self.subscription_id,
     )
     self.other_contribution = ContributionFactory(organization=self.org)
     self.payment_method_id = "testing-payment-method-id"
Example #3
0
 def setUp(self):
     self.user = create_test_user(
         role_assignment_data={"role_type": Roles.HUB_ADMIN})
     self.subscription_id = "test-subscription-id"
     self.stripe_account_id = "testing-stripe-account-id"
     self.org = OrganizationFactory(
         stripe_account_id=self.stripe_account_id)
     self.contributor = ContributorFactory()
     self.contribution = ContributionFactory(
         contributor=self.contributor,
         organization=self.org,
         provider_subscription_id=self.subscription_id,
     )
     self.other_contribution = ContributionFactory()
Example #4
0
 def test_reject_non_flagged_fails(self):
     request = self._make_listview_request()
     contribution = ContributionFactory(bad_actor_score=5,
                                        status=ContributionStatus.PAID)
     queryset = Contribution.objects.filter(pk=contribution.pk)
     self.assertRaises(MessageFailure,
                       self.contribution_admin.accept_flagged_contribution,
                       request, queryset)
Example #5
0
    def setUp(self):
        self.factory = RequestFactory()
        user_model = get_user_model()
        self.user = user_model.objects.create_superuser(email="*****@*****.**",
                                                        password="******")
        self.contribution_admin = ContributionAdmin(Contribution, AdminSite())

        self.organization = OrganizationFactory(
            default_payment_provider="stripe")

        self.contrib_score_2 = ContributionFactory(
            status=ContributionStatus.FLAGGED,
            bad_actor_score=2,
            organization=self.organization,
            payment_provider_used="Stripe",
        )
        self.contrib_score_4 = ContributionFactory(
            status=ContributionStatus.FLAGGED,
            bad_actor_score=4,
            organization=self.organization,
            payment_provider_used="Stripe",
        )
Example #6
0
    def setUp(self):
        self.factory = RequestFactory()
        self.permission = ContributorOwnsContribution()

        self.regular_user = user_model.objects.create_user(
            email="*****@*****.**", password="******")
        self.right_contributor = ContributorFactory(email="*****@*****.**")
        self.wrong_contributor = ContributorFactory(email="*****@*****.**")

        self.contribution = ContributionFactory(
            contributor=self.right_contributor)
        self.url = reverse("contribution-cancel-recurring-payment",
                           kwargs={"pk": self.contribution.pk})
Example #7
0
 def setUp(self):
     self.hub_integration = HubSlackIntegration.get_solo()
     self.hub_integration.bot_token = HUB_TOKEN
     self.hub_integration.channel = HUB_CHANNEL
     self.hub_integration.org_channel_prefix = HUB_ORG_PREFIX
     self.hub_integration.save()
     self.org = OrganizationFactory()
     self.org_channel = "org-contributions"
     self.org_integration = OrganizationSlackIntegration(
         organization=self.org, channel=ORG_CHANNEL, bot_token=ORG_TOKEN)
     self.org_channel_name = f"{HUB_ORG_PREFIX}{SlackManager.format_org_name(self.org.name)}"
     self.contributor = ContributorFactory()
     self.contribution = ContributionFactory(
         organization=self.org,
         contributor=self.contributor,
         amount=AMOUNT,
         last_payment_date=PAYMENT_DATE,
         interval=INTERVAL,
     )
Example #8
0
 def _set_up_contributions(cls):
     """ """
     # because we want to be able to provide scaffolding
     # to have contributors contributing to some but not
     # other pages
     if DonationPage.objects.count() < 2:
         logger.warn(
             "Tests relying on this mixin may be trivial when there are less than 2 donation pages"
         )
     for x in range(cls.contributors_count):
         contributor = ContributorFactory()
         for idx, page in enumerate(DonationPage.objects.all()):
             if any([
                     x % 2 == 0,
                     idx % 2 == 0,
             ]):
                 ContributionFactory(
                     donation_page=page,
                     organization=page.revenue_program.organization,
                     contributor=contributor,
                 )
     cls.contributor_user = Contributor.objects.first()
Example #9
0
 def _create_contribution(self, **kwargs):
     return ContributionFactory(organization=self.org, **kwargs)
Example #10
0
 def setUp(self):
     self.serializer = serializers.ContributorContributionSerializer
     self.test_stripe_account_id = "testing_123"
     self.org = OrganizationFactory(
         stripe_account_id=self.test_stripe_account_id)
     self.contribution = ContributionFactory()
Example #11
0
 def setUp(self):
     self.serializer = serializers.ContributionSerializer
     self.contributor = ContributorFactory()
     self.contribution = ContributionFactory(amount=1000,
                                             contributor=self.contributor,
                                             payment_provider_used="Stripe")
Example #12
0
class ContributionSerializer(TestCase):
    expected_fields = [
        "id",
        "contributor_email",
        "created",
        "amount",
        "currency",
        "interval",
        "last_payment_date",
        "bad_actor_score",
        "flagged_date",
        "auto_accepted_on",
        "status",
    ]

    def setUp(self):
        self.serializer = serializers.ContributionSerializer
        self.contributor = ContributorFactory()
        self.contribution = ContributionFactory(amount=1000,
                                                contributor=self.contributor,
                                                payment_provider_used="Stripe")

    def test_returned_fields(self):
        data = self.serializer(self.contribution).data
        for field in self.expected_fields:
            self.assertIn(field, data)

    def test_get_auto_accepted_on(self):
        # Should return null if empty
        self.contribution.flagged_date = None
        self.contribution.save()
        old_data = self.serializer(self.contribution).data
        self.assertIsNone(old_data["auto_accepted_on"])
        # Should return a datetime equal to flagged_date + "FLAGGED_PAYMENT_AUTO_ACCEPT_DELTA" setting
        self.contribution.flagged_date = timezone.now()
        self.contribution.save()
        target_date = self.contribution.flagged_date + settings.FLAGGED_PAYMENT_AUTO_ACCEPT_DELTA
        new_data = self.serializer(self.contribution).data
        self.assertEqual(new_data["auto_accepted_on"], target_date)

    def test_get_formatted_payment_provider_used(self):
        data = self.serializer(self.contribution).data
        self.assertEqual(data["formatted_payment_provider_used"], "Stripe")

    def test_contributor_email(self):
        data = self.serializer(self.contribution).data
        self.assertEqual(data["contributor_email"], self.contributor.email)

    def test_get_provider_payment_url(self):
        my_provider_payment_id = "my_provider_payment_id"
        self.contribution.provider_payment_id = my_provider_payment_id
        self.contribution.save()

        data = self.serializer(self.contribution).data
        self.assertIn(my_provider_payment_id, data["provider_payment_url"])

    def test_get_provider_subscription_url(self):
        my_provider_subscription_id = "my_provider_subscription_id"
        self.contribution.provider_subscription_id = my_provider_subscription_id
        self.contribution.save()

        data = self.serializer(self.contribution).data
        self.assertIn(my_provider_subscription_id,
                      data["provider_subscription_url"])

    def test_get_provider_customer_url(self):
        my_provider_customer_id = "my_provider_customer_id"
        self.contribution.provider_customer_id = my_provider_customer_id
        self.contribution.save()

        data = self.serializer(self.contribution).data
        self.assertIn(my_provider_customer_id, data["provider_customer_url"])