Skip to content

Commit

Permalink
(BSR)[API] feat: add missing fields in batch attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
cnormant-pass committed Jan 29, 2025
1 parent d26651a commit 8bf7425
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions api/src/pcapi/core/external/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def format_user_attributes(
"u.most_booked_movie_genre": user_attributes.most_booked_movie_genre,
"u.most_booked_music_type": user_attributes.most_booked_music_type,
"ut.most_favorite_offer_subcat": user_attributes.most_favorite_offer_subcategories, # max 30 char.
"u.eligibility": user_attributes.eligibility.value if user_attributes.eligibility else None,
"u.is_eligible": user_attributes.is_eligible,
}

for product_use_date_key, product_use_date_value in user_attributes.products_use_date.items():
Expand Down
9 changes: 8 additions & 1 deletion api/src/pcapi/core/external/sendinblue.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from dataclasses import dataclass
from datetime import datetime
import enum
from enum import Enum
from itertools import islice
import logging
Expand Down Expand Up @@ -167,6 +168,12 @@ def format_list_or_str(raw_value: str | Iterable[str]) -> str:
return format_list(raw_value)


def format_enum(enum_value: enum.Enum | str) -> str:
if isinstance(enum_value, str):
return enum_value
return enum_value.value


def _get_attr(
attributes: attributes_models.UserAttributes | attributes_models.ProAttributes,
name: str,
Expand Down Expand Up @@ -196,7 +203,7 @@ def format_user_attributes(attributes: attributes_models.UserAttributes | attrib
SendinblueAttributes.DEPOSIT_EXPIRATION_DATE.value: _get_attr(attributes, "deposit_expiration_date"),
SendinblueAttributes.DMS_APPLICATION_APPROVED.value: _get_attr(attributes, "dms_application_approved"),
SendinblueAttributes.DMS_APPLICATION_SUBMITTED.value: _get_attr(attributes, "dms_application_submitted"),
SendinblueAttributes.ELIGIBILITY.value: _get_attr(attributes, "eligibility"),
SendinblueAttributes.ELIGIBILITY.value: _get_attr(attributes, "eligibility", format_enum),
SendinblueAttributes.FIRSTNAME.value: _get_attr(attributes, "first_name"),
SendinblueAttributes.HAS_BANNER_URL.value: _get_attr(attributes, "has_banner_url"),
SendinblueAttributes.HAS_BOOKINGS.value: _get_attr(attributes, "has_bookings"),
Expand Down
3 changes: 2 additions & 1 deletion api/tests/core/external/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pcapi.core.offerers.models import VenueTypeCode
from pcapi.core.users.models import Credit
from pcapi.core.users.models import DomainsCredit
from pcapi.core.users.models import EligibilityType


common_user_attributes = attributes_models.UserAttributes(
Expand All @@ -24,7 +25,7 @@
digital=Credit(initial=Decimal("200"), remaining=Decimal("200")),
physical=Credit(initial=200, remaining=Decimal("180.00")),
),
eligibility="age-18",
eligibility=EligibilityType.AGE18,
first_name="First name",
has_completed_id_check=True,
is_active=True,
Expand Down
2 changes: 2 additions & 0 deletions api/tests/core/external/batch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def test_format_attributes(self):
"ut.permanent_theme_preference": ["cinema"],
"u.postal_code": None,
"ut.roles": ["BENEFICIARY"],
"u.eligibility": "age-18",
"u.is_eligible": True,
}

# ensure attributes keys are shorter than MAX_BATCH_PARAMETER_SIZE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from pcapi.core.users.factories import BeneficiaryGrant18Factory
from pcapi.core.users.factories import FavoriteFactory
from pcapi.core.users.factories import UserFactory
from pcapi.core.users.models import EligibilityType
from pcapi.core.users.models import UserRole
import pcapi.notifications.push.testing as push_testing
from pcapi.scripts.external_users.batch_update_users_attributes import format_batch_users
Expand Down Expand Up @@ -111,6 +112,8 @@ def test_format_batch_user():
"ut.booking_categories": ["FILM"],
"ut.booking_subcategories": ["SUPPORT_PHYSIQUE_FILM"],
"ut.roles": [UserRole.BENEFICIARY.value],
"u.eligibility": EligibilityType.AGE18.value,
"u.is_eligible": True,
}


Expand Down Expand Up @@ -139,7 +142,7 @@ def test_format_sendinblue_user():
"DEPOSIT_EXPIRATION_DATE": user.deposit_expiration_date,
"DMS_APPLICATION_APPROVED": None,
"DMS_APPLICATION_SUBMITTED": None,
"ELIGIBILITY": user.eligibility,
"ELIGIBILITY": user.eligibility.value,
"EAC_MEG": None,
"FIRSTNAME": "Jeanne",
"HAS_BANNER_URL": None,
Expand Down

0 comments on commit 8bf7425

Please sign in to comment.