Exemplo n.º 1
0
def validate_new_offerer(token) -> str:
    try:
        api.validate_offerer(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 effectuée"
Exemplo n.º 2
0
    def test_offerer_is_validated(self,
                                  mocked_async_index_offers_of_venue_ids):
        # Given
        applicant = users_factories.UserFactory()
        user_offerer = offers_factories.UserOffererFactory(
            user=applicant, offerer__validationToken="TOKEN")

        # When
        offerers_api.validate_offerer(user_offerer.offerer.validationToken)

        # Then
        assert user_offerer.offerer.validationToken is None
        assert user_offerer.offerer.dateValidated == datetime.utcnow()
Exemplo n.º 3
0
    def test_do_not_validate_attachment_if_token_does_not_exist(
            self, mocked_async_index_offers_of_venue_ids):
        # Given
        applicant = users_factories.UserFactory()
        user_offerer = offers_factories.UserOffererFactory(
            user=applicant, offerer__validationToken="TOKEN")

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

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

        # When
        offerers_api.validate_offerer(user_offerer.offerer.validationToken)

        # Then
        mocked_send_validation_confirmation_email_to_pro.assert_called_once_with(
            user_offerer.offerer)
Exemplo n.º 5
0
    def test_pro_role_is_added_to_user(self,
                                       mocked_async_index_offers_of_venue_ids):
        # Given
        applicant = users_factories.UserFactory()
        user_offerer = offers_factories.UserOffererFactory(
            user=applicant, offerer__validationToken="TOKEN")
        another_applicant = users_factories.UserFactory()
        another_user_on_same_offerer = offers_factories.UserOffererFactory(
            user=another_applicant, validationToken="TOKEN")

        # When
        offerers_api.validate_offerer(user_offerer.offerer.validationToken)

        # Then
        assert applicant.has_pro_role
        assert not another_applicant.has_pro_role
        assert another_user_on_same_offerer.validationToken is not None
Exemplo n.º 6
0
    def test_managed_venues_are_reindexed(
            self, mocked_async_index_offers_of_venue_ids):
        # Given
        applicant = users_factories.UserFactory()
        user_offerer = offers_factories.UserOffererFactory(
            user=applicant, offerer__validationToken="TOKEN")
        venue_1 = offerers_factories.VenueFactory(
            managingOfferer=user_offerer.offerer)
        venue_2 = offerers_factories.VenueFactory(
            managingOfferer=user_offerer.offerer)

        # When
        offerers_api.validate_offerer(user_offerer.offerer.validationToken)

        # Then
        mocked_async_index_offers_of_venue_ids.assert_called_once()
        called_args, _ = mocked_async_index_offers_of_venue_ids.call_args
        assert set(called_args[0]) == {venue_1.id, venue_2.id}