Ejemplo n.º 1
0
def validate_offerer_attachment(token) -> str:
    try:
        api.validate_offerer_attachment(token)
    except ValidationTokenNotFoundError:
        errors = ResourceNotFoundError()
        errors.add_error(
            "validation", "Aucun(e) objet ne correspond à ce code de validation" + " ou l'objet est déjà validé"
        )
        raise errors

    return "Validation du rattachement de la structure effectuée"
Ejemplo n.º 2
0
    def test_pro_role_is_added_to_user(self):
        # Given
        applicant = users_factories.UserFactory()
        user_offerer = offers_factories.UserOffererFactory(
            user=applicant, validationToken="TOKEN")

        # When
        offerers_api.validate_offerer_attachment(user_offerer.validationToken)

        # Then
        assert applicant.has_pro_role
Ejemplo n.º 3
0
    def test_offerer_attachment_is_validated(self):
        # Given
        applicant = users_factories.UserFactory()
        user_offerer = offers_factories.UserOffererFactory(
            user=applicant, validationToken="TOKEN")

        # When
        offerers_api.validate_offerer_attachment(user_offerer.validationToken)

        # Then
        assert user_offerer.validationToken is None
Ejemplo n.º 4
0
    def test_do_not_validate_attachment_if_token_does_not_exist(self):
        # Given
        applicant = users_factories.UserFactory()
        user_offerer = offers_factories.UserOffererFactory(
            user=applicant, validationToken="TOKEN")

        # When
        with pytest.raises(ValidationTokenNotFoundError):
            offerers_api.validate_offerer_attachment("OTHER TOKEN")

        # Then
        assert not applicant.has_pro_role
        assert user_offerer.validationToken == "TOKEN"
Ejemplo n.º 5
0
    def test_send_validation_confirmation_email(
            self, mocked_send_validation_confirmation_email_to_pro):
        # Given
        applicant = users_factories.UserFactory()
        user_offerer = offers_factories.UserOffererFactory(
            user=applicant, validationToken="TOKEN")

        # When
        offerers_api.validate_offerer_attachment(user_offerer.validationToken)

        # Then
        mocked_send_validation_confirmation_email_to_pro.assert_called_once_with(
            user_offerer)