<commit_before>from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from rest_framework.test import APITestCase

from agir.payments.models import Payment, Subscription
from agir.people.models import Person
from agir.presidentielle2022 import (
    AFCPJLMCheckDonationPaymentMode,
    AFCP2022SystemPayPaymentMode,
)
from agir.presidentielle2022.apps import Presidentielle2022Config


class PublicDonationAggregatesAPITestCase(APITestCase):
    def setUp(self):
        self.person = Person.objects.create_insoumise(
            "<EMAIL>", create_role=True
        )
        self.person.role.user_permissions.add(
            Permission.objects.get(
                content_type=ContentType.objects.get_for_model(Person),
                codename="view_person",
            )
        )
        self.pending_payment = Payment.objects.create(
            person=self.person,
            price=100,
            type=Presidentielle2022Config.DONATION_PAYMENT_TYPE,
            mode=AFCPJLMCheckDonationPaymentMode,
            status=Payment.STATUS_WAITING,
        )
        self.single_donation = Payment.objects.create(
            person=self.person,
            price=100,
            type=Presidentielle2022Config.DONATION_PAYMENT_TYPE,
            mode=AFCPJLMCheckDonationPaymentMode,
            status=Payment.STATUS_COMPLETED,
        )
        self.subscription = Subscription.objects.create(
            person=self.person,
            price=100,
            type=Presidentielle2022Config.DONATION_SUBSCRIPTION_TYPE,
            mode=AFCP2022SystemPayPaymentMode,
            status=Subscription.STATUS_ACTIVE,
        )
        self.monthly_donation = Payment.objects.create(
            person=self.person,
            price=100,
            type=Presidentielle2022Config.DONATION_SUBSCRIPTION_TYPE,
            mode=AFCP2022SystemPayPaymentMode,
            status=Payment.STATUS_COMPLETED,
            subscription=self.subscription,
        )
        self.expected_total_amount = 200

    def test_anonymous_cannot_get_donation_aggregates(self):
        self.client.logout()
        res = self.client.get("/api/2022/dons/")
        self.assertEqual(res.status_code, 401)

    def test_authenticated_user_can_get_right_donation_amount(self):
        self.client.force_login(self.person.role)
        res = self.client.get("/api/2022/dons/")
        self.assertIn("totalAmount", res.data)
        self.assertEqual(res.data["totalAmount"], self.expected_total_amount)


class DonationAggregatesAPITestCase(APITestCase):
    def setUp(self):
        self.person = Person.objects.create_insoumise(
            "<EMAIL>", create_role=True
        )
        self.person.role.user_permissions.add(
            Permission.objects.get(
                content_type=ContentType.objects.get_for_model(Person),
                codename="view_person",
            )
        )
        self.pending_payment = Payment.objects.create(
            person=self.person,
            price=100,
            type=Presidentielle2022Config.DONATION_PAYMENT_TYPE,
            mode=AFCPJLMCheckDonationPaymentMode,
            status=Payment.STATUS_WAITING,
        )
        self.single_donation = Payment.objects.create(
            person=self.person,
            price=100,
            type=Presidentielle2022Config.DONATION_PAYMENT_TYPE,
            mode=AFCPJLMCheckDonationPaymentMode,
            status=Payment.STATUS_COMPLETED,
        )
        self.subscription = Subscription.objects.create(
            person=self.person,
            price=100,
            type=Presidentielle2022Config.DONATION_SUBSCRIPTION_TYPE,
            mode=AFCP2022SystemPayPaymentMode,
            status=Subscription.STATUS_ACTIVE,
        )
        self.monthly_donation = Payment.objects.create(
            person=self.person,
            price=100,
            type=Presidentielle2022Config.DONATION_SUBSCRIPTION_TYPE,
            mode=AFCP2022SystemPayPaymentMode,
            status=Payment.STATUS_COMPLETED,
            subscription=self.subscription,
        )
        self.expected_total_amount = 200

    def test_anonymous_cannot_get_donation_aggregates(self):
        self.client.logout()
        res = self.client.get("/api/2022/dons/")
        self.assertEqual(res.status_code, 401)

    def test_authenticated_user_can_get_right_donation_amount(self):
        self.client.force_login(self.person.role)
        res = self.client.get("/api/2022/dons/")
        self.assertIn("totalAmount", res.data)
        self.assertEqual(res.data["totalAmount"], self.expected_total_amount)<commit_msg>fix: update donations aggregates tests<commit_after>from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from rest_framework.test import APITestCase

from agir.payments.models import Payment, Subscription
from agir.people.models import Person
from agir.presidentielle2022 import (
    AFCPJLMCheckDonationPaymentMode,
    AFCP2022SystemPayPaymentMode,
)
from agir.presidentielle2022.apps import Presidentielle2022Config


class PublicDonationAggregatesAPITestCase(APITestCase):
    def setUp(self):
        self.person = Person.objects.create_insoumise(
            "<EMAIL>", create_role=True
        )
        self.person.role.user_permissions.add(
            Permission.objects.get(
                content_type=ContentType.objects.get_for_model(Person),
                codename="view_person",
            )
        )
        self.pending_payment = Payment.objects.create(
            person=self.person,
            price=100,
            type=Presidentielle2022Config.DONATION_PAYMENT_TYPE,
            mode=AFCPJLMCheckDonationPaymentMode,
            status=Payment.STATUS_WAITING,
        )
        self.single_donation = Payment.objects.create(
            person=self.person,
            price=100,
            type=Presidentielle2022Config.DONATION_PAYMENT_TYPE,
            mode=AFCPJLMCheckDonationPaymentMode,
            status=Payment.STATUS_COMPLETED,
        )
        self.subscription = Subscription.objects.create(
            person=self.person,
            price=100,
            type=Presidentielle2022Config.DONATION_SUBSCRIPTION_TYPE,
            mode=AFCP2022SystemPayPaymentMode,
            status=Subscription.STATUS_ACTIVE,
        )
        self.monthly_donation = Payment.objects.create(
            person=self.person,
            price=100,
            type=Presidentielle2022Config.DONATION_SUBSCRIPTION_TYPE,
            mode=AFCP2022SystemPayPaymentMode,
            status=Payment.STATUS_COMPLETED,
            subscription=self.subscription,
        )
        self.expected_total_amount = 200

    def test_authenticated_user_can_get_right_donation_amount(self):
        self.client.force_login(self.person.role)
        res = self.client.get("/api/2022/dons/")
        self.assertIn("totalAmount", res.data)
        self.assertEqual(res.data["totalAmount"], self.expected_total_amount)


class DonationAggregatesAPITestCase(APITestCase):
    def setUp(self):
        self.person = Person.objects.create_insoumise(
            "<EMAIL>", create_role=True
        )
        self.person.role.user_permissions.add(
            Permission.objects.get(
                content_type=ContentType.objects.get_for_model(Person),
                codename="view_person",
            )
        )
        self.pending_payment = Payment.objects.create(
            person=self.person,
            price=100,
            type=Presidentielle2022Config.DONATION_PAYMENT_TYPE,
            mode=AFCPJLMCheckDonationPaymentMode,
            status=Payment.STATUS_WAITING,
        )
        self.single_donation = Payment.objects.create(
            person=self.person,
            price=100,
            type=Presidentielle2022Config.DONATION_PAYMENT_TYPE,
            mode=AFCPJLMCheckDonationPaymentMode,
            status=Payment.STATUS_COMPLETED,
        )
        self.subscription = Subscription.objects.create(
            person=self.person,
            price=100,
            type=Presidentielle2022Config.DONATION_SUBSCRIPTION_TYPE,
            mode=AFCP2022SystemPayPaymentMode,
            status=Subscription.STATUS_ACTIVE,
        )
        self.monthly_donation = Payment.objects.create(
            person=self.person,
            price=100,
            type=Presidentielle2022Config.DONATION_SUBSCRIPTION_TYPE,
            mode=AFCP2022SystemPayPaymentMode,
            status=Payment.STATUS_COMPLETED,
            subscription=self.subscription,
        )
        self.expected_total_amount = 200

    def test_authenticated_user_can_get_right_donation_amount(self):
        self.client.force_login(self.person.role)
        res = self.client.get("/api/2022/dons/")
        self.assertIn("totalAmount", res.data)
        self.assertEqual(res.data["totalAmount"], self.expected_total_amount)
{'fraction_non_alphanumeric': 0.08013000112069932, 'fraction_numerical': 0.02443124509694049, 'mean_word_length': 2.503729878288182, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1533819', 'n_tokens_mistral': 2682, 'n_tokens_neox': 2512, 'n_words': 285}