def test_search_return_offers_by_types_with_some_but_not_all_beginning_datetime_passed_and_no_booking_limit_datetime( self, app): # Given three_hours_ago = datetime.utcnow() - timedelta(hours=3) in_three_hours = datetime.utcnow() + timedelta(hours=3) in_four_hours = datetime.utcnow() + timedelta(hours=4) type_label = EventType.MUSEES_PATRIMOINE offerer = create_offerer() venue = create_venue(offerer) offer = create_offer_with_event_product(venue, event_type=type_label) outdated_event_occurrence = create_event_occurrence( offer, beginning_datetime=three_hours_ago, end_datetime=datetime.utcnow()) future_event_occurrence = create_event_occurrence( offer, beginning_datetime=in_three_hours, end_datetime=in_four_hours) future_stock = create_stock_from_event_occurrence( future_event_occurrence, booking_limit_date=None) outdated_stock = create_stock_from_event_occurrence( outdated_event_occurrence, booking_limit_date=None) PcObject.save(future_stock, outdated_stock) # When search_result_offers = get_offers_for_recommendations_search( type_values=[str(type_label)], ) # Then assert offer in search_result_offers
def test_should_not_return_activation_event(app): # Given offerer = create_offerer() venue_93 = create_venue(offerer, postal_code='93000', departement_code='93', siret=offerer.siren + '33333') offer_93 = create_offer_with_event_product(venue_93, thumb_count=1) offer_activation_93 = create_offer_with_event_product( venue_93, event_type=EventType.ACTIVATION, thumb_count=1) event_occurrence_93 = create_event_occurrence(offer_93) event_occurrence_activation_93 = create_event_occurrence( offer_activation_93) stock_93 = create_stock_from_event_occurrence(event_occurrence_93) stock_activation_93 = create_stock_from_event_occurrence( event_occurrence_activation_93) user = create_user(departement_code='00') PcObject.save(user, stock_93, stock_activation_93) # When offers = get_active_offers(user=user, departement_codes=['00'], offer_id=None) # Then assert offer_93 in offers assert offer_activation_93 not in offers
def when_tutos_are_not_already_read(self, app): # given offerer = create_offerer() venue = create_venue(offerer) offer = create_offer_with_event_product(venue) user = create_user() event_occurrence1 = create_event_occurrence(offer) event_occurrence2 = create_event_occurrence(offer) stock1 = create_stock_from_event_occurrence(event_occurrence1) stock2 = create_stock_from_event_occurrence(event_occurrence2) thing_offer1 = create_offer_with_thing_product(venue) thing_offer2 = create_offer_with_thing_product(venue) stock3 = create_stock_from_offer(thing_offer1) stock4 = create_stock_from_offer(thing_offer2) PcObject.save(stock1, stock2, stock3, stock4, user) upsert_tuto_mediations() # when auth_request = TestClient(app.test_client()).with_auth(user.email) response = auth_request.put(RECOMMENDATION_URL, json={}) # then assert response.status_code == 200 recommendations = response.json assert recommendations[0]['mediation']['tutoIndex'] == 0 assert recommendations[1]['mediation']['tutoIndex'] == 1
def when_it_is_an_offer_on_an_activation_event_and_user_patching_is_not_global_admin( self, app): # Given user = create_user() pro_user = create_user(email='*****@*****.**', is_admin=False) offerer = create_offerer() user_offerer = create_user_offerer(pro_user, offerer) venue = create_venue(offerer) activation_offer = create_offer_with_event_product( venue, event_type=EventType.ACTIVATION) activation_event_occurrence = create_event_occurrence( activation_offer) stock = create_stock_from_event_occurrence( activation_event_occurrence, price=0) activation_offer = create_offer_with_event_product( venue, event_type=EventType.ACTIVATION) activation_event_occurrence = create_event_occurrence( activation_offer, beginning_datetime=Patch.tomorrow, end_datetime=Patch.tomorrow_plus_one_hour) stock = create_stock_from_event_occurrence( activation_event_occurrence, price=0, booking_limit_date=Patch.tomorrow_minus_one_hour) booking = create_booking(user, stock, venue=venue) PcObject.save(booking, user_offerer) url = '/bookings/token/{}'.format(booking.token) # When response = TestClient( app.test_client()).with_auth('*****@*****.**').patch(url) # Then assert response.status_code == 403
def when_searching_by_keywords_and_distance_and_latitude_longitude( self, app): # Given user = create_user(email='*****@*****.**') concert_offer13 = create_offer_with_event_product( self.venue13, event_name='Funky Concert de Gael Faye', event_type=EventType.MUSIQUE) concert_offer75 = create_offer_with_event_product( self.venue75, event_name='Funky Concert de Gael Faye', event_type=EventType.MUSIQUE) concert_offer973 = create_offer_with_event_product( self.venue973, event_name='Kiwi', event_type=EventType.MUSIQUE) event_occurrence13 = create_event_occurrence( concert_offer13, beginning_datetime=self.in_one_hour, end_datetime=self.ten_days_from_now) event_occurrence75 = create_event_occurrence( concert_offer75, beginning_datetime=self.in_one_hour, end_datetime=self.ten_days_from_now) event_occurrence973 = create_event_occurrence( concert_offer973, beginning_datetime=self.in_one_hour, end_datetime=self.ten_days_from_now) recommendation13 = create_recommendation(concert_offer13, user) recommendation75 = create_recommendation(concert_offer75, user) recommendation973 = create_recommendation(concert_offer973, user) stock13 = create_stock_from_event_occurrence(event_occurrence13) stock75 = create_stock_from_event_occurrence(event_occurrence75) stock973 = create_stock_from_event_occurrence(event_occurrence973) PcObject.save(stock13, recommendation13, stock75, recommendation75, stock973, recommendation973) # When response = TestClient(app.test_client()).with_auth(user.email).get( RECOMMENDATION_URL + '?distance=20000&latitude=48.8363788&longitude=2.4002701&keywords=Macouria' ) # Then assert response.status_code == 200 offers = response.json assert len(offers) == 1 assert 'Kiwi' in offers[0]['offer']['product']['name']
def when_tutos_are_already_read(self, app): # given offerer = create_offerer() venue = create_venue(offerer) offer = create_offer_with_event_product(venue) user = create_user() event_occurrence1 = create_event_occurrence(offer) event_occurrence2 = create_event_occurrence(offer) stock1 = create_stock_from_event_occurrence(event_occurrence1) stock2 = create_stock_from_event_occurrence(event_occurrence2) thing_offer1 = create_offer_with_thing_product(venue) thing_offer2 = create_offer_with_thing_product(venue) stock3 = create_stock_from_offer(thing_offer1) stock4 = create_stock_from_offer(thing_offer2) PcObject.save(stock1, stock2, stock3, stock4, user) upsert_tuto_mediations() tuto_mediation0 = Mediation.query.filter_by(tutoIndex=0).one() tuto_mediation1 = Mediation.query.filter_by(tutoIndex=1).one() tuto_recommendation0 = create_recommendation( mediation=tuto_mediation0, user=user ) tuto_recommendation1 = create_recommendation( mediation=tuto_mediation1, user=user ) PcObject.save(tuto_recommendation0, tuto_recommendation1) humanized_tuto_recommendation0_id = humanize(tuto_recommendation0.id) humanized_tuto_recommendation1_id = humanize(tuto_recommendation1.id) reads = [ { "id": humanized_tuto_recommendation0_id, "dateRead": "2018-12-17T15:59:11.689Z" }, { "id": humanized_tuto_recommendation1_id, "dateRead": "2018-12-17T15:59:15.689Z" } ] data = {'readRecommendations': reads} auth_request = TestClient(app.test_client()).with_auth(user.email) # when response = auth_request.put(RECOMMENDATION_URL, json=data) # then assert response.status_code == 200 recommendations = response.json recommendation_ids = [r['id'] for r in recommendations] assert humanized_tuto_recommendation0_id not in recommendation_ids assert humanized_tuto_recommendation1_id not in recommendation_ids
def test_search_with_several_partial_keywords_returns_things_and_events_with_name_containing_keywords( self, app): # Given thing_ok = create_product_with_thing_type( thing_name='Rencontre de michel') thing_product = create_product_with_thing_type( thing_name='Rencontre avec jean-luc') event_product = create_product_with_event_type( event_name='Rencontre avec jean-mimi chelou') offerer = create_offerer() venue = create_venue(offerer) thing_ok_offer = create_offer_with_thing_product(venue, thing_ok) thing_ko_offer = create_offer_with_thing_product(venue, thing_product) event_ko_offer = create_offer_with_event_product(venue, event_product) event_ko_occurrence = create_event_occurrence(event_ko_offer) event_ko_stock = create_stock_from_event_occurrence( event_ko_occurrence) thing_ok_stock = create_stock_from_offer(thing_ok_offer) thing_ko_stock = create_stock_from_offer(thing_ko_offer) PcObject.save(event_ko_stock, thing_ok_stock, thing_ko_stock) # When offers = get_offers_for_recommendations_search( keywords_string='renc michel') # Then assert thing_ok_offer in offers assert thing_ko_offer not in offers assert event_ko_offer not in offers
def when_booking_user_email_has_special_character_url_encoded( self, app): # Given user = create_user(email='*****@*****.**') user_admin = create_user(email='*****@*****.**') offerer = create_offerer() user_offerer = create_user_offerer(user_admin, offerer, is_admin=True) venue = create_venue(offerer) offer = create_offer_with_event_product(venue, event_name='Event Name') event_occurrence = create_event_occurrence( offer, beginning_datetime=Patch.tomorrow, end_datetime=Patch.tomorrow_plus_one_hour) stock = create_stock_from_event_occurrence( event_occurrence, price=0, booking_limit_date=Patch.tomorrow_minus_one_hour) booking = create_booking(user, stock, venue=venue) PcObject.save(user_offerer, booking) url_email = urlencode({'email': '*****@*****.**'}) url = '/bookings/token/{}?{}'.format(booking.token, url_email) # When response = TestClient( app.test_client()).with_auth('*****@*****.**').patch(url) # Then assert response.status_code == 204
def when_user_patching_is_global_admin_is_activation_offer_and_existing_deposit_for_booking_user( self, app): # Given user = create_user(is_admin=False, can_book_free_offers=False) pro_user = create_user(email='*****@*****.**', is_admin=True, can_book_free_offers=False) offerer = create_offerer() user_offerer = create_user_offerer(pro_user, offerer) venue = create_venue(offerer) activation_offer = create_offer_with_event_product( venue, event_type=EventType.ACTIVATION) activation_event_occurrence = create_event_occurrence( activation_offer, beginning_datetime=Patch.tomorrow, end_datetime=Patch.tomorrow_plus_one_hour) stock = create_stock_from_event_occurrence( activation_event_occurrence, price=0, booking_limit_date=Patch.tomorrow_minus_one_hour) booking = create_booking(user, stock, venue=venue) deposit = create_deposit(user, amount=500) PcObject.save(booking, user_offerer, deposit) user_id = user.id url = '/bookings/token/{}'.format(booking.token) # When response = TestClient( app.test_client()).with_auth('*****@*****.**').patch(url) # Then deposits_for_user = Deposit.query.filter_by(userId=user_id).all() assert response.status_code == 405 assert len(deposits_for_user) == 1 assert deposits_for_user[0].amount == 500
def when_user_not_logged_in_and_wrong_email(self, app): # Given user = create_user(email='*****@*****.**') admin_user = create_user(email='*****@*****.**') offerer = create_offerer() venue = create_venue(offerer) offer = create_offer_with_event_product(venue, event_name='Event Name') event_occurrence = create_event_occurrence(offer) stock = create_stock_from_event_occurrence(event_occurrence, price=0) booking = create_booking(user, stock, venue=venue) PcObject.save(admin_user, booking) # When url = '/bookings/token/{}?email={}'.format(booking.token, '*****@*****.**') response = TestClient( app.test_client()).with_auth('*****@*****.**').get(url) # Then assert response.status_code == 404 assert response.json['global'] == [ "Cette contremarque n'a pas été trouvée" ]
def when_user_has_rights_and_regular_offer(self, app): # Given user = create_user(public_name='John Doe', email='*****@*****.**') admin_user = create_user(email='*****@*****.**') offerer = create_offerer() user_offerer = create_user_offerer(admin_user, offerer) venue = create_venue(offerer) offer = create_offer_with_event_product( venue, event_name='Event Name', event_type=EventType.CINEMA) event_occurrence = create_event_occurrence(offer) stock = create_stock_from_event_occurrence(event_occurrence, price=0) booking = create_booking(user, stock, venue=venue) PcObject.save(user_offerer, booking) expected_json = { 'bookingId': humanize(booking.id), 'date': serialize(booking.stock.beginningDatetime), 'email': '*****@*****.**', 'isUsed': False, 'offerName': 'Event Name', 'userName': '******', 'venueDepartementCode': '93' } # When response = TestClient( app.test_client()).with_auth('*****@*****.**').get( '/bookings/token/{}'.format(booking.token)) # Then assert response.status_code == 200 response_json = response.json assert response_json == expected_json
def test_only_returns_both_EventType_and_ThingType(app): # Given user = create_user(departement_code='93') offerer = create_offerer() venue = create_venue(offerer, departement_code='93') offer1 = create_offer_with_thing_product(venue, thumb_count=1) offer2 = create_offer_with_event_product(venue, thumb_count=1) now = datetime.utcnow() event_occurrence = create_event_occurrence( offer2, beginning_datetime=now + timedelta(hours=72), end_datetime=now + timedelta(hours=74)) mediation = create_mediation(offer2) stock1 = create_stock_from_offer(offer1, price=0) stock2 = create_stock_from_event_occurrence(event_occurrence, price=0, available=10, booking_limit_date=now + timedelta(days=2)) PcObject.save(user, stock1, stock2, mediation) # When offers = get_active_offers(user=user, departement_codes=['93']) # Then assert len(offers) == 2
def when_searching_by_date_and_date_range(self, app): # Given user = create_user(email='*****@*****.**') offerer = create_offerer() venue = create_venue(offerer) offer = create_offer_with_event_product( venue, event_name='Training in Modern Jazz') event_occurrence = create_event_occurrence( offer, beginning_datetime=self.three_days_from_now, end_datetime=self.three_days_and_one_hour_from_now) recommendation = create_recommendation(offer, user) stock = create_stock_from_event_occurrence(event_occurrence) PcObject.save(stock, recommendation) # When response = TestClient(app.test_client()).with_auth( user.email).get(RECOMMENDATION_URL + '?date=%s&days=1-5' % strftime(self.now)) # Then recommendations = response.json assert response.status_code == 200 assert recommendations[0]['offer']['dateRange'] == [ strftime(self.three_days_from_now), strftime(self.three_days_and_one_hour_from_now) ] assert len(response.json) == 1
def expect_activation_booking_to_be_used_and_linked_user_to_be_able_to_book( self, app): # Given user = create_user(can_book_free_offers=False, is_admin=False) pro_user = create_user(email='*****@*****.**', can_book_free_offers=False, is_admin=True) offerer = create_offerer() user_offerer = create_user_offerer(pro_user, offerer) venue = create_venue(offerer) activation_offer = create_offer_with_event_product( venue, event_type=ThingType.ACTIVATION) activation_event_occurrence = create_event_occurrence( activation_offer) stock = create_stock_from_event_occurrence( activation_event_occurrence, price=0) booking = create_booking(user, stock, venue=venue) PcObject.save(booking, user_offerer) user_id = user.id url = '/bookings/token/{}'.format(booking.token) # When response = TestClient( app.test_client()).with_auth('*****@*****.**').patch(url) # Then user = User.query.get(user_id) assert response.status_code == 204 assert user.canBookFreeOffers is True assert user.deposits[0].amount == 500
def test_return_only_not_soft_deleted_stock(self, app): # Given offerer = create_offerer() venue = create_venue(offerer) offer = create_offer_with_event_product(venue) event_occurrence = create_event_occurrence(offer) stock1 = create_stock_from_event_occurrence(event_occurrence) stock2 = create_stock_from_event_occurrence(event_occurrence) stock3 = create_stock_from_event_occurrence(event_occurrence) stock4 = create_stock_from_event_occurrence(event_occurrence) stock1.isSoftDeleted = True PcObject.save(stock1, stock2, stock3, stock4) # When request = handle_rest_get_list(Stock) # Then assert '"id":"{}"'.format(humanize(stock1.id)) not in str( request[0].response) assert '"id":"{}"'.format(humanize(stock2.id)) in str( request[0].response) assert '"id":"{}"'.format(humanize(stock3.id)) in str( request[0].response) assert '"id":"{}"'.format(humanize(stock4.id)) in str( request[0].response)
def when_offers_have_a_thumb_count_for_event_and_no_mediation( self, app): # given now = datetime.utcnow() four_days_from_now = now + timedelta(days=4) eight_days_from_now = now + timedelta(days=8) user = create_user(email='*****@*****.**') offerer = create_offerer() venue = create_venue(offerer) offer = create_offer_with_event_product(venue, thumb_count=1, dominant_color=b'123') event_occurrence = create_event_occurrence( offer, beginning_datetime=four_days_from_now, end_datetime=eight_days_from_now ) stock = create_stock_from_event_occurrence(event_occurrence, price=0, available=20) PcObject.save(user, stock) auth_request = TestClient(app.test_client()).with_auth(user.email) # when response = auth_request.put(RECOMMENDATION_URL, json={'seenRecommendationIds': []}) # then assert response.status_code == 200 assert len(response.json) == 1
def test_returns_two_recommendations_with_one_event_and_one_thing(self, app): # given now = datetime.utcnow() four_days_from_now = now + timedelta(days=4) eight_days_from_now = now + timedelta(days=8) user = create_user(email='*****@*****.**') offerer = create_offerer() venue = create_venue(offerer) offer_event = create_offer_with_event_product(venue, thumb_count=1, dominant_color=b'123') event_occurrence = create_event_occurrence( offer_event, beginning_datetime=four_days_from_now, end_datetime=eight_days_from_now ) event_stock = create_stock_from_event_occurrence(event_occurrence, price=0, available=20) offer_thing = create_offer_with_thing_product(venue, thumb_count=1, dominant_color=b'123') stock_thing = create_stock_with_thing_offer(offerer, venue, offer_thing, price=0) PcObject.save(user, event_stock, stock_thing) auth_request = TestClient(app.test_client()).with_auth(user.email) # when response = auth_request.put(RECOMMENDATION_URL, json={'seenRecommendationIds': []}) # then assert response.status_code == 200 assert len(response.json) == 2
def when_email_has_special_characters_but_is_not_url_encoded( self, app): # Given user = create_user(email='*****@*****.**') user_admin = create_user(email='*****@*****.**') offerer = create_offerer() user_offerer = create_user_offerer(user_admin, offerer, is_admin=True) venue = create_venue(offerer) offer = create_offer_with_event_product( venue, event_name='Event Name') event_occurrence = create_event_occurrence(offer) stock = create_stock_from_event_occurrence(event_occurrence, price=0) booking = create_booking(user, stock, venue=venue) PcObject.save(user_offerer, booking) url = '/bookings/token/{}?email={}'.format( booking.token, user.email) # When response = TestClient( app.test_client()).with_auth('*****@*****.**').patch(url) # Then assert response.status_code == 404
def expect_no_new_deposits_when_the_linked_user_has_been_already_activated( self, app): # Given user = create_user(can_book_free_offers=False, is_admin=False) pro_user = create_user(email='*****@*****.**', can_book_free_offers=False, is_admin=True) offerer = create_offerer() user_offerer = create_user_offerer(pro_user, offerer) venue = create_venue(offerer) activation_offer = create_offer_with_event_product( venue, event_type=EventType.ACTIVATION) activation_event_occurrence = create_event_occurrence( activation_offer) stock = create_stock_from_event_occurrence( activation_event_occurrence, price=0) booking = create_booking(user, stock, venue=venue) deposit = create_deposit(user, amount=500) PcObject.save(booking, user_offerer, deposit) user_id = user.id url = '/bookings/token/{}'.format(booking.token) # When response = TestClient( app.test_client()).with_auth('*****@*****.**').patch(url) # Then deposits_for_user = Deposit.query.filter_by( userId=user_id).all() assert response.status_code == 405 assert len(deposits_for_user) == 1 assert deposits_for_user[0].amount == 500
def expect_booking_to_be_used_with_special_char_in_url(self, app): # Given user = create_user(email='*****@*****.**') user_admin = create_user(email='*****@*****.**') offerer = create_offerer() user_offerer = create_user_offerer(user_admin, offerer, is_admin=True) venue = create_venue(offerer) offer = create_offer_with_event_product( venue, event_name='Event Name') event_occurrence = create_event_occurrence(offer) stock = create_stock_from_event_occurrence(event_occurrence, price=0) booking = create_booking(user, stock, venue=venue) PcObject.save(user_offerer, booking) url_email = urlencode({'email': '*****@*****.**'}) url = '/bookings/token/{}?{}'.format(booking.token, url_email) # When response = TestClient( app.test_client()).with_auth('*****@*****.**').patch(url) # Then assert response.status_code == 204
def when_searching_by_matching_date_and_non_matching_keywords( self, app): # Given user = create_user(email='*****@*****.**') offerer = create_offerer() venue = create_venue(offerer) offer = create_offer_with_event_product( venue, event_name='Training in Modern Jazz') event_occurrence = create_event_occurrence( offer, beginning_datetime=self.in_one_hour, end_datetime=self.ten_days_from_now) recommendation = create_recommendation(offer, user) stock = create_stock_from_event_occurrence(event_occurrence) PcObject.save(stock, recommendation) # When response = TestClient(app.test_client()).with_auth( user.email).get(RECOMMENDATION_URL + '?date=%s&keywords=nekfeu' % strftime(self.ten_days_from_now)) # Then assert response.status_code == 200 assert len(response.json) == 0
def when_searching_by_date_and_type_and_pagination_not_in_range( self, app): # Given user = create_user(email='*****@*****.**') offerer = create_offerer() venue = create_venue(offerer) offer = create_offer_with_event_product( venue, event_name='The new film', event_type=EventType.CINEMA) thing_product = create_product_with_thing_type( thing_name='Lire un livre', is_national=True) thingOffer = create_offer_with_thing_product(venue, thing_product) event_occurrence = create_event_occurrence( offer, beginning_datetime=self.three_days_from_now, end_datetime=self.three_days_and_one_hour_from_now) recommendation = create_recommendation(offer, user) recommendation2 = create_recommendation(thingOffer, user) stock = create_stock_from_event_occurrence(event_occurrence) thing_stock = create_stock(price=12, available=5, offer=thingOffer) PcObject.save(stock, recommendation, recommendation2, thing_stock) # When response = TestClient(app.test_client()).with_auth( user.email).get(RECOMMENDATION_URL + '?categories=Lire%2CRegarder&days=1-5&page=2' + '&date=%s' % strftime(self.now)) # Then assert response.status_code == 200 assert len(response.json) == 0
def when_searching_by_keywords_and_distance(self, app): # Given user = create_user(email='*****@*****.**') concert_offer13 = create_offer_with_event_product( self.venue13, event_name='Funky Concert de Gael Faye', event_type=EventType.MUSIQUE) concert_offer75 = create_offer_with_event_product( self.venue75, event_name='Funky Concert de Gael Faye', event_type=EventType.MUSIQUE) concert_offer973 = create_offer_with_event_product( self.venue973, event_name='Kiwi', event_type=EventType.MUSIQUE) event_occurrence13 = create_event_occurrence( concert_offer13, beginning_datetime=self.in_one_hour, end_datetime=self.ten_days_from_now) event_occurrence75 = create_event_occurrence( concert_offer75, beginning_datetime=self.in_one_hour, end_datetime=self.ten_days_from_now) event_occurrence973 = create_event_occurrence( concert_offer973, beginning_datetime=self.in_one_hour, end_datetime=self.ten_days_from_now) recommendation13 = create_recommendation(concert_offer13, user) recommendation75 = create_recommendation(concert_offer75, user) recommendation973 = create_recommendation(concert_offer973, user) stock13 = create_stock_from_event_occurrence(event_occurrence13) stock75 = create_stock_from_event_occurrence(event_occurrence75) stock973 = create_stock_from_event_occurrence(event_occurrence973) PcObject.save(stock13, recommendation13, stock75, recommendation75, stock973, recommendation973) # When response = TestClient(app.test_client()).with_auth( user.email).get(RECOMMENDATION_URL + '?distance=1&keywords=funky') # Then assert len(response.json) == 2
def test_filter_out_recommendation_with_not_bookable_stocks_returns_recos_with_at_least_one_not_soft_deleted_stock( app): # Given offerer = create_offerer() venue = create_venue(offerer) user = create_user() event_offer = create_offer_with_event_product(venue) soft_deleted_thing_offer = create_offer_with_thing_product(venue) active_thing_offer = create_offer_with_thing_product(venue) event_occurrence1 = create_event_occurrence(event_offer) event_occurrence2 = create_event_occurrence(event_offer) active_thing_stock = create_stock_from_offer(active_thing_offer) active_event_stock = create_stock_from_event_occurrence(event_occurrence2) soft_deleted_event_stock = create_stock_from_event_occurrence( event_occurrence1) soft_deleted_event_stock.isSoftDeleted = True soft_deleted_thing_stock = create_stock_from_offer( soft_deleted_thing_offer) soft_deleted_thing_stock.isSoftDeleted = True recommendation_on_active_thing_stock = create_recommendation( active_thing_offer, user) recommendation_on_both_soft_deleted_and_active_event_stocks = create_recommendation( event_offer, user) recommendation_on_soft_deleted_thing_stock = create_recommendation( soft_deleted_thing_offer, user) PcObject.save(soft_deleted_event_stock, active_event_stock, soft_deleted_thing_stock, active_thing_stock, recommendation_on_both_soft_deleted_and_active_event_stocks, recommendation_on_soft_deleted_thing_stock, recommendation_on_active_thing_stock) # When result = keep_only_bookable_stocks().all() # Then recommendation_ids = [r.id for r in result] assert recommendation_on_both_soft_deleted_and_active_event_stocks.id in recommendation_ids assert recommendation_on_soft_deleted_thing_stock.id not in recommendation_ids assert recommendation_on_active_thing_stock.id in recommendation_ids
def when_searching_by_keywords_ignores_soft_deleted_stocks(self, app): # given search = 'keywords={}'.format('rencontres') user = create_user(email='*****@*****.**') offerer = create_offerer() venue = create_venue(offerer) offer1 = create_offer_with_event_product( venue, event_name='Rencontres avec des peintres') offer2 = create_offer_with_event_product( venue, event_name='Rencontres avec des auteurs') recommendation1 = create_recommendation(offer1, user, search=search) recommendation2 = create_recommendation(offer2, user, search=search) # NOTE: we need to create event occurrence and stock because # GET recommendations filter offer without stock event_occurrence1 = create_event_occurrence(offer1) event_occurrence2 = create_event_occurrence(offer1) event_occurrence3 = create_event_occurrence(offer2) stock1 = create_stock_from_event_occurrence(event_occurrence1, price=10, soft_deleted=False) stock2 = create_stock_from_event_occurrence(event_occurrence2, price=20, soft_deleted=True) stock3 = create_stock_from_event_occurrence(event_occurrence3, price=30, soft_deleted=True) PcObject.save(stock1, stock2, stock3, recommendation1, recommendation2) # when response = TestClient(app.test_client()).with_auth( user.email).get(RECOMMENDATION_URL + '?keywords={}'.format('rencontres')) # then assert response.status_code == 200 assert len(response.json) == 1
def test_update_read_recommendations(app): # Given offerer = create_offerer() venue = create_venue(offerer) offer = create_offer_with_event_product(venue) user = create_user() event_occurrence1 = create_event_occurrence(offer) event_occurrence2 = create_event_occurrence(offer) stock1 = create_stock_from_event_occurrence(event_occurrence1) stock2 = create_stock_from_event_occurrence(event_occurrence2) thing_offer1 = create_offer_with_thing_product(venue) thing_offer2 = create_offer_with_thing_product(venue) stock3 = create_stock_from_offer(thing_offer1) stock4 = create_stock_from_offer(thing_offer2) recommendation1 = create_recommendation(offer, user) recommendation2 = create_recommendation(thing_offer1, user) recommendation3 = create_recommendation(thing_offer2, user) PcObject.save(stock1, stock2, stock3, stock4, recommendation1, recommendation2, recommendation3) # When reads = [ { "id": humanize(recommendation1.id), "dateRead": "2018-12-17T15:59:11.689Z" }, { "id": humanize(recommendation2.id), "dateRead": "2018-12-17T15:59:15.689Z" }, { "id": humanize(recommendation3.id), "dateRead": "2018-12-17T15:59:21.689Z" }, ] update_read_recommendations(reads) # Then assert recommendation1.dateRead == datetime(2018, 12, 17, 15, 59, 11, 689000) assert recommendation2.dateRead == datetime(2018, 12, 17, 15, 59, 15, 689000) assert recommendation3.dateRead == datetime(2018, 12, 17, 15, 59, 21, 689000)
def _create_event_stock_and_offer_for_date(venue, date): product = create_product_with_event_type() offer = create_offer_with_event_product(venue, product) event_occurrence = create_event_occurrence(offer, beginning_datetime=date, end_datetime=date + timedelta(hours=1)) stock = create_stock_from_event_occurrence(event_occurrence, booking_limit_date=date) return stock
def save_free_event_offer_with_stocks(venue: Venue): free_event_offer = create_offer_with_event_product( venue, event_name='Free event', event_type=EventType.SPECTACLE_VIVANT) past_occurrence = create_event_occurrence( free_event_offer, beginning_datetime=now - three_days, end_datetime=now - three_days + two_hours) future_occurrence = create_event_occurrence( free_event_offer, beginning_datetime=now + three_days, end_datetime=now + three_days + two_hours) past_free_event_stock = create_stock_from_event_occurrence(past_occurrence, price=0) future_free_event_stock = create_stock_from_event_occurrence( future_occurrence, price=0) PcObject.save(past_free_event_stock, future_free_event_stock) logger.info( 'created 1 event offer with 1 past and 1 future occurrence with 1 free stock each' ) return past_free_event_stock, future_free_event_stock
def when_read_recommendations_are_given(self, app): # Given offerer = create_offerer() venue = create_venue(offerer) offer = create_offer_with_event_product(venue) user = create_user(email='*****@*****.**') event_occurrence1 = create_event_occurrence(offer) event_occurrence2 = create_event_occurrence(offer) stock1 = create_stock_from_event_occurrence(event_occurrence1, soft_deleted=True) stock2 = create_stock_from_event_occurrence(event_occurrence2, soft_deleted=False) thing_offer1 = create_offer_with_thing_product(venue) thing_offer2 = create_offer_with_thing_product(venue) stock3 = create_stock_from_offer(thing_offer1, soft_deleted=True) stock4 = create_stock_from_offer(thing_offer2, soft_deleted=False) recommendation1 = create_recommendation(offer, user) recommendation2 = create_recommendation(thing_offer1, user) recommendation3 = create_recommendation(thing_offer2, user) PcObject.save( stock1, stock2, stock3, stock4, recommendation1, recommendation2, recommendation3 ) read_recommendation_data = [ { "dateRead": "2018-12-17T15:59:11.689000Z", "id": humanize(recommendation1.id) }, { "dateRead": "2018-12-17T15:59:14.689000Z", "id": humanize(recommendation2.id) } ] # When response = TestClient(app.test_client()).with_auth('*****@*****.**') \ .put('{}/read'.format(RECOMMENDATION_URL), json=read_recommendation_data) # Then read_recommendation_date_reads = [r['dateRead'] for r in response.json] assert len(read_recommendation_date_reads) == 2 assert {"2018-12-17T15:59:11.689000Z", "2018-12-17T15:59:14.689000Z"} == set(read_recommendation_date_reads)
def when_updating_read_recommendations(self, app): # given offerer = create_offerer() venue = create_venue(offerer) offer = create_offer_with_event_product(venue) user = create_user() event_occurrence1 = create_event_occurrence(offer) event_occurrence2 = create_event_occurrence(offer) stock1 = create_stock_from_event_occurrence(event_occurrence1) stock2 = create_stock_from_event_occurrence(event_occurrence2) thing_offer1 = create_offer_with_thing_product(venue) thing_offer2 = create_offer_with_thing_product(venue) stock3 = create_stock_from_offer(thing_offer1) stock4 = create_stock_from_offer(thing_offer2) recommendation1 = create_recommendation(offer, user) recommendation2 = create_recommendation(thing_offer1, user) recommendation3 = create_recommendation(thing_offer2, user) PcObject.save(stock1, stock2, stock3, stock4, recommendation1, recommendation2, recommendation3) auth_request = TestClient(app.test_client()).with_auth(user.email) reads = [ {"id": humanize(recommendation1.id), "dateRead": "2018-12-17T15:59:11.689000Z"}, {"id": humanize(recommendation2.id), "dateRead": "2018-12-17T15:59:15.689000Z"}, {"id": humanize(recommendation3.id), "dateRead": "2018-12-17T15:59:21.689000Z"}, ] data = {'readRecommendations': reads} # when response = auth_request.put(RECOMMENDATION_URL, json=data) # then assert response.status_code == 200 assert recommendation1.dateRead is None assert recommendation2.dateRead is None assert recommendation3.dateRead is None unread_recos = Recommendation.query.filter(Recommendation.dateRead != None).all() assert len(unread_recos) == 3