Commit bbb0aec6 authored by carlosperate's avatar carlosperate

Force normalised file/dir addressed in the server file/dir browser.

parent 529e9151
......@@ -7,6 +7,7 @@
# http://www.apache.org/licenses/LICENSE-2.0
#
from __future__ import unicode_literals, absolute_import
import os
try:
# 2.x name
import Tkinter
......@@ -37,6 +38,9 @@ def browse_file_dialog():
root.update()
file_path = tkFileDialog.askopenfilename()
root.destroy()
if file_path:
return os.path.normpath(file_path)
else:
return file_path
......@@ -54,7 +58,10 @@ def browse_dir_dialog():
root.deiconify()
root.lift()
root.focus_force()
file_path = tkFileDialog.askdirectory(
dir_path = tkFileDialog.askdirectory(
parent=root, initialdir="/", title='Please select a directory')
root.destroy()
return file_path
if dir_path:
return os.path.normpath(dir_path)
else:
return dir_path
......@@ -29,10 +29,10 @@ class GuiTestCase(unittest.TestCase):
#
# Tests for checking browsing for paths and files
#
@mock.patch('ardublocklyserver.gui.tkFileDialog')
@mock.patch('ardublocklyserver.gui.tkFileDialog.askopenfilename')
def test_browse_file(self, mock_file_select):
test_file = 'test_file'
mock_file_select.askopenfilename.return_value = test_file
test_file = os.path.join(os.getcwd(), 'test_file')
mock_file_select.return_value = test_file
new_file = gui.browse_file_dialog()
self.assertEqual(new_file, test_file)
......@@ -44,11 +44,11 @@ class GuiTestCase(unittest.TestCase):
function_file = gui.browse_file_dialog()
self.assertEqual(canceled_file, function_file)
@mock.patch('ardublocklyserver.gui.tkFileDialog')
@mock.patch('ardublocklyserver.gui.tkFileDialog.askdirectory')
def test_browse_path(self, mock_path_select):
test_path = 'test_path'
mock_path_select.askopenfilename.return_value = test_path
new_path = gui.browse_file_dialog()
test_path = os.path.join(os.getcwd(), 'test_path')
mock_path_select.return_value = test_path
new_path = gui.browse_dir_dialog()
self.assertEqual(new_path, test_path)
def test_browse_path_cancel(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment