Esempio n. 1
0
def maybe_send_offerer_validation_email(offerer: Offerer,
                                        user_offerer: UserOfferer) -> bool:
    if offerer.isValidated and user_offerer.isValidated:
        return None
    email = make_validation_email_object(offerer, user_offerer)
    recipients = [settings.ADMINISTRATION_EMAIL_ADDRESS]
    return mails.send(recipients=recipients, data=email)
def maybe_send_offerer_validation_email(
        offerer: Offerer, user_offerer: UserOfferer,
        send_email: Callable[[dict], bool]) -> bool:
    if offerer.isValidated and user_offerer.isValidated:
        return None
    email = make_validation_email_object(offerer, user_offerer)
    recipients = [settings.ADMINISTRATION_EMAIL_ADDRESS]
    email["Html-part"], email["To"] = compute_email_html_part_and_recipients(
        email["Html-part"], recipients)
    return send_email(data=email)
Esempio n. 3
0
    def test_should_return_subject_with_correct_departement_code(self):
        # Given
        user = create_user(departement_code="93")
        offerer = create_offerer(postal_code="95490")
        user_offerer = create_user_offerer(user=user, offerer=offerer)

        # When
        email_object = make_validation_email_object(
            user_offerer=user_offerer, offerer=offerer, get_by_siren=get_by_siren_stub
        )

        # Then
        assert email_object.get("Subject") == "95 - inscription / rattachement PRO à valider : Test Offerer"
Esempio n. 4
0
def test_validation_email_object_does_not_include_validation_link_if_offerer_is_already_validated(
        app):
    # Given
    offerer = create_offerer()
    user = create_user()
    user_offerer = create_user_offerer(user=user, offerer=offerer)

    # When
    email = make_validation_email_object(offerer,
                                         user_offerer,
                                         get_by_siren=get_by_siren_stub)

    # Then
    html = BeautifulSoup(email["Html-part"], features="html.parser")
    assert not html.select("div.offerer strong.validation a")
    assert html.select("div.offerer h2")[0].text == "Structure :"
def test_validation_email_should_neither_return_clearTextPassword_nor_totallysafepsswd(
        app):
    # Given
    offerer = create_offerer()
    pro = users_factories.ProFactory.build()
    user_offerer = create_user_offerer(user=pro, offerer=offerer)

    mocked_api_entreprises = get_by_siren_stub

    # When
    email = make_validation_email_object(offerer,
                                         user_offerer,
                                         get_by_siren=mocked_api_entreprises)

    # Then
    email_html_soup = BeautifulSoup(email["Html-part"], features="html.parser")
    assert "clearTextPassword" not in str(email_html_soup)
    assert "totallysafepsswd" not in str(email_html_soup)
def test_validation_email_object_does_not_include_validation_link_if_user_offerer_is_already_validated(
        app):
    # Given
    offerer = create_offerer()
    pro = users_factories.ProFactory.build()
    user_offerer = create_user_offerer(pro, offerer)

    # When
    email = make_validation_email_object(offerer,
                                         user_offerer,
                                         get_by_siren=get_by_siren_stub)

    # Then
    html = BeautifulSoup(email["Html-part"], features="html.parser")
    assert "Nouveau rattachement :" not in [
        h2.text for h2 in html.select("section[data-testId='summary'] h2")
    ]
    assert not html.select(
        "section[data-testId='user_offerer'] strong.validation a")
    assert html.select(
        "section[data-testId='user_offerer'] h2")[0].text == "Rattachement :"
def test_write_object_validation_email(app):
    # Given
    validation_token = secrets.token_urlsafe(20)
    offerer = create_offerer(
        idx=123,
        siren="732075312",
        address="122 AVENUE DE FRANCE",
        city="Paris",
        postal_code="75013",
        name="Accenture",
        validation_token=validation_token,
    )

    user = users_factories.ProFactory.build(
        departementCode="75",
        email="*****@*****.**",
        publicName="Test",
        validationToken=validation_token,
    )

    user_offerer = create_user_offerer(user=user,
                                       offerer=offerer,
                                       validation_token=validation_token)

    # When
    email = make_validation_email_object(offerer,
                                         user_offerer,
                                         get_by_siren=get_by_siren_stub)

    # Then
    html = BeautifulSoup(email["Html-part"], features="html.parser")
    assert html.h1.text == "Inscription ou rattachement PRO à valider"

    summary_section = html.select_one("section[data-testId='summary']")
    assert summary_section.select("h2")[0].a.text == "Structure :"
    assert summary_section.select(
        "h2")[0].a["href"] == "http://localhost:3001/accueil?structure=PM"
    assert summary_section.select("h2")[1].text == "Utilisateur :"
    assert summary_section.select("h2")[2].text == "Nouveau rattachement :"
    assert summary_section.select("strong")[0].a[
        "href"] == "http://localhost:5000/validate/user-offerer/{}".format(
            user_offerer.validationToken)
    assert summary_section.select("strong")[0].a.text == "cliquez ici"
    assert summary_section.select("h2")[3].text == "Nouvelle structure :"
    assert summary_section.select("strong")[1].a[
        "href"] == "http://localhost:5000/validate/offerer/{}".format(
            offerer.validationToken)
    assert summary_section.select("strong")[1].a.text == "cliquez ici"

    offerer_section = html.select_one("section[data-testId='offerer']")
    assert offerer_section.h2.text == "Nouvelle structure :"
    assert offerer_section.h3.text == "Infos API entreprise :"
    assert offerer_section.strong.a[
        "href"] == "http://localhost:5000/validate/offerer/{}".format(
            offerer.validationToken)
    assert offerer_section.strong.a.text == "cliquez ici"

    user_offerer_section = html.select_one(
        "section[data-testId='user_offerer']")
    assert user_offerer_section.h2.text == "Nouveau rattachement :"
    assert user_offerer_section.h3.text == "Utilisateur :"
    assert user_offerer_section.strong.a[
        "href"] == "http://localhost:5000/validate/user-offerer/{}".format(
            user_offerer.validationToken)
    assert user_offerer_section.strong.a.text == "cliquez ici"

    offerer_data = offerer_section.select_one("pre.offerer-data").text
    assert "'address': '122 AVENUE DE FRANCE'" in offerer_data
    assert "'city': 'Paris'" in offerer_data
    assert "'name': 'Accenture'" in offerer_data
    assert "'postalCode': '75013'" in offerer_data
    assert "'siren': '732075312'" in offerer_data
    assert "'validationToken': '{}'".format(validation_token) in offerer_data

    api_entreprise_data = offerer_section.select_one(
        "pre.api-entreprise-data").text
    assert "'other_etablissements_sirets':['39525144000032','39525144000065']" in api_entreprise_data.replace(
        " ", "").replace("\n", "")
    assert "etablissement_siege" in api_entreprise_data
Esempio n. 8
0
def test_write_object_validation_email(app):
    # Given
    validation_token = secrets.token_urlsafe(20)
    offerer = create_offerer(
        siren="732075312",
        address="122 AVENUE DE FRANCE",
        city="Paris",
        postal_code="75013",
        name="Accenture",
        validation_token=validation_token,
    )

    user = create_user(
        is_beneficiary=False,
        departement_code="75",
        email="*****@*****.**",
        public_name="Test",
        validation_token=validation_token,
    )

    user_offerer = create_user_offerer(user=user,
                                       offerer=offerer,
                                       validation_token=validation_token)

    # When
    email = make_validation_email_object(offerer,
                                         user_offerer,
                                         get_by_siren=get_by_siren_stub)

    # Then
    html = BeautifulSoup(email["Html-part"], features="html.parser")
    assert html.h1.text == "Inscription ou rattachement PRO à valider"

    div_offerer = html.select("div.offerer")[0]
    assert div_offerer.h2.text == "Nouvelle structure :"
    assert div_offerer.h3.text == "Infos API entreprise :"
    assert div_offerer.strong.a[
        "href"] == "http://localhost/validate/offerer/{}".format(
            offerer.validationToken)
    assert div_offerer.strong.a.text == "cliquez ici"

    div_user_offerer = html.select("div.user_offerer")[0]
    assert div_user_offerer.h2.text == "Nouveau rattachement :"
    assert div_user_offerer.h3.text == "Utilisateur :"
    assert div_user_offerer.strong.a[
        "href"] == "http://localhost/validate/user-offerer/{}".format(
            user_offerer.validationToken)
    assert div_user_offerer.strong.a.text == "cliquez ici"

    offerer_data = div_offerer.select("pre.offerer-data")[0].text
    assert "'address': '122 AVENUE DE FRANCE'" in offerer_data
    assert "'city': 'Paris'" in offerer_data
    assert "'name': 'Accenture'" in offerer_data
    assert "'postalCode': '75013'" in offerer_data
    assert "'siren': '732075312'" in offerer_data
    assert "'validationToken': '{}'".format(validation_token) in offerer_data

    api_entreprise_data = div_offerer.select("pre.api-entreprise-data")[0].text
    assert "'other_etablissements_sirets':['39525144000032','39525144000065']" in api_entreprise_data.replace(
        " ", "").replace("\n", "")
    assert "etablissement_siege" in api_entreprise_data