Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/save_code_now/test_origin_save_admin.py
# Copyright (C) 2015-2021 The Software Heritage developers | # Copyright (C) 2015-2021 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 | ||||
from urllib.parse import unquote | from urllib.parse import unquote | ||||
import pytest | import pytest | ||||
from django.conf import settings | |||||
from swh.web.save_code_now.models import ( | from swh.web.save_code_now.models import ( | ||||
SAVE_REQUEST_ACCEPTED, | SAVE_REQUEST_ACCEPTED, | ||||
SAVE_REQUEST_PENDING, | SAVE_REQUEST_PENDING, | ||||
SAVE_REQUEST_REJECTED, | SAVE_REQUEST_REJECTED, | ||||
SAVE_TASK_NOT_YET_SCHEDULED, | SAVE_TASK_NOT_YET_SCHEDULED, | ||||
SaveAuthorizedOrigin, | SaveAuthorizedOrigin, | ||||
SaveOriginRequest, | SaveOriginRequest, | ||||
SaveUnauthorizedOrigin, | SaveUnauthorizedOrigin, | ||||
Show All 11 Lines | |||||
@pytest.fixture(autouse=True) | @pytest.fixture(autouse=True) | ||||
def populated_db(): | def populated_db(): | ||||
SaveAuthorizedOrigin.objects.create(url=_authorized_origin_url) | SaveAuthorizedOrigin.objects.create(url=_authorized_origin_url) | ||||
SaveUnauthorizedOrigin.objects.create(url=_unauthorized_origin_url) | SaveUnauthorizedOrigin.objects.create(url=_unauthorized_origin_url) | ||||
def check_not_login(client, url): | def check_not_login(client, url): | ||||
login_url = reverse("login", query_params={"next": url}) | login_url = reverse(settings.LOGIN_URL, query_params={"next_path": url}) | ||||
resp = check_http_post_response(client, url, status_code=302) | resp = check_http_post_response(client, url, status_code=302) | ||||
assert unquote(resp.url) == login_url | assert unquote(resp.url) == login_url | ||||
def test_add_authorized_origin_url(client, staff_user): | def test_add_authorized_origin_url(client, staff_user): | ||||
authorized_url = "https://scm.adullact.net/anonscm/" | authorized_url = "https://scm.adullact.net/anonscm/" | ||||
assert can_save_origin(authorized_url) == SAVE_REQUEST_PENDING | assert can_save_origin(authorized_url) == SAVE_REQUEST_PENDING | ||||
▲ Show 20 Lines • Show All 182 Lines • Show Last 20 Lines |