コード例 #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_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 == []
コード例 #3
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 == []
コード例 #4
0
def create_activated_user_offerer(
    csv_row: list[str],
    find_user: Callable = find_user_by_email,
    find_offerer: Callable = find_offerer_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_venue_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 test_raise_error_when_offerer_relative_to_csv_not_created(self):
        # given
        blake = ProFactory(email="*****@*****.**", id=123)
        blakes_company = Offerer(siren="362521879", name="MyBletcheyCompany")

        # when
        with pytest.raises(OffererNotCreatedException):
            fill_user_offerer_from(UserOfferer(), blake, blakes_company)
コード例 #6
0
    def from_orm(cls,
                 offerer: Offerer,
                 venue_stats_by_ids: Optional[Dict[
                     int, VenueStatsResponseModel]] = None):  # type: ignore
        offerer.apiKey = {
            "maxAllowed": settings.MAX_API_KEY_PER_OFFERER,
            "prefixes": get_api_key_prefixes(offerer.id),
        }
        if venue_stats_by_ids:
            for managedVenue in offerer.managedVenues:
                managedVenue.stats = venue_stats_by_ids[managedVenue.id]

        offerer.hasDigitalVenueAtLeastOneOffer = has_digital_venue_with_at_least_one_offer(
            offerer.id)
        offerer.hasMissingBankInformation = not offerer.demarchesSimplifieesApplicationId and (
            has_physical_venue_without_draft_or_accepted_bank_information(
                offerer.id) or offerer.hasDigitalVenueAtLeastOneOffer)
        return super().from_orm(offerer)
コード例 #7
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
コード例 #8
0
def create_offerer_from_csv(row: dict) -> Offerer:
    offerer = Offerer()
    offerer.name = row["nom_structure"] if row["nom_structure"] else row["Name"]
    offerer.siren = row["SIREN"]
    offerer.address = _get_address_from_row(row)
    offerer.postalCode = _get_postal_code(row)
    offerer.city = row["City"]

    return offerer
コード例 #9
0
    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)
コード例 #10
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
コード例 #11
0
ファイル: api.py プロジェクト: pass-culture/pass-culture-api
def create_offerer(user: User, offerer_informations: CreateOffererQueryModel):
    offerer = find_offerer_by_siren(offerer_informations.siren)

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

    else:
        offerer = Offerer()
        offerer.address = offerer_informations.address
        offerer.city = offerer_informations.city
        offerer.name = offerer_informations.name
        offerer.postalCode = offerer_informations.postalCode
        offerer.siren = offerer_informations.siren
        offerer.generate_validation_token()
        digital_venue = create_digital_venue(offerer)
        user_offerer = offerer.grant_access(user)
        repository.save(offerer, digital_venue, user_offerer)

    _send_to_pc_admin_offerer_to_validate_email(offerer, user_offerer)

    return user_offerer
コード例 #12
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)
コード例 #13
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,
    date_validated: datetime = 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
    offerer.dateValidated = date_validated

    return offerer