-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(PC-31838)[API] feat: add allowed actions for collective offer templates #14242
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
|
||
from pcapi.core.educational import exceptions | ||
from pcapi.core.educational import factories | ||
from pcapi.core.educational.factories import create_collective_offer_by_status | ||
from pcapi.core.educational.models import ALLOWED_ACTIONS_BY_DISPLAYED_STATUS | ||
from pcapi.core.educational.models import CollectiveBookingStatus | ||
from pcapi.core.educational.models import CollectiveOffer | ||
|
@@ -16,6 +15,7 @@ | |
from pcapi.core.educational.models import CollectiveStock | ||
from pcapi.core.educational.models import EducationalDeposit | ||
from pcapi.core.educational.models import HasImageMixin | ||
from pcapi.core.educational.models import TEMPLATE_ALLOWED_ACTIONS_BY_DISPLAYED_STATUS | ||
import pcapi.core.offerers.factories as offerers_factories | ||
import pcapi.core.providers.factories as providers_factories | ||
from pcapi.models import db | ||
|
@@ -28,6 +28,15 @@ | |
|
||
pytestmark = pytest.mark.usefixtures("db_session") | ||
|
||
COLLECTIVE_OFFER_TEMPLATE_STATUS_LIST = [ | ||
CollectiveOfferDisplayedStatus.ARCHIVED, | ||
CollectiveOfferDisplayedStatus.REJECTED, | ||
CollectiveOfferDisplayedStatus.PENDING, | ||
CollectiveOfferDisplayedStatus.DRAFT, | ||
CollectiveOfferDisplayedStatus.INACTIVE, | ||
CollectiveOfferDisplayedStatus.ACTIVE, | ||
] | ||
|
||
|
||
class EducationalDepositTest: | ||
def test_should_raise_insufficient_fund(self) -> None: | ||
|
@@ -609,7 +618,7 @@ def test_unique_program_for_an_educational_institution(self): | |
class CollectiveOfferDisplayedStatusTest: | ||
@pytest.mark.parametrize("status", CollectiveOfferDisplayedStatus) | ||
def test_get_offer_displayed_status(self, status): | ||
offer = create_collective_offer_by_status(status) | ||
offer = factories.create_collective_offer_by_status(status) | ||
|
||
assert offer.displayedStatus == status | ||
|
||
|
@@ -630,29 +639,24 @@ def test_get_displayed_status_for_inactive_offer_due_to_booking_date_passed(self | |
class CollectiveOfferAllowedActionsTest: | ||
@pytest.mark.parametrize("status", CollectiveOfferDisplayedStatus) | ||
def test_get_offer_allowed_actions(self, status): | ||
offer = create_collective_offer_by_status(status) | ||
offer = factories.create_collective_offer_by_status(status) | ||
|
||
assert offer.allowed_actions == list(ALLOWED_ACTIONS_BY_DISPLAYED_STATUS[status]) | ||
assert offer.allowedActions == list(ALLOWED_ACTIONS_BY_DISPLAYED_STATUS[status]) | ||
|
||
def test_get_ended_offer_allowed_actions(self): | ||
offer = create_collective_offer_by_status(CollectiveOfferDisplayedStatus.ENDED) | ||
offer = factories.create_collective_offer_by_status(CollectiveOfferDisplayedStatus.ENDED) | ||
|
||
assert offer.allowed_actions == [ | ||
assert offer.allowedActions == [ | ||
CollectiveOfferAllowedAction.CAN_EDIT_DISCOUNT, | ||
CollectiveOfferAllowedAction.CAN_DUPLICATE, | ||
CollectiveOfferAllowedAction.CAN_CANCEL, | ||
] | ||
|
||
offer.collectiveStock.endDatetime = datetime.datetime.utcnow() - datetime.timedelta(days=3) | ||
assert offer.allowed_actions == [ | ||
assert offer.allowedActions == [ | ||
CollectiveOfferAllowedAction.CAN_DUPLICATE, | ||
] | ||
|
||
def test_get_offer_template_allowed_actions(self): | ||
offer = factories.CollectiveOfferTemplateFactory() | ||
|
||
assert offer.allowed_actions == None | ||
|
||
def test_is_two_days_past_end(self): | ||
offer = factories.CollectiveOfferFactory() | ||
factories.CollectiveStockFactory(collectiveOffer=offer) | ||
|
@@ -665,3 +669,9 @@ def test_is_two_days_past_end(self): | |
|
||
offer.collectiveStock.endDatetime = datetime.datetime.utcnow() - datetime.timedelta(days=3) | ||
assert offer.is_two_days_past_end | ||
|
||
@pytest.mark.parametrize("status", COLLECTIVE_OFFER_TEMPLATE_STATUS_LIST) | ||
def test_get_offer_template_allowed_actions(self, status): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Je ne vois pas vraiement l'intéret de ce test -> il me semble trop proche de l'implementation, le jour ou l'implementation change, ce test devra changer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ça a le mérite d'appeler la méthode directement Et comme ça boucle sur tous les statuts ça vérifie qu'on en a pas oublié un dans le dico |
||
offer = factories.create_collective_offer_template_by_status(status) | ||
|
||
assert offer.allowedActions == list(TEMPLATE_ALLOWED_ACTIONS_BY_DISPLAYED_STATUS[status]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* generated using openapi-typescript-codegen -- do not edit */ | ||
/* istanbul ignore file */ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
/** | ||
* An enumeration. | ||
*/ | ||
export enum CollectiveOfferTemplateAllowedAction { | ||
CAN_EDIT_DETAILS = 'CAN_EDIT_DETAILS', | ||
CAN_DUPLICATE = 'CAN_DUPLICATE', | ||
CAN_ARCHIVE = 'CAN_ARCHIVE', | ||
CAN_CREATE_BOOKABLE_OFFER = 'CAN_CREATE_BOOKABLE_OFFER', | ||
CAN_PUBLISH = 'CAN_PUBLISH', | ||
CAN_HIDE = 'CAN_HIDE', | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Les CollectiveOfferTemplateAllowedAction étant de taille variable une liste ou un set me semble plus approprié.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Un tuple a l'avantage de ne pas être mutable, comme ce sont des "constantes" ça me paraissait adapté
Dans ma 1è PR j'étais même tombé sur le piège : c'était une liste, je le récupère dans une méthode, je modifie la liste.. et boum c'est modifié pour tout le monde