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
def test_send_transactions_should_send_an_email_with_xml_attachment(app):
    # given
    offerer1 = create_offerer(name='first offerer')
    user = create_user()
    venue1 = create_venue(offerer1)
    stock1 = create_stock_from_offer(create_offer_with_thing_product(venue1))
    booking1 = create_booking(user, stock1)
    booking2 = create_booking(user, stock1)
    booking3 = create_booking(user, stock1)
    deposit = create_deposit(user, amount=500)
    PcObject.save(deposit)
    payments = [
        create_payment(booking1, offerer1, Decimal(10)),
        create_payment(booking2, offerer1, Decimal(20)),
        create_payment(booking3, offerer1, Decimal(20))
    ]

    app.mailjet_client.send.create.return_value = Mock(status_code=200)

    # when
    send_transactions(payments, 'BD12AZERTY123456', 'AZERTY9Q666', '0000',
                      ['*****@*****.**'])

    # then
    app.mailjet_client.send.create.assert_called_once()
    args = app.mailjet_client.send.create.call_args
    assert len(args[1]['data']['Attachments']) == 1
    def test_returns_payments_matching_message(self, app):
        # given
        user = create_user()
        booking = create_booking(user)
        deposit = create_deposit(user)
        offerer = booking.stock.resolvedOffer.venue.managingOfferer

        transaction1 = create_payment_message(name='XML1')
        transaction2 = create_payment_message(name='XML2')
        transaction3 = create_payment_message(name='XML3')

        uuid1, uuid2, uuid3 = uuid.uuid4(), uuid.uuid4(), uuid.uuid4()

        payments = [
            create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid1, payment_message=transaction1),
            create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid2, payment_message=transaction2),
            create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid1, payment_message=transaction3),
            create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid3, payment_message=transaction1),
            create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid1, payment_message=transaction1)
        ]

        PcObject.save(deposit, *payments)

        # when
        matching_payments = find_payments_by_message('XML1')

        # then
        assert len(matching_payments) == 3
        for p in matching_payments:
            assert p.paymentMessageName == 'XML1'
        def test_returns_stocks_with_isBookable_property(self, app):
            # Given
            expired_booking_limit_date = datetime(1970, 1, 1)

            user = create_user()
            offerer = create_offerer()
            venue = create_venue(offerer)
            offer = create_offer_with_thing_product(venue, thing_name='Guitar for dummies')
            mediation = create_mediation(offer, is_active=True)

            create_stock_from_offer(offer, price=14)
            create_stock_from_offer(offer, price=26, booking_limit_datetime=expired_booking_limit_date)

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

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

            # When
            recommendations_req = auth_request.put(RECOMMENDATION_URL, json={})

            # Then
            assert recommendations_req.status_code == 200
            recommendations = recommendations_req.json
            assert len(recommendations) == 1
            recommendation = recommendations[0]
            assert recommendation['offer']['name'] == 'Guitar for dummies'
            stocks_response = recommendation['offer']['stocks']
            assert len(stocks_response) == 2
            assert all('isBookable' in stocks_response[i] for i in range(0, len(stocks_response)))
示例#5
0
    def test_returns_offer_in_all_ile_de_france_for_user_from_93(self, app):
        # given
        departements_ok = ['75', '77', '78', '91', '92', '93', '94', '95']
        departements_ko = ['34', '973']

        user = create_user(departement_code='93')
        offerer_ok = create_offerer()
        offerer_ko = create_offerer(siren='987654321')
        expected_stocks_recommended = _create_and_save_stock_for_offererer_in_departements(
            offerer_ok, departements_ok)
        expected_stocks_not_recommended = _create_and_save_stock_for_offererer_in_departements(
            offerer_ko, departements_ko)
        PcObject.save(user)
        PcObject.save(*(expected_stocks_recommended +
                        expected_stocks_not_recommended))
        offer_ids_in_adjacent_department = set(
            [stock.offerId for stock in expected_stocks_recommended])

        #  when
        recommendations = create_recommendations_for_discovery(user=user,
                                                               limit=10)

        # then
        recommended_offer_ids = set(
            [recommendation.offerId for recommendation in recommendations])
        assert len(recommendations) == 8
        assert recommended_offer_ids == offer_ids_in_adjacent_department
        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 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
示例#8
0
def test_create_payment_for_booking_with_common_information(app):
    # given
    user = create_user()
    stock = create_stock(price=10, available=5)
    booking = create_booking(user, stock=stock, quantity=1)
    booking.stock.offer = Offer()
    booking.stock.offer.venue = Venue()
    offerer = create_offerer()
    offerer_bank_information = create_bank_information(bic='QSDFGH8Z555',
                                                       iban='CF13QSDFGH456789',
                                                       offerer=offerer)
    booking.stock.offer.venue.managingOfferer = offerer
    booking_reimbursement = BookingReimbursement(
        booking, ReimbursementRules.PHYSICAL_OFFERS, Decimal(10))

    # when
    payment = create_payment_for_booking(booking_reimbursement)

    # then
    assert payment.booking == booking
    assert payment.amount == Decimal(10)
    assert payment.reimbursementRule == ReimbursementRules.PHYSICAL_OFFERS.value.description
    assert payment.reimbursementRate == ReimbursementRules.PHYSICAL_OFFERS.value.rate
    assert payment.comment is None
    assert payment.author == 'batch'
    assert payment.transactionLabel == 'pass Culture Pro - remboursement 2nde quinzaine 10-2018'
示例#9
0
    def test_it_returns_only_payments_with_current_status_as_not_processable(
            self):
        # given
        user = create_user()
        booking = create_booking(user)
        offerer = create_offerer()
        payments = [
            create_payment(booking,
                           offerer,
                           30,
                           status=TransactionStatus.PENDING),
            create_payment(booking,
                           offerer,
                           30,
                           status=TransactionStatus.NOT_PROCESSABLE),
            create_payment(booking,
                           offerer,
                           30,
                           status=TransactionStatus.ERROR)
        ]

        # when
        pending_payments = keep_only_not_processable_payments(payments)

        # then
        assert len(pending_payments) == 1
        assert pending_payments[
            0].currentStatus.status == TransactionStatus.NOT_PROCESSABLE
示例#10
0
        def when_user_has_rights_on_managing_offerer(self, app):
            # Given
            user = create_user(email='*****@*****.**')
            offerer = create_offerer()
            venue = create_venue(offerer)
            offer = create_offer_with_thing_product(venue)
            stock = create_stock(offer=offer)
            create_bank_information(venue=venue, id_at_providers=venue.siret)
            create_bank_information(offerer=offerer,
                                    id_at_providers=offerer.siren)

            PcObject.save(user, stock)

            # when
            response = TestClient(app.test_client()).with_auth(email='*****@*****.**') \
                .get(f'/offers/{humanize(offer.id)}')

            # then
            response_json = response.json
            assert response.status_code == 200
            assert 'iban' in response_json['venue']
            assert 'bic' in response_json['venue']
            assert 'iban' in response_json['venue']['managingOfferer']
            assert 'bic' in response_json['venue']['managingOfferer']
            assert 'validationToken' not in response_json['venue'][
                'managingOfferer']
示例#11
0
def test_cannot_create_admin_that_can_book(app):
    # Given
    user = create_user(can_book_free_offers=True, is_admin=True)

    # When
    with pytest.raises(ApiErrors):
        PcObject.save(user)
        def test_records_new_payment_lines_in_database(self, app):
            # Given
            offerer = create_offerer()
            venue = create_venue(offerer)
            offer = create_offer_with_thing_product(venue)
            paying_stock = create_stock_from_offer(offer)
            free_stock = create_stock_from_offer(offer, price=0)
            user = create_user()
            deposit = create_deposit(user, amount=500)
            booking1 = create_booking(user, paying_stock, venue, is_used=True)
            booking2 = create_booking(user, paying_stock, venue, is_used=True)
            booking3 = create_booking(user, paying_stock, venue, is_used=True)
            booking4 = create_booking(user, free_stock, venue, is_used=True)
            payment1 = create_payment(booking2,
                                      offerer,
                                      10,
                                      payment_message_name="ABCD123")

            PcObject.save(payment1)
            PcObject.save(deposit, booking1, booking3, booking4)

            initial_payment_count = Payment.query.count()

            # When
            generate_new_payments()

            # Then
            assert Payment.query.count() - initial_payment_count == 2
        def when_activating_all_venue_offers(self, app):
            # Given
            user = create_user(email='*****@*****.**')
            offerer = create_offerer()
            user_offerer = create_user_offerer(user, offerer)
            venue = create_venue(offerer)
            offer = create_offer_with_event_product(venue)
            offer2 = create_offer_with_thing_product(venue)
            stock1 = create_stock_from_offer(offer)
            offer.isActive = False
            offer2.isActive = False
            PcObject.save(offer2, stock1, user_offerer, venue)

            api_url = API_URL + humanize(venue.id) + '/offers/activate'

            # When
            response = TestClient(app.test_client()) \
                .with_auth('*****@*****.**') \
                .put(api_url)

            # Then
            assert response.status_code == 200
            assert response.json[0]['isActive'] == True
            assert response.json[1]['isActive'] == True

            offers = Offer.query.all()
            assert offers[0].isActive == True
            assert offers[1].isActive == True
        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"
            ]
        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
示例#16
0
def test_create_payment_for_booking_when_iban_is_on_venue_should_take_payment_info_from_venue(
        app):
    # given
    user = create_user()
    stock = create_stock(price=10, available=5)
    offerer = create_offerer(name='Test Offerer')
    venue = create_venue(
        offerer,
        name='Test Venue',
    )
    booking = create_booking(user, stock=stock, quantity=1)

    offerer_bank_information = create_bank_information(bic='Lajr93',
                                                       iban='B135TGGEG532TG',
                                                       offerer=offerer)
    venue_bank_information = create_bank_information(bic='LokiJU76',
                                                     iban='KD98765RFGHZ788',
                                                     venue=venue)

    booking.stock.offer = Offer()
    booking.stock.offer.venue = venue
    booking.stock.offer.venue.managingOfferer = offerer
    booking_reimbursement = BookingReimbursement(
        booking, ReimbursementRules.PHYSICAL_OFFERS, Decimal(10))

    # when
    payment = create_payment_for_booking(booking_reimbursement)

    # then
    assert payment.iban == 'KD98765RFGHZ788'
    assert payment.bic == 'LOKIJU76'
        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
示例#18
0
    def test_contains_info_on_offer(self):
        # given
        user = create_user(email='*****@*****.**', idx=3)
        offerer = create_offerer(siren='987654321', name='Joe le Libraire')
        venue = create_venue(offerer,
                             name='Jack le Sculpteur',
                             siret='1234567891234')
        offer = create_offer_with_thing_product(venue)
        stock = create_stock(price=12, available=5, offer=offer)
        booking = create_booking(user,
                                 stock,
                                 date_created=datetime(2018, 2, 5),
                                 quantity=2,
                                 idx=5)
        payment = create_payment(booking, offerer, 35)
        find_date = Mock()
        find_date.return_value = datetime(2018, 2, 19)

        # when
        details = create_payment_details(payment,
                                         find_booking_date_used=find_date)

        # then
        assert details.offer_name == 'Test Book'
        assert details.offer_type == 'Audiovisuel — films sur supports physiques et VOD'
        def test_discovery_recommendations_should_not_include_search_recommendations(self, app):
            # Given
            user = create_user()
            offerer = create_offerer()
            venue = create_venue(offerer)
            venue_outside_dept = create_venue(offerer, postal_code='29100', siret='12345678912341')
            offer1 = create_offer_with_thing_product(venue, thumb_count=0)
            stock1 = create_stock_from_offer(offer1, price=0)
            mediation1 = create_mediation(offer1, is_active=True)
            offer2 = create_offer_with_thing_product(venue_outside_dept, thumb_count=0)
            stock2 = create_stock_from_offer(offer2, price=0)
            mediation2 = create_mediation(offer2, is_active=True)

            recommendation = create_recommendation(offer=offer2, user=user, mediation=mediation2, search="bla")

            PcObject.save(user, stock1, mediation1, stock2, mediation2, recommendation)

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

            # When
            recommendations_req = auth_request.put(RECOMMENDATION_URL, json={})

            # Then
            assert recommendations_req.status_code == 200
            recommendations = recommendations_req.json
            assert len(recommendations) == 1
            assert recommendations[0]['search'] is None
示例#20
0
    def test_returns_as_much_payment_details_as_there_are_payments_given(self):
        # given
        offerer1, offerer2 = create_offerer(), create_offerer()
        user1, user2 = create_user(), create_user()
        payments = [
            create_payment(create_booking(user1), offerer1, 10),
            create_payment(create_booking(user1), offerer1, 20),
            create_payment(create_booking(user2), offerer2, 30)
        ]

        # when
        details = create_all_payments_details(payments,
                                              find_booking_date_used=Mock())

        # then
        assert len(details) == 3
        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
示例#22
0
def test_create_payment_for_booking_when_no_iban_on_venue_should_take_payment_info_from_offerer(
        app):
    # given
    user = create_user()
    stock = create_stock(price=10, available=5)
    offerer = create_offerer(name='Test Offerer')
    venue = create_venue(offerer, name='Test Venue')

    offerer_bank_information = create_bank_information(bic='QsdFGH8Z555',
                                                       iban='cf13QSDFGH456789',
                                                       offerer=offerer)
    venue_bank_information = create_bank_information(bic=None,
                                                     iban=None,
                                                     venue=venue)

    booking = create_booking(user, stock=stock, quantity=1)
    booking.stock.offer = Offer()
    booking.stock.offer.venue = venue
    booking.stock.offer.venue.managingOfferer = offerer
    booking_reimbursement = BookingReimbursement(
        booking, ReimbursementRules.PHYSICAL_OFFERS, Decimal(10))

    # when
    payment = create_payment_for_booking(booking_reimbursement)

    # then
    assert payment.iban == 'CF13QSDFGH456789'
    assert payment.bic == 'QSDFGH8Z555'
示例#23
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'
                ]
        def when_user_has_no_offer_in_his_department(self, app):
            # given
            user = create_user(departement_code='973', can_book_free_offers=True, is_admin=False)
            offerer = create_offerer()
            venue29 = create_venue(offerer, siret=offerer.siren + '98765', postal_code='29000', departement_code='29')
            venue34 = create_venue(offerer, siret=offerer.siren + '12345', postal_code='34000', departement_code='34')
            venue93 = create_venue(offerer, siret=offerer.siren + '54321', postal_code='93000', departement_code='93')
            venue67 = create_venue(offerer, siret=offerer.siren + '56789', postal_code='67000', departement_code='67')
            thing_offer1 = create_offer_with_thing_product(venue93, thing_name='thing 93', url=None, is_national=False)
            thing_offer2 = create_offer_with_thing_product(venue67, thing_name='thing 67', url=None, is_national=False)
            thing_offer3 = create_offer_with_thing_product(venue29, thing_name='thing 29', url=None, is_national=False)
            thing_offer4 = create_offer_with_thing_product(venue34, thing_name='thing 34', url=None, is_national=False)
            stock1 = create_stock_from_offer(thing_offer1)
            stock2 = create_stock_from_offer(thing_offer2)
            stock3 = create_stock_from_offer(thing_offer3)
            stock4 = create_stock_from_offer(thing_offer4)
            PcObject.save(user, stock1, stock2, stock3, stock4)

            # when
            response = TestClient(app.test_client()).with_auth(user.email) \
                .put(RECOMMENDATION_URL, json={'readRecommendations': []})

            # then
            assert response.status_code == 200
            assert len(response.json) == 0
示例#25
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'
        def when_user_has_one_offer_in_his_department(self, app):
            # given
            user = create_user(departement_code='93', can_book_free_offers=True, is_admin=False)
            offerer = create_offerer()
            venue93 = create_venue(offerer, siret=offerer.siren + '54321', postal_code='93000', departement_code='93')
            venue67 = create_venue(offerer, siret=offerer.siren + '56789', postal_code='67000', departement_code='67')
            thing_offer1 = create_offer_with_thing_product(venue93, thing_name='thing 93', url=None, is_national=False)
            thing_offer2 = create_offer_with_thing_product(venue67, thing_name='thing 67', url=None, is_national=False)
            stock1 = create_stock_from_offer(thing_offer1)
            stock2 = create_stock_from_offer(thing_offer2)
            PcObject.save(user, stock1, stock2)

            # when
            response = TestClient(app.test_client()).with_auth(user.email) \
                .put(RECOMMENDATION_URL, json={'readRecommendations': []})

            # then
            assert response.status_code == 200
            assert len(response.json) == 1
            recommendation_response = response.json[0]
            assert 'offer' in recommendation_response
            assert 'venue' in recommendation_response['offer']
            assert 'validationToken' not in recommendation_response['offer']['venue']
            assert 'managingOfferer' in recommendation_response['offer']['venue']
            assert 'validationToken' not in recommendation_response['offer']['venue']['managingOfferer']
示例#27
0
def test_send_transactions_with_malformed_iban_on_payments_gives_them_an_error_status_with_a_cause(
        app):
    # given
    offerer = create_offerer(name='first offerer')
    user = create_user()
    venue = create_venue(offerer)
    stock = create_stock_from_offer(create_offer_with_thing_product(venue))
    booking = create_booking(user, stock)
    deposit = create_deposit(user, amount=500)
    payments = [
        create_payment(booking,
                       offerer,
                       Decimal(10),
                       iban='CF  13QSDFGH45 qbc //',
                       bic='QSDFGH8Z555'),
    ]

    PcObject.save(deposit, *payments)
    app.mailjet_client.send.create.return_value = Mock(status_code=400)

    # when
    with pytest.raises(DocumentInvalid):
        send_transactions(payments, 'BD12AZERTY123456', 'AZERTY9Q666', '0000',
                          ['*****@*****.**'])

    # then
    updated_payments = Payment.query.all()
    for payment in updated_payments:
        assert len(payment.statuses) == 2
        assert payment.currentStatus.status == TransactionStatus.NOT_PROCESSABLE
        assert payment.currentStatus.detail == "Element '{urn:iso:std:iso:20022:tech:xsd:pain.001.001.03}IBAN': " \
                                               "[facet 'pattern'] The value 'CF  13QSDFGH45 qbc //' is not accepted " \
                                               "by the pattern '[A-Z]{2,2}[0-9]{2,2}[a-zA-Z0-9]{1,30}'., line 76"
        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_nothing_if_message_is_not_matched(self, app):
        # given
        user = create_user()
        booking = create_booking(user)
        deposit = create_deposit(user)
        offerer = booking.stock.resolvedOffer.venue.managingOfferer

        message1 = create_payment_message(name='XML1')
        message2 = create_payment_message(name='XML2')
        message3 = create_payment_message(name='XML3')

        uuid1, uuid2, uuid3 = uuid.uuid4(), uuid.uuid4(), uuid.uuid4()

        payments = [
            create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid1, payment_message=message1),
            create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid2, payment_message=message2),
            create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid3, payment_message=message3)
        ]

        PcObject.save(deposit, *payments)

        # when
        matching_payments = find_payments_by_message('unknown message')

        # then
        assert matching_payments == []
        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