refactor!: merge get_site_url into get_url (#22308)

* chore: merge get_site_url into get_url

* fix: keep alias with deprecation notice
This commit is contained in:
David Arnold 2023-09-11 11:39:05 +02:00 committed by GitHub
parent 1ec87615fe
commit 2001bc278f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 21 additions and 22 deletions

View file

@ -33,6 +33,7 @@ from frappe.query_builder import (
)
from frappe.utils.caching import request_cache
from frappe.utils.data import cint, cstr, sbool
from frappe.utils.deprecations import deprecated
# Local application imports
from .exceptions import *
@ -531,6 +532,11 @@ def msgprint(
_raise_exception()
@deprecated
def get_site_url(site):
return frappe.utils.get_url()
def clear_messages():
local.message_log = []

View file

@ -1101,7 +1101,7 @@ def browse(context, site, user=None):
else:
click.echo("Please enable developer mode to login as a user")
url = f"{frappe.utils.get_site_url(site)}{sid}"
url = f"{frappe.utils.get_url()}{sid}"
if user == "Administrator":
click.echo(f"Login URL: {url}")

View file

@ -864,7 +864,7 @@ def run_ui_tests(
"Run UI tests"
site = get_site(context)
app_base_path = frappe.get_app_source_path(app)
site_url = frappe.utils.get_site_url(site)
site_url = frappe.utils.get_url(site)
admin_password = frappe.get_conf(site).admin_password
# override baseUrl using env variable

View file

@ -15,7 +15,7 @@ from frappe.core.doctype.user.user import generate_keys
# imports - standard imports
from frappe.tests.utils import FrappeTestCase
from frappe.utils import cstr, get_site_url
from frappe.utils import cstr, get_url
class TestAccessLog(FrappeTestCase):
@ -154,7 +154,7 @@ class TestAccessLog(FrappeTestCase):
new_private_file.insert()
# access the created file
private_file_link = get_site_url(frappe.local.site) + new_private_file.file_url
private_file_link = get_url() + new_private_file.file_url
try:
request = requests.post(private_file_link, headers=self.header)

View file

@ -6,7 +6,7 @@ import frappe
from frappe.core.doctype.scheduled_job_type.scheduled_job_type import sync_jobs
from frappe.frappeclient import FrappeClient, FrappeException
from frappe.tests.utils import FrappeTestCase
from frappe.utils import get_site_url
from frappe.utils import get_url
scripts = [
dict(
@ -122,7 +122,7 @@ class TestServerScript(FrappeTestCase):
)
def test_api(self):
response = requests.post(get_site_url(frappe.local.site) + "/api/method/test_server_script")
response = requests.post(get_url() + "/api/method/test_server_script")
self.assertEqual(response.status_code, 200)
self.assertEqual("hello", response.json()["message"])
@ -267,7 +267,7 @@ frappe.qb.from_(todo).select(todo.name).where(todo.name == "{todo.name}").run()
frappe.db.commit()
site = frappe.utils.get_site_url(frappe.local.site)
site = frappe.utils.get_url()
client = FrappeClient(site)
# Exhaust rate limit

View file

@ -3,5 +3,5 @@ import frappe
def execute():
frappe.reload_doc("website", "doctype", "web_page_view", force=True)
site_url = frappe.utils.get_site_url(frappe.local.site)
site_url = frappe.utils.get_url()
frappe.db.sql(f"""UPDATE `tabWeb Page View` set is_unique=1 where referrer LIKE '%{site_url}%'""")

View file

@ -12,7 +12,7 @@ from werkzeug.test import TestResponse
import frappe
from frappe.installer import update_site_config
from frappe.tests.utils import FrappeTestCase, patch_hooks
from frappe.utils import get_site_url, get_test_client
from frappe.utils import get_test_client, get_url
try:
_site = frappe.local.site
@ -73,7 +73,7 @@ class ThreadWithReturnValue(Thread):
class FrappeAPITestCase(FrappeTestCase):
SITE = frappe.local.site
SITE_URL = get_site_url(SITE)
SITE_URL = get_url()
RESOURCE_URL = f"{SITE_URL}/api/resource"
TEST_CLIENT = get_test_client()

View file

@ -11,7 +11,7 @@ from frappe.frappeclient import AuthError, FrappeClient
from frappe.sessions import Session, get_expired_sessions, get_expiry_in_seconds
from frappe.tests.test_api import FrappeAPITestCase
from frappe.tests.utils import FrappeTestCase
from frappe.utils import get_site_url, now
from frappe.utils import get_url, now
from frappe.utils.data import add_to_date
from frappe.www.login import _generate_temporary_login_link
@ -30,7 +30,7 @@ class TestAuth(FrappeTestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.HOST_NAME = frappe.get_site_config().host_name or get_site_url(frappe.local.site)
cls.HOST_NAME = get_url()
cls.test_user_email = "test_auth@test.com"
cls.test_user_name = "test_auth_user"
cls.test_user_mobile = "+911234567890"

View file

@ -4,7 +4,7 @@ from unittest.mock import patch
import frappe
from frappe.tests.utils import FrappeTestCase
from frappe.utils import get_site_url
from frappe.utils import get_url
class TestClient(FrappeTestCase):
@ -135,7 +135,7 @@ class TestClient(FrappeTestCase):
"accept": "application/json",
"content-type": "application/json",
}
url = get_site_url(frappe.local.site)
url = get_url()
url += "/api/method/frappe.client.get_list"
res = requests.post(url, json=params, headers=headers)

View file

@ -43,7 +43,7 @@ class TestPerformance(FrappeTestCase):
frappe.clear_cache()
def setUp(self) -> None:
self.HOST = frappe.utils.get_site_url(frappe.local.site)
self.HOST = frappe.utils.get_url()
self.reset_request_specific_caches()

View file

@ -528,13 +528,6 @@ def get_request_site_address(full_address=False):
return get_url(full_address=full_address)
def get_site_url(site):
conf = frappe.get_conf(site)
if conf.host_name:
return conf.host_name
return f"http://{site}:{conf.webserver_port}"
def encode_dict(d, encoding="utf-8"):
for key in d:
if isinstance(d[key], str) and isinstance(d[key], str):