Add deplyVM tests
diff --git a/gstack/controllers/instances.py b/gstack/controllers/instances.py
index 032ba0e..8bb0e14 100755
--- a/gstack/controllers/instances.py
+++ b/gstack/controllers/instances.py
@@ -290,10 +290,10 @@
 @authentication.required
 def addinstance(authorization, projectid, zone):
     data = json.loads(request.data)
-    print data
     args = {}
     args['name'] = data['name']
     args['serviceoffering'] = data['machineType'].rsplit('/', 1)[1]
+    print args['serviceoffering']
     args['template'] = data['disks'][0]['initializeParams']['sourceImage'].rsplit('/', 1)[1]
     args['zone'] = zone
 
@@ -321,8 +321,7 @@
     else:
         populated_response = operations.create_response(
             projectid=projectid,
-            operationid=deployment_result[
-                'deployvirtualmachineresponse']['jobid'],
+            operationid=deployment_result['deployvirtualmachineresponse']['jobid'],
             authorization=authorization
         )
 
diff --git a/gstack/controllers/operations.py b/gstack/controllers/operations.py
index faa7ad6..de31b32 100644
--- a/gstack/controllers/operations.py
+++ b/gstack/controllers/operations.py
@@ -141,7 +141,7 @@
                 'getinstance',
                 projectid=projectid,
                 zone=async_result['jobresult']['virtualmachine']['zonename'],
-                instance=async_result['jobresult']['virtualmachine']['displayname']))
+                instance=async_result['jobresult']['virtualmachine']['name']))
         _add_sshkey_metadata(
             authorization=authorization,
             publickey=publickey_storage[projectid],
diff --git a/tests/__init__.py b/tests/__init__.py
index 9ce950c..b7a5e33 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -36,7 +36,7 @@
 
         with mock.patch('requests.get', get):
             self.get('/oauth2/auth?scope=example&redirect_uri=http://127.0.0.1:9999&response_type=code&client_id=ExampleAPIKey&access_type=offline')
-            response = self.post('/oauth2/token', data=data)
+            response = self.post_html('/oauth2/token', data=data)
 
         GStackAppTestCase.access_token = json.loads(response.data)['access_token']
 
diff --git a/tests/data/valid_async_deploy_vm.json b/tests/data/valid_async_deploy_vm.json
new file mode 100644
index 0000000..5c0edfd
--- /dev/null
+++ b/tests/data/valid_async_deploy_vm.json
@@ -0,0 +1,6 @@
+{
+    "deployvirtualmachineresponse": {
+        "id": "d0140ed4-988e-495c-b46f-19b9637ee969",
+        "jobid": "955dc9dd-f900-4fb4-80ef-b96ca3fc2687"
+    }
+}
diff --git a/tests/instances_tests.py b/tests/instances_tests.py
index 47e71c9..802af99 100644
--- a/tests/instances_tests.py
+++ b/tests/instances_tests.py
@@ -3,6 +3,7 @@
 
 import mock
 import json
+from gstack import publickey_storage
 
 from gstack.helpers import read_file
 from . import GStackAppTestCase
@@ -117,3 +118,87 @@
 
     #    self.assert_ok(response)
 
+    def test_add_instance(self):
+        data = {
+             'kind':  'compte#instance',
+             'machineType':  'https://localhost:5000/compte/v1/projects/brogand93@darrenbrogan.ie/zones/ch-gva-2/machineTypes/machinetypename',
+             'description':  '',
+             'tags': {
+                 'items': []
+             },
+             'disks': [{
+                 'deviceName':  'machinetypename',
+                 'initializeParams': {
+                     'diskName':  'machinetypename',
+                     'sourceImage':  'https://localhost:5000/compte/v1/projects/brogand93@darrenbrogan.ie/global/images/imagename'
+                 },
+                 'autoDelete': False,
+                 'boot': True,
+                 'mode':  'READ_WRITE',
+                 'type':  'PERSISTENT'
+             }],
+             'metadata': {
+                 'items': [],
+                 'kind':  'compte#metadata'
+             },
+             'networkInterfaces': [{
+                 'accessConfigs': [{
+                     'type':  'ONE_TO_ONE_NAT',
+                     'name':  'External NAT'
+                 }],
+                 'network':  'https://localhost:5000/compte/v1/projects/brogand93@darrenbrogan.ie/global/networks/networkname'
+             }],
+             'name':  'foobar'
+        }
+
+        publickey_storage['admin'] = 'testkey'
+
+        data = json.dumps(data)
+
+        get = mock.Mock()
+        get.return_value.text = read_file('tests/data/valid_async_deploy_vm.json')
+        get.return_value.status_code = 200
+
+        get_templates = mock.Mock()
+        get_templates.return_value = json.loads(read_file('tests/data/valid_describe_images.json'))
+
+        get_zones = mock.Mock()
+        get_zones.return_value = json.loads(read_file('tests/data/valid_describe_zone.json'))
+
+        get_service_offerings = mock.Mock()
+        get_service_offerings.return_value = json.loads(read_file('tests/data/valid_describe_service_offering.json'))
+
+        get_networks = mock.Mock()
+        get_networks.return_value = json.loads(read_file('tests/data/valid_describe_security_group.json'))
+
+        get_async_result = mock.Mock()
+        get_async_result.return_value = json.loads(read_file('tests/data/valid_run_instance.json'))
+
+        with mock.patch('requests.get', get):
+            with mock.patch(
+                'gstack.controllers.images._get_templates',
+                get_templates
+            ):
+                with mock.patch(
+                    'gstack.controllers.zones._get_zones',
+                    get_zones
+                ):
+                     with mock.patch(
+                        'gstack.controllers.machine_type._get_machinetypes',
+                        get_service_offerings
+                    ):
+                         with mock.patch(
+                            'gstack.controllers.networks._get_networks',
+                            get_networks
+                        ):
+                            with mock.patch(
+                                'gstack.controllers.operations._get_async_result',
+                                get_async_result
+                            ):
+                                headers = {
+                                    'authorization': 'Bearer ' + str(GStackAppTestCase.access_token),
+                                }
+
+                                response = self.post_json('/compute/v1/projects/admin/zones/zonename/instances', data=data, headers=headers)
+
+        self.assert_ok(response)
diff --git a/tests/utils.py b/tests/utils.py
index 8101ea7..60f57b1 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -14,18 +14,28 @@
     def _html_data(kwargs):
         if not kwargs.get('content_type'):
             kwargs['content_type'] = 'application/x-www-form-urlencoded'
+        return kwargs
 
+    @staticmethod
+    def _json_data(kwargs):
+        if not kwargs.get('content_type'):
+            kwargs['content_type'] = 'application/json'
         return kwargs
 
     @staticmethod
     def _request(method, *args, **kwargs):
         return method(*args, **kwargs)
 
-    def post(self, *args, **kwargs):
+    def post_html(self, *args, **kwargs):
         return (
             self._request(self.client.post, *args, **self._html_data(kwargs))
         )
 
+    def post_json(self, *args, **kwargs):
+        return (
+            self._request(self.client.post, *args, **self._json_data(kwargs))
+        )
+
     def get(self, *args, **kwargs):
         return self._request(self.client.get, *args, **kwargs)