|
@@ -34,3 +34,85 @@ class TestUtils(unittest.TestCase):
|
|
|
expected_result,
|
|
|
"fail getting the parent parent path from the given path")
|
|
|
|
|
|
+ def test_get_real_file_path(self):
|
|
|
+ """
|
|
|
+ Expect to load the proper file following the order :
|
|
|
+ - Provided absolute path
|
|
|
+ - Current user path + file_name
|
|
|
+ - /etc/kalliope + file_name
|
|
|
+ - /path/to/kalliope/ +file_name
|
|
|
+ """
|
|
|
+ ###
|
|
|
+ # Test the absolute path
|
|
|
+ dir_path = "/tmp/kalliope/tests/"
|
|
|
+ file_name = "test_real_file_path"
|
|
|
+ absolute_path_to_test = os.path.join(dir_path,file_name)
|
|
|
+ expected_result = absolute_path_to_test
|
|
|
+ if not os.path.exists(dir_path):
|
|
|
+ os.makedirs(dir_path)
|
|
|
+
|
|
|
+ # touch the file
|
|
|
+ open(absolute_path_to_test, 'a').close()
|
|
|
+
|
|
|
+ self.assertEquals(Utils.get_real_file_path(absolute_path_to_test),
|
|
|
+ expected_result,
|
|
|
+ "Fail to match the given absolute path ")
|
|
|
+ # Clean up
|
|
|
+ if os.path.exists(absolute_path_to_test):
|
|
|
+ os.remove(absolute_path_to_test)
|
|
|
+
|
|
|
+ ###
|
|
|
+ # test the Current path
|
|
|
+ file_name = "test_real_file_path"
|
|
|
+ expected_result = os.getcwd() + os.sep + file_name
|
|
|
+
|
|
|
+ # touch the file
|
|
|
+ open(file_name, 'a').close()
|
|
|
+
|
|
|
+ self.assertEquals(Utils.get_real_file_path(file_name),
|
|
|
+ expected_result,
|
|
|
+ "Fail to match the Current path ")
|
|
|
+ # Clean up
|
|
|
+ if os.path.exists(file_name):
|
|
|
+ os.remove(file_name)
|
|
|
+
|
|
|
+ ###
|
|
|
+ # test /etc/kalliope
|
|
|
+ # /!\ need permissions
|
|
|
+ # dir_path = "/etc/kalliope/"
|
|
|
+ # file_name = "test_real_file_path"
|
|
|
+ # path_to_test = os.path.join(dir_path,file_name)
|
|
|
+ # expected_result = "/etc/kalliope" + os.sep + file_name
|
|
|
+ # if not os.path.exists(dir_path):
|
|
|
+ # os.makedirs(dir_path)
|
|
|
+ #
|
|
|
+ # # touch the file
|
|
|
+ # open(path_to_test, 'a').close()
|
|
|
+ #
|
|
|
+ # self.assertEquals(Utils.get_real_file_path(file_name),
|
|
|
+ # expected_result,
|
|
|
+ # "Fail to match the /etc/kalliope path")
|
|
|
+ # # Clean up
|
|
|
+ # if os.path.exists(file_name):
|
|
|
+ # os.remove(file_name)
|
|
|
+
|
|
|
+ ###
|
|
|
+ # /an/unknown/path/kalliope/
|
|
|
+ dir_path = "../kalliope/"
|
|
|
+ file_name = "test_real_file_path"
|
|
|
+ path_to_test = os.path.join(dir_path, file_name)
|
|
|
+ expected_result = os.path.normpath(os.getcwd() + os.sep + os.pardir + os.sep +"kalliope" + os.sep + file_name)
|
|
|
+ if not os.path.exists(dir_path):
|
|
|
+ os.makedirs(dir_path)
|
|
|
+
|
|
|
+ # touch the file
|
|
|
+ open(path_to_test, 'a').close()
|
|
|
+
|
|
|
+ pp = Utils.get_real_file_path(file_name)
|
|
|
+
|
|
|
+ self.assertEquals(Utils.get_real_file_path(file_name),
|
|
|
+ expected_result,
|
|
|
+ "Fail to match the /an/unknown/path/kalliope path")
|
|
|
+ # Clean up
|
|
|
+ if os.path.exists(file_name):
|
|
|
+ os.remove(file_name)
|