diff --git a/ate/utils.py b/ate/utils.py index e904d6f2..1f914396 100644 --- a/ate/utils.py +++ b/ate/utils.py @@ -39,6 +39,13 @@ def get_sign(*args): sign = hmac.new(sign_key, content, hashlib.sha1).hexdigest() return sign +def remove_prefix(text, prefix): + """ remove prefix from text + """ + if text.startswith(prefix): + return text[len(prefix):] + return text + def load_folder_files(folder_path, recursive=True): """ load folder path, return all files in list format. @param diff --git a/tests/test_utils.py b/tests/test_utils.py index d56f0573..8b03df1d 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -8,6 +8,14 @@ from tests.base import ApiServerUnittest class TestUtils(ApiServerUnittest): + def test_remove_prefix(self): + full_url = "http://debugtalk.com/post/123" + prefix = "http://debugtalk.com" + self.assertEqual( + utils.remove_prefix(full_url, prefix), + "/post/123" + ) + def test_load_folder_files(self): folder = os.path.join(os.getcwd(), 'tests') file1 = os.path.join(os.getcwd(), 'tests', 'test_utils.py')