-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
305 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,305 @@ | ||
import pytest | ||
|
||
from models import event_year | ||
from models.cfp import Proposal, TalkProposal | ||
|
||
# base webhook. current year, no videos enabled. | ||
WEBHOOK_CONTENTS_BASE = { | ||
"message": "none", | ||
"is_master": True, | ||
"fahrplan": { | ||
"conference": f"emf{event_year()}", | ||
"id": 0, | ||
}, | ||
"voctoweb": { | ||
"enabled": False, | ||
}, | ||
"youtube": { | ||
"enabled": False, | ||
}, | ||
} | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def proposal(db, user): | ||
proposal = TalkProposal() | ||
proposal.title = "Title" | ||
proposal.description = "Description" | ||
proposal.user = user | ||
|
||
db.session.add(proposal) | ||
db.session.commit() | ||
|
||
return proposal | ||
|
||
|
||
def test_denies_request_without_api_key(client, app, proposal): | ||
app.config.update( | ||
{ | ||
"VIDEO_API_KEY": "api-key", | ||
} | ||
) | ||
|
||
rv = client.patch( | ||
f"/api/proposal/c3voc-publishing-webhook", | ||
json=WEBHOOK_CONTENTS_BASE | ||
) | ||
assert rv.status_code == 401 | ||
|
||
|
||
def test_denies_request_no_master(client, app, proposal): | ||
app.config.update( | ||
{ | ||
"VIDEO_API_KEY": "api-key", | ||
} | ||
) | ||
|
||
webhook = WEBHOOK_CONTENTS_BASE | ||
webhook["is_master"] = False | ||
|
||
rv = client.patch( | ||
f"/api/proposal/c3voc-publishing-webhook", | ||
headers={ | ||
"Authorization": "Bearer api-key", | ||
}, | ||
json=webhook | ||
) | ||
assert rv.status_code == 403 | ||
|
||
|
||
def test_denies_request_wrong_year(client, app, proposal): | ||
app.config.update( | ||
{ | ||
"VIDEO_API_KEY": "api-key", | ||
} | ||
) | ||
|
||
webhook = WEBHOOK_CONTENTS_BASE | ||
webhook["fahrplan"]["conference"] = "emf1970" | ||
|
||
rv = client.patch( | ||
f"/api/proposal/c3voc-publishing-webhook", | ||
headers={ | ||
"Authorization": "Bearer api-key", | ||
}, | ||
json=webhook | ||
) | ||
assert rv.status_code == 422 | ||
|
||
|
||
def test_request_none_update_none(client, app, proposal): | ||
app.config.update( | ||
{ | ||
"VIDEO_API_KEY": "api-key", | ||
} | ||
) | ||
|
||
webhook = WEBHOOK_CONTENTS_BASE | ||
webhook["fahrplan"]["id"] = proposal.id | ||
|
||
rv = client.patch( | ||
f"/api/proposal/c3voc-publishing-webhook", | ||
headers={ | ||
"Authorization": "Bearer api-key", | ||
}, | ||
json=webhook | ||
) | ||
assert rv.status_code == 204 | ||
|
||
proposal = Proposal.query.get(proposal.id) | ||
assert proposal.youtube_url == None | ||
assert proposal.c3voc_url == None | ||
|
||
|
||
def test_request_voctoweb_update_voctoweb_correct_url(client, app, proposal): | ||
app.config.update( | ||
{ | ||
"VIDEO_API_KEY": "api-key", | ||
} | ||
) | ||
|
||
webhook = WEBHOOK_CONTENTS_BASE | ||
webhook["fahrplan"]["id"] = proposal.id | ||
webhook["voctoweb"] = { | ||
"enabled": True, | ||
"frontend_url": "https://media.ccc.de/", | ||
} | ||
|
||
proposal.video_recording_lost = True | ||
db.session.add(proposal) | ||
db.session.commit() | ||
|
||
rv = client.patch( | ||
f"/api/proposal/c3voc-publishing-webhook", | ||
headers={ | ||
"Authorization": "Bearer api-key", | ||
}, | ||
json=webhook | ||
) | ||
assert rv.status_code == 204 | ||
|
||
proposal = Proposal.query.get(proposal.id) | ||
assert proposal.c3voc_url == "https://media.ccc.de/" | ||
assert proposal.video_recording_lost == False | ||
assert proposal.youtube_url == None | ||
|
||
|
||
def test_request_voctoweb_update_voctoweb_wrong_url(client, app, proposal): | ||
app.config.update( | ||
{ | ||
"VIDEO_API_KEY": "api-key", | ||
} | ||
) | ||
|
||
webhook = WEBHOOK_CONTENTS_BASE | ||
webhook["fahrplan"]["id"] = proposal.id | ||
webhook["voctoweb"] = { | ||
"enabled": True, | ||
"frontend_url": "https://example.org", | ||
} | ||
|
||
proposal.c3voc_url = "https://example.com" | ||
db.session.add(proposal) | ||
db.session.commit() | ||
|
||
rv = client.patch( | ||
f"/api/proposal/c3voc-publishing-webhook", | ||
headers={ | ||
"Authorization": "Bearer api-key", | ||
}, | ||
json=webhook | ||
) | ||
assert rv.status_code == 406 | ||
|
||
proposal = Proposal.query.get(proposal.id) | ||
assert proposal.c3voc_url == "https://example.com" | ||
|
||
|
||
def test_request_voctoweb_clears_voctoweb(client, app, proposal): | ||
app.config.update( | ||
{ | ||
"VIDEO_API_KEY": "api-key", | ||
} | ||
) | ||
|
||
webhook = WEBHOOK_CONTENTS_BASE | ||
webhook["fahrplan"]["id"] = proposal.id | ||
webhook["voctoweb"] = { | ||
"enabled": True, | ||
"frontend_url": "", | ||
} | ||
|
||
proposal.c3voc_url = "https://example.com" | ||
db.session.add(proposal) | ||
db.session.commit() | ||
|
||
rv = client.patch( | ||
f"/api/proposal/c3voc-publishing-webhook", | ||
headers={ | ||
"Authorization": "Bearer api-key", | ||
}, | ||
json=webhook | ||
) | ||
assert rv.status_code == 406 | ||
|
||
proposal = Proposal.query.get(proposal.id) | ||
assert proposal.c3voc_url == None | ||
|
||
|
||
def test_request_youtube_update_youtube_correct_url(client, app, proposal): | ||
app.config.update( | ||
{ | ||
"VIDEO_API_KEY": "api-key", | ||
} | ||
) | ||
|
||
webhook = WEBHOOK_CONTENTS_BASE | ||
webhook["fahrplan"]["id"] = proposal.id | ||
webhook["youtube"] = { | ||
"enabled": True, | ||
"urls": [ | ||
"https://www.youtube.com/watch", | ||
], | ||
} | ||
|
||
proposal.video_recording_lost = True | ||
db.session.add(proposal) | ||
db.session.commit() | ||
|
||
rv = client.patch( | ||
f"/api/proposal/c3voc-publishing-webhook", | ||
headers={ | ||
"Authorization": "Bearer api-key", | ||
}, | ||
json=webhook | ||
) | ||
assert rv.status_code == 204 | ||
|
||
proposal = Proposal.query.get(proposal.id) | ||
assert proposal.c3voc_url == None | ||
assert proposal.video_recording_lost == False | ||
assert proposal.youtube_url == "https://www.youtube.com/watch" | ||
|
||
|
||
def test_request_youtube_update_youtube_wrong_url(client, app, proposal): | ||
app.config.update( | ||
{ | ||
"VIDEO_API_KEY": "api-key", | ||
} | ||
) | ||
|
||
webhook = WEBHOOK_CONTENTS_BASE | ||
webhook["fahrplan"]["id"] = proposal.id | ||
webhook["youtube"] = { | ||
"enabled": True, | ||
"urls": [ | ||
"https://example.org", | ||
], | ||
} | ||
|
||
proposal.youtube_url = "https://example.com" | ||
db.session.add(proposal) | ||
db.session.commit() | ||
|
||
rv = client.patch( | ||
f"/api/proposal/c3voc-publishing-webhook", | ||
headers={ | ||
"Authorization": "Bearer api-key", | ||
}, | ||
json=webhook | ||
) | ||
assert rv.status_code == 204 | ||
|
||
proposal = Proposal.query.get(proposal.id) | ||
assert proposal.youtube_url == "https://example.com" | ||
|
||
|
||
def test_request_youtube_clears_youtube(client, app, proposal): | ||
app.config.update( | ||
{ | ||
"VIDEO_API_KEY": "api-key", | ||
} | ||
) | ||
|
||
webhook = WEBHOOK_CONTENTS_BASE | ||
webhook["fahrplan"]["id"] = proposal.id | ||
webhook["youtube"] = { | ||
"enabled": True, | ||
"urls": [], | ||
} | ||
|
||
proposal.youtube_url = "https://example.com" | ||
db.session.add(proposal) | ||
db.session.commit() | ||
|
||
rv = client.patch( | ||
f"/api/proposal/c3voc-publishing-webhook", | ||
headers={ | ||
"Authorization": "Bearer api-key", | ||
}, | ||
json=webhook | ||
) | ||
assert rv.status_code == 204 | ||
|
||
proposal = Proposal.query.get(proposal.id) | ||
assert proposal.youtube_url == None |