|
5 | 5 |
|
6 | 6 | import pytest |
7 | 7 | from cryptography.fernet import Fernet, InvalidToken |
| 8 | +from faker import Faker |
8 | 9 | from starlette.datastructures import URL |
9 | 10 |
|
10 | 11 |
|
@@ -44,18 +45,45 @@ def consume(url): |
44 | 45 | raise |
45 | 46 |
|
46 | 47 | except InvalidToken as err: |
47 | | - # TODO: cannot decode |
48 | 48 | print("Invalid Key", err) |
49 | 49 | raise |
50 | 50 |
|
51 | 51 |
|
52 | | -def test_encrypt_and_decrypt(monkeypatch: pytest.MonkeyPatch): |
| 52 | +@pytest.fixture( |
| 53 | + params=[ |
| 54 | + "en_US", # English (United States) |
| 55 | + "fr_FR", # French (France) |
| 56 | + "de_DE", # German (Germany) |
| 57 | + "ru_RU", # Russian |
| 58 | + "ja_JP", # Japanese |
| 59 | + "zh_CN", # Chinese (Simplified) |
| 60 | + "ko_KR", # Korean |
| 61 | + "ar_EG", # Arabic (Egypt) |
| 62 | + "he_IL", # Hebrew (Israel) |
| 63 | + "hi_IN", # Hindi (India) |
| 64 | + "th_TH", # Thai (Thailand) |
| 65 | + "vi_VN", # Vietnamese (Vietnam) |
| 66 | + "ta_IN", # Tamil (India) |
| 67 | + ] |
| 68 | +) |
| 69 | +def fake_email(request): |
| 70 | + locale = request.param |
| 71 | + faker = Faker(locale) |
| 72 | + # Use a localized name for the username part of the email |
| 73 | + name = faker.name().replace(" ", "").replace(".", "").lower() |
| 74 | + # Construct the email address |
| 75 | + return f"{name}@example.{locale.split('_')[-1].lower()}" |
| 76 | + |
| 77 | + |
| 78 | +def test_encrypt_and_decrypt(monkeypatch: pytest.MonkeyPatch, fake_email: str): |
53 | 79 | secret_key = Fernet.generate_key() |
54 | 80 | monkeypatch.setenv("SECRET_KEY", secret_key.decode()) |
55 | 81 |
|
56 | 82 | # invitation generator app |
57 | | - invitation_url = produce( guest_email="[email protected]") |
| 83 | + invitation_url = produce(guest_email=fake_email) |
| 84 | + assert invitation_url.fragment |
58 | 85 |
|
59 | 86 | # osparc side |
60 | 87 | invitation_data = consume(invitation_url) |
61 | 88 | print(json.dumps(invitation_data, indent=1)) |
| 89 | + assert invitation_data["guest"] == fake_email |
0 commit comments