Skip to content

Commit

Permalink
(PC-31475)[ADAGE] fix: Ensure if venue is concerned with meg
Browse files Browse the repository at this point in the history
We must test all relevant venue (not only those with adageId)
  • Loading branch information
rprasquier-pass committed Sep 11, 2024
1 parent 5791937 commit ad4384e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
3 changes: 3 additions & 0 deletions api/src/pcapi/core/educational/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1873,6 +1873,9 @@ class CollectiveOfferTemplateEducationalRedactor(PcObject, Base, Model):
)


PROGRAM_MARSEILLE_EN_GRAND = "marseille_en_grand"


class EducationalInstitutionProgramAssociation(Base, Model):
"""Association model between EducationalInstitution and
EducationalInstitutionProgram (many-to-many)
Expand Down
11 changes: 4 additions & 7 deletions api/src/pcapi/core/external/attributes/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,10 @@ def get_pro_attributes(email: str) -> models.ProAttributes:
.all()
)

is_eac_meg = False

venue_with_collective_offer = any(venue.adageId for venue in venues)

if venue_with_collective_offer:
venue_ids = {venue.id for venue in venues}
is_eac_meg = has_collective_offers_for_program_and_venue_ids("marseille_en_grand", venue_ids)
venue_ids = {venue.id for venue in venues}
is_eac_meg = has_collective_offers_for_program_and_venue_ids(
educational_models.PROGRAM_MARSEILLE_EN_GRAND, venue_ids
)

if venues:

Expand Down
2 changes: 1 addition & 1 deletion api/tests/core/bookings/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def test_create_booking(self, mocked_async_index_offer_ids, app):
# 1 - SELECT from offer that I don't get
# 1 - SELECT bookings for the venue ???
# 1 - SELECT feature
with assert_num_queries(35):
with assert_num_queries(36):
booking = api.book_offer(beneficiary=beneficiary, stock_id=stock_id, quantity=1)

# One request should have been sent to Batch to trigger the event
Expand Down
16 changes: 8 additions & 8 deletions api/tests/core/external/external_pro_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
# 1 query on venue table with joinedload
# 2 extra SQL queries: select exists on offer and booking tables
# 1 extra query to check if the venue has any related collective offer with 'marseille en grand'
EXPECTED_PRO_ATTR_NUM_QUERIES = 5
# 1 check if the venue is concerned with marseille_en_grand
EXPECTED_PRO_ATTR_NUM_QUERIES = 6


def _build_params(subs, virt, perman, draft, accep, offer, book, attach, colloff, tploff, megoff):
Expand Down Expand Up @@ -239,8 +240,6 @@ def test_update_external_pro_user_attributes(
)

num_queries = EXPECTED_PRO_ATTR_NUM_QUERIES
if create_collective_offer or create_collective_offer_meg:
num_queries += 1

with assert_num_queries(num_queries):
attributes = get_pro_attributes(email)
Expand Down Expand Up @@ -357,7 +356,7 @@ def test_update_external_pro_booking_email_attributes():
venueTypeCode=VenueTypeCode.MUSEUM,
)

with assert_num_queries(4):
with assert_num_queries(5):
attributes = get_pro_attributes(email)

assert attributes.is_pro is True
Expand Down Expand Up @@ -403,7 +402,7 @@ def test_update_external_pro_booking_email_attributes_for_permanent_venue_with_b
_bannerUrl="https://example.net/banner.jpg",
)

with assert_num_queries(4):
with assert_num_queries(5):
attributes = get_pro_attributes(email)
assert attributes.isPermanent is True
assert attributes.has_banner_url is True
Expand All @@ -424,7 +423,7 @@ def test_update_external_pro_booking_email_attributes_for_non_permanent_venue_wi
_bannerUrl="https://example.net/banner.jpg",
)

with assert_num_queries(4):
with assert_num_queries(5):
attributes = get_pro_attributes(email)
assert attributes.isPermanent is False
assert attributes.has_banner_url is True
Expand All @@ -444,15 +443,16 @@ def test_update_external_pro_booking_email_attributes_for_non_permanent_venue_wi
venueTypeCode=VenueTypeCode.MUSEUM,
)

with assert_num_queries(4):
with assert_num_queries(5):
attributes = get_pro_attributes(email)
assert attributes.isPermanent is False
assert attributes.has_banner_url is True


def test_update_external_pro_removed_email_attributes():
# only 2 queries: user and venue - nothing found
with assert_num_queries(2):
# one query for marseille_en_grand
with assert_num_queries(3):
attributes = get_pro_attributes("[email protected]")

assert attributes.is_pro is True
Expand Down
4 changes: 2 additions & 2 deletions api/tests/routes/native/v1/bookings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ def test_cancel_booking(self, client):
booking = booking_factories.BookingFactory(user=user)

client = client.with_token(self.identifier)
with assert_num_queries(24):
with assert_num_queries(25):
response = client.post(f"/native/v1/bookings/{booking.id}/cancel")

assert response.status_code == 204
Expand All @@ -1003,7 +1003,7 @@ def test_cancel_booking_trigger_recredit_event(self, client):
booking = booking_factories.BookingFactory(user=user)

client = client.with_token(self.identifier)
with assert_num_queries(24):
with assert_num_queries(25):
response = client.post(f"/native/v1/bookings/{booking.id}/cancel")

assert response.status_code == 204
Expand Down

0 comments on commit ad4384e

Please sign in to comment.