Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/save_origin_webhooks/test_sourceforge.py
- This file was added.
# Copyright (C) 2022 The Software Heritage developers | |||||
# See the AUTHORS file at the top-level directory of this distribution | |||||
# License: GNU Affero General Public License version 3, or any later version | |||||
# See top-level LICENSE file for more information | |||||
import json | |||||
import os | |||||
import pytest | |||||
from .utils import ( | |||||
origin_save_webhook_receiver_invalid_content_type_test, | |||||
origin_save_webhook_receiver_invalid_request_test, | |||||
origin_save_webhook_receiver_no_repo_url_test, | |||||
origin_save_webhook_receiver_test, | |||||
) | |||||
@pytest.mark.django_db | |||||
@pytest.mark.parametrize( | |||||
"payload_file,expected_origin_url,expected_visit_type", | |||||
[ | |||||
( | |||||
"sourceforge_webhook_payload_hg.json", | |||||
"http://hg.code.sf.net/p/webhook-test-hg/code", | |||||
"hg", | |||||
), | |||||
( | |||||
"sourceforge_webhook_payload_git.json", | |||||
"https://git.code.sf.net/p/webhook-test-git/code", | |||||
"git", | |||||
), | |||||
( | |||||
"sourceforge_webhook_payload_svn.json", | |||||
"https://svn.code.sf.net/p/webhook-test-svn/code/", | |||||
"svn", | |||||
), | |||||
], | |||||
) | |||||
def test_origin_save_sourceforge_webhook_receiver( | |||||
api_client, | |||||
swh_scheduler, | |||||
datadir, | |||||
requests_mock_datadir, | |||||
payload_file, | |||||
expected_origin_url, | |||||
expected_visit_type, | |||||
): | |||||
with open(os.path.join(datadir, payload_file), "rb") as payload: | |||||
origin_save_webhook_receiver_test( | |||||
forge_type="SourceForge", | |||||
http_headers={ | |||||
"User-Agent": "Allura Webhook (https://allura.apache.org/)", | |||||
}, | |||||
payload=json.load(payload), | |||||
expected_origin_url=expected_origin_url, | |||||
expected_visit_type=expected_visit_type, | |||||
api_client=api_client, | |||||
swh_scheduler=swh_scheduler, | |||||
) | |||||
def test_origin_save_sourceforge_webhook_receiver_invalid_request( | |||||
api_client, | |||||
): | |||||
origin_save_webhook_receiver_invalid_request_test( | |||||
forge_type="SourceForge", | |||||
http_headers={}, | |||||
payload={}, | |||||
api_client=api_client, | |||||
) | |||||
def test_origin_save_sourceforge_webhook_receiver_invalid_content_type( | |||||
api_client, | |||||
): | |||||
origin_save_webhook_receiver_invalid_content_type_test( | |||||
forge_type="SourceForge", | |||||
http_headers={ | |||||
"User-Agent": "Allura Webhook (https://allura.apache.org/)", | |||||
}, | |||||
payload={}, | |||||
api_client=api_client, | |||||
) | |||||
def test_origin_save_sourceforge_webhook_receiver_no_repo_url(api_client, datadir): | |||||
with open( | |||||
os.path.join(datadir, "sourceforge_webhook_payload_git.json"), "rb" | |||||
) as payload: | |||||
payload = json.load(payload) | |||||
del payload["repository"] | |||||
origin_save_webhook_receiver_no_repo_url_test( | |||||
forge_type="SourceForge", | |||||
http_headers={ | |||||
"User-Agent": "Allura Webhook (https://allura.apache.org/)", | |||||
}, | |||||
payload=payload, | |||||
api_client=api_client, | |||||
) |