From fddd3b24f7ab56bd9e2309cf651f2f02a164fa60 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Mon, 31 Jul 2023 02:16:23 -0500 Subject: [PATCH] test: skip tests on RO app paths which require write access (#21878) --- frappe/core/doctype/doctype/test_doctype.py | 14 ++++++++++++++ .../doctype/print_format/test_print_format.py | 4 ++++ frappe/tests/test_boilerplate.py | 9 +++++++++ frappe/tests/test_modules.py | 16 ++++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/frappe/core/doctype/doctype/test_doctype.py b/frappe/core/doctype/doctype/test_doctype.py index c819663962..40c55c594e 100644 --- a/frappe/core/doctype/doctype/test_doctype.py +++ b/frappe/core/doctype/doctype/test_doctype.py @@ -1,7 +1,9 @@ # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors # License: MIT. See LICENSE +import os import random import string +import unittest from unittest.mock import patch import frappe @@ -172,6 +174,9 @@ class TestDocType(FrappeTestCase): if condition: self.assertFalse(re.match(pattern, condition)) + @unittest.skipUnless( + os.access(frappe.get_app_path("frappe"), os.W_OK), "Only run if frappe app paths is writable" + ) def test_sync_field_order(self): import os @@ -648,6 +653,9 @@ class TestDocType(FrappeTestCase): def test_no_delete_doc(self): self.assertRaises(frappe.ValidationError, frappe.delete_doc, "DocType", "Address") + @unittest.skipUnless( + os.access(frappe.get_app_path("frappe"), os.W_OK), "Only run if frappe app paths is writable" + ) @patch.dict(frappe.conf, {"developer_mode": 1}) def test_export_types(self): """Export python types.""" @@ -686,6 +694,9 @@ class TestDocType(FrappeTestCase): doctype.delete() frappe.db.commit() + @unittest.skipUnless( + os.access(frappe.get_app_path("frappe"), os.W_OK), "Only run if frappe app paths is writable" + ) @patch.dict(frappe.conf, {"developer_mode": 1}) def test_custom_field_deletion(self): """Custom child tables whose doctype doesn't exist should be auto deleted.""" @@ -698,6 +709,9 @@ class TestDocType(FrappeTestCase): frappe.delete_doc("DocType", child) self.assertFalse(frappe.get_meta(doctype).get_field(field)) + @unittest.skipUnless( + os.access(frappe.get_app_path("frappe"), os.W_OK), "Only run if frappe app paths is writable" + ) @patch.dict(frappe.conf, {"developer_mode": 1}) def test_delete_doctype_with_customization(self): from frappe.custom.doctype.property_setter.property_setter import make_property_setter diff --git a/frappe/printing/doctype/print_format/test_print_format.py b/frappe/printing/doctype/print_format/test_print_format.py index 7caa5c6102..c54e421861 100644 --- a/frappe/printing/doctype/print_format/test_print_format.py +++ b/frappe/printing/doctype/print_format/test_print_format.py @@ -2,6 +2,7 @@ # License: MIT. See LICENSE import os import re +import unittest from typing import TYPE_CHECKING import frappe @@ -36,6 +37,9 @@ class TestPrintFormat(FrappeTestCase): print_html = self.test_print_user("Classic") self.assertTrue("/* classic format: for-test */" in print_html) + @unittest.skipUnless( + os.access(frappe.get_app_path("frappe"), os.W_OK), "Only run if frappe app paths is writable" + ) def test_export_doc(self): doc: "PrintFormat" = frappe.get_doc("Print Format", test_records[0]["name"]) diff --git a/frappe/tests/test_boilerplate.py b/frappe/tests/test_boilerplate.py index 4a405de2f8..9a2b774977 100644 --- a/frappe/tests/test_boilerplate.py +++ b/frappe/tests/test_boilerplate.py @@ -111,6 +111,9 @@ class TestBoilerPlate(unittest.TestCase): def test_valid_ci_yaml(self): yaml.safe_load(github_workflow_template.format(**self.default_hooks)) + @unittest.skipUnless( + os.access(frappe.get_app_path("frappe"), os.W_OK), "Only run if frappe app paths is writable" + ) def test_create_app(self): app_name = "test_app" @@ -142,6 +145,9 @@ class TestBoilerPlate(unittest.TestCase): self.assertEqual(parse_as_configfile(patches_file), []) + @unittest.skipUnless( + os.access(frappe.get_app_path("frappe"), os.W_OK), "Only run if frappe app paths is writable" + ) def test_create_app_without_git_init(self): app_name = "test_app_no_git" @@ -192,6 +198,9 @@ class TestBoilerPlate(unittest.TestCase): except Exception as e: self.fail(f"Can't parse python file in new app: {python_file}\n" + str(e)) + @unittest.skipUnless( + os.access(frappe.get_app_path("frappe"), os.W_OK), "Only run if frappe app paths is writable" + ) def test_new_patch_util(self): user_inputs = { "app_name": "frappe", diff --git a/frappe/tests/test_modules.py b/frappe/tests/test_modules.py index d355577e99..a19b45691f 100644 --- a/frappe/tests/test_modules.py +++ b/frappe/tests/test_modules.py @@ -1,5 +1,6 @@ import os import shutil +import unittest import frappe from frappe import scrub @@ -82,6 +83,9 @@ class TestUtils(FrappeTestCase): doc = frappe.get_last_doc("DocType") self.assertIsNone(export_module_json(doc=doc, is_standard=True, module=doc.module)) + @unittest.skipUnless( + os.access(frappe.get_app_path("frappe"), os.W_OK), "Only run if frappe app paths is writable" + ) def test_export_module_json(self): doc = frappe.get_last_doc("DocType", {"issingle": 0, "custom": 0}) export_doc_path = os.path.join( @@ -107,12 +111,18 @@ class TestUtils(FrappeTestCase): self.assertTrue(last_modified_after > last_modified_before) + @unittest.skipUnless( + os.access(frappe.get_app_path("frappe"), os.W_OK), "Only run if frappe app paths is writable" + ) def test_export_customizations(self): file_path = export_customizations(module="Custom", doctype="Note") self.addCleanup(delete_file, path=file_path) self.assertTrue(file_path.endswith("/custom/custom/note.json")) self.assertTrue(os.path.exists(file_path)) + @unittest.skipUnless( + os.access(frappe.get_app_path("frappe"), os.W_OK), "Only run if frappe app paths is writable" + ) def test_sync_customizations(self): custom_field = frappe.get_doc( "Custom Field", {"dt": "Note", "fieldname": "test_export_customizations_field"} @@ -157,6 +167,9 @@ class TestUtils(FrappeTestCase): ) self.assertTrue(frappe.db.get_value("DocType", "Note", "migration_hash")) + @unittest.skipUnless( + os.access(frappe.get_app_path("frappe"), os.W_OK), "Only run if frappe app paths is writable" + ) def test_export_doc(self): exported_doc_path = frappe.get_app_path( "frappe", "desk", "note", self.note.name, f"{self.note.name}.json" @@ -166,6 +179,9 @@ class TestUtils(FrappeTestCase): self.addCleanup(delete_path, path=folder_path) self.assertTrue(os.path.exists(exported_doc_path)) + @unittest.skipUnless( + os.access(frappe.get_app_path("frappe"), os.W_OK), "Only run if frappe app paths is writable" + ) def test_make_boilerplate(self): scrubbed = frappe.scrub(self.doctype.name) self.assertFalse(