Beispiel #1
0
def create_user_offerer(user: User, offerer: Offerer) -> UserOfferer:
    user_offerer = UserOfferer()
    user_offerer.user = user
    user_offerer.offerer = offerer
    user_offerer.rights = RightsType.editor

    return user_offerer
Beispiel #2
0
def fill_user_offerer_from(user_offerer: UserOfferer, created_user: User,
                           created_offerer: Offerer) -> UserOfferer:
    if created_user.id is None:
        raise UserNotCreatedException()
    if created_offerer.id is None:
        raise OffererNotCreatedException()

    user_offerer.user = created_user
    user_offerer.offerer = created_offerer
    return user_offerer
Beispiel #3
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
Beispiel #4
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)
Beispiel #5
0
def create_user_offerer(user: User,
                        offerer: Offerer,
                        idx: int = None,
                        is_admin: bool = False,
                        validation_token: str = None) -> UserOfferer:
    user_offerer = UserOfferer()
    user_offerer.id = idx
    user_offerer.offerer = offerer
    user_offerer.rights = RightsType.admin if is_admin else RightsType.editor
    user_offerer.user = user
    user_offerer.validationToken = validation_token

    return user_offerer
Beispiel #6
0
    def test_returns_a_user_offerer_built_with_user_and_offerer_relative_to_csv_row(
            self):
        # given
        blake = ProFactory(email="*****@*****.**", id=123)
        blakes_company = OffererFactory(siren="362521879",
                                        name="MyBletcheyCompany",
                                        id=234)

        # when
        user_offerer = fill_user_offerer_from(UserOfferer(), blake,
                                              blakes_company)

        # then
        assert user_offerer.user == blake
        assert user_offerer.offerer == blakes_company
Beispiel #7
0
def create_user_offerer(user: User,
                        offerer: Offerer,
                        idx: int = None,
                        validation_token: str = None) -> UserOfferer:
    user_offerer = UserOfferer()
    user_offerer.id = idx
    user_offerer.offerer = offerer
    user_offerer.user = user
    user_offerer.validationToken = validation_token

    return user_offerer
Beispiel #8
0
    def test_ignores_empty_lines(self, mocked_create_activated_user_offerer):
        # given
        create_activated_user_offerer.return_value = UserOfferer()
        csv_reader = [
            ["nom", "prénom", "email"],
            [],
            ["Mortimer", "Philip",
             "*****@*****.**" % random_token()],
            [""],
            ["Mortimer", "Philip",
             "*****@*****.**" % random_token()],
        ]

        # when
        user_offerers = iterate_rows_for_user_offerers(csv_reader)

        # then
        assert len(user_offerers) == 2
Beispiel #9
0
def create_user_offerer(user: User, offerer: Offerer) -> UserOfferer:
    user_offerer = UserOfferer()
    user_offerer.user = user
    user_offerer.offerer = offerer

    return user_offerer
Beispiel #10
0
def _validate_offerer(offerer: Offerer, user_offerer: UserOfferer):
    offerer.validationToken = None
    user_offerer.validationToken = None
    repository.save(offerer, user_offerer)