|
7 | 7 |
|
8 | 8 | from collections.abc import Callable |
9 | 9 | from pathlib import Path |
| 10 | +from typing import Any |
10 | 11 | from uuid import UUID |
11 | 12 |
|
| 13 | +import pycountry |
| 14 | +import pytest |
12 | 15 | from pytest import MonkeyPatch |
13 | 16 | from sqlalchemy.orm import Session as OrmSession |
14 | 17 |
|
|
24 | 27 | from cms_backend.mill import update_language_codes |
25 | 28 | from cms_backend.mill.processors.zimfarm_notification import process_notification |
26 | 29 |
|
27 | | -VALID_NOTIFICATION_CONTENT = { |
| 30 | +VALID_NOTIFICATION_CONTENT: dict[str, Any] = { |
28 | 31 | "article_count": 1000, |
29 | 32 | "media_count": 500, |
30 | 33 | "size": 1000000, |
|
48 | 51 | } |
49 | 52 |
|
50 | 53 |
|
| 54 | +@pytest.fixture(autouse=True) |
| 55 | +def restore_language_codes(): |
| 56 | + """Fixture to restore pycountry language codes after test modifications.""" |
| 57 | + original_entries = list(pycountry.languages) # pyright: ignore[reportUnknownVariableType] |
| 58 | + yield |
| 59 | + current_entries = list(pycountry.languages) # pyright: ignore[reportUnknownVariableType] |
| 60 | + for entry in current_entries: # pyright: ignore[reportUnknownVariableType] |
| 61 | + try: |
| 62 | + pycountry.languages.remove_entry(alpha_3=entry.alpha_3) # pyright: ignore[reportUnknownMemberType,reportUnknownArgumentType] |
| 63 | + except Exception: # noqa: S110 |
| 64 | + pass |
| 65 | + |
| 66 | + for entry in original_entries: # pyright: ignore[reportUnknownVariableType] |
| 67 | + try: |
| 68 | + pycountry.languages.add_entry( # pyright: ignore[reportUnknownMemberType] |
| 69 | + alpha_3=entry.alpha_3, # pyright: ignore[reportUnknownMemberType,reportUnknownArgumentType] |
| 70 | + name=entry.name, # pyright: ignore[reportUnknownMemberType,reportUnknownArgumentType] |
| 71 | + ) |
| 72 | + except Exception: # noqa: S110 |
| 73 | + pass |
| 74 | + |
| 75 | + |
51 | 76 | class TestBadNotifications: |
52 | 77 | """Test notifications that fail validation and are marked as bad_notification.""" |
53 | 78 |
|
|
0 commit comments