Permalink
Browse files

new tests for operations on an instance, such as create and destroy u…

…sers and databases.
  • Loading branch information...
1 parent c4d533a commit f34fe5e9d17427b3065170fdcaf57a7177c0e5bd @adregner committed Jul 23, 2012
Showing with 107 additions and 1 deletion.
  1. +2 −0 test_clouddb/__init__.py
  2. +104 −0 test_clouddb/test_database_and_user.py
  3. +1 −1 test_clouddb/test_instance.py
View
@@ -27,11 +27,13 @@ def __init__(self, *args, **kwargs):
import test_connection
import test_instance
+import test_database_and_user
def suite():
suite = unittest.TestSuite()
suite.addTest(test_connection.suite())
suite.addTest(test_instance.suite())
+ suite.addTest(test_database_and_user.suite())
return suite
if __name__ == "__main__":
@@ -0,0 +1,104 @@
+
+"""Primary testing suite for clouddb.models.instance.
+
+This code is licensed under the MIT license. See COPYING for more details."""
+
+import time
+import unittest
+
+import clouddb
+import test_clouddb
+
+CLOUDDB_TEST_INSTANCE_NAME = "testsuite-dbu-%d" % time.time()
+CLOUDDB_TEST_DATABASE_NAME = "testdb_%d_%%d" % time.time()
+CLOUDDB_TEST_DATABASE_I = 1
+
+CLOUDDB_TEST_INSTANCE_OBJECT = None
+
+class InstanceMakerBaseTestCase(test_clouddb.BaseTestCase):
+ def __init__(self, *args, **kwargs):
+ super(InstanceMakerBaseTestCase, self).__init__(*args, **kwargs)
+ if CLOUDDB_TEST_INSTANCE_OBJECT is None:
+ CLOUDDB_TEST_INSTANCE_OBJECT = self.raxdb.create_instance({
+ 'name': CLOUDDB_TEST_INSTANCE_NAME,
+ 'flavorRef': 1,
+ 'volume': {'size': 1},
+ }, wait=True)
+
+ self.instance = CLOUDDB_TEST_INSTANCE_OBJECT
+ self.assertIsInstance(self.instance, clouddb.models.instance.Instance)
+ self.assertEqual(self.instance['status'], "ACTIVE")
+
+class StartWithNoDatabases(InstanceMakerBaseTestCase):
+ def test_create_database(self):
+ dbs = self.instance.databases()
+ self.assertIsInstance(dbs, list)
+ self.assertEqual(len(dbs), 0)
+
+class CreateDatabases(InstanceMakerBaseTestCase):
+ def test_create_database(self):
+ self.instance.create_database(CLOUDDB_TEST_DATABASE_NAME % 1)
+ self.assertEqual(len(self.instance.databases()), 1)
+ self.instance.create_database([CLOUDDB_TEST_DATABASE_NAME % 2, CLOUDDB_TEST_DATABASE_NAME % 3])
+ self.assertEqual(len(self.instance.databases()), 3)
+
+class StartWithNoUsers(InstanceMakerBaseTestCase):
+ def test_create_database(self):
+ us = self.instance.users()
+ self.assertIsInstance(us, list)
+ self.assertEqual(len(us), 0)
+
+class CreateUsers(InstanceMakerBaseTestCase):
+ def test_create_users(self):
+ self.instance.create_user("userA", "password123")
+ self.assertEqual(len(self.instance.users()), 1)
+ self.instance.create_user("userB", "password123", [CLOUDDB_TEST_DATABASE_NAME % 1, CLOUDDB_TEST_DATABASE_NAME % 2])
+ self.assertEqual(len(self.instance.users()), 2)
+
+class DeleteUsers(InstanceMakerBaseTestCase):
+ def test_delete_users(self):
+ self.assertEqual(len(self.instance.users()), 2)
+
+ #delete a user by GETing it
+ user = self.instance.get_user("userB")
+ self.assertIsInstance(user, clouddb.User)
+ user.delete()
+ self.assertEqual(len(self.instance.users()), 1)
+
+ #make sure we know what we have left
+ self.assertEqual(self.instance.users()[0]['name'], "userA")
+
+ #delete the other user outright
+ self.instance.delete_user("userA")
+ self.assertEqual(len(self.instance.users()), 0)
+
+class DeleteDatabases(InstanceMakerBaseTestCase):
+ def test_create_database(self):
+ self.assertEqual(len(self.instance.databases()), 3)
+
+ #delete a database by GETing it
+ db = self.instance.get_database(CLOUDDB_TEST_DATABASE_NAME % 1)
+ self.assertIsInstance(db, clouddb.Database)
+ db.delete()
+ self.assertEqual(len(self.instance.databases()), 2)
+
+ #make sure we know what we have left
+ self.assertEqual(self.instance.databases()[0]['name'], CLOUDDB_TEST_DATABASE_NAME % 2)
+ self.assertEqual(self.instance.databases()[1]['name'], CLOUDDB_TEST_DATABASE_NAME % 3)
+
+ #delete the other user outright
+ self.instance.delete_database(CLOUDDB_TEST_DATABASE_NAME % 2)
+ self.instance.delete_database(CLOUDDB_TEST_DATABASE_NAME % 3)
+ self.assertEqual(len(self.instance.databases()), 0)
+
+def suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(StartWithNoDatabases))
+ suite.addTest(unittest.makeSuite(CreateDatabases))
+ suite.addTest(unittest.makeSuite(InstanceListGet))
+ suite.addTest(unittest.makeSuite(InstanceDestroy))
+ suite.addTest(unittest.makeSuite(InstanceListFinal))
+ return suite
+
+if __name__ == "__main__":
+ unittest.main()
@@ -11,7 +11,7 @@
CLOUDDB_TEST_INSTANCE_OBJECT = None
CLOUDDB_TEST_BASELINE_INSTANCE_COUNT = None
-CLOUDDB_TEST_INSTANCE_NAME = "testsuite-%d" % time.time()
+CLOUDDB_TEST_INSTANCE_NAME = "testsuite-ci-%d" % time.time()
class InstanceBaseline(test_clouddb.BaseTestCase):
def test_instance_list_baseline(self):

0 comments on commit f34fe5e

Please sign in to comment.