commit cdeadadcd7ca23c99677e8321c8520cab0516fc1
Author: Stavros Sachtouris <saxtouri@admin.grnet.gr>
Date:   Wed Aug 7 18:29:17 2013 +0300

    Initialize tests for kamaki.cli.utils
    
    Refs: #4058

diff --git a/kamaki/cli/test.py b/kamaki/cli/test.py
index 3ece519..aa7372f 100644
--- a/kamaki/cli/test.py
+++ b/kamaki/cli/test.py
@@ -279,6 +279,76 @@ class LoggerMethods(TestCase):
         GL.assert_called_once_with('my logger name')
 
 
+class UtilsMethods(TestCase):
+
+    def assert_dicts_are_equal(self, d1, d2):
+        for k, v in d1.items():
+            self.assertTrue(k in d2)
+            if isinstance(v, dict):
+                self.assert_dicts_are_equal(v, d2[k])
+            else:
+                self.assertEqual(unicode(v), unicode(d2[k]))
+
+    def test_guess_mime_type(self):
+        from kamaki.cli.utils import guess_mime_type
+        from mimetypes import guess_type
+        for args in product(
+                ('file.txt', 'file.png', 'file.zip', 'file.gz', None, 'X'),
+                ('a type', None),
+                ('an/encoding', None)):
+            filename, ctype, cencoding = args
+            if filename:
+                exp_type, exp_enc = guess_type(filename)
+                self.assertEqual(
+                    guess_mime_type(*args),
+                    (exp_type or ctype, exp_enc or cencoding))
+            else:
+                self.assertRaises(AssertionError, guess_mime_type, *args)
+
+    def test_pretty_keys(self):
+        from kamaki.cli.utils import pretty_keys
+        for args, exp in (
+                (
+                    ({'k1': 'v1', 'k1_k2': 'v2'}, ),
+                    {'k1': 'v1', 'k1 k2': 'v2'}),
+                (
+                    ({'k1': 'v1', 'k1_k2': 'v2'}, '1'),
+                    {'k': 'v1', 'k _k2': 'v2'}),
+                (
+                    ({'k1_k2': 'v1', 'k1': {'k2': 'v2', 'k2_k3': 'v3'}}, ),
+                    {'k1 k2': 'v1', 'k1': {'k2': 'v2', 'k2_k3': 'v3'}}),
+                (
+                    (
+                        {'k1_k2': 'v1', 'k1': {'k2': 'v2', 'k2_k3': 'v3'}},
+                        '_',
+                        True),
+                    {'k1 k2': 'v1', 'k1': {'k2': 'v2', 'k2 k3': 'v3'}}),
+                (
+                    (
+                        {
+                            'k1_k2': {'k_1': 'v_1', 'k_2': {'k_3': 'v_3'}},
+                            'k1': {'k2': 'v2', 'k2_k3': 'v3'}},
+                        '_',
+                        True),
+                    {
+                        'k1 k2': {'k 1': 'v_1', 'k 2': {'k 3': 'v_3'}},
+                        'k1': {'k2': 'v2', 'k2 k3': 'v3'}}),
+                (
+                    (
+                        {
+                            'k1_k2': {'k_1': 'v_1', 'k_2': {'k_3': 'v_3'}},
+                            'k1': {'k2': 'v2', 'k2_k3': 'v3'}},
+                        '1',
+                        True),
+                    {
+                        'k _k2': {'k_': 'v_1', 'k_2': {'k_3': 'v_3'}},
+                        'k': {'k2': 'v2', 'k2_k3': 'v3'}})
+            ):
+            initial = dict(args[0])
+            self.assert_dicts_are_equal(pretty_keys(*args), exp)
+            self.assert_dicts_are_equal(initial, args[0])
+
+
 #  TestCase auxiliary methods
 
 def runTestCase(cls, test_name, args=[], failure_collector=[]):
diff --git a/kamaki/cli/utils.py b/kamaki/cli/utils.py
index eaf3d57..baed1c3 100644
--- a/kamaki/cli/utils.py
+++ b/kamaki/cli/utils.py
@@ -100,17 +100,14 @@ def remove_colors():
     red = yellow = magenta = bold = dummy
 
 
-def pretty_keys(d, delim='_', recurcive=False):
-    """<term>delim<term> to <term> <term> transformation
-    """
-    new_d = {}
-    for key, val in d.items():
-        new_key = key.split(delim)[-1]
-        if recurcive and isinstance(val, dict):
-            new_val = pretty_keys(val, delim, recurcive)
-        else:
-            new_val = val
-        new_d[new_key] = new_val
+def pretty_keys(d, delim='_', recursive=False):
+    """<term>delim<term> to <term> <term> transformation"""
+    new_d = dict(d)
+    for k, v in d.items():
+        new_v = new_d.pop(k)
+        new_d[k.replace(delim, ' ').strip()] = pretty_keys(
+            new_v, delim, True) if (
+                recursive and isinstance(v, dict)) else new_v
     return new_d
 
 
