Repository: Zepmanbc/creopyson

Issue:
Exception thrown in creo_list_dirs
* Creopyson version: 0.3.1
* Python version: 3.6
* Operating System: Windows

### Description

I tried to list the directories in the current session with `creo_list_dirs()` but I received an exception telling that Creoson did not return the right data.

### What I Did

```
>>> c.creo_list_dirs()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Tim\.virtualenvs\creopyson_test-yJfFsqNW\lib\site-packages\creopyson\creo.py", line 111, in list_dirs
    return client._creoson_post("creo", "list_dirs", data, "dirlist")
  File "C:\Users\Tim\.virtualenvs\creopyson_test-yJfFsqNW\lib\site-packages\creopyson\connection.py", line 81, in _creoson_post
    raise MissingKey("Missing `data` in creoson return")
creopyson.exceptions.MissingKey: Missing `data` in creoson return
```

Comments:

Patch:
diff --git a/creopyson/creo.py b/creopyson/creo.py
index 890f29d..1d86c48 100755
--- a/creopyson/creo.py
+++ b/creopyson/creo.py
@@ -1,4 +1,5 @@
 """Creo module."""
+from creopyson.exceptions import MissingKey
 
 
 def cd(client, dirname):
@@ -108,7 +109,11 @@ def list_dirs(client, dirname=None):
     data = {"dirname": "*"}
     if dirname:
         data["dirname"] = dirname
-    return client._creoson_post("creo", "list_dirs", data, "dirlist")
+    try:
+        result = client._creoson_post("creo", "list_dirs", data, "dirlist")
+    except MissingKey:
+        result = []
+    return result
 
 
 def list_files(client, filename=None):


Test patch:
diff --git a/tests/fixtures.py b/tests/fixtures.py
index 8919eca..6d2ff6e 100644
--- a/tests/fixtures.py
+++ b/tests/fixtures.py
@@ -55,7 +55,7 @@ def mk_creoson_post_dict(monkeypatch):
 @pytest.fixture
 def mk_creoson_post_None(monkeypatch):
     """Mock _creoson_post return None."""
-    def fake_func(client, command, function, data=None):
+    def fake_func(client, command, function, data=None, key_data=None):
         return None
     monkeypatch.setattr(
         creopyson.connection.Client, '_creoson_post', fake_func)
@@ -64,7 +64,7 @@ def mk_creoson_post_None(monkeypatch):
 @pytest.fixture
 def mk_creoson_post_list(monkeypatch):
     """Mock _creoson_post return list."""
-    def fake_func(client, command, function, data=None):
+    def fake_func(client, command, function, data=None, key_data=None):
         return ['information']
     monkeypatch.setattr(
         creopyson.connection.Client, '_creoson_post', fake_func)
diff --git a/tests/test_creo.py b/tests/test_creo.py
index ccdb9fe..1398006 100644
--- a/tests/test_creo.py
+++ b/tests/test_creo.py
@@ -1,5 +1,6 @@
 """Creo testing."""
 import creopyson
+from creopyson.exceptions import MissingKey
 from .fixtures import mk_creoson_post_dict, mk_creoson_post_None
 
 
@@ -43,6 +44,23 @@ def test_creo_list_dirs(mk_creoson_post_dict):
     c = creopyson.Client()
     result = c.creo_list_dirs("filter_*")
     assert isinstance(result, (list))
+    result = c.creo_list_dirs()
+    assert isinstance(result, (list))
+
+
+def test_creo_list_dirs_empty(monkeypatch):
+    """Correction issue #1.
+
+    if there is no folder in directory, creoson does not return `data`.
+    Need to return an empty list.
+    """
+    def fake_func(client, command, function, data=None, key_data=None):
+        raise MissingKey("Missing `data` in creoson return")
+    monkeypatch.setattr(
+        creopyson.connection.Client, '_creoson_post', fake_func)
+    c = creopyson.Client()
+    result = c.creo_list_dirs()
+    assert result == []
 
 
 def test_creo_list_files(mk_creoson_post_dict):