Skip to content

Commit

Permalink
Tests: c3voc: extract common HTTP auth headers fixture.
Browse files Browse the repository at this point in the history
  • Loading branch information
jayaddison committed Sep 1, 2024
1 parent b996797 commit 435e2f1
Showing 1 changed file with 33 additions and 56 deletions.
89 changes: 33 additions & 56 deletions tests/test_api_c3voc.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def proposal(db, user):
db.session.commit()


@pytest.fixture
def valid_auth_headers():
return {"Authorization": "Bearer video-api-test-token"}


def test_denies_request_without_api_key(client, app, proposal):
rv = client.post(
f"/api/proposal/c3voc-publishing-webhook",
Expand All @@ -44,12 +49,10 @@ def test_denies_request_without_api_key(client, app, proposal):
assert rv.status_code == 401


def test_denies_request_no_master(client, app, proposal):
def test_denies_request_no_master(client, app, proposal, valid_auth_headers):
rv = client.post(
f"/api/proposal/c3voc-publishing-webhook",
headers={
"Authorization": "Bearer video-api-test-token",
},
headers=valid_auth_headers,
json={
"is_master": False,
"fahrplan": {
Expand All @@ -67,12 +70,10 @@ def test_denies_request_no_master(client, app, proposal):
assert rv.status_code == 403


def test_denies_request_wrong_year(client, app, proposal):
def test_denies_request_wrong_year(client, app, proposal, valid_auth_headers):
rv = client.post(
f"/api/proposal/c3voc-publishing-webhook",
headers={
"Authorization": "Bearer video-api-test-token",
},
headers=valid_auth_headers,
json={
"is_master": True,
"fahrplan": {
Expand All @@ -90,12 +91,10 @@ def test_denies_request_wrong_year(client, app, proposal):
assert rv.status_code == 422


def test_request_none_unchanged(client, app, db, proposal):
def test_request_none_unchanged(client, app, db, proposal, valid_auth_headers):
rv = client.post(
f"/api/proposal/c3voc-publishing-webhook",
headers={
"Authorization": "Bearer video-api-test-token",
},
headers=valid_auth_headers,
json={
"is_master": True,
"fahrplan": {
Expand All @@ -117,12 +116,10 @@ def test_request_none_unchanged(client, app, db, proposal):
assert proposal.c3voc_url is None


def test_update_voctoweb_with_correct_url(client, app, db, proposal):
def test_update_voctoweb_with_correct_url(client, app, db, proposal, valid_auth_headers):
rv = client.post(
f"/api/proposal/c3voc-publishing-webhook",
headers={
"Authorization": "Bearer video-api-test-token",
},
headers=valid_auth_headers,
json={
"is_master": True,
"fahrplan": {
Expand All @@ -147,17 +144,15 @@ def test_update_voctoweb_with_correct_url(client, app, db, proposal):
assert proposal.youtube_url is None


def test_denies_voctoweb_with_wrong_url(client, app, db, proposal):
def test_denies_voctoweb_with_wrong_url(client, app, db, proposal, valid_auth_headers):
proposal.c3voc_url = "https://example.com"
proposal.video_recording_lost = True
db.session.add(proposal)
db.session.commit()

rv = client.post(
f"/api/proposal/c3voc-publishing-webhook",
headers={
"Authorization": "Bearer video-api-test-token",
},
headers=valid_auth_headers,
json={
"is_master": True,
"fahrplan": {
Expand All @@ -182,16 +177,14 @@ def test_denies_voctoweb_with_wrong_url(client, app, db, proposal):
assert proposal.c3voc_url == "https://example.com"


def test_clears_voctoweb(client, app, db, proposal):
def test_clears_voctoweb(client, app, db, proposal, valid_auth_headers):
proposal.c3voc_url = "https://example.com"
db.session.add(proposal)
db.session.commit()

rv = client.post(
f"/api/proposal/c3voc-publishing-webhook",
headers={
"Authorization": "Bearer video-api-test-token",
},
headers=valid_auth_headers,
json={
"is_master": True,
"fahrplan": {
Expand All @@ -214,12 +207,10 @@ def test_clears_voctoweb(client, app, db, proposal):
assert proposal.c3voc_url is None


def test_update_thumbnail_with_path(client, app, db, proposal):
def test_update_thumbnail_with_path(client, app, db, proposal, valid_auth_headers):
rv = client.post(
f"/api/proposal/c3voc-publishing-webhook",
headers={
"Authorization": "Bearer video-api-test-token",
},
headers=valid_auth_headers,
json={
"is_master": True,
"fahrplan": {
Expand All @@ -244,12 +235,10 @@ def test_update_thumbnail_with_path(client, app, db, proposal):
assert proposal.youtube_url is None


def test_update_thumbnail_with_url(client, app, db, proposal):
def test_update_thumbnail_with_url(client, app, db, proposal, valid_auth_headers):
rv = client.post(
f"/api/proposal/c3voc-publishing-webhook",
headers={
"Authorization": "Bearer video-api-test-token",
},
headers=valid_auth_headers,
json={
"is_master": True,
"fahrplan": {
Expand All @@ -274,16 +263,14 @@ def test_update_thumbnail_with_url(client, app, db, proposal):
assert proposal.youtube_url is None


def test_denies_thumbnail_not_url(client, app, db, proposal):
def test_denies_thumbnail_not_url(client, app, db, proposal, valid_auth_headers):
proposal.thumbnail_url = "https://example.com/thumb.jpg"
db.session.add(proposal)
db.session.commit()

rv = client.post(
f"/api/proposal/c3voc-publishing-webhook",
headers={
"Authorization": "Bearer video-api-test-token",
},
headers=valid_auth_headers,
json={
"is_master": True,
"fahrplan": {
Expand All @@ -306,16 +293,14 @@ def test_denies_thumbnail_not_url(client, app, db, proposal):
assert proposal.thumbnail_url == "https://example.com/thumb.jpg"


def test_clears_thumbnail(client, app, db, proposal):
def test_clears_thumbnail(client, app, db, proposal, valid_auth_headers):
proposal.thumbnail_url = "https://example.com/thumb.jpg"
db.session.add(proposal)
db.session.commit()

rv = client.post(
f"/api/proposal/c3voc-publishing-webhook",
headers={
"Authorization": "Bearer video-api-test-token",
},
headers=valid_auth_headers,
json={
"is_master": True,
"fahrplan": {
Expand All @@ -338,12 +323,10 @@ def test_clears_thumbnail(client, app, db, proposal):
assert proposal.thumbnail_url is None


def test_update_youtube_with_correct_url(client, app, db, proposal):
def test_update_youtube_with_correct_url(client, app, db, proposal, valid_auth_headers):
rv = client.post(
f"/api/proposal/c3voc-publishing-webhook",
headers={
"Authorization": "Bearer video-api-test-token",
},
headers=valid_auth_headers,
json={
"is_master": True,
"fahrplan": {
Expand All @@ -369,17 +352,15 @@ def test_update_youtube_with_correct_url(client, app, db, proposal):
assert proposal.youtube_url == "https://www.youtube.com/watch"


def test_denies_youtube_update_with_exisiting_url(client, app, db, proposal):
def test_denies_youtube_update_with_exisiting_url(client, app, db, proposal, valid_auth_headers):
proposal.youtube_url = "https://example.com"
proposal.video_recording_lost = True
db.session.add(proposal)
db.session.commit()

rv = client.post(
f"/api/proposal/c3voc-publishing-webhook",
headers={
"Authorization": "Bearer video-api-test-token",
},
headers=valid_auth_headers,
json={
"is_master": True,
"fahrplan": {
Expand All @@ -405,17 +386,15 @@ def test_denies_youtube_update_with_exisiting_url(client, app, db, proposal):
assert proposal.youtube_url == "https://example.com"


def test_denies_youtube_update_with_wrong_url(client, app, db, proposal):
def test_denies_youtube_update_with_wrong_url(client, app, db, proposal, valid_auth_headers):
proposal.youtube_url = "https://example.com"
proposal.video_recording_lost = True
db.session.add(proposal)
db.session.commit()

rv = client.post(
f"/api/proposal/c3voc-publishing-webhook",
headers={
"Authorization": "Bearer video-api-test-token",
},
headers=valid_auth_headers,
json={
"is_master": True,
"fahrplan": {
Expand All @@ -441,16 +420,14 @@ def test_denies_youtube_update_with_wrong_url(client, app, db, proposal):
assert proposal.youtube_url == "https://example.com"


def test_clears_youtube(client, app, db, proposal):
def test_clears_youtube(client, app, db, proposal, valid_auth_headers):
proposal.youtube_url = "https://example.com"
db.session.add(proposal)
db.session.commit()

rv = client.post(
f"/api/proposal/c3voc-publishing-webhook",
headers={
"Authorization": "Bearer video-api-test-token",
},
headers=valid_auth_headers,
json={
"is_master": True,
"fahrplan": {
Expand Down

0 comments on commit 435e2f1

Please sign in to comment.