Skip to content

Commit 7541717

Browse files
committed
add sanity check tests for management commands
1 parent 6fa2d4c commit 7541717

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

intbot/core/management/commands/download_pretix_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from core.integrations.pretalx import (
1+
from core.integrations.pretix import (
22
PRETIX_EVENTS,
33
download_latest_orders,
44
download_latest_products,

intbot/core/models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ class PretalxResources(models.TextChoices):
106106
modified_at = models.DateTimeField(auto_now=True)
107107
processed_at = models.DateTimeField(blank=True, null=True)
108108

109+
class Meta:
110+
verbose_name_plural = "Pretalx Data"
111+
109112
def __str__(self):
110113
return f"{self.uuid}"
111114

@@ -133,5 +136,8 @@ class PretixResources(models.TextChoices):
133136
modified_at = models.DateTimeField(auto_now=True)
134137
processed_at = models.DateTimeField(blank=True, null=True)
135138

139+
class Meta:
140+
verbose_name_plural = "Pretix Data"
141+
136142
def __str__(self):
137143
return f"{self.uuid}"
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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

Comments
 (0)