Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/api/views/test_add_forge_now.py
# Copyright (C) 2022 The Software Heritage developers | # Copyright (C) 2022 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import copy | |||||
import datetime | import datetime | ||||
import threading | import threading | ||||
import time | import time | ||||
from typing import Dict | from typing import Dict | ||||
from urllib.parse import urlencode, urlparse | from urllib.parse import urlencode, urlparse | ||||
import iso8601 | import iso8601 | ||||
import pytest | import pytest | ||||
▲ Show 20 Lines • Show All 181 Lines • ▼ Show 20 Lines | check_api_post_response( | ||||
status_code=409, | status_code=409, | ||||
) | ) | ||||
requests = Request.objects.all() | requests = Request.objects.all() | ||||
assert len(requests) == 1 | assert len(requests) == 1 | ||||
@pytest.mark.django_db(transaction=True, reset_sequences=True) | @pytest.mark.django_db(transaction=True, reset_sequences=True) | ||||
def test_add_forge_request_create_invalid_forge_url(api_client, regular_user): | |||||
api_client.force_login(regular_user) | |||||
url = reverse("api-1-add-forge-request-create") | |||||
forge_data = copy.deepcopy(ADD_FORGE_DATA_FORGE1) | |||||
forge_data["forge_url"] = "foo" | |||||
resp = check_api_post_response( | |||||
api_client, | |||||
url, | |||||
data=forge_data, | |||||
status_code=400, | |||||
) | |||||
assert resp.data == { | |||||
"exception": "BadInputExc", | |||||
"reason": '{"forge_url": ["Enter a valid URL."]}', | |||||
} | |||||
@pytest.mark.django_db(transaction=True, reset_sequences=True) | |||||
def test_add_forge_request_update_anonymous_user(api_client): | def test_add_forge_request_update_anonymous_user(api_client): | ||||
url = reverse("api-1-add-forge-request-update", url_args={"id": 1}) | url = reverse("api-1-add-forge-request-update", url_args={"id": 1}) | ||||
check_api_post_response(api_client, url, status_code=403) | check_api_post_response(api_client, url, status_code=403) | ||||
@pytest.mark.django_db(transaction=True, reset_sequences=True) | @pytest.mark.django_db(transaction=True, reset_sequences=True) | ||||
def test_add_forge_request_update_regular_user(api_client, regular_user): | def test_add_forge_request_update_regular_user(api_client, regular_user): | ||||
api_client.force_login(regular_user) | api_client.force_login(regular_user) | ||||
▲ Show 20 Lines • Show All 419 Lines • Show Last 20 Lines |