add remove_prefix utils

This commit is contained in:
debugtalk
2017-11-02 18:42:26 +08:00
parent 3d8c4d4913
commit 5a61e15595
2 changed files with 15 additions and 0 deletions

View File

@@ -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

View File

@@ -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')