-
Notifications
You must be signed in to change notification settings - Fork 0
Pretalx data #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Pretalx data #30
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3814ffd
first draft of downloading and storing the pretalx data
artcz 9672021
add basic admin support
artcz 7265cec
small refactoring and review feedback
artcz 8e7fac9
PretalxData admin sanity check
artcz 47f9024
fix urls
artcz 8dbb561
add schema migration
artcz f8e1aa7
fix lint
artcz 5bf441c
fix format
artcz 58aa3c5
add management command
artcz 9461e9c
add basic support for cron jobs
artcz 7fafb65
fix typo
artcz 01b03d0
tweak pagination
artcz c4136b6
remove extra breakpoint
artcz 86fd6ab
Update intbot/core/integrations/pretalx.py
artcz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,67 @@ | ||||||
from typing import Any | ||||||
|
||||||
import httpx | ||||||
from core.models import PretalxData | ||||||
from django.conf import settings | ||||||
|
||||||
PRETALX_EVENT = "ep2025" | ||||||
base_url = f"https://pretalx.com/api/events/{PRETALX_EVENT}/" | ||||||
artcz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
||||||
RESOURCES = { | ||||||
# Questions need to be passed to include answers in the same endpoint, | ||||||
# saving us later time with joining the answers. | ||||||
PretalxData.PretalxEndpoints.submissions: "submissions?questions=all", | ||||||
PretalxData.PretalxEndpoints.speakers: "speakers?questions=all", | ||||||
} | ||||||
|
||||||
|
||||||
JsonType = dict[str, Any] | ||||||
|
||||||
|
||||||
def fetch_pretalx_data(resource) -> list[JsonType]: | ||||||
artcz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
headers = { | ||||||
"Authorization": f"Token {settings.PRETALX_API_TOKEN}", | ||||||
"Content-Type": "application/json", | ||||||
} | ||||||
|
||||||
endpoint = RESOURCES[resource] | ||||||
url = base_url + f"{endpoint}" | ||||||
artcz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
||||||
# Pretalx paginates the output, so we will need to do multiple requests and | ||||||
# then merge mutliple pages to one big dictionary | ||||||
|
# then merge mutliple pages to one big dictionary | |
# then merge multiple pages to one big dictionary |
Copilot uses AI. Check for mistakes.
Positive FeedbackNegative Feedback
artcz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
artcz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
import respx | ||
import pytest | ||
from core.integrations import pretalx | ||
from core.models import PretalxData | ||
from httpx import Response | ||
|
||
|
||
@respx.mock | ||
def test_fetch_submissions_from_pretalx(): | ||
endpoint = pretalx.RESOURCES[PretalxData.PretalxEndpoints.submissions] | ||
url = pretalx.base_url + endpoint | ||
respx.get(url).mock( | ||
return_value=Response( | ||
200, | ||
json={ | ||
"results": [ | ||
{"hello": "world"}, | ||
], | ||
"next": f"{url}&page=2", | ||
}, | ||
) | ||
) | ||
respx.get(url + "&page=2").mock( | ||
return_value=Response( | ||
200, | ||
json={ | ||
"results": [ | ||
{"foo": "bar"}, | ||
], | ||
# It's important to make it last page in tests. | ||
# Otherwise it will be infinite loop :) | ||
"next": None, | ||
}, | ||
) | ||
) | ||
|
||
submissions = pretalx.fetch_pretalx_data( | ||
PretalxData.PretalxEndpoints.submissions, | ||
) | ||
|
||
assert submissions == [ | ||
{"hello": "world"}, | ||
{"foo": "bar"}, | ||
] | ||
|
||
|
||
@respx.mock | ||
def test_fetch_speakers_from_pretalx(): | ||
endpoint = pretalx.RESOURCES[PretalxData.PretalxEndpoints.speakers] | ||
url = pretalx.base_url + endpoint | ||
respx.get(url).mock( | ||
return_value=Response( | ||
200, | ||
json={ | ||
"results": [ | ||
{"hello": "world"}, | ||
], | ||
"next": f"{url}&page=2", | ||
}, | ||
) | ||
) | ||
respx.get(url + "&page=2").mock( | ||
return_value=Response( | ||
200, | ||
json={ | ||
"results": [ | ||
{"foo": "bar"}, | ||
], | ||
# It's important to make it last page in tests. | ||
# Otherwise it will be infinite loop :) | ||
"next": None, | ||
}, | ||
) | ||
) | ||
|
||
submissions = pretalx.fetch_pretalx_data( | ||
PretalxData.PretalxEndpoints.speakers, | ||
) | ||
|
||
assert submissions == [ | ||
{"hello": "world"}, | ||
{"foo": "bar"}, | ||
] | ||
|
||
|
||
@respx.mock | ||
@pytest.mark.django_db | ||
def test_download_latest_submissions(): | ||
endpoint = pretalx.RESOURCES[PretalxData.PretalxEndpoints.submissions] | ||
url = pretalx.base_url + endpoint | ||
respx.get(url).mock( | ||
return_value=Response( | ||
200, | ||
json={ | ||
"results": [ | ||
{"hello": "world"}, | ||
], | ||
"next": f"{url}&page=2", | ||
}, | ||
) | ||
) | ||
respx.get(url + "&page=2").mock( | ||
return_value=Response( | ||
200, | ||
json={ | ||
"results": [ | ||
{"foo": "bar"}, | ||
], | ||
# It's important to make it last page in tests. | ||
# Otherwise it will be infinite loop :) | ||
"next": None, | ||
}, | ||
) | ||
) | ||
|
||
pretalx.download_latest_submissions() | ||
|
||
pd = PretalxData.objects.get(endpoint=PretalxData.PretalxEndpoints.submissions) | ||
|
||
assert pd.endpoint == "submissions" | ||
assert pd.content == [ | ||
{"hello": "world"}, | ||
{"foo": "bar"}, | ||
] | ||
|
||
@respx.mock | ||
@pytest.mark.django_db | ||
def test_download_latest_speakers(): | ||
endpoint = pretalx.RESOURCES[PretalxData.PretalxEndpoints.speakers] | ||
url = pretalx.base_url + endpoint | ||
respx.get(url).mock( | ||
return_value=Response( | ||
200, | ||
json={ | ||
"results": [ | ||
{"hello": "world"}, | ||
], | ||
"next": f"{url}&page=2", | ||
}, | ||
) | ||
) | ||
respx.get(url + "&page=2").mock( | ||
return_value=Response( | ||
200, | ||
json={ | ||
"results": [ | ||
{"foo": "bar"}, | ||
], | ||
# It's important to make it last page in tests. | ||
# Otherwise it will be infinite loop :) | ||
"next": None, | ||
}, | ||
) | ||
) | ||
|
||
pretalx.download_latest_speakers() | ||
|
||
pd = PretalxData.objects.get(endpoint=PretalxData.PretalxEndpoints.speakers) | ||
|
||
assert pd.endpoint == "speakers" | ||
assert pd.content == [ | ||
{"hello": "world"}, | ||
{"foo": "bar"}, | ||
] | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.