|
| 1 | +import pytest |
| 2 | +import respx |
| 3 | +from core.models import PretalxData, PretixData |
| 4 | +from django.core.management import call_command |
| 5 | +from httpx import Response |
| 6 | + |
| 7 | + |
| 8 | +@respx.mock |
| 9 | +@pytest.mark.django_db |
| 10 | +def test_download_pretix_data_command(capsys): |
| 11 | + for url in [ |
| 12 | + "https://pretalx.com/api/events/europython-2025/submissions/?questions=all", |
| 13 | + "https://pretalx.com/api/events/europython-2025/speakers/?questions=all", |
| 14 | + ]: |
| 15 | + respx.get(url).mock( |
| 16 | + return_value=Response(200, json={"results": [], "next": None}) |
| 17 | + ) |
| 18 | + |
| 19 | + call_command("download_pretalx_data", event="europython-2025") |
| 20 | + |
| 21 | + # Minimal sanity checks |
| 22 | + stdout, stderr = capsys.readouterr() # capture stdout / stderr |
| 23 | + assert "Downloading latest products" in stdout |
| 24 | + assert "Downloading latest vouchers" in stdout |
| 25 | + assert "Downloading latest orders" in stdout |
| 26 | + assert ( |
| 27 | + PretalxData.objects.get( |
| 28 | + resource=PretalxData.PretalxResource.submissions |
| 29 | + ).content |
| 30 | + == [] |
| 31 | + ) |
| 32 | + assert ( |
| 33 | + PretalxData.objects.get(resource=PretalxData.PretalxResource.speakers).content |
| 34 | + == [] |
| 35 | + ) |
| 36 | + |
| 37 | + |
| 38 | +@respx.mock |
| 39 | +@pytest.mark.django_db |
| 40 | +def test_download_pretix_data_command(capsys): |
| 41 | + for url in [ |
| 42 | + "https://tickets.europython.eu/api/v1/organizers/europython/events/ep2025/orders/", |
| 43 | + "https://tickets.europython.eu/api/v1/organizers/europython/events/ep2025/items/", |
| 44 | + "https://tickets.europython.eu/api/v1/organizers/europython/events/ep2025/vouchers/", |
| 45 | + ]: |
| 46 | + respx.get(url).mock( |
| 47 | + return_value=Response(200, json={"results": [], "next": None}) |
| 48 | + ) |
| 49 | + |
| 50 | + call_command("download_pretix_data", event="ep2025") |
| 51 | + |
| 52 | + # Minimal sanity checks |
| 53 | + stdout, stderr = capsys.readouterr() # capture stdout / stderr |
| 54 | + assert "Downloading latest products" in stdout |
| 55 | + assert "Downloading latest vouchers" in stdout |
| 56 | + assert "Downloading latest orders" in stdout |
| 57 | + assert ( |
| 58 | + PretixData.objects.get(resource=PretixData.PretixResources.orders).content == [] |
| 59 | + ) |
| 60 | + assert ( |
| 61 | + PretixData.objects.get(resource=PretixData.PretixResources.vouchers).content |
| 62 | + == [] |
| 63 | + ) |
| 64 | + assert ( |
| 65 | + PretixData.objects.get(resource=PretixData.PretixResources.products).content |
| 66 | + == [] |
| 67 | + ) |
0 commit comments