-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(PC-31975)[API] feat: log stock update changes
- Loading branch information
1 parent
2216134
commit bcc6b9d
Showing
8 changed files
with
141 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import dataclasses | ||
import datetime | ||
from decimal import Decimal | ||
import logging | ||
from unittest import mock | ||
from unittest.mock import patch | ||
|
||
|
@@ -342,7 +343,7 @@ def test_edit_one_event_stock_using_price_category(self, mocked_async_index_offe | |
assert offers_models.PriceCategoryLabel.query.count() == 1 | ||
|
||
@patch("pcapi.core.search.async_index_offer_ids") | ||
def test_edit_one_event_stock_created_with_price_category(self, mocked_async_index_offer_ids, client): | ||
def test_edit_one_event_stock_created_with_price_category(self, mocked_async_index_offer_ids, client, caplog): | ||
venue = offerers_factories.VenueFactory() | ||
offer = offers_factories.EventOfferFactory( | ||
isActive=False, | ||
|
@@ -355,10 +356,10 @@ def test_edit_one_event_stock_created_with_price_category(self, mocked_async_ind | |
) | ||
|
||
existing_stock = offers_factories.StockFactory(offer=offer, price=10, priceCategory=old_price_category) | ||
offerers_factories.UserOffererFactory( | ||
user = offerers_factories.UserOffererFactory( | ||
user__email="[email protected]", | ||
offerer=offer.venue.managingOfferer, | ||
) | ||
).user | ||
beginning = datetime.datetime.utcnow() + relativedelta(days=10) | ||
|
||
stock_data = { | ||
|
@@ -372,13 +373,34 @@ def test_edit_one_event_stock_created_with_price_category(self, mocked_async_ind | |
} | ||
], | ||
} | ||
client.with_session_auth("[email protected]").post("/stocks/bulk/", json=stock_data) | ||
with caplog.at_level(logging.INFO): | ||
response = client.with_session_auth(user.email).post("/stocks/bulk/", json=stock_data) | ||
|
||
created_stock = Stock.query.first() | ||
assert offer.id == created_stock.offerId | ||
assert len(Stock.query.all()) == 1 | ||
assert created_stock.priceCategory == new_price_category | ||
assert created_stock.price == 25 | ||
|
||
target_log_message = "Stock updated with beginning datetime updated" | ||
log = next(record for record in caplog.records if record.message == target_log_message) | ||
|
||
assert log.extra["user_id"] == user.id | ||
|
||
changes = log.extra["changes"] | ||
|
||
expected_updated_field = {"beginningDatetime", "bookingLimitDatetime", "priceCategory", "price"} | ||
assert expected_updated_field <= set(changes) | ||
|
||
assert changes["beginningDatetime"]["old"] != changes["beginningDatetime"]["new"] | ||
assert changes["beginningDatetime"]["new"] == beginning | ||
|
||
assert changes["bookingLimitDatetime"]["old"] != changes["bookingLimitDatetime"]["new"] | ||
assert changes["bookingLimitDatetime"]["new"] == beginning | ||
|
||
assert changes["priceCategory"]["old"] != changes["priceCategory"]["new"] | ||
assert changes["priceCategory"]["new"] == new_price_category | ||
|
||
def test_create_one_stock_with_activation_codes(self, client): | ||
# Given | ||
offer = offers_factories.DigitalOfferFactory(url="https://chartreu.se") | ||
|
Oops, something went wrong.