Пример #1
0
    def test_value_error_is_raised_if_payments_ids_do_not_match_payments(self):
        # given
        payments = [
            create_payment(Booking(), Offerer(), 10, idx=111),
            create_payment(Booking(), Offerer(), 10, idx=222),
        ]
        ids_to_ban = [222, 333]

        # when
        with pytest.raises(UnmatchedPayments) as e:
            apply_banishment(payments, ids_to_ban)

        # then
        assert e.value.payment_ids == {333}
Пример #2
0
    def test_no_payments_to_retry_if_all_are_banned(self):
        # given
        payments = [
            create_payment(Booking(), Offerer(), 10, idx=111),
            create_payment(Booking(), Offerer(), 10, idx=222),
        ]
        ids_to_ban = [111, 222]

        # when
        banned_payments, retry_payments = apply_banishment(
            payments, ids_to_ban)

        # then
        assert len(banned_payments) == 2
        assert retry_payments == []
Пример #3
0
    def test_no_payments_are_returned_if_no_ids_are_provided(self):
        # given
        payments = [
            create_payment(Booking(), Offerer(), 10, idx=111),
            create_payment(Booking(), Offerer(), 10, idx=222),
        ]
        ids_to_ban = []

        # when
        banned_payments, retry_payments = apply_banishment(
            payments, ids_to_ban)

        # then
        assert banned_payments == []
        assert retry_payments == []
Пример #4
0
def create_activated_user_offerer(
    csv_row: List[str],
    find_user: Callable = find_user_by_email,
    find_offerer: Callable = find_by_siren,
    find_user_offerer: Callable = find_one_or_none_by_user_id_and_offerer_id,
) -> UserOfferer:
    user = find_user(csv_row[USER_EMAIL_COLUMN_INDEX])
    if not user:
        user = User()
    filled_user = fill_user_from(csv_row, user)
    repository.save(filled_user)

    offerer = find_offerer(csv_row[OFFERER_SIREN_COLUMN_INDEX])
    if not offerer:
        offerer = Offerer()

    filled_offerer = fill_offerer_from(csv_row, offerer)
    repository.save(filled_offerer)

    virtual_venue = find_by_managing_offerer_id(filled_offerer.id)
    if not virtual_venue:
        filled_virtual_venue = create_digital_venue(offerer)
        repository.save(filled_virtual_venue)

    user_offerer = find_user_offerer(filled_user.id, filled_offerer.id)
    if not user_offerer:
        filled_user_offerer = fill_user_offerer_from(UserOfferer(),
                                                     filled_user,
                                                     filled_offerer)
        repository.save(filled_user_offerer)
        return filled_user_offerer
    return None
Пример #5
0
def create_offerer():
    siren = request.json["siren"]
    offerer = find_by_siren(siren)

    if offerer is not None:
        user_offerer = offerer.grant_access(current_user)
        user_offerer.generate_validation_token()
        repository.save(user_offerer)

        try:
            send_ongoing_offerer_attachment_information_email_to_pro(
                user_offerer)
        except MailServiceException as mail_service_exception:
            app.logger.exception(
                "[send_ongoing_offerer_attachment_information_email_to_pro] "
                "Mail service failure",
                mail_service_exception,
            )
    else:
        offerer = Offerer()
        offerer.populate_from_dict(request.json)
        digital_venue = create_digital_venue(offerer)
        offerer.generate_validation_token()
        user_offerer = offerer.grant_access(current_user)
        repository.save(offerer, digital_venue, user_offerer)
        user = User.query.filter_by(id=user_offerer.userId).first()

        _send_to_pro_offer_validation_in_progress_email(user, offerer)

    _send_to_pc_admin_offerer_to_validate_email(offerer, user_offerer)

    return jsonify(get_dict_offerer(offerer)), 201
Пример #6
0
    def test_payments_not_matching_given_ids_must_be_retried(self):
        # given
        payments = [
            create_payment(Booking(), Offerer(), 10, idx=111),
            create_payment(Booking(), Offerer(), 10, idx=222),
            create_payment(Booking(), Offerer(), 10, idx=333),
            create_payment(Booking(), Offerer(), 10, idx=444),
        ]
        ids_to_ban = [222, 333]

        # when
        _banned_payments, retry_payments = apply_banishment(
            payments, ids_to_ban)

        # then
        assert len(retry_payments) == 2
        for p in retry_payments:
            assert p.currentStatus.status == TransactionStatus.RETRY
            assert p.id not in ids_to_ban
    def test_returns_an_user_with_data_from_csv_row(self):
        # when
        offerer = fill_offerer_from(self.csv_row, Offerer())

        # then
        assert offerer.siren == "362521879"
        assert offerer.name == "MyBletcheyCompany"
        assert offerer.thumbCount == 0
        assert offerer.postalCode == "29200"
        assert offerer.city == "Bletchley"
        assert offerer.dateCreated == datetime(2019, 10, 13)
Пример #8
0
def _generate_offerer(data):
    offerer = Offerer()
    offerer.populate_from_dict(data)

    if not settings.IS_INTEGRATION:
        offerer.generate_validation_token()
    return offerer
Пример #9
0
def fill_offerer_from(csv_row: List[str], offerer: Offerer) -> Offerer:
    offerer.siren = csv_row[OFFERER_SIREN_COLUMN_INDEX]
    offerer.name = csv_row[OFFERER_NAME_COLUMN_INDEX]
    offerer.thumbCount = 0
    offerer.postalCode = csv_row[OFFERER_POSTAL_CODE_COLUMN_INDEX]
    offerer.city = csv_row[OFFERER_CITY_COLUMN_INDEX]
    offerer.dateCreated = datetime.utcnow()
    return offerer
Пример #10
0
    def when_feature_send_mail_to_users_is_enabled_sends_email_to_all_users_linked_to_offerer(
            self, mock_retrieve_data_for_new_offerer_validation_email):
        # Given
        offerer = Offerer()
        mocked_send_email = Mock()

        # When
        send_validation_confirmation_email_to_pro(offerer, mocked_send_email)

        # Then
        mock_retrieve_data_for_new_offerer_validation_email.assert_called_once_with(
            offerer)
        mocked_send_email.assert_called_once_with(
            data={"Mj-TemplateID": 778723})
Пример #11
0
def create_offerer(
    address: str = None,
    city: str = "Montreuil",
    date_created: datetime = datetime.utcnow(),
    date_modified_at_last_provider: datetime = None,
    idx: int = None,
    id_at_providers: str = None,
    is_active: bool = True,
    last_provider_id: int = None,
    name: str = "Test Offerer",
    postal_code: str = "93100",
    siren: Optional[str] = "123456789",
    thumb_count: int = 0,
    validation_token: str = None,
) -> Offerer:
    offerer = Offerer()
    offerer.address = address
    offerer.city = city
    offerer.dateCreated = date_created
    offerer.dateModifiedAtLastProvider = date_modified_at_last_provider
    offerer.id = idx
    offerer.idAtProviders = id_at_providers
    offerer.isActive = is_active
    offerer.lastProviderId = last_provider_id
    offerer.name = name
    offerer.postalCode = postal_code
    offerer.siren = siren
    offerer.thumbCount = thumb_count
    offerer.validationToken = validation_token

    return offerer
Пример #12
0
def _validate_offerer(offerer: Offerer, user_offerer: UserOfferer):
    offerer.validationToken = None
    user_offerer.validationToken = None
    repository.save(offerer, user_offerer)
Пример #13
0
def get_dict_offerer(offerer: Offerer) -> dict:
    offerer.append_user_has_access_attribute(user_id=current_user.id,
                                             is_admin=current_user.isAdmin)

    return as_dict(offerer, includes=OFFERER_INCLUDES)