Skip to content

Commit

Permalink
(PC-31953)[API] feat: Handle manual edition on pro side
Browse files Browse the repository at this point in the history
  • Loading branch information
dramelet-pass committed Sep 19, 2024
1 parent 022bee4 commit f7847aa
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 15 deletions.
33 changes: 22 additions & 11 deletions api/src/pcapi/core/offerers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2727,18 +2727,29 @@ def create_offerer_address_from_address_api(
city: str,
latitude: float,
longitude: float,
is_manual_edition: bool,
) -> geography_models.Address:
is_manual_edition: bool = False
address_info = api_adresse.get_address(street, postal_code, city)
location_data = LocationData(
city=address_info.city,
postal_code=address_info.postcode,
latitude=address_info.latitude,
longitude=address_info.longitude,
street=address_info.street,
insee_code=address_info.citycode,
ban_id=address_info.id,
)
if not is_manual_edition:
address_info = api_adresse.get_address(street, postal_code, city)
location_data = LocationData(
city=address_info.city,
postal_code=address_info.postcode,
latitude=address_info.latitude,
longitude=address_info.longitude,
street=address_info.street,
insee_code=address_info.citycode,
ban_id=address_info.id,
)
else:
location_data = LocationData(
city=city,
postal_code=postal_code,
latitude=latitude,
longitude=longitude,
street=street,
ban_id=None,
insee_code=None
)
return get_or_create_address(location_data, is_manual_edition=is_manual_edition)


Expand Down
1 change: 1 addition & 0 deletions api/src/pcapi/core/offerers/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,4 @@ class AddressBodyModel(BaseModel):
longitude: float | str
postalCode: VenuePostalCode
street: VenueAddress
isManualEdition: bool = False
1 change: 1 addition & 0 deletions api/src/pcapi/core/offers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ def get_offerer_address_from_address(
city=address.city,
latitude=float(address.latitude),
longitude=float(address.longitude),
is_manual_edition=address.isManualEdition
)
return offerers_api.get_or_create_offerer_address(
venue.managingOffererId,
Expand Down
44 changes: 44 additions & 0 deletions api/tests/routes/pro/patch_offer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,49 @@ def test_patch_offer_with_address(self, get_address_mock, label, offer_has_oa, a
assert address.postalCode == "75102"
assert address.latitude == Decimal("48.85660")
assert address.longitude == Decimal("2.3522")
assert address.isManualEdition is False

def test_patch_offer_with_manual_address_edition(self, client):
# Given
user_offerer = offerers_factories.UserOffererFactory(user__email="[email protected]")
venue = offerers_factories.VenueFactory(managingOfferer=user_offerer.offerer)
offer = offers_factories.OfferFactory(
subcategoryId=subcategories.ABO_MEDIATHEQUE.id,
venue=venue,
name="New name",
description="description",
)

# When
data = {
"name": "New name",
"externalTicketOfficeUrl": "http://example.net",
"mentalDisabilityCompliant": True,
"address": {
"street": "42, Rue qui n’existe pas",
"city": "Ville inconnue",
"postalCode": "00000",
"latitude": 1,
"longitude": 1,
"label": "label",
"isManualEdition": True,
},
}

response = client.with_session_auth("[email protected]").patch(f"/offers/{offer.id}", json=data)

assert response.status_code == 200
assert response.json["id"] == offer.id
updated_offer = Offer.query.get(offer.id)
address = updated_offer.offererAddress.address
assert updated_offer.offererAddress.label == "label"
assert address.street == "42, Rue qui n’existe pas"
assert address.city == "Ville inconnue"
assert address.postalCode == "00000"
assert address.latitude == Decimal("1")
assert address.longitude == Decimal("1")
assert address.isManualEdition is True


@pytest.mark.parametrize("label", ["", None, True])
@patch("pcapi.connectors.api_adresse.get_address")
Expand Down Expand Up @@ -193,6 +236,7 @@ def test_patch_offer_with_address_twice(self, get_address_mock, label, client):
assert address.postalCode == "75102"
assert address.latitude == Decimal("48.85660")
assert address.longitude == Decimal("2.3522")
assert address.isManualEdition is False

def test_withdrawal_can_be_updated(self, client):
offer = offers_factories.OfferFactory(
Expand Down
6 changes: 2 additions & 4 deletions api/tests/routes/pro/post_offer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,17 @@ def test_create_event_offer_with_manual_offerer_address(self, oa_label, client):
"longitude": "2.308289",
"postalCode": "75001",
"street": "3 Rue de Valois",
"isManualEdition": True
},
}
with patch("pcapi.connectors.api_adresse.get_address") as mocked_get_address:
mocked_get_address.side_effect = api_adresse.NoResultException
response = client.with_session_auth("[email protected]").post("/offers", json=data)
response = client.with_session_auth("[email protected]").post("/offers", json=data)

# Then
assert response.status_code == 201
offer_id = response.json["id"]
offer = Offer.query.get(offer_id)
assert offer.offererAddress.address.isManualEdition
assert offer.offererAddress.label == oa_label
assert offer.offererAddress.address.inseeCode == "06029"
assert not offer.offererAddress.address.banId

def when_creating_new_thing_offer(self, client):
Expand Down

0 comments on commit f7847aa

Please sign in to comment.