def create_stock(): request_data = request.json check_request_has_offer_id(request_data) offer_id = dehumanize(request_data.get('offerId', None)) offer = find_offer_by_id(offer_id) check_offer_is_editable(offer) check_dates_are_allowed_on_new_stock(request_data, offer) offerer = offerer_queries.get_by_offer_id(offer_id) ensure_current_user_has_rights(RightsType.editor, offerer.id) new_stock = Stock(from_dict=request_data) PcObject.save(new_stock) return jsonify(as_dict(new_stock)), 201
def test_doesnt_raise_error_with_missing_booking_limit_datetime(self): # Given offer = create_offer_with_thing_product(Venue()) beginningDatetime = datetime(2019, 2, 14) data = {'price': 0, 'offerId': humanize(offer.id)} # When try: check_dates_are_allowed_on_new_stock(data, offer) except ApiErrors: # Then assert pytest.fail("Should not fail with valid params")
def test_raises_error_with_end_datetime_only(self): # Given offer = create_offer_with_thing_product(Venue()) beginningDatetime = datetime(2019, 2, 14) data = { 'price': 0, 'offerId': humanize(offer.id), 'endDatetime': serialize(beginningDatetime) } # When with pytest.raises(ApiErrors) as e: check_dates_are_allowed_on_new_stock(data, offer) # Then assert e.value.errors['global'] == [ 'Impossible de mettre des dates de début et fin si l\'offre ne porte pas sur un évenement' ]
def test_raises_error_with_none_booking_limit_datetime(self): # Given offer = create_offer_with_event_product() data = { 'price': 0, 'offerId': humanize(offer.id), 'bookingLimitDatetime': None, 'endDatetime': serialize(datetime(2019, 2, 14)), 'beginningDatetime': serialize(datetime(2019, 2, 14)) } # When with pytest.raises(ApiErrors) as e: check_dates_are_allowed_on_new_stock(data, offer) # Then assert e.value.errors['bookingLimitDatetime'] == [ 'Ce paramètre est obligatoire' ]