def when_user_is_logged_in_and_has_two_favorite_offers(self, app): # Given user = create_user() offerer = create_offerer() venue = create_venue(offerer, postal_code='29100', siret='12345678912341') offer1 = create_offer_with_thing_product(venue, thumb_count=0) mediation1 = create_mediation(offer1, is_active=True) favorite1 = create_favorite(mediation1, offer1, user) offer2 = create_offer_with_thing_product(venue, thumb_count=0) mediation2 = create_mediation(offer2, is_active=True) favorite2 = create_favorite(mediation2, offer2, user) PcObject.save(user, favorite1, favorite2) # When response = TestClient(app.test_client()).with_auth(user.email) \ .get(API_URL + '/favorites') # Then assert response.status_code == 200 assert len(response.json) == 2 first_favorite = response.json[0] assert 'offer' in first_favorite assert 'venue' in first_favorite['offer'] assert 'validationToken' not in first_favorite['offer']['venue']
def test_model_should_return_true_if_favorite_exists_for_offer_mediation_and_user( app): # given user = create_user(email='*****@*****.**') offerer = create_offerer() venue = create_venue(offerer) offer = create_offer_with_event_product(venue) mediation = create_mediation(offer) favorite = create_favorite(mediation, offer, user) PcObject.save(favorite) # when recommendation = create_recommendation(offer, user, mediation=mediation) PcObject.save(recommendation) # then assert recommendation.isFavorite is True
def when_expected_parameters_are_not_given(self, app): # Given user = create_user(email='*****@*****.**') offerer = create_offerer() venue = create_venue(offerer, postal_code='29100', siret='12345678912341') offer = create_offer_with_thing_product(venue, thumb_count=0) mediation = create_mediation(offer, is_active=True) recommendation = create_recommendation(offer=offer, user=user, mediation=mediation, is_clicked=False) favorite = create_favorite(mediation, offer, user) PcObject.save(recommendation, user, favorite) # When response = TestClient(app.test_client()).with_auth( user.email).delete(f'{API_URL}/favorites/1') # Then assert response.status_code == 404
def when_favorite_exists_with_offerId(self, app): # Given user = create_user(email='*****@*****.**') offerer = create_offerer() venue = create_venue(offerer, postal_code='29100', siret='12345678912341') offer = create_offer_with_thing_product(venue, thumb_count=0) mediation = None recommendation = create_recommendation(offer=offer, user=user, mediation=mediation) favorite = create_favorite(mediation, offer, user) PcObject.save(recommendation, user, favorite) # When response = TestClient(app.test_client()).with_auth( user.email).delete(f'{API_URL}/favorites/{humanize(offer.id)}') # Then assert response.status_code == 200 assert 'id' in response.json deleted_favorite = Favorite.query.first() assert deleted_favorite is None