コード例 #1
0
        def when_offers_have_non_validated_venues(self, app):
            # Given
            offerer = create_offerer()
            venue_not_validated = create_venue(offerer, siret=None, comment='random reason')
            venue_not_validated.generate_validation_token()
            venue_validated = create_venue(offerer, siret=None, comment='random reason')
            offer_venue_not_validated = create_offer_with_thing_product(venue_not_validated, thumb_count=1)
            offer_venue_validated = create_offer_with_thing_product(venue_validated, thumb_count=1)
            stock_venue_not_validated = create_stock_from_offer(offer_venue_not_validated)
            stock_venue_validated = create_stock_from_offer(offer_venue_validated)
            user = create_user(email='*****@*****.**')
            PcObject.save(stock_venue_not_validated, stock_venue_validated, user)
            venue_validated_id = venue_validated.id
            venue_not_validated_id = venue_not_validated.id
            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
            recommendations = response.json
            venue_ids = set(map(lambda x: x['offer']['venue']['id'], recommendations))
            assert humanize(venue_validated_id) in venue_ids
            assert humanize(venue_not_validated_id) not in venue_ids
コード例 #2
0
    def test_returns_true_when_all_information_are_present_and_well_formed(self, app):
        # given
        provider = Provider()
        provider.name = 'Open Agenda'
        provider.localClass = 'OpenAgenda'
        provider.isActive = True
        provider.enabledForPro = True
        offerer = create_offerer()
        user = create_user()
        user_offerer = create_user_offerer(user, offerer, is_admin=True)
        venue = create_venue(offerer, name='Librairie Titelive', siret='77567146400110')
        PcObject.save(provider, user_offerer, venue)

        payload = {
            'providerId': humanize(provider.id),
            'venueId': humanize(venue.id),
            'venueIdAtOfferProvider': '567890'
        }

        # when
        try:
            validate_new_venue_provider_information(payload)
        except ApiErrors:
            # then
            assert False
コード例 #3
0
        def when_mediation_is_edited(self, app):
            # given
            user = create_user()
            offerer = create_offerer()
            venue = create_venue(offerer)
            offer = create_offer_with_event_product(venue)
            user_offerer = create_user_offerer(user, offerer)
            mediation = create_mediation(offer)
            PcObject.save(mediation)
            PcObject.save(user, venue, offerer, user_offerer)
            mediation_id = mediation.id
            auth_request = TestClient(
                app.test_client()).with_auth(email=user.email)
            data = {
                'frontText': 'new front text',
                'backText': 'new back text',
                'isActive': False
            }

            # when
            response = auth_request.patch('/mediations/%s' %
                                          humanize(mediation.id),
                                          json=data)

            # then
            mediation = Mediation.query.get(mediation_id)
            assert response.status_code == 200
            assert response.json['id'] == humanize(mediation.id)
            assert response.json['frontText'] == mediation.frontText
            assert response.json['backText'] == mediation.backText
            assert response.json['isActive'] == mediation.isActive
            assert response.json['thumbUrl'] == mediation.thumbUrl
            assert mediation.isActive == data['isActive']
            assert mediation.frontText == data['frontText']
            assert mediation.backText == data['backText']
コード例 #4
0
        def when_venue_provider_exists(self, app):
            # given
            offerer = create_offerer(siren='775671464')
            venue = create_venue(offerer,
                                 name='Librairie Titelive',
                                 siret='77567146400110')
            PcObject.save(venue)

            provider = activate_provider('TiteLiveStocks')
            product = create_product_with_thing_type(
                id_at_providers='0002730757438')

            venue_provider_data = {
                'providerId': humanize(provider.id),
                'venueId': humanize(venue.id),
                'venueIdAtOfferProvider': '77567146400110'
            }
            user = create_user(is_admin=True, can_book_free_offers=False)
            PcObject.save(product, user)
            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 = response.json
            assert 'id' in json_response
            venue_provider_id = json_response['id']
            assert json_response['lastSyncDate'] is None
コード例 #5
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)
            recommendation = create_recommendation(offer=offer,
                                                   user=user,
                                                   mediation=mediation,
                                                   is_clicked=False)
            PcObject.save(recommendation, user)

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

            # When
            response = TestClient(app.test_client()).with_auth(
                user.email).post(f'{API_URL}/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
コード例 #6
0
    def test_raise_errors_if_venue_provider_already_exists(self, app):
        # given
        provider = Provider()
        provider.name = 'Open Agenda'
        provider.localClass = 'OpenAgenda'
        provider.isActive = True
        provider.enabledForPro = True
        offerer = create_offerer()
        user = create_user()
        user_offerer = create_user_offerer(user, offerer, is_admin=True)
        venue = create_venue(offerer, name='Librairie Titelive', siret='77567146400110')
        venue_provider = create_venue_provider(venue, provider, venue_id_at_offer_provider="775671464")
        PcObject.save(provider, user_offerer, venue, venue_provider)

        payload = {
            'providerId': humanize(provider.id),
            'venueId': humanize(venue.id),
            'venueIdAtOfferProvider': '775671464'
        }

        # when
        with pytest.raises(ApiErrors) as errors:
            validate_new_venue_provider_information(payload)

        # then
        assert errors.value.status_code == 400
        assert errors.value.errors['venueProvider'] == ["Votre lieu est déjà lié à cette source"]
コード例 #7
0
        def expect_the_booking_to_have_good_includes(self, app):
            offerer = create_offerer('987654321', 'Test address', 'Test city',
                                     '93000', 'Test name')
            venue = create_venue(offerer, 'Test offerer',
                                 '*****@*****.**', '123 rue test',
                                 '93000', 'Test city', '93')
            ok_stock = create_stock_with_event_offer(offerer=offerer,
                                                     venue=venue,
                                                     price=0)
            ok_stock.bookingLimitDatetime = datetime.utcnow() + timedelta(
                minutes=2)
            ok_stock.bookingLimitDatetime = datetime.utcnow() + timedelta(
                minutes=2)
            PcObject.save(ok_stock)

            user = create_user(email='*****@*****.**')
            PcObject.save(user)

            recommendation = create_recommendation(offer=ok_stock.offer,
                                                   user=user)
            PcObject.save(recommendation)

            booking_json = {
                'stockId': humanize(ok_stock.id),
                'recommendationId': humanize(recommendation.id),
                'quantity': 1
            }

            r_create = TestClient(app.test_client()).with_auth(
                email='*****@*****.**').post('/bookings', json=booking_json)
            assert r_create.status_code == 201
            assert r_create.json['stock']['isBookable']
コード例 #8
0
        def when_mediation_is_created_with_thumb_url(self, read_thumb, app):
            # given
            user = create_user()
            offerer = create_offerer()
            venue = create_venue(offerer)
            offer = create_offer_with_event_product(venue)
            user_offerer = create_user_offerer(user, offerer)

            PcObject.save(offer)
            PcObject.save(user, venue, offerer, user_offerer)

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

            with open(MODULE_PATH / '..' / 'files/mouette_full_size.jpg',
                      'rb') as f:
                read_thumb.return_value = f.read()

            data = {
                'offerId':
                humanize(offer.id),
                'offererId':
                humanize(offerer.id),
                'thumbUrl':
                'https://www.deridet.com/photo/art/grande/8682609-13705793.jpg?v=1450665370'
            }

            # when
            response = auth_request.post('/mediations', form=data)

            # then
            assert response.status_code == 201
コード例 #9
0
        def when_mediation_is_created_with_thumb_file(self, app):
            # given
            user = create_user()
            offerer = create_offerer()
            venue = create_venue(offerer)
            offer = create_offer_with_event_product(venue)
            user_offerer = create_user_offerer(user, offerer)

            PcObject.save(offer)
            PcObject.save(user, venue, offerer, user_offerer)

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

            with open(MODULE_PATH / '..' / 'files/mouette_full_size.jpg',
                      'rb') as f:
                thumb = f.read()

            files = {
                'offerId': humanize(offer.id),
                'offererId': humanize(offerer.id),
                'thumb': (BytesIO(thumb), 'image.png')
            }

            # when
            response = auth_request.post('/mediations', files=files)

            # then
            assert response.status_code == 201
コード例 #10
0
        def expect_mediation_not_to_be_saved(self, PcObject, app):
            # given
            user = create_user()
            offerer = create_offerer()
            venue = create_venue(offerer)
            offer = create_offer_with_event_product(venue)
            user_offerer = create_user_offerer(user, offerer)
            PcObject.save(user, venue, user_offerer)
            with open(MODULE_PATH / '..' / 'files/mouette_small.jpg',
                      'rb') as f:
                thumb = f.read()
            data = {
                'offerId': humanize(offer.id),
                'offererId': humanize(offerer.id),
                'thumb': (BytesIO(thumb), 'image.png')
            }
            PcObject.reset_mock()

            # when
            TestClient(app.test_client()) \
                .with_auth(email=user.email) \
                .post('/mediations', form=data)

            # then
            PcObject.save.assert_not_called()
コード例 #11
0
        def when_mediation_is_created_with_file_upload_but_image_is_too_small(
                self, app):
            # given
            user = create_user()
            offerer = create_offerer()
            venue = create_venue(offerer)
            offer = create_offer_with_event_product(venue)
            user_offerer = create_user_offerer(user, offerer)
            PcObject.save(user, venue, user_offerer)
            with open(MODULE_PATH / '..' / 'files/mouette_small.jpg',
                      'rb') as f:
                thumb = f.read()
            data = {
                'offerId': humanize(offer.id),
                'offererId': humanize(offerer.id),
                'thumb': (BytesIO(thumb), 'image.png')
            }

            # when
            response = TestClient(app.test_client()) \
                .with_auth(email=user.email) \
                .post('/mediations', form=data)

            # then
            assert response.status_code == 400
            assert response.json['thumb'] == [
                "L'image doit faire 100 ko minimum et 400 * 400 px minimum"
            ]
コード例 #12
0
        def when_mediation_is_created_with_file_upload_but_without_filename(
                self, app):
            # given
            user = create_user()
            offerer = create_offerer()
            venue = create_venue(offerer)
            offer = create_offer_with_event_product(venue)
            user_offerer = create_user_offerer(user, offerer)
            PcObject.save(user, venue, user_offerer)

            data = {
                'offerId': humanize(offer.id),
                'offererId': humanize(offerer.id),
                'thumb': (BytesIO(ONE_PIXEL_PNG), '')
            }

            # when
            response = TestClient(app.test_client()) \
                .with_auth(email=user.email) \
                .post('/mediations', form=data)

            # then
            assert response.status_code == 400
            assert response.json['thumb'] == [
                "Vous devez fournir une image d'accroche"
            ]
コード例 #13
0
        def when_mediation_is_created_with_thumb_url_pointing_to_not_an_image(
                self, app):
            # given
            user = create_user()
            offerer = create_offerer()
            venue = create_venue(offerer)
            offer = create_offer_with_event_product(venue)
            user_offerer = create_user_offerer(user, offerer)
            PcObject.save(user, venue, user_offerer)

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

            data = {
                'offerId': humanize(offer.id),
                'offererId': humanize(offerer.id),
                'thumbUrl': 'https://beta.gouv.fr/'
            }

            # when
            response = auth_request.post('/mediations', form=data)

            # then
            assert response.status_code == 400
            assert response.json['thumbUrl'] == [
                "L'adresse saisie n'est pas valide"
            ]
コード例 #14
0
        def test_returns_new_recommendation_with_active_mediation_for_already_existing_but_invalid_recommendations(
                self, app):
            # given
            user = create_user()
            offerer = create_offerer()
            venue = create_venue(offerer)
            offer1 = create_offer_with_thing_product(venue, thumb_count=0)
            stock1 = create_stock_from_offer(offer1, price=0)
            inactive_mediation = create_mediation(offer1, is_active=False)
            active_mediation = create_mediation(offer1, is_active=True)
            invalid_recommendation = create_recommendation(offer1, user, inactive_mediation,
                                                           valid_until_date=datetime.utcnow() - timedelta(hours=2))
            PcObject.save(user, stock1, inactive_mediation, active_mediation, invalid_recommendation)
            active_mediation_id = active_mediation.id
            inactive_mediation_id = inactive_mediation.id
            auth_request = TestClient(app.test_client()).with_auth(user.email)

            data = {'seenRecommendationIds': []}

            # when
            response = auth_request.put(RECOMMENDATION_URL, json=data)

            # then
            assert response.status_code == 200
            json = response.json
            mediation_ids = list(map(lambda x: x['mediationId'], json))
            assert humanize(active_mediation_id) in mediation_ids
            assert humanize(inactive_mediation_id) not in mediation_ids
コード例 #15
0
        def when_offers_have_active_mediations(self, app):
            # given
            user = create_user()
            offerer = create_offerer()
            venue = create_venue(offerer)
            offer1 = create_offer_with_thing_product(venue, thumb_count=0)
            stock1 = create_stock_from_offer(offer1, price=0)
            mediation1 = create_mediation(offer1, is_active=False)
            offer2 = create_offer_with_thing_product(venue, thumb_count=0)
            stock2 = create_stock_from_offer(offer2, price=0)
            mediation2 = create_mediation(offer2, is_active=False)
            mediation3 = create_mediation(offer2, is_active=True)
            PcObject.save(user, stock1, mediation1, stock2, mediation2, mediation3)
            auth_request = TestClient(app.test_client()).with_auth(user.email)
            mediation3_id = mediation3.id
            mediation2_id = mediation2.id
            mediation1_id = mediation1.id

            # when
            response = auth_request.put(RECOMMENDATION_URL, json={'seenRecommendationIds': []})

            # then
            assert response.status_code == 200
            json = response.json
            mediation_ids = list(map(lambda x: x['mediationId'], json))
            assert humanize(mediation3_id) in mediation_ids
            assert humanize(mediation2_id) not in mediation_ids
            assert humanize(mediation1_id) not in mediation_ids
コード例 #16
0
def test_14_create_booking_should_work_if_user_can_book():
    booking_json = {
        'offerId': humanize(3),
        'recommendationId': humanize(1)
    }
    r_create = req_with_auth('*****@*****.**').post(API_URL + '/bookings', json=booking_json)
    assert r_create.status_code == 201
コード例 #17
0
        def when_mediation_id_is_given(self, app):
            # Given
            offerer = create_offerer()
            venue = create_venue(offerer)
            offer = create_offer_with_event_product(venue)
            mediation1 = create_mediation(offer)
            mediation2 = create_mediation(offer)
            user = create_user(email='*****@*****.**')
            recommendation1 = create_recommendation(offer,
                                                    user,
                                                    mediation=mediation1)
            recommendation2 = create_recommendation(offer,
                                                    user,
                                                    mediation=mediation2)
            PcObject.save(recommendation1, recommendation2)

            # When
            path = '/recommendations/offers/{}?mediationId={}'.format(
                humanize(offer.id), humanize(recommendation1.mediationId))
            response = TestClient(app.test_client()) \
                .with_auth(email='*****@*****.**') \
                .get(path)

            # Then
            assert response.status_code == 200
            assert response.json['id'] == humanize(recommendation1.id)
            assert response.json['offerId'] == humanize(offer.id)
            assert response.json['mediationId'] == humanize(mediation1.id)
            assert response.json['offer']['product']['offerType'][
                'proLabel'] == 'Spectacle vivant'
コード例 #18
0
        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)
            PcObject.save(venue_provider)

            user = create_user()
            PcObject.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
            logger.info(response.json)
            assert response.json[0].get('id') == humanize(venue_provider.id)
            assert response.json[0].get('venueId') == humanize(venue.id)
コード例 #19
0
        def when_editing_non_authorised_fields(self, app):
            # given
            user = create_user()
            offerer = create_offerer()
            user_offerer = create_user_offerer(user, offerer, is_admin=True)
            PcObject.save(user_offerer)
            body = {
                'thumbCount': 0,
                'idAtProviders': 'zfeej',
                'dateModifiedAtLastProvider': serialize(datetime(2016, 2, 1)),
                'address': '123 nouvelle adresse',
                'postalCode': '75001',
                'city': 'Paris',
                'validationToken': 'ozieghieof',
                'id': humanize(10),
                'dateCreated': serialize(datetime(2015, 2, 1)),
                'name': 'Nouveau Nom',
                'siren': '989807829',
                'lastProviderId': humanize(1)
            }

            # when
            response = TestClient(app.test_client()) \
                .with_auth(user.email) \
                .patch('/offerers/%s' % humanize(offerer.id), json=body)

            # then
            assert response.status_code == 400
            for key in body:
                assert response.json[key] == [
                    'Vous ne pouvez pas modifier ce champ'
                ]
コード例 #20
0
    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)
コード例 #21
0
def test_15_create_booking_should_not_work_if_user_can_not_book():
    # with default admin user
    booking_json = {
        'offerId': humanize(3),
        'recommendationId': humanize(1)
    }
    r_create = req_with_auth().post(API_URL + '/bookings', json=booking_json)
    assert r_create.status_code == 400
コード例 #22
0
        def when_only_public_credit_and_limit_of_physical_thing_reached(
                self, app):
            # Given
            user = create_user(email='*****@*****.**')
            PcObject.save(user)

            offerer = create_offerer()
            PcObject.save(offerer)

            venue = create_venue(offerer)
            PcObject.save(venue)

            thing_offer = create_offer_with_thing_product(venue)
            PcObject.save(thing_offer)

            thing_stock_price_190 = create_stock_with_thing_offer(offerer,
                                                                  venue,
                                                                  thing_offer,
                                                                  price=190)

            thing_stock_price_12 = create_stock_with_thing_offer(offerer,
                                                                 venue,
                                                                 thing_offer,
                                                                 price=12)

            PcObject.save(thing_stock_price_190, thing_stock_price_12)

            deposit_date = datetime.utcnow() - timedelta(minutes=2)

            deposit = create_deposit(user, amount=500, source='public')

            PcObject.save(deposit)

            booking_thing_price_190 = create_booking(user,
                                                     thing_stock_price_190,
                                                     venue,
                                                     recommendation=None)
            PcObject.save(booking_thing_price_190)

            recommendation = create_recommendation(thing_offer, user)
            PcObject.save(recommendation)

            booking_thing_price_12_json = {
                "stockId": humanize(thing_stock_price_12.id),
                "recommendationId": humanize(recommendation.id),
                "quantity": 1
            }

            # When
            response = TestClient(app.test_client()) \
                .with_auth('*****@*****.**') \
                .post('/bookings', json=booking_thing_price_12_json)

            # Then
            error_message = response.json
            assert response.status_code == 400
            assert error_message['global'] == ['Le plafond de 200 € pour les biens culturels ' \
                                               'ne vous permet pas de réserver cette offre.']
コード例 #23
0
        def when_user_cannot_book_free_offers_and_free_offer(self, app):
            # Given
            user = create_user(email='*****@*****.**',
                               can_book_free_offers=False)
            PcObject.save(user)

            offerer = create_offerer(siren='899999768',
                                     address='2 Test adress',
                                     city='Test city',
                                     postal_code='93000',
                                     name='Test offerer')
            PcObject.save(offerer)

            venue = create_venue(offerer=offerer,
                                 name='Venue name',
                                 booking_email='*****@*****.**',
                                 address='1 Test address',
                                 postal_code='93000',
                                 city='Test city',
                                 departement_code='93')
            PcObject.save(venue)

            thing_offer = create_offer_with_thing_product(venue)
            PcObject.save(thing_offer)

            stock = create_stock_with_thing_offer(offerer,
                                                  venue,
                                                  thing_offer,
                                                  price=0)
            PcObject.save(stock)

            recommendation = create_recommendation(thing_offer, user)
            PcObject.save(recommendation)

            deposit_date = datetime.utcnow() - timedelta(minutes=2)
            deposit = create_deposit(user, amount=500)
            PcObject.save(deposit)

            booking_json = {
                'stockId': humanize(stock.id),
                'recommendationId': humanize(recommendation.id),
                'quantity': 1
            }

            # When
            r_create = TestClient(app.test_client()) \
                .with_auth('*****@*****.**') \
                .post('/bookings', json=booking_json)

            # Then
            assert r_create.status_code == 400
            assert 'cannotBookFreeOffers' in r_create.json
            assert r_create.json['cannotBookFreeOffers'] == [
                "Votre compte ne vous permet pas de faire de réservation."
            ]
コード例 #24
0
def _create_detail_response(application_id=145, offerer_id=267, venue_id=578, bic="TRPUFRP1",
                            iban="FR7610271490201000200481837"):
    return {
        "dossier": {
            "id": application_id,
            "created_at": "2019-04-25T15:20:06.532Z",
            "updated_at": "2019-04-25T15:23:36.490Z",
            "state": "closed",
            "simplified_state": "Validé",
            "initiated_at": "2019-04-25T15:23:35.255Z",
            "instructeurs": [],
            "individual": {
                "civilite": "M.",
                "nom": "PORT MUSEE",
                "prenom": " \tCOMMUNE DE DOUARNENEZ"
            },
            "champs": [
                {
                    "value": "https://pro.passculture.beta.gouv.fr/"
                             "structures/" + humanize(offerer_id) + "/"
                                                                    "lieux/" + humanize(venue_id),
                    "type_de_champ": {
                        "id": 407889,
                        "libelle": "URL",
                        "type_champ": "text",
                        "order_place": 1,
                        "description": ""
                    }
                },
                {
                    "value": bic,
                    "type_de_champ": {
                        "id": 352727,
                        "libelle": "BIC",
                        "type_champ": "text",
                        "order_place": 9,
                        "description": ""
                    }
                },
                {
                    "value": iban,
                    "type_de_champ": {
                        "id": 352722,
                        "libelle": "IBAN",
                        "type_champ": "text",
                        "order_place": 10,
                        "description": ""
                    }
                }
            ]
        }
    }
コード例 #25
0
        def test_list_activation_offers_returns_offers_of_event_type(
                self, app):
            # given
            user = create_user()
            PcObject.save(user)
            auth_request = TestClient(
                app.test_client()).with_auth(email=user.email)
            now = datetime.utcnow()
            five_days_ago = now - timedelta(days=5)
            next_week = now + timedelta(days=7)
            offerer = create_offerer()
            venue1 = create_venue(offerer,
                                  siret=offerer.siren + '12345',
                                  postal_code='93000',
                                  departement_code='93')
            venue2 = create_venue(offerer,
                                  siret=offerer.siren + '67890',
                                  postal_code='93000',
                                  departement_code='93')
            venue3 = create_venue(offerer,
                                  siret=offerer.siren + '54321',
                                  postal_code='93000',
                                  departement_code='93')
            offer1 = create_offer_with_event_product(
                venue1, event_type=EventType.ACTIVATION)
            offer2 = create_offer_with_event_product(
                venue2, event_type=EventType.ACTIVATION)
            offer3 = create_offer_with_event_product(
                venue3, event_type=EventType.ACTIVATION)
            stock1 = create_stock_from_offer(
                offer1, price=0, booking_limit_datetime=five_days_ago)
            stock2 = create_stock_from_offer(offer2,
                                             price=0,
                                             booking_limit_datetime=next_week)
            stock3 = create_stock_from_offer(offer3,
                                             price=0,
                                             booking_limit_datetime=None)
            PcObject.save(stock1, stock2, stock3)

            # when
            response = auth_request.get('/offers/activation')

            # then
            json = response.json
            event_ids = [
                info['productId'] for info in json
                if ProductType.is_event(info['type'])
            ]
            assert len(json) == 2
            assert response.status_code == 200
            assert humanize(offer2.productId) in event_ids
            assert humanize(offer3.productId) in event_ids
コード例 #26
0
def test_10_create_booking():
    booking_json = {
        'offerId': humanize(3),
        'recommendationId': humanize(1)
    }
    r_create = req_with_auth('*****@*****.**').post(API_URL + '/bookings', json=booking_json)
    assert r_create.status_code == 201
    id = r_create.json()['id']
    r_check = req_with_auth().get(API_URL + '/bookings/'+id)
    assert r_check.status_code == 200
    created_booking_json = r_check.json()
    for (key, value) in booking_json.items():
        assert created_booking_json[key] == booking_json[key]
コード例 #27
0
        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
コード例 #28
0
        def when_user_cannot_book_free_offers_but_has_enough_credit_for_paid_offer(
                self, app):
            user = create_user(email='*****@*****.**',
                               can_book_free_offers=False)
            PcObject.save(user)

            offerer = create_offerer(siren='899999768',
                                     address='2 Test adress',
                                     city='Test city',
                                     postal_code='93000',
                                     name='Test offerer')
            PcObject.save(offerer)

            venue = create_venue(offerer, 'Test offerer',
                                 '*****@*****.**', '123 rue test',
                                 '93000', 'Test city', '93')
            PcObject.save(venue)

            thing_offer = create_offer_with_thing_product(venue)
            PcObject.save(thing_offer)

            stock = create_stock_with_thing_offer(offerer,
                                                  venue,
                                                  thing_offer,
                                                  price=10)
            PcObject.save(stock)

            recommendation = create_recommendation(thing_offer, user)
            PcObject.save(recommendation)

            deposit_date = datetime.utcnow() - timedelta(minutes=2)
            deposit = create_deposit(user, amount=500)
            PcObject.save(deposit)

            booking_json = {
                "stockId": humanize(stock.id),
                "recommendationId": humanize(recommendation.id),
                "quantity": 1
            }

            # When
            r_create = TestClient(app.test_client()) \
                .with_auth('*****@*****.**') \
                .post('/bookings', json=booking_json)

            # Then
            r_create_json = r_create.json
            assert r_create.status_code == 201
            assert r_create_json['amount'] == 10.0
            assert r_create_json['quantity'] == 1
コード例 #29
0
def test_12_create_offer():
    offer_data = {
        'price': 1222,
        'offererId': humanize(3),
        'venueId': humanize(3),
        'thingId': humanize(1)
    }
    r_create = req_with_auth().post(API_URL + '/offers/', json=offer_data)
    assert r_create.status_code == 201
    id = r_create.json()['id']
    r_check = req_with_auth().get(API_URL + '/offers/' + id)
    assert r_check.status_code == 200
    created_offer_data = r_check.json()
    for (key, value) in offer_data.items():
        assert created_offer_data[key] == offer_data[key]
コード例 #30
0
        def when_already_booked_by_user_but_cancelled(self, app):
            # Given
            user = create_user(email='*****@*****.**')
            offerer = create_offerer()
            venue = create_venue(offerer)
            thing_offer = create_offer_with_thing_product(venue)
            deposit_date = datetime.utcnow() - timedelta(minutes=2)
            deposit = create_deposit(user, amount=200)
            stock = create_stock_with_thing_offer(offerer,
                                                  venue,
                                                  thing_offer,
                                                  price=90)
            booking = create_booking(user, stock, venue, is_cancelled=True)
            PcObject.save(stock, user, booking)

            booking_json = {
                'stockId': humanize(stock.id),
                'recommendationId': None,
                'quantity': 1
            }

            # When
            response = TestClient(
                app.test_client()).with_auth('*****@*****.**').post(
                    '/bookings', json=booking_json)
            # Then
            assert response.status_code == 201