You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2011/03/18 01:23:51 UTC

svn commit: r1082769 - /incubator/libcloud/trunk/test/compute/test_elastichosts.py

Author: tomaz
Date: Fri Mar 18 00:23:51 2011
New Revision: 1082769

URL: http://svn.apache.org/viewvc?rev=1082769&view=rev
Log:
Add more tests for ElasticHosts driver.

Modified:
    incubator/libcloud/trunk/test/compute/test_elastichosts.py

Modified: incubator/libcloud/trunk/test/compute/test_elastichosts.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/compute/test_elastichosts.py?rev=1082769&r1=1082768&r2=1082769&view=diff
==============================================================================
--- incubator/libcloud/trunk/test/compute/test_elastichosts.py (original)
+++ incubator/libcloud/trunk/test/compute/test_elastichosts.py Fri Mar 18 00:23:51 2011
@@ -18,17 +18,65 @@ import sys
 import unittest
 import httplib
 
-from libcloud.compute.drivers.elastichosts import ElasticHostsBaseNodeDriver
+from libcloud.compute.base import Node
+from libcloud.compute.drivers.elastichosts import \
+                              (ElasticHostsBaseNodeDriver as ElasticHosts,
+                               ElasticHostsException)
+from libcloud.common.types import InvalidCredsError, MalformedResponseError
 
 from test import MockHttp
 from test.compute import TestCaseMixin
 from test.file_fixtures import ComputeFileFixtures
 
 class ElasticHostsTestCase(unittest.TestCase):
+
     def setUp(self):
-        ElasticHostsBaseNodeDriver.connectionCls.conn_classes = (None,
+        ElasticHosts.connectionCls.conn_classes = (None,
                                                             ElasticHostsHttp)
-        self.driver = ElasticHostsBaseNodeDriver('foo', 'bar')
+        ElasticHostsHttp.type = None
+        self.driver = ElasticHosts('foo', 'bar')
+        self.node = Node(id=72258, name=None, state=None, public_ip=None,
+                         private_ip=None, driver=self.driver)
+
+    def test_invalid_creds(self):
+        ElasticHostsHttp.type = 'UNAUTHORIZED'
+        try:
+            self.driver.list_nodes()
+        except InvalidCredsError, e:
+            self.assertEqual(True, isinstance(e, InvalidCredsError))
+        else:
+            self.fail('test should have thrown')
+
+    def test_malformed_response(self):
+        ElasticHostsHttp.type = 'MALFORMED'
+        try:
+            self.driver.list_nodes()
+        except MalformedResponseError:
+            pass
+        else:
+            self.fail('test should have thrown')
+
+    def test_parse_error(self):
+        ElasticHostsHttp.type = 'PARSE_ERROR'
+        try:
+            self.driver.list_nodes()
+        except Exception, e:
+            self.assertTrue(str(e).find('X-Elastic-Error') != -1)
+        else:
+            self.fail('test should have thrown')
+
+    def test_ex_set_node_configuration(self):
+        success = self.driver.ex_set_node_configuration(node=self.node,
+                                                        name='name',
+                                                        cpu='2')
+
+    def test_ex_set_node_configuration_invalid_keys(self):
+        try:
+            self.driver.ex_set_node_configuration(node=self.node, foo='bar')
+        except ElasticHostsException:
+            pass
+        else:
+            self.fail('Invalid option specified, but an exception was not thrown')
 
     def test_list_nodes(self):
         nodes = self.driver.list_nodes()
@@ -59,9 +107,6 @@ class ElasticHostsTestCase(unittest.Test
         self.assertEqual(size.id, '38df0986-4d85-4b76-b502-3878ffc80161')
         self.assertEqual(size.name, 'CentOS Linux 5.5')
 
-    def test_list_locations_response(self):
-        pass
-
     def test_reboot_node(self):
         node = self.driver.list_nodes()[0]
         self.assertTrue(self.driver.reboot_node(node))
@@ -70,7 +115,7 @@ class ElasticHostsTestCase(unittest.Test
         node = self.driver.list_nodes()[0]
         self.assertTrue(self.driver.destroy_node(node))
 
-    '''def test_create_node(self):
+    def test_create_node(self):
         sizes = self.driver.list_sizes()
         size = [s for s in sizes if \
                 s.id == 'large'][0]
@@ -79,12 +124,22 @@ class ElasticHostsTestCase(unittest.Test
                 i.id == '38df0986-4d85-4b76-b502-3878ffc80161'][0]
 
         self.assertTrue(self.driver.create_node(name="api.ivan.net.nz",
-        image=image, size=size))'''
+                                                image=image, size=size))
 
 class ElasticHostsHttp(MockHttp):
 
     fixtures = ComputeFileFixtures('elastichosts')
 
+    def _servers_info_UNAUTHORIZED(self, method, url, body, headers):
+         return (httplib.UNAUTHORIZED, body, {}, httplib.responses[httplib.NO_CONTENT])
+
+    def _servers_info_MALFORMED(self, method, url, body, headers):
+         body = "{malformed: '"
+         return (httplib.OK, body, {}, httplib.responses[httplib.NO_CONTENT])
+
+    def _servers_info_PARSE_ERROR(self, method, url, body, headers):
+         return (505, body, {}, httplib.responses[httplib.NO_CONTENT])
+
     def _servers_b605ca90_c3e6_4cee_85f8_a8ebdf8f9903_reset(self, method, url, body, headers):
          return (httplib.NO_CONTENT, body, {}, httplib.responses[httplib.NO_CONTENT])
 
@@ -110,5 +165,9 @@ class ElasticHostsHttp(MockHttp):
         body = self.fixtures.load('servers_info.json')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
+    def _servers_72258_set(self, method, url, body, headers):
+        body = '{}'
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
 if __name__ == '__main__':
     sys.exit(unittest.main())