Esempio n. 1
0
    def when_user_is_logged_in_and_has_two_favorite_offers(self, app):
        # Given
        user = users_factories.BeneficiaryGrant18Factory()
        offerer = create_offerer()
        venue = create_venue(offerer,
                             postal_code="29100",
                             siret="12345678912341")
        offer1 = create_offer_with_thing_product(venue=venue, thumb_count=0)
        mediation1 = create_mediation(offer=offer1, is_active=True, idx=123)
        favorite1 = create_favorite(mediation=mediation1,
                                    offer=offer1,
                                    user=user)
        offer2 = create_offer_with_thing_product(venue=venue, thumb_count=0)
        favorite2 = create_favorite(offer=offer2, user=user)
        repository.save(user, favorite1, favorite2)

        # When
        response = TestClient(app.test_client()).with_session_auth(
            user.email).get("/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 "mediationId" in first_favorite
        assert "validationToken" not in first_favorite["offer"]["venue"]
Esempio n. 2
0
        def when_user_is_logged_in_and_a_favorite_booked_offer_exist(self, app):
            # Given
            user = create_user()
            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)
            favorite = create_favorite(mediation=mediation, offer=offer, user=user)
            stock = create_stock(offer=offer, price=0)
            booking = create_booking(user=user, stock=stock)
            repository.save(booking, favorite)

            # When
            response = TestClient(app.test_client()).with_auth(user.email).get("/favorites")

            # Then
            assert response.status_code == 200
            assert len(response.json) == 1
            favorite = response.json[0]
            assert "offer" in favorite
            assert "venue" in favorite["offer"]
            assert "stocks" in favorite["offer"]
            assert stock.price == favorite["offer"]["stocks"][0]["price"]
            assert booking.quantity == favorite["booking"]["quantity"]
            assert humanize(booking.id) in favorite["booking"]["id"]
            assert "validationToken" not in favorite["offer"]["venue"]
Esempio n. 3
0
    def test_should_delete_product_when_related_offer_is_on_user_favorite_list(
            self, app):
        # Given
        isbn = "1111111111111"
        beneficiary = users_factories.BeneficiaryGrant18Factory()
        offerer = create_offerer(siren="775671464")
        venue = create_venue(offerer,
                             name="Librairie Titelive",
                             siret="77567146400110")
        product = create_product_with_thing_subcategory(id_at_providers=isbn)
        offer = create_offer_with_thing_product(venue, product=product)
        stock = create_stock(offer=offer, price=0)
        mediation = create_mediation(offer=offer)
        favorite = create_favorite(mediation=mediation,
                                   offer=offer,
                                   user=beneficiary)

        repository.save(venue, product, offer, stock, mediation, favorite)

        # When
        delete_unwanted_existing_product("1111111111111")

        # Then
        assert Product.query.count() == 0
        assert Offer.query.count() == 0
        assert Stock.query.count() == 0
        assert Mediation.query.count() == 0
        assert Favorite.query.count() == 0
    def test_returns_a_list_of_beneficiary_favorites(self, app):
        # given
        beneficiary = create_user()
        offerer = create_offerer()
        venue = create_venue(offerer=offerer)
        offer_1 = create_offer_with_thing_product(venue=venue)
        mediation_1 = create_mediation(offer=offer_1)
        favorite_1 = create_favorite(mediation=mediation_1, offer=offer_1, user=beneficiary)
        offer_2 = create_offer_with_thing_product(venue=venue)
        favorite_2 = create_favorite(offer=offer_2, user=beneficiary)
        repository.save(favorite_1, favorite_2)

        # when
        favorites = self.favorite_sql_repository.find_by_beneficiary(beneficiary.id)

        # then
        assert len(favorites) == 2
        assert isinstance(favorites[0], Favorite)
        assert isinstance(favorites[1], Favorite)
Esempio n. 5
0
        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)
            favorite = create_favorite(mediation=mediation, offer=offer, user=user)
            repository.save(user, favorite)

            # When
            response = TestClient(app.test_client()).with_auth(user.email).delete("/favorites/1")

            # Then
            assert response.status_code == 404
    def test_should_not_return_favorites_of_other_beneficiary(self, app):
        # given
        beneficiary = create_user()
        other_beneficiary = create_user()
        offerer = create_offerer()
        venue = create_venue(offerer=offerer)
        offer = create_offer_with_thing_product(venue=venue)
        mediation = create_mediation(offer=offer)
        favorite = create_favorite(mediation=mediation, offer=offer, user=other_beneficiary)
        repository.save(favorite)

        # when
        favorites = self.favorite_sql_repository.find_by_beneficiary(beneficiary.id)

        # then
        assert len(favorites) == 0
Esempio n. 7
0
        def when_favorite_does_not_exist(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)
            favorite = create_favorite(mediation=mediation, offer=offer, user=user)
            repository.save(user, favorite)

            # When
            response = TestClient(app.test_client()).with_auth(user.email).delete("/favorites/ABCD/ABCD")

            # Then
            assert response.status_code == 404
            deleted_favorite = FavoriteSQLEntity.query.first()
            assert deleted_favorite == favorite
Esempio n. 8
0
        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
            favorite = create_favorite(mediation=mediation, offer=offer, user=user)
            repository.save(user, favorite)

            # When
            response = TestClient(app.test_client()).with_auth(user.email).delete(f"/favorites/{humanize(offer.id)}")

            # Then
            assert response.status_code == 200
            assert "id" in response.json
            deleted_favorite = FavoriteSQLEntity.query.first()
            assert deleted_favorite is None
    def test_should_not_return_booking_when_favorite_offer_booking_is_cancelled(self, app):
        # given
        beneficiary = create_user()
        offerer = create_offerer()
        venue = create_venue(offerer=offerer)
        offer = create_offer_with_thing_product(venue=venue)
        stock = create_stock_from_offer(idx=123, offer=offer, price=0)
        booking = create_booking(idx=321, stock=stock, venue=venue, user=beneficiary, is_cancelled=True)
        mediation = create_mediation(offer=offer)
        favorite = create_favorite(mediation=mediation, offer=offer, user=beneficiary)
        repository.save(favorite, booking)

        # when
        favorites = self.favorite_sql_repository.find_by_beneficiary(beneficiary.id)

        # then
        assert len(favorites) == 1
        favorite = favorites[0]
        assert favorite.is_booked is False