Exemplo n.º 1
0
 def test_drop(self):
     db = DatabaseManager("otherdatabase")
     db.create_database()
     db.drop_database()
     self.cursor.execute("select SCHEMA_NAME from information_schema.SCHEMATA where SCHEMA_NAME = 'otherdatabase'")
     row = self.cursor.fetchone()
     self.assertFalse(row)
Exemplo n.º 2
0
 def test_create(self):
     db = DatabaseManager("newdatabase")
     db.create_database()
     self.cursor.execute("select SCHEMA_NAME from information_schema.SCHEMATA where SCHEMA_NAME = 'newdatabase'")
     row = self.cursor.fetchone()
     self.assertEqual("newdatabase", row[0])
     db.drop_database()
Exemplo n.º 3
0
 def test_create_database_with_custom_hostname(self):
     db = DatabaseManager("newdatabase", host="127.0.0.1")
     db.create_database()
     sql = "select SCHEMA_NAME from information_schema.SCHEMATA " +\
           "where SCHEMA_NAME = 'newdatabase'"
     self.cursor.execute(sql)
     row = self.cursor.fetchone()
     self.assertEqual("newdatabase", row[0])
     db.drop_database()
Exemplo n.º 4
0
 def test_drop(self):
     db = DatabaseManager("otherdatabase")
     db.create_database()
     db.drop_database()
     sql = "select SCHEMA_NAME from information_schema.SCHEMATA where " +\
           "SCHEMA_NAME = 'otherdatabase'"
     self.cursor.execute(sql)
     row = self.cursor.fetchone()
     self.assertFalse(row)
Exemplo n.º 5
0
 def test_create(self):
     db = DatabaseManager("newdatabase")
     db.create_database()
     sql = "select SCHEMA_NAME from information_schema.SCHEMATA " +\
           "where SCHEMA_NAME = 'newdatabase'"
     self.cursor.execute(sql)
     row = self.cursor.fetchone()
     self.assertEqual("newdatabase", row[0])
     db.drop_database()
Exemplo n.º 6
0
 def delete(self, request, name, *args, **kwargs):
     try:
         instance = Instance.objects.get(name=name)
     except Instance.DoesNotExist:
         return HttpResponse("Can't drop database 'doesnotexists'; database doesn't exist", status=500)
     self._client.terminate(instance)
     instance.delete()
     host = _get_service_host(request.GET)
     db = DatabaseManager(name, host)
     try:
         db.drop_database()
     except Exception, e:
         return HttpResponse(e[1], status=500)
Exemplo n.º 7
0
 def test_create_database(self):
     try:
         request = RequestFactory().post("/", {"name": "ciclops"})
         view = CreateDatabase()
         view._client = mocks.FakeEC2Client()
         response = view.post(request)
         self.assertEqual(201, response.status_code)
         self.assertEqual("ok", response.content)
         time.sleep(0.5)
         self.cursor.execute("select SCHEMA_NAME from information_schema.SCHEMATA where SCHEMA_NAME = 'ciclops'")
         row = self.cursor.fetchone()
         self.assertEqual("ciclops", row[0])
     finally:
         db = DatabaseManager("ciclops")
         db.drop_database()
Exemplo n.º 8
0
    def test_export(self):
        db = DatabaseManager("magneto")
        db.create_database()
        db.create_user("magneto", "localhost")
        self.cursor.execute("create table magneto.foo ( test varchar(255) );")
        expected = """/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `foo` (
  `test` varchar(255) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
"""
        result = db.export()
        self.assertEqual(expected, result.replace("InnoDB", "MyISAM"))
        db.drop_database()
        db.drop_user("magneto", "localhost")
Exemplo n.º 9
0
    def test_export(self):
        db = DatabaseManager("magneto")
        db.create_database()
        db.create_user("magneto", "%")
        self.cursor.execute("create table magneto.foo ( test varchar(255) );")
        expected = """\
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `foo` (
  `test` varchar(255) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
"""
        result = db.export()
        self.assertEqual(expected, result.replace("InnoDB", "MyISAM"))
        db.drop_database()
        db.drop_user("magneto", "%")
Exemplo n.º 10
0
    def test_export_from_a_custom_service_host(self):
        db = DatabaseManager("magneto", host="127.0.0.1")
        db.create_database()
        db.create_user("magneto", "localhost")
        self.cursor.execute("create table magneto.foo ( test varchar(255) );")
        expected = """/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `foo` (
  `test` varchar(255) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
"""
        request = RequestFactory().get("/", {"service_host": "127.0.0.1"})
        result = export(request, "magneto")
        self.assertEqual(200, result.status_code)
        self.assertEqual(expected, result.content.replace("InnoDB", "MyISAM"))
        db.drop_database()
        db.drop_user("magneto", "localhost")
Exemplo n.º 11
0
 def test_create_database_ec2(self):
     try:
         client = mocks.FakeEC2Client()
         t = start_creator(DatabaseManager, client)
         request = RequestFactory().post("/", {"name": "ciclops"})
         view = CreateDatabase()
         view._client = client
         response = view.post(request)
         self.assertEqual(201, response.status_code)
         self.assertEqual("", response.content)
         t.stop()
         sql = "select SCHEMA_NAME from information_schema.SCHEMATA " + \
               "where SCHEMA_NAME = 'ciclops'"
         self.cursor.execute(sql)
         row = self.cursor.fetchone()
         self.assertEqual("ciclops", row[0])
     finally:
         db = DatabaseManager("ciclops")
         db.drop_database()
Exemplo n.º 12
0
 def test_create_database_ec2(self):
     try:
         client = mocks.FakeEC2Client()
         t = start_creator(DatabaseManager, client)
         request = RequestFactory().post("/", {"name": "ciclops"})
         view = CreateDatabase()
         view._client = client
         response = view.post(request)
         self.assertEqual(201, response.status_code)
         self.assertEqual("", response.content)
         t.stop()
         sql = "select SCHEMA_NAME from information_schema.SCHEMATA " + \
               "where SCHEMA_NAME = 'ciclops'"
         self.cursor.execute(sql)
         row = self.cursor.fetchone()
         self.assertEqual("ciclops", row[0])
     finally:
         db = DatabaseManager("ciclops")
         db.drop_database()
Exemplo n.º 13
0
    def test_export_from_a_custom_service_host(self):
        db = DatabaseManager("magneto", host="127.0.0.1")
        db.create_database()
        db.create_user("magneto", "%")
        self.cursor.execute("create table magneto.foo ( test varchar(255) );")
        expected = """\
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `foo` (
  `test` varchar(255) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
"""
        request = RequestFactory().get("/", {"service_host": "127.0.0.1"})
        result = export(request, "magneto")
        self.assertEqual(200, result.status_code)
        self.assertEqual(expected, result.content.replace("InnoDB", "MyISAM"))
        db.drop_database()
        db.drop_user("magneto", "%")