diff --git a/frappe/__init__.py b/frappe/__init__.py index dd15329106..5c1c7cf569 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -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 = [] diff --git a/frappe/commands/site.py b/frappe/commands/site.py index defc735ddd..386ebc6762 100644 --- a/frappe/commands/site.py +++ b/frappe/commands/site.py @@ -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}") diff --git a/frappe/commands/utils.py b/frappe/commands/utils.py index 925c75d421..ad015eec13 100644 --- a/frappe/commands/utils.py +++ b/frappe/commands/utils.py @@ -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 diff --git a/frappe/core/doctype/access_log/test_access_log.py b/frappe/core/doctype/access_log/test_access_log.py index b3432d60bf..dc00d1ecd7 100644 --- a/frappe/core/doctype/access_log/test_access_log.py +++ b/frappe/core/doctype/access_log/test_access_log.py @@ -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) diff --git a/frappe/core/doctype/server_script/test_server_script.py b/frappe/core/doctype/server_script/test_server_script.py index b83d1edda4..147d346807 100644 --- a/frappe/core/doctype/server_script/test_server_script.py +++ b/frappe/core/doctype/server_script/test_server_script.py @@ -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 diff --git a/frappe/patches/v13_0/set_unique_for_page_view.py b/frappe/patches/v13_0/set_unique_for_page_view.py index 45351afdde..bdf8ec076d 100644 --- a/frappe/patches/v13_0/set_unique_for_page_view.py +++ b/frappe/patches/v13_0/set_unique_for_page_view.py @@ -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}%'""") diff --git a/frappe/tests/test_api.py b/frappe/tests/test_api.py index 17c71f8c75..8e5d4b3d24 100644 --- a/frappe/tests/test_api.py +++ b/frappe/tests/test_api.py @@ -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() diff --git a/frappe/tests/test_auth.py b/frappe/tests/test_auth.py index 6aa8d2cc2f..c805d353f5 100644 --- a/frappe/tests/test_auth.py +++ b/frappe/tests/test_auth.py @@ -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" diff --git a/frappe/tests/test_client.py b/frappe/tests/test_client.py index 1fb46d1e52..751a8d2692 100644 --- a/frappe/tests/test_client.py +++ b/frappe/tests/test_client.py @@ -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) diff --git a/frappe/tests/test_perf.py b/frappe/tests/test_perf.py index d4fc933571..43a635e2a5 100644 --- a/frappe/tests/test_perf.py +++ b/frappe/tests/test_perf.py @@ -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() diff --git a/frappe/utils/__init__.py b/frappe/utils/__init__.py index f5c6320aee..4992e83ef0 100644 --- a/frappe/utils/__init__.py +++ b/frappe/utils/__init__.py @@ -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):