-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(PC-33659)[API] chore: script to disabled old integration provider
- Loading branch information
1 parent
a808850
commit 75d397d
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
api/src/pcapi/scripts/provider_clean_old_integration_data/main.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import logging | ||
|
||
from pcapi.core.offers import models as offers_models | ||
from pcapi.core.providers import models as providers_models | ||
from pcapi.flask_app import app | ||
from pcapi.repository import transaction | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
_LEGACY_API_PROVIDERS_IDS = [ | ||
15, # TiteLive Stocks (Epagine / Place des libraires.com) | ||
59, # Praxiel/Inférence | ||
58, # FNAC | ||
23, # www.leslibraires.fr | ||
66, # Decitre | ||
63, # Librisoft | ||
68, # TMIC-Ellipses | ||
65, # Mollat | ||
67, # CDI-Bookshop | ||
] | ||
|
||
|
||
def clean_old_provider_data(provider_ids: list[int]) -> None: | ||
for provider_id in provider_ids: | ||
with transaction(): | ||
provider = providers_models.Provider.query.get(provider_id) | ||
|
||
logger.info("Cleaning data for provider %s (id: %s)", provider.name, provider.id) | ||
|
||
if "[DÉPRÉCIÉ]" not in provider.name: | ||
provider.name = f"[DÉPRÉCIÉ] {provider.name}" | ||
provider.enabledForPro = False | ||
provider.isActive = False | ||
|
||
offers_models.Offer.query.filter(offers_models.Offer.lastProviderId == provider_id).update( | ||
{"idAtProvider": None}, synchronize_session=False | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
app.app_context().push() | ||
clean_old_provider_data(_LEGACY_API_PROVIDERS_IDS) |
37 changes: 37 additions & 0 deletions
37
api/tests/scripts/provider_clean_old_integraiton_data/main_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import pytest | ||
|
||
from pcapi.core.offers import factories as offers_factories | ||
from pcapi.core.providers import factories as providers_factories | ||
from pcapi.models import db | ||
from pcapi.scripts.provider_clean_old_integration_data.main import clean_old_provider_data | ||
|
||
|
||
@pytest.mark.usefixtures("db_session") | ||
def test_clean_old_provider_data(): | ||
provider_1 = providers_factories.ProviderFactory(name="Old Provider that should be deprecated") | ||
provider_already_deprecated = providers_factories.ProviderFactory(name="[DÉPRÉCIÉ] Old Provider") | ||
provider_3 = providers_factories.ProviderFactory() | ||
offer_provider_1 = offers_factories.ThingOfferFactory(lastProvider=provider_1, idAtProvider="12345") | ||
offer_provider_2 = offers_factories.EventOfferFactory(lastProvider=provider_already_deprecated, idAtProvider=None) | ||
offer_provider_3 = offers_factories.ThingOfferFactory(lastProvider=provider_3, idAtProvider="offerId3") | ||
|
||
clean_old_provider_data([provider_1.id, provider_already_deprecated.id]) | ||
|
||
db.session.refresh(offer_provider_1) | ||
db.session.refresh(offer_provider_2) | ||
db.session.refresh(offer_provider_3) | ||
|
||
# should be deprecated | ||
assert provider_1.name == "[DÉPRÉCIÉ] Old Provider that should be deprecated" | ||
assert not provider_1.enabledForPro | ||
assert not provider_1.isActive | ||
assert not offer_provider_1.idAtProvider | ||
assert provider_already_deprecated.name == "[DÉPRÉCIÉ] Old Provider" | ||
assert not provider_already_deprecated.enabledForPro | ||
assert not provider_already_deprecated.isActive | ||
assert not offer_provider_2.idAtProvider | ||
|
||
# should stay the same | ||
assert offer_provider_3.idAtProvider | ||
assert provider_3.enabledForPro | ||
assert provider_3.isActive |