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)
 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()
 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()
 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)
 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()
    def test_drop_database_that_needs_name_canonicalization(self):
        settings.SHARED_SERVER = "127.0.0.1"
        canonical_name = canonicalize_db_name("xu-xu")
        Instance.objects.create(name=canonical_name, shared=True)
        db = DatabaseManager("xu-xu", settings.SHARED_SERVER)
        db.create_database()

        view = DropDatabase()
        request = RequestFactory().delete("/xu-xu")
        resp = view.delete(request, "xu-xu")
        self.assertEqual(200, resp.status_code)
        sql = "select SCHEMA_NAME from information_schema.SCHEMATA " +\
              "where SCHEMA_NAME = '{0}'"
        self.cursor.execute(sql.format(canonical_name))
        row = self.cursor.fetchone()
        self.assertIsNone(row)
    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")
    def test_drop_database_that_needs_name_canonicalization(self):
        settings.SHARED_SERVER = "127.0.0.1"
        canonical_name = canonicalize_db_name("xu-xu")
        Instance.objects.create(name=canonical_name, shared=True)
        db = DatabaseManager("xu-xu", settings.SHARED_SERVER)
        db.create_database()

        view = DropDatabase()
        request = RequestFactory().delete("/xu-xu")
        resp = view.delete(request, "xu-xu")
        self.assertEqual(200, resp.status_code)
        sql = "select SCHEMA_NAME from information_schema.SCHEMATA " +\
              "where SCHEMA_NAME = '{0}'"
        self.cursor.execute(sql.format(canonical_name))
        row = self.cursor.fetchone()
        self.assertIsNone(row)
    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", "%")
Beispiel #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")
Beispiel #11
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", "%")
 def create_fandango_shared(self):
     Instance.objects.create(name="fandango", shared=True)
     db = DatabaseManager("fandango", settings.SHARED_SERVER)
     db.create_database()
Beispiel #13
0
 def create_ciclops(self):
     Instance.objects.create(name="ciclops")
     db = DatabaseManager("ciclops", "127.0.0.1")
     db.create_database()
 def create_fandango_shared(self):
     Instance.objects.create(name="fandango", shared=True)
     db = DatabaseManager("fandango", settings.SHARED_SERVER)
     db.create_database()