def export(request, name): host = request.GET.get("service_host", "localhost") try: db = DatabaseManager(name, host) return HttpResponse(db.export()) except subprocess.CalledProcessError, e: return HttpResponse(e.output.split(":")[-1].strip(), status=500)
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_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", "%")