commit 058ee9a80ff92a550a2c774075ee07693007020a
Author: Stavros Sachtouris <saxtouri@admin.grnet.gr>
Date:   Fri Nov 1 18:32:45 2013 +0200

    Implement clients.network.NetworkClient (part)
    
    Refs: #4546
    
    Implemented in this commit: list_networks, create_network, unittests for both

diff --git a/kamaki/clients/network/__init__.py b/kamaki/clients/network/__init__.py
index 498c653..804d46f 100644
--- a/kamaki/clients/network/__init__.py
+++ b/kamaki/clients/network/__init__.py
@@ -37,3 +37,13 @@ from kamaki.clients.network.rest_api import NetworkRestClient
 
 class NetworkClient(NetworkRestClient):
     """OpenStack Network API 2.0 client"""
+
+    def list_networks(self):
+        r = self.networks_get(success=200)
+        return r.json['networks']
+
+    def create_network(self, name=None, admin_state_up=None, shared=None):
+        req = dict(network=dict(
+            name=name or '', admin_state_up=bool(admin_state_up)))
+        r = self.networks_post(json_data=req, shared=shared, success=201)
+        return r.json['network']
diff --git a/kamaki/clients/network/test.py b/kamaki/clients/network/test.py
index ac647c7..4a43a96 100644
--- a/kamaki/clients/network/test.py
+++ b/kamaki/clients/network/test.py
@@ -48,7 +48,7 @@ class NetworkRestClient(TestCase):
         self.client = network.NetworkRestClient(self.url, self.token)
 
     def tearDown(self):
-        pass
+        del self.client
 
     def _assert(self, method_call, path, set_param=None, params=(), **kwargs):
         """Assert the REST method call is called as expected"""
@@ -260,13 +260,61 @@ class NetworkRestClient(TestCase):
                 data=dumps(json_data), **kwargs)
 
 
+class FakeObject(object):
+
+    json = None
+
+
+class NetworkClient(TestCase):
+
+    """Set up a ComputesRest thorough test"""
+    def setUp(self):
+        self.url = 'http://network.example.com'
+        self.token = 'n2tw0rk70k3n'
+        self.client = network.NetworkClient(self.url, self.token)
+
+    def tearDown(self):
+        del self.client
+
+    @patch(
+        'kamaki.clients.network.NetworkClient.networks_get',
+        return_value=FakeObject())
+    def test_list_networks(self, networks_get):
+        FakeObject.json = dict(networks='ret val')
+        self.assertEqual(self.client.list_networks(), 'ret val')
+        networks_get.assert_called_once_with(success=200)
+
+    @patch(
+        'kamaki.clients.network.NetworkClient.networks_post',
+        return_value=FakeObject())
+    def test_create_network(self, networks_post):
+        FakeObject.json = dict(network='ret val')
+        req = dict()
+        for kwargs in (dict(shared=None), dict(shared=True)):
+            for body_params in product(
+                    (('name', None, ''), ('name', 'some name', 'some name')),
+                    (
+                        ('admin_state_up', None, False),
+                        ('admin_state_up', True, True))):
+                fullargs = dict(kwargs)
+                for k, v, exp in body_params:
+                    fullargs[k] = v
+                    req[k] = exp
+                self.assertEqual(
+                    self.client.create_network(**fullargs), 'ret val')
+                expargs = dict(kwargs)
+                expargs = dict(json_data=dict(network=req), success=201)
+                expargs.update(kwargs)
+                self.assertEqual(networks_post.mock_calls[-1], call(**expargs))
+
+
 if __name__ == '__main__':
     from sys import argv
     from kamaki.clients.test import runTestCase
     not_found = True
-    #if not argv[1:] or argv[1] == 'NetworkClient':
-    #    not_found = False
-    #    runTestCase(NetworkClient, 'Network Client', argv[2:])
+    if not argv[1:] or argv[1] == 'NetworkClient':
+        not_found = False
+        runTestCase(NetworkClient, 'Network Client', argv[2:])
     if not argv[1:] or argv[1] == 'NetworkRest':
         not_found = False
         runTestCase(NetworkRestClient, 'NetworkRest Client', argv[2:])
diff --git a/kamaki/clients/test.py b/kamaki/clients/test.py
index 17e6372..0ad4236 100644
--- a/kamaki/clients/test.py
+++ b/kamaki/clients/test.py
@@ -41,7 +41,7 @@ from random import randint
 from kamaki.clients.utils.test import Utils
 from kamaki.clients.astakos.test import AstakosClient
 from kamaki.clients.compute.test import ComputeClient, ComputeRestClient
-from kamaki.clients.network.test import NetworkRestClient
+from kamaki.clients.network.test import NetworkClient, NetworkRestClient
 from kamaki.clients.cyclades.test import CycladesClient
 from kamaki.clients.cyclades.test import CycladesRestClient
 from kamaki.clients.image.test import ImageClient
