Skip to content

Commit

Permalink
(BSR)[API] fix: yes we hack provider creation
Browse files Browse the repository at this point in the history
This has been fixed by hand for this week, it will need to be HF on staging before Wednesday
  • Loading branch information
R0ntheo committed Jul 2, 2024
1 parent 0b0bfc2 commit 48b1e50
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 6 additions & 2 deletions api/src/pcapi/scripts/beneficiary/import_test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,15 @@ def _add_or_update_admin(update_if_exists: bool) -> None:


def _create_provider(venue: offerers_models.Venue, row: dict) -> None:
formatted_email = sanitize_email(row["Mail"]).replace("_", "-")
provider = providers_models.Provider(name=row["Prénom"])
offerer_provider = offerers_models.OffererProvider(offerer=venue.managingOfferer, provider=provider)
prefix = f"staging_{row['Mail']}"
prefix = f"staging_{formatted_email}"
key = offerers_models.ApiKey(
offerer=venue.managingOfferer, provider=provider, prefix=prefix, secret=crypto.hash_public_api_key(row["Mail"])
offerer=venue.managingOfferer,
provider=provider,
prefix=prefix,
secret=crypto.hash_public_api_key(formatted_email),
)
venue_provider = providers_models.VenueProvider(venue=venue, provider=provider)

Expand Down
11 changes: 6 additions & 5 deletions api/tests/scripts/beneficiary/import_test_users_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pcapi.core.users.models import User
from pcapi.scripts.beneficiary import import_test_users
from pcapi.utils import crypto
from pcapi.utils.email import sanitize_email


AGE18_ELIGIBLE_BIRTH_DATE = datetime.datetime.utcnow() - relativedelta(years=18, months=4)
Expand All @@ -24,7 +25,7 @@
Pro,Pierre,[email protected],0123456789,06,06000,2000-01-01,PRO,11122233,PierrePro$123,interne:test
"""

BOUNTY_EMAIL = "unit-test-bùg-bounty-hunter-0123456789abcdef@bugbounty.ninja"
BOUNTY_EMAIL = "Unit_test-bùg-bounty-hunter_0123456789abcdef@bugbounty.ninja"
BOUNTY_FIRST_NAME = "Hackèrman"
BOUNTY_CSV = f"""Nom,Prénom,Mail,Téléphone,Département,Code postal,Date de naissance,Role,SIREN,Mot de passe,Type
Doux,{BOUNTY_FIRST_NAME},{BOUNTY_EMAIL},0102030405,86,86140,2000-01-01,PRO,10000135,,externe:bug-bounty
Expand Down Expand Up @@ -129,14 +130,14 @@ def test_read_file(self, update_if_exists, caplog):
def test_create_provider_for_bounty_users(self, client):
csv_file = io.StringIO(BOUNTY_CSV)
import_test_users.create_users_from_csv(csv_file)

prefix = f"staging_{BOUNTY_EMAIL}"
sanitized_email = sanitize_email(BOUNTY_EMAIL).replace("_", "-")
prefix = f"staging_{sanitized_email}"
api_key = offerers_models.ApiKey.query.filter_by(prefix=prefix).one()
assert crypto.hash_public_api_key(BOUNTY_EMAIL) == api_key.secret
assert crypto.hash_public_api_key(sanitized_email) == api_key.secret

# This call ensures that we have access to the api and at least one venue
# attached to this provider
client = client.with_explicit_token(f"{prefix}_{BOUNTY_EMAIL}")
client = client.with_explicit_token(f"{prefix}_{sanitized_email}")
response = client.get("/public/offers/v1/offerer_venues")
assert response.status_code == 200
assert len(response.json) == 1

0 comments on commit 48b1e50

Please sign in to comment.