示例#1
0
    def test_returns_only_payment_total_by_department(self, app):
        # Given
        offerer = create_offerer(siren='111111111')
        venue = create_venue(offerer,
                             postal_code='78490',
                             siret='11111111100002')
        offer = create_offer_with_thing_product(venue)
        stock = create_stock(price=10, offer=offer)

        user_in_35 = create_user(email='*****@*****.**',
                                 departement_code='35')
        user_in_78 = create_user(email='*****@*****.**',
                                 departement_code='78')
        create_deposit(user_in_35, amount=500)
        create_deposit(user_in_78, amount=500)

        booking_in_35 = create_booking(user_in_35, stock=stock, venue=venue)
        booking_in_78 = create_booking(user_in_78, stock=stock, venue=venue)

        payment1 = create_payment(booking_in_35, offerer, amount=20)
        payment2 = create_payment(booking_in_78, offerer, amount=10)

        PcObject.save(user_in_35, venue, payment1, payment2)

        # When
        total_amount_to_pay = get_total_amount_to_pay('35')

        # Then
        assert total_amount_to_pay == 20
示例#2
0
    def test_returns_offerers_filtered_by_departement_based_on_venue(
            self, app):
        # Given
        offerer1 = create_offerer(name='Small library', siren='111111111')
        venue1 = create_venue(offerer1,
                              postal_code='33130',
                              siret='11111111100001')
        offer1 = create_offer_with_thing_product(venue1)
        stock1 = create_stock(offer=offer1, price=30)

        offerer2 = create_offerer(name='National book store',
                                  siren='222222222')
        venue2 = create_venue(offerer2,
                              postal_code='33130',
                              siret='22222222200001')
        offer2 = create_offer_with_thing_product(venue=venue2)
        stock2 = create_stock(offer=offer2, price=10)

        user_76 = create_user(departement_code='76')
        user_77 = create_user(email='*****@*****.**', departement_code='77')
        create_deposit(user_76, amount=500)
        create_deposit(user_77, amount=500)
        booking1 = create_booking(user_76, stock1, quantity=2)
        booking2 = create_booking(user_76, stock2, quantity=2)
        booking3 = create_booking(user_77, stock2, quantity=2)

        PcObject.save(booking1, booking2, booking3)

        # When
        bookings_counts = _query_get_top_20_offerers_by_booking_amounts('76')

        # Then
        assert bookings_counts == [('Small library', 2, 60),
                                   ('National book store', 2, 20)]
示例#3
0
def _create_balances_for_user1(stock1, stock2, stock3, user1, venue):
    deposit1 = create_deposit(user1, amount=100)
    deposit2 = create_deposit(user1, amount=50)
    booking1 = create_booking(user1, venue=venue, stock=stock1, quantity=1, is_cancelled=True, is_used=False)
    booking2 = create_booking(user1, venue=venue, stock=stock2, quantity=2, is_cancelled=False, is_used=True)
    booking3 = create_booking(user1, venue=venue, stock=stock3, quantity=1, is_cancelled=False, is_used=False)
    PcObject.save(deposit1, deposit2, booking1, booking2, booking3)
    def test_should_return_multiple_departements_and_order_by_desc_booking_counts(self, app):
        # Given
        offerer93 = create_offerer(name='Offerer dans le 93', siren=111111111)
        venue93 = create_venue(offerer93, departement_code='93', siret=11111111100001)
        offer93 = create_offer_with_thing_product(venue93)
        stock93 = create_stock(offer=offer93, price=10)

        offerer95 = create_offerer(name='Offerer dans le 95', siren=222222222)
        venue95 = create_venue(offerer95, departement_code='95', siret=22222222200001)
        offer95 = create_offer_with_thing_product(venue95)
        stock95 = create_stock(offer=offer95, price=10)

        user_in_95 = create_user(departement_code='95', email="*****@*****.**")
        create_deposit(user_in_95, amount=500)
        booking_in_95 = create_booking(user_in_95, stock95, quantity=5)

        user_in_93 = create_user(departement_code='93', email="*****@*****.**")
        create_deposit(user_in_93, amount=500)
        booking_in_93 = create_booking(user_in_93, stock93, quantity=2)

        PcObject.save(booking_in_93, booking_in_95)

        # When
        bookings_by_departement = _query_get_non_cancelled_bookings_by_user_departement()

        # Then
        assert len(bookings_by_departement) == 2
        assert bookings_by_departement == [('95', 5), ('93', 2)]
        def when_user_has_booked_some_offers(self, app):
            # Given
            user = create_user(public_name='Test', departement_code='93', email='*****@*****.**')
            offerer = create_offerer('999199987', '2 Test adress', 'Test city', '93000', 'Test offerer')
            venue = create_venue(offerer)
            thing_offer = create_offer_with_thing_product(venue=None)
            stock = create_stock_with_thing_offer(offerer, venue, thing_offer, price=5)
            recommendation = create_recommendation(thing_offer, user)
            deposit_1_date = datetime.utcnow() - timedelta(minutes=2)
            deposit_1 = create_deposit(user, amount=10)
            deposit_2_date = datetime.utcnow() - timedelta(minutes=2)
            deposit_2 = create_deposit(user, amount=10)
            booking = create_booking(user, stock, venue, recommendation, quantity=1)

            PcObject.save(user, venue, deposit_1, deposit_2, booking)

            # when
            response = TestClient(app.test_client()).with_auth('*****@*****.**').get('/users/current')

            # Then
            assert response.json['wallet_balance'] == 15
            assert response.json['expenses'] == {
                'all': {'max': 500, 'actual': 5.0},
                'physical': {'max': 200, 'actual': 5.0},
                'digital': {'max': 200, 'actual': 0}
            }
示例#6
0
    def test_wallet_balance_is_the_sum_of_deposits_if_no_bookings(self, app):
        # given
        user = create_user()
        deposit1 = create_deposit(user, amount=100)
        deposit2 = create_deposit(user, amount=50)
        PcObject.save(deposit1, deposit2)

        # when
        balance = user.wallet_balance

        # then
        assert balance == Decimal(150)
def save_users_with_deposits():
    user1 = create_user(email='*****@*****.**', can_book_free_offers=True)
    user2 = create_user(email='*****@*****.**', can_book_free_offers=True)
    user3 = create_user(email='*****@*****.**', can_book_free_offers=True)
    user4 = create_user(email='*****@*****.**', can_book_free_offers=True)
    user5 = create_user(email='*****@*****.**', can_book_free_offers=True)
    deposit1 = create_deposit(user1, amount=500)
    deposit2 = create_deposit(user2, amount=500)
    deposit3 = create_deposit(user3, amount=500)
    deposit4 = create_deposit(user4, amount=500)
    deposit5 = create_deposit(user5, amount=500)
    PcObject.save(deposit1, deposit2, deposit3, deposit4, deposit5)
    logger.info('created 5 users with 500 € deposits')
    return user1, user2, user3, user4, user5
示例#8
0
    def test_returns_1000_if_two_deposits(self, app):
        # Given
        user1 = create_user(email='*****@*****.**')
        deposit1 = create_deposit(user1, amount=500)
        user2 = create_user(email='*****@*****.**')
        deposit2 = create_deposit(user2, amount=500)

        PcObject.save(deposit1, deposit2)

        # When
        total_deposits = get_total_deposits()

        # Then
        assert total_deposits == 1000
def _create_bookings_for_departement(bookings_by_departement):
    bookings = []

    offerer = create_offerer(name='Offerer', siren=222222222)
    venue = create_venue(offerer, departement_code='95', siret=22222222200001)
    offer = create_offer_with_thing_product(venue)
    stock = create_stock(offer=offer, price=10, available=1000)

    for departement_code, quantity in bookings_by_departement:
        user = create_user(departement_code=departement_code, email=f"user_in_{departement_code}@example.net")
        create_deposit(user, amount=500)
        bookings.append(create_booking(user, stock, quantity=quantity))

    return bookings
示例#10
0
    def test_returns_500_if_two_deposits_but_filtered_by_departement(
            self, app):
        # Given
        user1 = create_user(email='*****@*****.**', departement_code='42')
        deposit1 = create_deposit(user1, amount=500)
        user2 = create_user(email='*****@*****.**', departement_code='95')
        deposit2 = create_deposit(user2, amount=500)

        PcObject.save(deposit1, deposit2)

        # When
        total_deposits = get_total_deposits('95')

        # Then
        assert total_deposits == 500
            def expect_no_new_deposits_when_the_linked_user_has_been_already_activated(
                    self, app):
                # Given
                user = create_user(can_book_free_offers=False, is_admin=False)
                pro_user = create_user(email='*****@*****.**',
                                       can_book_free_offers=False,
                                       is_admin=True)
                offerer = create_offerer()
                user_offerer = create_user_offerer(pro_user, offerer)
                venue = create_venue(offerer)
                activation_offer = create_offer_with_event_product(
                    venue, event_type=EventType.ACTIVATION)
                activation_event_occurrence = create_event_occurrence(
                    activation_offer)
                stock = create_stock_from_event_occurrence(
                    activation_event_occurrence, price=0)
                booking = create_booking(user, stock, venue=venue)
                deposit = create_deposit(user, amount=500)
                PcObject.save(booking, user_offerer, deposit)
                user_id = user.id
                url = '/bookings/token/{}'.format(booking.token)

                # When
                response = TestClient(
                    app.test_client()).with_auth('*****@*****.**').patch(url)

                # Then
                deposits_for_user = Deposit.query.filter_by(
                    userId=user_id).all()
                assert response.status_code == 405
                assert len(deposits_for_user) == 1
                assert deposits_for_user[0].amount == 500
示例#12
0
    def test_does_not_modify_statuses_on_given_payments_if_a_payment_id_is_not_found(
            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')

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

        payment1 = create_payment(booking,
                                  offerer,
                                  5,
                                  transaction_end_to_end_id=uuid1,
                                  payment_message=transaction1)
        payment2 = create_payment(booking,
                                  offerer,
                                  5,
                                  transaction_end_to_end_id=uuid2,
                                  payment_message=transaction2)

        PcObject.save(deposit, payment1, payment2)

        # when
        do_ban_payments('XML1', [payment1.id, 123456])

        # then
        assert payment1.currentStatus.status == TransactionStatus.PENDING
        assert payment2.currentStatus.status == TransactionStatus.PENDING
示例#13
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
示例#14
0
        def when_non_validated_venue(self, app):
            # Given
            user = create_user(email='*****@*****.**')
            deposit = create_deposit(user)
            offerer = create_offerer()
            venue = create_venue(offerer)
            venue.generate_validation_token()
            thing_offer = create_offer_with_thing_product(venue)
            stock = create_stock_with_thing_offer(offerer,
                                                  venue,
                                                  thing_offer,
                                                  price=10)
            PcObject.save(stock, user, deposit)

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

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

            # Then
            assert r_create.status_code == 400
            assert r_create.json['stockId'] == [
                'Vous ne pouvez pas encore réserver cette offre, son lieu est en attente de validation'
            ]
示例#15
0
        def when_thing_booking_limit_datetime_has_expired(self, app):
            # Given
            four_days_ago = datetime.utcnow() - timedelta(days=4)
            five_days_ago = datetime.utcnow() - timedelta(days=5)
            user = create_user(email='*****@*****.**')
            offerer = create_offerer()
            deposit_date = datetime.utcnow() - timedelta(minutes=2)
            deposit = create_deposit(user, amount=200)
            venue = create_venue(offerer)

            stock = create_stock_with_thing_offer(
                offerer, venue, price=20, booking_limit_datetime=four_days_ago)

            PcObject.save(deposit, stock, user)

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

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

            # Then
            error_message = response.json
            assert response.status_code == 400
            assert error_message['global'] == [
                "La date limite de réservation de cette offre est dépassée"
            ]
    def test_only_returns_payments_with_given_message(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(booking1, offerer, 10, payment_message_name="ABCD123")
        payment2 = create_payment(booking2, offerer, 10, payment_message_name="EFGH456")

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

        # When
        payements_by_id = get_payments_by_message_id('ABCD123')

        # Then
        assert len(payements_by_id) == 1
        assert payements_by_id[0].paymentMessage.name == 'ABCD123'
    def test_returns_payments_with_last_payment_status_retry(self, app):
        # Given
        user = create_user()
        booking = create_booking(user)
        deposit = create_deposit(user)
        offerer = booking.stock.resolvedOffer.venue.managingOfferer
        retry_payment1 = create_payment(booking, offerer, 10)
        retry_payment2 = create_payment(booking, offerer, 10)
        pending_payment = create_payment(booking, offerer, 10, status=TransactionStatus.PENDING)
        retry_status1 = PaymentStatus()
        retry_status1.status = TransactionStatus.RETRY
        retry_payment1.statuses.append(retry_status1)
        retry_status2 = PaymentStatus()
        retry_status2.status = TransactionStatus.RETRY
        retry_payment2.statuses.append(retry_status2)

        PcObject.save(retry_payment1, retry_payment2, pending_payment, deposit)

        # When
        payments = find_retry_payments()

        # Then
        assert len(payments) == 2
        for p in payments:
            assert p.currentStatus.status == TransactionStatus.RETRY
    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_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 == []
示例#20
0
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
示例#21
0
        def test_check_offer_with_all_remaining_stocks(self, app):
            # given
            user = create_user(email='*****@*****.**')
            user2 = create_user(email='*****@*****.**')
            offerer = create_offerer()
            venue = create_venue(offerer)
            offer = create_offer_with_event_product(venue)
            recommendation = create_recommendation(offer, user)
            stock = create_stock_from_offer(offer, available=10)
            stock2 = create_stock_from_offer(offer, available=40)

            deposit = create_deposit(user2, amount=500)
            booking = create_booking(user2,
                                     stock,
                                     venue,
                                     recommendation,
                                     quantity=3)
            booking2 = create_booking(user2,
                                      stock2,
                                      venue,
                                      recommendation,
                                      quantity=11)

            PcObject.save(booking, booking2, deposit, user, offer, stock,
                          stock2, user2)

            # when
            result = offer.stockAlertMessage

            # then
            assert result == 'encore 36 places'
        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
示例#23
0
        def test_check_offer_with_one_unlimited_and_one_available_zero_stock(
                self, app):
            # given
            user = create_user(email='*****@*****.**')
            user2 = create_user(email='*****@*****.**')
            offerer = create_offerer()
            venue = create_venue(offerer)
            offer = create_offer_with_thing_product(venue)
            recommendation = create_recommendation(offer, user)
            stock = create_stock_from_offer(offer, available=None)
            stock2 = create_stock_from_offer(offer, available=0)

            deposit = create_deposit(user2, amount=500)
            booking = create_booking(user2,
                                     stock,
                                     venue,
                                     recommendation,
                                     quantity=3)

            PcObject.save(booking, deposit, user, offer, stock, stock2, user2)

            # when
            result = offer.stockAlertMessage

            # then
            assert result == 'plus de stock pour 2 offres'
    def test_generate_payment_details_csv_with_right_values(self, app):
        # given
        deactivate_feature(FeatureToggle.DEGRESSIVE_REIMBURSEMENT_RATE)
        user = create_user(email='*****@*****.**')
        deposit = create_deposit(user, amount=500, source='public')
        offerer1 = create_offerer()
        user_offerer1 = create_user_offerer(user, offerer1, validation_token=None)
        venue1 = create_venue(offerer1)
        bank_information1 = create_bank_information(id_at_providers='79387501900056', venue=venue1)
        stock1 = create_stock_with_thing_offer(offerer=offerer1, venue=venue1, price=10)
        booking1 = create_booking(user, stock1, venue=venue1, token='ABCDEF', is_used=True)
        booking2 = create_booking(user, stock1, venue=venue1, token='ABCDEG')

        PcObject.save(deposit, booking1, booking2, user_offerer1, bank_information1)

        generate_new_payments()

        reimbursement_details = find_all_offerer_reimbursement_details(offerer1.id)

        # when
        csv = generate_reimbursement_details_csv(reimbursement_details)

        # then
        assert _count_non_empty_lines(csv) == 2
        assert _get_header(csv,
                           1) == "2019;Juillet : remboursement 1ère quinzaine;La petite librairie;12345678912345;123 rue de Paris;FR7630006000011234567890189;La petite librairie;Test Book;Doe;John;ABCDEF;;10.00;Remboursement initié"
示例#25
0
        def when_user_patching_is_global_admin_is_activation_offer_and_existing_deposit_for_booking_user(
                self, app):
            # Given
            user = create_user(is_admin=False, can_book_free_offers=False)
            pro_user = create_user(email='*****@*****.**',
                                   is_admin=True,
                                   can_book_free_offers=False)
            offerer = create_offerer()
            user_offerer = create_user_offerer(pro_user, offerer)
            venue = create_venue(offerer)
            activation_offer = create_offer_with_event_product(
                venue, event_type=EventType.ACTIVATION)
            activation_event_occurrence = create_event_occurrence(
                activation_offer,
                beginning_datetime=Patch.tomorrow,
                end_datetime=Patch.tomorrow_plus_one_hour)
            stock = create_stock_from_event_occurrence(
                activation_event_occurrence,
                price=0,
                booking_limit_date=Patch.tomorrow_minus_one_hour)
            booking = create_booking(user, stock, venue=venue)
            deposit = create_deposit(user, amount=500)
            PcObject.save(booking, user_offerer, deposit)
            user_id = user.id
            url = '/bookings/token/{}'.format(booking.token)

            # When
            response = TestClient(
                app.test_client()).with_auth('*****@*****.**').patch(url)

            # Then
            deposits_for_user = Deposit.query.filter_by(userId=user_id).all()
            assert response.status_code == 405
            assert len(deposits_for_user) == 1
            assert deposits_for_user[0].amount == 500
    def test_generate_bookings_details_csv_with_headers_and_three_bookings_lines(
            self, app):
        # given
        user = create_user(email='*****@*****.**', idx=3)
        offerer = create_offerer(siren='987654321', name='Joe le Libraire')
        venue = create_venue(offerer)
        offer = create_offer_with_thing_product(venue)
        stock = create_stock(price=12, available=5, offer=offer)
        booking = create_booking(user,
                                 stock,
                                 date_created=datetime(2010, 1, 1, 0, 0, 0, 0))
        deposit1 = create_deposit(user, amount=100)

        PcObject.save(user, offerer, venue, offer, stock, booking, deposit1)

        bookings = Booking.query.all()

        expected_line = 'La petite librairie;Test Book;Doe;John;[email protected];2010-01-01 00:00:00;12;En attente'

        # when
        csv = generate_bookings_details_csv(bookings)

        # then
        assert _count_non_empty_lines(csv) == 2
        assert csv.split('\r\n')[1] == expected_line
示例#27
0
        def when_booking_limit_datetime_is_none(self, app):
            # Given
            user = create_user(email='*****@*****.**')
            offerer = create_offerer()
            deposit = create_deposit(user, amount=200)
            venue = create_venue(offerer)
            thing_offer = create_offer_with_thing_product(venue)
            stock = create_stock_with_thing_offer(offerer,
                                                  venue,
                                                  thing_offer,
                                                  price=20,
                                                  booking_limit_datetime=None)

            PcObject.save(deposit, stock, user)

            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
示例#28
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"
示例#29
0
        def test_check_offer_with_two_sold_out_one_unlimited_and_one_remaining_stocks(
                self, app):
            # given
            user = create_user(email='*****@*****.**')
            user2 = create_user(email='*****@*****.**')
            offerer = create_offerer()
            venue = create_venue(offerer)
            offer = create_offer_with_event_product(venue)
            recommendation = create_recommendation(offer, user)

            stock = create_stock_from_offer(offer, available=10)
            stock2 = create_stock_from_offer(offer, available=5)
            stock3 = create_stock_from_offer(offer, available=1)
            stock4 = create_stock_from_offer(offer, available=None)

            deposit = create_deposit(user2, amount=500)
            booking = create_booking(user2,
                                     stock2,
                                     venue,
                                     recommendation,
                                     quantity=5)
            booking2 = create_booking(user2,
                                      stock3,
                                      venue,
                                      recommendation,
                                      quantity=1)

            PcObject.save(booking, booking2, deposit, user, offer, stock,
                          stock2, stock3, stock4, user2)

            # when
            result = offer.stockAlertMessage

            # then
            assert result == 'plus de places pour 3 offres'
    def test_should_ignore_cancelled_bookings(self, app):
        # Given
        offerer = create_offerer(name='Offerer dans le 93')
        venue = create_venue(offerer, departement_code='93')
        offer = create_offer_with_thing_product(venue)
        stock = create_stock(offer=offer, price=10)

        user_in_93 = create_user(departement_code='93')
        create_deposit(user_in_93, amount=500)
        booking = create_booking(user_in_93, stock, quantity=1, is_cancelled=True)
        PcObject.save(booking)

        # When
        bookings_by_departement = _query_get_non_cancelled_bookings_by_user_departement()

        # Then
        assert len(bookings_by_departement) == 0