Skip to content

Commit

Permalink
(PC-23764)[API] feat: update connect_venue_provider to add all perm…
Browse files Browse the repository at this point in the history
…issions on new connection
  • Loading branch information
tcoudray-pass committed Jul 22, 2024
1 parent c0cbed3 commit f7b964d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/src/pcapi/core/providers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ def connect_venue_to_provider(
venue_provider.venueIdAtOfferProvider = id_at_provider

repository.save(venue_provider)

# TODO: For now, we add all permissions to new venue_provider
# Soon permissions will depend on the data sent by venue owner
providers_repository.add_all_permissions_for_venue_provider(venue_provider=venue_provider)
return venue_provider


Expand Down
10 changes: 10 additions & 0 deletions api/tests/core/providers/connect_provider_to_venue_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
from pcapi.core.providers.exceptions import ProviderWithoutApiImplementation
from pcapi.core.providers.exceptions import VenueSiretNotRegistered
import pcapi.core.providers.factories as providers_factories
from pcapi.core.providers.models import ApiResourceEnum
from pcapi.core.providers.models import PermissionEnum
from pcapi.core.providers.models import VenueProvider
from pcapi.core.providers.repository import get_venue_provider_permission_or_none


@pytest.mark.usefixtures("db_session")
Expand All @@ -29,6 +32,13 @@ def test_when_venue_id_at_offer_provider_is_given(can_be_synchronized):
venue_provider = VenueProvider.query.one()
assert venue_provider.venueIdAtOfferProvider == venue_id_at_offer_provider
can_be_synchronized.assert_called_once_with("id_for_remote_system")
# Check permissions have been added
for resource in ApiResourceEnum:
for permission in PermissionEnum:
assert (
get_venue_provider_permission_or_none(venue_provider.id, resource=resource, permission=permission)
is not None
)


@pytest.mark.usefixtures("db_session")
Expand Down
30 changes: 30 additions & 0 deletions api/tests/routes/pro/post_venue_provider_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import pcapi.core.offerers.factories as offerers_factories
import pcapi.core.providers.factories as providers_factories
from pcapi.core.providers.factories import CinemaProviderPivotFactory
from pcapi.core.providers.models import ApiResourceEnum
from pcapi.core.providers.models import PermissionEnum
from pcapi.core.providers.models import Provider
from pcapi.core.providers.models import VenueProvider
import pcapi.core.providers.repository as providers_repository
Expand Down Expand Up @@ -55,6 +57,17 @@ def test_when_venue_provider_is_successfully_created(

venue_provider_id = response.json["id"]
mock_synchronize_venue_provider.assert_called_once_with(venue_provider_id)
# assert permissions have been created
for resource in ApiResourceEnum:
for permission in PermissionEnum:
assert (
providers_repository.get_venue_provider_permission_or_none(
venue_provider_id=venue_provider.id,
resource=resource,
permission=permission,
)
is not None
)

@pytest.mark.usefixtures("db_session")
@patch("pcapi.workers.venue_provider_job.synchronize_venue_provider")
Expand Down Expand Up @@ -87,6 +100,7 @@ def test_when_add_allocine_stocks_provider_with_default_settings_at_import(
assert response.json["quantity"] == 50
venue_provider = VenueProvider.query.one()
mock_synchronize_venue_provider.assert_called_once_with(venue_provider)
assert len(venue_provider.permissions) == 0

@pytest.mark.usefixtures("db_session")
@patch("pcapi.workers.venue_provider_job.synchronize_venue_provider")
Expand Down Expand Up @@ -117,6 +131,7 @@ def test_when_add_allocine_stocks_provider_for_venue_without_siret(self, mock_sy
assert response.json["quantity"] == 50
venue_provider = VenueProvider.query.one()
mock_synchronize_venue_provider.assert_called_once_with(venue_provider)
assert len(venue_provider.permissions) == 0

@pytest.mark.usefixtures("db_session")
@patch("pcapi.workers.venue_provider_job.venue_provider_job.delay")
Expand Down Expand Up @@ -195,6 +210,17 @@ def test_when_venue_id_at_offer_provider_is_ignored_for_pro(
assert "id" in response.json
venue_provider_id = response.json["id"]
mock_synchronize_venue_provider.assert_called_once_with(venue_provider_id)
# assert permissions have been created
for resource in ApiResourceEnum:
for permission in PermissionEnum:
assert (
providers_repository.get_venue_provider_permission_or_none(
venue_provider_id=venue_provider.id,
resource=resource,
permission=permission,
)
is not None
)

@pytest.mark.usefixtures("db_session")
@patch("pcapi.core.providers.api._siret_can_be_synchronized", lambda *args: True)
Expand Down Expand Up @@ -308,6 +334,8 @@ def test_create_venue_provider_for_cds_cinema(self, mock_get_venue_movies, mock_
assert response.json["provider"]["id"] == provider.id
assert response.json["venueId"] == venue.id
assert response.json["venueIdAtOfferProvider"] == cds_pivot.idAtProvider
venue_provider = VenueProvider.query.one()
assert len(venue_provider.permissions) == 0

@pytest.mark.usefixtures("db_session")
@patch("pcapi.workers.venue_provider_job.synchronize_ems_venue_provider")
Expand All @@ -329,6 +357,8 @@ def test_create_venue_provider_for_ems_cinema(self, mocked_synchronize_ems_venue
assert response.json["venueIdAtOfferProvider"] == pivot.idAtProvider
venue_provider = VenueProvider.query.one()
mocked_synchronize_ems_venue_provider.assert_called_once_with(venue_provider)
venue_provider = VenueProvider.query.one()
assert len(venue_provider.permissions) == 0


class Returns400Test:
Expand Down

0 comments on commit f7b964d

Please sign in to comment.