def should_connect_venue_when_synchronization_is_allowed(self, app):
        # Given
        offerer = create_offerer()
        venue = create_venue(offerer)
        provider = activate_provider("PraxielStocks")

        repository.save(venue)

        self.find_by_id.return_value = venue
        stock_repository = MagicMock()
        stock_repository.can_be_synchronized.return_value = True
        provider_type = PraxielStocks

        venue_provider_payload = {
            "providerId": humanize(provider.id),
            "venueId": humanize(venue.id),
        }

        # When
        connect_venue_to_provider(provider_type, stock_repository,
                                  venue_provider_payload, self.find_by_id)

        # Then
        praxiel_venue_provider = VenueProvider.query.one()
        assert praxiel_venue_provider.venue == venue
    def test_allocine_venue_provider_is_successfully_updated(self, app):
        # Given
        user_offerer = offer_factories.UserOffererFactory()
        user = user_offerer.user
        offerer = user_offerer.offerer
        venue = offer_factories.VenueFactory(managingOfferer=offerer)
        provider = offerers_factories.AllocineProviderFactory()
        venue_provider = offerers_factories.AllocineVenueProviderFactory(
            venue=venue,
            provider=provider,
            isDuo=False,
            quantity=42,
        )
        offerers_factories.AllocineVenueProviderPriceRuleFactory(allocineVenueProvider=venue_provider, price=10)

        updated_venue_provider_data = {
            "providerId": humanize(provider.id),
            "venueId": humanize(venue.id),
            "isDuo": True,
            "quantity": 77,
            "price": 64,
        }

        auth_request = TestClient(app.test_client()).with_session_auth(email=user.email)

        # When
        response = auth_request.put("/venueProviders", json=updated_venue_provider_data)

        # Then
        assert response.status_code == 200
        assert response.json["provider"]["id"] == humanize(provider.id)
        assert response.json["venueId"] == humanize(venue.id)
        assert response.json["quantity"] == updated_venue_provider_data["quantity"]
        assert response.json["price"] == updated_venue_provider_data["price"]
        assert response.json["isDuo"] == updated_venue_provider_data["isDuo"]
Exemplo n.º 3
0
def get_expected_base_email_data(booking, mediation, **overrides):
    email_data = {
        "FromEmail": "*****@*****.**",
        "MJ-TemplateID": 1163067,
        "MJ-TemplateLanguage": True,
        "To": "*****@*****.**",
        "Vars": {
            "user_first_name": "Joe",
            "booking_date": "3 octobre",
            "booking_hour": "15h24",
            "offer_name": "Super événement",
            "offerer_name": "Théâtre du coin",
            "event_date": "6 novembre",
            "event_hour": "15h59",
            "offer_price": "23.99",
            "offer_token": "ABC123",
            "venue_name": "Lieu de l'offreur",
            "venue_address": "25 avenue du lieu",
            "venue_postal_code": "75010",
            "venue_city": "Paris",
            "all_but_not_virtual_thing": 1,
            "all_things_not_virtual_thing": 0,
            "is_event": 1,
            "is_single_event": 1,
            "is_duo_event": 0,
            "can_expire": 0,
            "offer_id": humanize(booking.stock.offer.id),
            "mediation_id": humanize(mediation.id),
            "env": "",
        },
    }
    email_data["Vars"].update(overrides)
    return email_data
    def test_should_humanize_ids(self):
        # Given
        user = create_user(email="*****@*****.**", public_name="John Doe")
        offerer = create_offerer()
        venue = create_venue(offerer,
                             name="Venue name",
                             address="Venue address")
        offer = create_offer_with_event_product(venue=venue,
                                                event_name="Event Name",
                                                event_type=EventType.CINEMA,
                                                idx=999)
        event_occurrence = create_event_occurrence(
            offer, beginning_datetime=datetime.utcnow())
        stock = create_stock_from_event_occurrence(event_occurrence, price=12)
        booking = create_booking(user=user,
                                 quantity=3,
                                 stock=stock,
                                 venue=venue)

        # When
        response = serialize_booking(booking)

        # Then
        assert response["bookingId"] == humanize(booking.id)
        assert response["offerId"] == offer.id
        assert response["publicOfferId"] == humanize(offer.id)
    def when_mediation_is_edited(self, app):
        # given
        mediation = offers_factories.MediationFactory()
        offerer = mediation.offer.venue.managingOfferer
        offers_factories.UserOffererFactory(
            user__email="*****@*****.**",
            offerer=offerer,
        )

        # when
        client = TestClient(app.test_client()).with_auth(email="*****@*****.**")
        data = {"isActive": False}
        response = client.patch(f"/mediations/{humanize(mediation.id)}", json=data)

        # then
        mediation = Mediation.query.one()
        assert not mediation.isActive
        assert response.status_code == 200
        assert response.json["id"] == humanize(mediation.id)
        assert response.json["thumbUrl"] == mediation.thumbUrl

        assert response.json == {
            "authorId": None,
            "credit": None,
            "dateCreated": format_into_utc_date(mediation.dateCreated),
            "dateModifiedAtLastProvider": format_into_utc_date(mediation.dateModifiedAtLastProvider),
            "fieldsUpdated": [],
            "id": humanize(mediation.id),
            "idAtProviders": None,
            "isActive": data["isActive"],
            "lastProviderId": None,
            "offerId": humanize(mediation.offer.id),
            "thumbCount": 0,
            "thumbUrl": None,
        }
Exemplo n.º 6
0
    def test_erase_former_mediations(self):
        # Given
        user = users_factories.UserFactory()
        offer = factories.ThingOfferFactory()
        image_as_bytes = (IMAGES_DIR / "mouette_full_size.jpg").read_bytes()
        existing_number_of_files = len(os.listdir(self.THUMBS_DIR))

        mediation_1 = api.create_mediation_v2(user, offer, "©Photographe",
                                              image_as_bytes)
        mediation_2 = api.create_mediation_v2(user, offer, "©Alice",
                                              image_as_bytes)
        thumb_1_id = humanize(mediation_1.id)
        thumb_2_id = humanize(mediation_2.id)

        # When
        api.create_mediation_v2(user, offer, "©moi", image_as_bytes)

        # Then
        mediation_3 = models.Mediation.query.one()
        assert mediation_3.credit == "©moi"
        thumb_3_id = humanize(mediation_3.id)

        assert not (self.THUMBS_DIR / thumb_1_id).exists()
        assert not (self.THUMBS_DIR / (thumb_1_id + ".type")).exists()
        assert not (self.THUMBS_DIR / thumb_2_id).exists()
        assert not (self.THUMBS_DIR / (thumb_2_id + ".type")).exists()

        assert len(os.listdir(self.THUMBS_DIR)) == existing_number_of_files + 2
        assert (self.THUMBS_DIR / thumb_3_id).exists()
        assert (self.THUMBS_DIR / (thumb_3_id + ".type")).exists()
        def when_listing_all_venues_with_a_valid_venue_id(self, app):
            # given
            offerer = create_offerer(siren="775671464")
            venue = create_venue(offerer,
                                 name="Librairie Titelive",
                                 siret="77567146400110")
            titelive_things_provider = get_provider_by_local_class(
                "TiteLiveThings")
            venue_provider = create_venue_provider(
                venue=venue, provider=titelive_things_provider)
            repository.save(venue_provider)

            user = create_user()
            repository.save(user)
            auth_request = TestClient(
                app.test_client()).with_auth(email=user.email)

            # when
            response = auth_request.get("/venueProviders?venueId=" +
                                        humanize(venue.id))

            # then
            assert response.status_code == 200
            assert response.json[0].get("id") == humanize(venue_provider.id)
            assert response.json[0].get("venueId") == humanize(venue.id)
Exemplo n.º 8
0
def test_response_serialization(app):
    user_offerer = offers_factories.UserOffererFactory(
        user__email="*****@*****.**",
    )
    venue = offers_factories.VenueFactory(managingOfferer=user_offerer.offerer)

    # when
    response = TestClient(app.test_client()).with_session_auth(user_offerer.user.email).get("/venues")

    # then
    assert response.status_code == 200

    assert "venues" in response.json
    assert len(response.json["venues"]) == 1
    assert response.json["venues"][0] == {
        "id": humanize(venue.id),
        "managingOffererId": humanize(venue.managingOffererId),
        "name": venue.name,
        "offererName": user_offerer.offerer.name,
        "publicName": venue.publicName,
        "isVirtual": venue.isVirtual,
        "bookingEmail": venue.bookingEmail,
        "withdrawalDetails": venue.withdrawalDetails,
        "audioDisabilityCompliant": venue.audioDisabilityCompliant,
        "mentalDisabilityCompliant": venue.mentalDisabilityCompliant,
        "motorDisabilityCompliant": venue.motorDisabilityCompliant,
        "visualDisabilityCompliant": venue.visualDisabilityCompliant,
    }
        def when_add_allocine_stocks_provider_with_price_but_no_isDuo_config(
            self, stubbed_get_theaterid_for_venue, stubbed_find_by_id, app
        ):
            # Given
            offerer = create_offerer(siren="775671464")
            venue = create_venue(offerer)
            user = create_user(is_admin=True, is_beneficiary=False)
            allocine_pivot = create_allocine_pivot(siret=venue.siret)
            repository.save(venue, user, allocine_pivot)
            stubbed_find_by_id.return_value = venue
            stubbed_get_theaterid_for_venue.return_value = allocine_pivot.theaterId

            provider = activate_provider("AllocineStocks")

            venue_provider_data = {"providerId": humanize(provider.id), "venueId": humanize(venue.id), "price": "9.99"}

            auth_request = TestClient(app.test_client()).with_auth(email=user.email)

            # When
            response = auth_request.post("/venueProviders", json=venue_provider_data)

            # Then
            assert response.status_code == 201
            json = response.json
            assert "_sa_polymorphic_on" not in json
            venue_provider = VenueProvider.query.one()
            assert json["venueId"] == humanize(venue_provider.venueId)
Exemplo n.º 10
0
    def should_connect_venue_to_allocine_provider(self, app):
        # Given
        offerer = create_offerer()
        venue = create_venue(offerer)
        provider = activate_provider("AllocineStocks")
        allocine_pivot = create_allocine_pivot(siret=venue.siret)

        repository.save(venue, allocine_pivot)

        self.find_by_id.return_value = venue
        self.get_theaterid_for_venue.return_value = allocine_pivot.theaterId

        venue_provider_payload = {
            "providerId": humanize(provider.id),
            "venueId": humanize(venue.id),
            "price": "9.99",
            "isDuo": True,
            "quantity": 50,
        }

        # When
        connect_venue_to_allocine(venue_provider_payload, self.find_by_id,
                                  self.get_theaterid_for_venue)

        # Then
        allocine_venue_provider = AllocineVenueProvider.query.one()
        venue_provider_price_rule = AllocineVenueProviderPriceRule.query.one()

        assert allocine_venue_provider.venue == venue
        assert allocine_venue_provider.isDuo
        assert allocine_venue_provider.quantity == 50
        assert venue_provider_price_rule.price == Decimal("9.99")
Exemplo n.º 11
0
        def when_offer_is_added_as_favorite_for_current_user(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)
            repository.save(user, mediation)

            json = {
                "offerId": humanize(offer.id),
                "mediationId": humanize(mediation.id),
            }

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

            # Then
            assert response.status_code == 201

            favorite = FavoriteSQLEntity.query.one()
            assert favorite.offerId == offer.id
            assert favorite.mediationId == mediation.id
            assert favorite.userId == user.id
    def should_not_connect_venue_when_venue_has_no_siret(self, app):
        # Given
        offerer = create_offerer()
        venue = create_venue(offerer, siret=None, is_virtual=True)
        provider = activate_provider("LibrairesStocks")

        repository.save(venue)

        self.find_by_id.return_value = venue
        stock_repository = MagicMock()
        provider_type = LibrairesStocks

        venue_provider_payload = {
            "providerId": humanize(provider.id),
            "venueId": humanize(venue.id),
        }

        # when
        with pytest.raises(ApiErrors) as error:
            connect_venue_to_provider(provider_type, stock_repository,
                                      venue_provider_payload, self.find_by_id)

        # then
        assert error.value.errors["provider"] == [
            "L’importation d’offres avec LesLibraires n’est pas disponible sans SIRET associé au lieu. Ajoutez un SIRET pour pouvoir importer les offres."
        ]
    def should_not_connect_venue_when_synchronization_is_not_allowed(
            self, app):
        # Given
        offerer = create_offerer()
        venue = create_venue(offerer, siret="12345678912345")
        provider = activate_provider("LibrairesStocks")

        repository.save(venue)

        self.find_by_id.return_value = venue
        stock_repository = MagicMock()
        stock_repository.can_be_synchronized.return_value = False
        provider_class = LibrairesStocks

        venue_provider_payload = {
            "providerId": humanize(provider.id),
            "venueId": humanize(venue.id),
        }

        # when
        with pytest.raises(ApiErrors) as error:
            print(
                connect_venue_to_provider(provider_class, stock_repository,
                                          venue_provider_payload,
                                          self.find_by_id))

        # then
        assert error.value.errors["provider"] == [
            "L’importation d’offres avec LesLibraires n’est pas disponible pour le SIRET 12345678912345"
        ]
    def should_raise_an_error(self, app):
        # Given
        offerer = create_offerer()
        venue = create_venue(offerer)
        provider = create_provider(local_class="TestLocalProvider")
        repository.save(venue, provider)

        self.find_by_id.return_value = venue
        stock_repository = MagicMock()
        provider_type = TestLocalProvider

        venue_provider_payload = {
            "providerId": humanize(provider.id),
            "venueId": humanize(venue.id),
        }

        # When
        with pytest.raises(ApiErrors) as error:
            connect_venue_to_provider(provider_type, stock_repository,
                                      venue_provider_payload, self.find_by_id)

        # Then
        assert error.value.errors["provider"] == [
            "Provider non pris en charge"
        ]
    def when_mediation_is_created_with_bad_thumb_url(self, app):
        # given
        offer = offers_factories.ThingOfferFactory()
        offerer = offer.venue.managingOfferer
        offers_factories.UserOffererFactory(
            user__email="*****@*****.**",
            offerer=offerer,
        )

        # when
        client = TestClient(
            app.test_client()).with_auth(email="*****@*****.**")
        data = {
            "offerId": humanize(offer.id),
            "offererId": humanize(offerer.id),
            "thumbUrl": "https://example.com/image.jpg",
        }
        with requests_mock.Mocker() as mock:
            mock.get("https://example.com/image.jpg", status_code=404)
            response = client.post("/mediations", form=data)

        # then
        assert response.status_code == 400
        assert response.json == {
            "thumbUrl": ["L'adresse saisie n'est pas valide"]
        }
        def when_add_allocine_stocks_provider_with_default_settings_at_import(self, stubbed_find_by_id, app):
            # Given
            offerer = create_offerer(siren="775671464")
            venue = create_venue(offerer)
            user = create_user(is_admin=True, is_beneficiary=False)
            repository.save(venue, user)
            stubbed_find_by_id.return_value = venue

            provider = activate_provider("AllocineStocks")

            venue_provider_data = {
                "providerId": humanize(provider.id),
                "venueId": humanize(venue.id),
                "price": "9.99",
                "available": 50,
                "isDuo": True,
            }

            auth_request = TestClient(app.test_client()).with_auth(email=user.email)

            # When
            response = auth_request.post("/venueProviders", json=venue_provider_data)

            # Then
            assert response.status_code == 201
def get_expected_base_email_data(booking, **overrides):
    offer_id = humanize(booking.stock.offer.id)
    venue_id = humanize(booking.stock.offer.venue.id)
    offerer_id = humanize(booking.stock.offer.venue.managingOfferer.id)
    email_data = {
        "MJ-TemplateID": 2418750,
        "MJ-TemplateLanguage": True,
        "Headers": {
            "Reply-To": "*****@*****.**",
        },
        "Vars": {
            "nom_offre": "Super événement",
            "nom_lieu": "Lieu de l'offreur",
            "prix": "Gratuit",
            "date": "06-Nov-2019",
            "heure": "15h59",
            "quantity": 1,
            "user_firstName": "John",
            "user_lastName": "Doe",
            "user_email": "*****@*****.**",
            "user_phoneNumber": "",
            "is_event": 1,
            "can_expire": 0,
            "contremarque": "ABC123",
            "ISBN": "",
            "lien_offre_pcpro":
            f"http://localhost:3001/offres/{offer_id}?lieu={venue_id}&structure={offerer_id}",
            "offer_type": "EventType.SPECTACLE_VIVANT",
            "departement": "75",
        },
    }
    email_data["Vars"].update(overrides)
    return email_data
        def when_add_allocine_stocks_provider_with_wrong_format_price(self, stubbed_find_by_id, app):
            # Given
            offerer = create_offerer(siren="775671464")
            venue = create_venue(offerer)
            user = create_user(is_admin=True, is_beneficiary=False)
            repository.save(venue, user)
            stubbed_find_by_id.return_value = venue

            provider = activate_provider("AllocineStocks")

            venue_provider_data = {
                "providerId": humanize(provider.id),
                "venueId": humanize(venue.id),
                "price": "wrong_price",
            }

            auth_request = TestClient(app.test_client()).with_auth(email=user.email)

            # When
            response = auth_request.post("/venueProviders", json=venue_provider_data)

            # Then
            assert response.status_code == 400
            assert response.json["global"] == ["Le prix doit être un nombre décimal"]
            assert VenueProvider.query.count() == 0
Exemplo n.º 19
0
    def test_create_offer_from_existing_product(
            self, mocked_offer_creation_notification_to_admin):
        product = factories.ProductFactory(
            name="An excellent offer",
            type=str(offer_type.EventType.CINEMA),
        )
        venue = factories.VenueFactory()
        offerer = venue.managingOfferer
        user_offerer = factories.UserOffererFactory(offerer=offerer)
        user = user_offerer.user

        data = offers_serialize.PostOfferBodyModel(
            venueId=humanize(venue.id),
            productId=humanize(product.id),
            externalTicketOfficeUrl="http://example.net",
            audioDisabilityCompliant=True,
            mentalDisabilityCompliant=True,
            motorDisabilityCompliant=True,
            visualDisabilityCompliant=True,
        )
        offer = api.create_offer(data, user)

        assert offer.name == "An excellent offer"
        assert offer.type == str(offer_type.EventType.CINEMA)
        assert offer.product == product
        assert offer.externalTicketOfficeUrl == "http://example.net"
        assert offer.audioDisabilityCompliant
        assert offer.mentalDisabilityCompliant
        assert offer.motorDisabilityCompliant
        assert offer.visualDisabilityCompliant
        assert Offer.query.count() == 1
        mocked_offer_creation_notification_to_admin.assert_called_once_with(
            offer, user)
        def when_provider_api_not_available(self, stubbed_find_by_id, stubbed_check, app):
            # Given
            user = create_user(is_admin=True, is_beneficiary=False)
            offerer = create_offerer()
            venue = create_venue(offerer, siret="12345678912345")
            repository.save(venue, user)
            stubbed_find_by_id.return_value = venue

            provider = activate_provider("LibrairesStocks")

            venue_provider_data = {
                "providerId": humanize(provider.id),
                "venueId": humanize(venue.id),
            }

            auth_request = TestClient(app.test_client()).with_auth(email=user.email)

            errors = ApiErrors()
            errors.status_code = 422
            errors.add_error(
                "provider",
                "L’importation d’offres avec LesLibraires n’est pas disponible " "pour le SIRET 12345678912345",
            )
            stubbed_check.side_effect = [errors]

            # When
            response = auth_request.post("/venueProviders", json=venue_provider_data)

            # Then
            assert response.status_code == 422
            assert response.json["provider"] == [
                "L’importation d’offres avec LesLibraires n’est pas disponible pour le SIRET 12345678912345"
            ]
            assert VenueProvider.query.count() == 0
    def test_should_return_booking_with_expected_information(self):
        # Given
        booking = BookingFactory(
            amount=1,
            quantity=1,
            token="GQTQR9",
            stock__price=10,
        )

        # When
        serialized = serialize_booking_minimal(booking)

        # Then
        assert serialized == {
            "amount": 1.0,
            "isCancelled": booking.isCancelled,
            "id": humanize(booking.id),
            "stockId": humanize(booking.stockId),
            "quantity": 1,
            "stock": {
                "price": 10,
            },
            "token": "GQTQR9",
            "completedUrl": None,
        }
        def should_inject_the_appropriate_repository_to_the_usecase(
            self, mocked_connect_venue_to_provider, stubbed_find_by_id, stubbed_check, app
        ):
            # Given
            user = create_user(is_admin=True, is_beneficiary=False)
            offerer = create_offerer()
            venue = create_venue(offerer, siret="12345678912345")
            repository.save(venue, user)
            stubbed_find_by_id.return_value = venue

            provider = activate_provider("LibrairesStocks")

            venue_provider_data = {
                "providerId": humanize(provider.id),
                "venueId": humanize(venue.id),
            }

            auth_request = TestClient(app.test_client()).with_auth(email=user.email)
            stubbed_check.return_value = True

            # When
            auth_request.post("/venueProviders", json=venue_provider_data)

            # Then
            mocked_connect_venue_to_provider.assert_called_once_with(
                LibrairesStocks,
                api_libraires_stocks,
                {"providerId": humanize(provider.id), "venueId": humanize(venue.id)},
                stubbed_find_by_id,
            )
Exemplo n.º 23
0
    def test_booking_creation_with_activation_code(self, app):
        # Given
        user = users_factories.BeneficiaryGrant18Factory()
        stock = offers_factories.StockWithActivationCodesFactory(
            activationCodes=["code-vgya451afvyux"],
            offer__url="https://new.example.com?token={token}")

        # When
        data = {"stockId": humanize(stock.id), "quantity": 1}
        client = TestClient(app.test_client()).with_session_auth(user.email)
        response = client.post("/bookings", json=data)

        # Then
        assert response.status_code == 201
        booking = bookings_models.Booking.query.one()
        assert response.json == {
            "amount": 10.0,
            "completedUrl": "https://new.example.com?token=code-vgya451afvyux",
            "id": humanize(booking.id),
            "isCancelled": False,
            "quantity": 1,
            "stock": {
                "price": 10.0
            },
            "stockId": humanize(stock.id),
            "token": booking.token,
            "activationCode": {
                "code": "code-vgya451afvyux",
                "expirationDate": None
            },
            "qrCode": booking.qrCode,
        }
        def when_venue_provider_is_successfully_created(
            self, stubbed_find_by_id, stubbed_check, mock_synchronize_venue_provider, app
        ):
            # Given
            user = create_user(is_admin=True, is_beneficiary=False)
            offerer = create_offerer()
            venue = create_venue(offerer, siret="12345678912345")
            repository.save(venue, user)

            stubbed_find_by_id.return_value = venue

            provider = activate_provider("LibrairesStocks")

            venue_provider_data = {
                "providerId": humanize(provider.id),
                "venueId": humanize(venue.id),
            }

            auth_request = TestClient(app.test_client()).with_auth(email=user.email)
            stubbed_check.return_value = True

            # When
            response = auth_request.post("/venueProviders", json=venue_provider_data)

            # Then
            assert response.status_code == 201
            venue_provider = VenueProvider.query.one()
            assert venue_provider.venueId == venue.id
            assert venue_provider.providerId == provider.id
            assert venue_provider.venueIdAtOfferProvider == "12345678912345"
            assert "id" in response.json
            venue_provider_id = response.json["id"]
            mock_synchronize_venue_provider.assert_called_once_with(dehumanize(venue_provider_id))
    def expect_the_booking_to_be_cancelled_by_current_user(self, app):
        # Given
        in_four_days = datetime.utcnow() + timedelta(days=4)
        stock = offers_factories.EventStockFactory(
            beginningDatetime=in_four_days)
        booking = bookings_factories.BookingFactory(stock=stock)

        # When
        client = TestClient(app.test_client()).with_auth(booking.user.email)
        response = client.put(f"/bookings/{humanize(booking.id)}/cancel")

        # Then
        assert response.status_code == 200
        assert Booking.query.get(booking.id).isCancelled
        assert response.json == {
            "amount": 10.0,
            "completedUrl": None,
            "id": humanize(booking.id),
            "isCancelled": True,
            "quantity": booking.quantity,
            "stock": {
                "price": 10.0
            },
            "stockId": humanize(stock.id),
            "token": booking.token,
        }
    def when_mediation_is_created_with_thumb_url(self, app):
        # given
        offer = offers_factories.ThingOfferFactory()
        offerer = offer.venue.managingOfferer
        offers_factories.UserOffererFactory(
            user__email="*****@*****.**",
            offerer=offerer,
        )

        # when
        client = TestClient(
            app.test_client()).with_auth(email="*****@*****.**")
        image_as_bytes = (IMAGES_DIR / "mouette_full_size.jpg").read_bytes()
        data = {
            "offerId": humanize(offer.id),
            "offererId": humanize(offerer.id),
            "thumbUrl": "https://example.com/image.jpg",
        }
        with requests_mock.Mocker() as mock:
            mock.get(
                "https://example.com/image.jpg",
                content=image_as_bytes,
                headers={"Content-Type": "image/jpeg"},
            )
            response = client.post("/mediations", form=data)

        # then
        assert response.status_code == 201
        mediation = Mediation.query.one()
        assert mediation.thumbCount == 1
        assert response.json == {
            "id": humanize(mediation.id),
        }
    def test_user_has_right_on_venue(self, app):
        # Given
        user = user_factories.ProFactory()
        owner_offerer = offer_factories.UserOffererFactory()
        offerer = owner_offerer.offerer
        venue = offer_factories.VenueFactory(managingOfferer=offerer)
        provider = offerers_factories.AllocineProviderFactory()
        venue_provider = offerers_factories.AllocineVenueProviderFactory(
            venue=venue,
            provider=provider,
            isDuo=False,
            quantity=42,
        )
        offerers_factories.AllocineVenueProviderPriceRuleFactory(allocineVenueProvider=venue_provider, price=10)

        updated_venue_provider_data = {
            "providerId": humanize(provider.id),
            "venueId": humanize(venue.id),
            "isDuo": True,
            "quantity": 77,
            "price": 64,
        }

        auth_request = TestClient(app.test_client()).with_session_auth(email=user.email)

        # When
        response = auth_request.put("/venueProviders", json=updated_venue_provider_data)

        # Then
        assert response.status_code == 403
    def when_mediation_is_created_with_thumb_file(self, app):
        # given
        offer = offers_factories.ThingOfferFactory()
        offerer = offer.venue.managingOfferer
        offers_factories.UserOffererFactory(
            user__email="*****@*****.**",
            offerer=offerer,
        )

        # when
        client = TestClient(
            app.test_client()).with_auth(email="*****@*****.**")
        thumb = (IMAGES_DIR / "mouette_full_size.jpg").read_bytes()
        files = {
            "offerId": humanize(offer.id),
            "offererId": humanize(offerer.id),
            "thumb": (BytesIO(thumb), "image.png"),
        }
        response = client.post("/mediations", files=files)

        # then
        assert response.status_code == 201
        mediation = Mediation.query.one()
        assert mediation.thumbCount == 1
        assert response.status_code == 201
Exemplo n.º 29
0
        def test_should_consider_the_venue_to_be_permanent(self, app):
            # given
            offerer = create_offerer(siren="302559178")
            user = create_user()
            user_offerer = create_user_offerer(user, offerer)
            venue_type = create_venue_type(label="Musée")
            venue_label = create_venue_label(
                label="CAC - Centre d'art contemporain d'intérêt national")
            repository.save(user_offerer, venue_type, venue_label)
            auth_request = TestClient(
                app.test_client()).with_auth(email=user.email)
            venue_data = {
                "name": "Ma venue",
                "siret": "30255917810045",
                "address": "75 Rue Charles Fourier, 75013 Paris",
                "postalCode": "75200",
                "bookingEmail": "*****@*****.**",
                "city": "Paris",
                "managingOffererId": humanize(offerer.id),
                "latitude": 48.82387,
                "longitude": 2.35284,
                "publicName": "Ma venue publique",
                "venueTypeId": humanize(venue_type.id),
                "venueLabelId": humanize(venue_label.id),
            }

            # when
            auth_request.post("/venues", json=venue_data)

            # then
            venue = Venue.query.one()
            assert venue.isPermanent == True
    def when_offer_is_added_as_favorite_for_current_user(self, app):
        # Given
        user = users_factories.BeneficiaryGrant18Factory(
            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)
        repository.save(mediation)

        json = {
            "offerId": humanize(offer.id),
            "mediationId": humanize(mediation.id),
        }

        # When
        response = TestClient(app.test_client()).with_session_auth(
            user.email).post("/favorites", json=json)

        # Then
        assert response.status_code == 201

        favorite = Favorite.query.one()
        assert favorite.offerId == offer.id
        assert favorite.mediationId == mediation.id
        assert favorite.userId == user.id

        # One call should be sent to batch, and one to sendinblue
        assert len(push_testing.requests) == 1
        assert len(users_testing.sendinblue_requests) == 1
        sendinblue_data = users_testing.sendinblue_requests[0]
        assert sendinblue_data["attributes"][
            "LAST_FAVORITE_CREATION_DATE"] is not None