示例#1
0
 def test_drop_user(self):
     db = DatabaseManager("magneto")
     db.create_user("magneto", "localhost")
     db.drop_user("magneto", "localhost")
     self.cursor.execute("select User, Host FROM mysql.user WHERE User='******' AND Host='localhost'")
     row = self.cursor.fetchone()
     self.assertFalse(row)
示例#2
0
 def test_create_user(self):
     db = DatabaseManager("wolverine")
     db.create_user("wolverine", "localhost")
     self.cursor.execute("select User, Host FROM mysql.user WHERE User='******' AND Host='localhost'")
     row = self.cursor.fetchone()
     self.assertEqual("wolverine", row[0])
     self.assertEqual("localhost", row[1])
     db.drop_user("wolverine", "localhost")
示例#3
0
 def test_drop_user(self):
     db = DatabaseManager("magneto")
     db.create_user("magneto", "%")
     db.drop_user("magneto", "%")
     sql = "select User, Host FROM mysql.user " +\
           "WHERE User='******' AND Host='%'"
     self.cursor.execute(sql)
     row = self.cursor.fetchone()
     self.assertFalse(row)
 def test_drop_user(self):
     db = DatabaseManager("magneto")
     db.create_user("magneto", "%")
     db.drop_user("magneto", "%")
     sql = "select User, Host FROM mysql.user " +\
           "WHERE User='******' AND Host='%'"
     self.cursor.execute(sql)
     row = self.cursor.fetchone()
     self.assertFalse(row)
 def test_create__and_drop_user_username_greater_than_16_chars(self):
     db = DatabaseManager("anusernamegreaterthan16")
     db.create_user("anusernamegreaterthan16", "%")
     db.drop_user("anusernamegreaterthan16", "%")
     sql = "select User, Host FROM mysql.user " + \
         "WHERE User LIKE 'anusernamegr%' AND Host='%'"
     self.cursor.execute(sql)
     row = self.cursor.fetchone()
     self.assertFalse(row)
示例#6
0
 def test_create__and_drop_user_username_greater_than_16_chars(self):
     db = DatabaseManager("anusernamegreaterthan16")
     db.create_user("anusernamegreaterthan16", "%")
     db.drop_user("anusernamegreaterthan16", "%")
     sql = "select User, Host FROM mysql.user " + \
         "WHERE User LIKE 'anusernamegr%' AND Host='%'"
     self.cursor.execute(sql)
     row = self.cursor.fetchone()
     self.assertFalse(row)
 def test_create_user(self):
     db = DatabaseManager("wolverine")
     db.create_user("wolverine", "%")
     sql = "select User, Host FROM mysql.user " +\
           "WHERE User='******' AND Host='%'"
     self.cursor.execute(sql)
     row = self.cursor.fetchone()
     self.assertEqual("wolverine", row[0])
     self.assertEqual("%", row[1])
     db.drop_user("wolverine", "%")
示例#8
0
 def test_create_user(self):
     db = DatabaseManager("wolverine")
     db.create_user("wolverine", "%")
     sql = "select User, Host FROM mysql.user " +\
           "WHERE User='******' AND Host='%'"
     self.cursor.execute(sql)
     row = self.cursor.fetchone()
     self.assertEqual("wolverine", row[0])
     self.assertEqual("%", row[1])
     db.drop_user("wolverine", "%")
示例#9
0
    def test_drop_user_fom_custom_service_host(self):
        db = DatabaseManager("ciclops", "127.0.0.1")
        db.create_user("ciclops", "localhost")

        request = RequestFactory().delete("/ciclops", {"service_host": "127.0.0.1"})
        response = drop_user(request, "ciclops", "localhost")
        self.assertEqual(200, response.status_code)

        self.cursor.execute("select User, Host FROM mysql.user WHERE User='******' AND Host='localhost'")
        row = self.cursor.fetchone()
        self.assertFalse(row)
示例#10
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")
示例#11
0
 def test_drop_user_from_shared_instance(self):
     settings.SHARED_SERVER = "127.0.0.1"
     instance = Instance.objects.create(name="used", shared=True)
     try:
         db = DatabaseManager("used")
         db.create_user("used", "127.0.0.1")
         request = RequestFactory().delete("/used")
         response = drop_user(request, "used", "127.0.0.1")
         self.assertEqual(200, response.status_code)
         sql = "select User, Host FROM mysql.user " +\
               "WHERE User='******' AND Host='%'"
         self.cursor.execute(sql)
         row = self.cursor.fetchone()
         self.assertIsNone(row)
     finally:
         instance.delete()
示例#12
0
 def test_unbind_app_drops_the_user_on_shared_instance(self):
     settings.SHARED_SERVER = "127.0.0.1"
     instance = Instance.objects.create(name="used", shared=True)
     try:
         db = DatabaseManager("used")
         db.create_user("used", "127.0.0.1")
         request = RequestFactory().delete("/used")
         response = BindApp.as_view()(request, "used")
         self.assertEqual(200, response.status_code)
         sql = "select User, Host FROM mysql.user " +\
               "WHERE User='******' AND Host='%'"
         self.cursor.execute(sql)
         row = self.cursor.fetchone()
         self.assertIsNone(row)
     finally:
         instance.delete()
示例#13
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", "%")
示例#14
0
    def test_drop_user(self):
        instance = Instance.objects.create(name="ciclops", host="127.0.0.1")
        try:
            db = DatabaseManager("ciclops")
            db.create_user("ciclops", "localhost")

            request = RequestFactory().delete("/ciclops")
            response = drop_user(request, "ciclops", "localhost")
            self.assertEqual(200, response.status_code)

            sql = "select User, Host FROM mysql.user " +\
                  "WHERE User='******' AND Host='%'"
            self.cursor.execute(sql)
            row = self.cursor.fetchone()
            self.assertFalse(row)
        finally:
            instance.delete()
示例#15
0
 def test_create_user_should_generate_an_username_when_username_length_is_greater_than_16(self):
     db = DatabaseManager("usernamegreaterthan16")
     username, password = db.create_user("usernamegreaterthan16", "localhost")
     self.cursor.execute("select User, Host FROM mysql.user WHERE User like 'usernamegrea%' AND Host='localhost'")
     row = self.cursor.fetchone()
     self.assertEqual("usernamegrea", row[0][:12])
     db = DatabaseManager(row[0])
     db.drop_user(username, "localhost")
示例#16
0
    def test_unbind_app_drops_the_user(self):
        instance = Instance.objects.create(name="ciclops", host="127.0.0.1")
        try:
            db = DatabaseManager("ciclops")
            db.create_user("ciclops", "localhost")

            request = RequestFactory().delete("/ciclops")
            response = BindApp.as_view()(request, "ciclops")
            self.assertEqual(200, response.status_code)

            sql = "select User, Host FROM mysql.user " +\
                  "WHERE User='******' AND Host='%'"
            self.cursor.execute(sql)
            row = self.cursor.fetchone()
            self.assertFalse(row)
        finally:
            instance.delete()
示例#17
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")
示例#18
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 test_create_user_generates_username_for_dbs_grater_than_16_chars(self):
     db = DatabaseManager("usernamegreaterthan16")
     username, password = db.create_user("usernamegreaterthan16", "%")
     sql = "select User, Host FROM mysql.user " +\
           "WHERE User like 'usernamegrea%' AND Host='%'"
     self.cursor.execute(sql)
     row = self.cursor.fetchone()
     self.assertEqual("usernamegrea", row[0][:12])
     db = DatabaseManager(row[0])
     db.drop_user(username, "%")
示例#20
0
 def test_create_user_generates_username_for_dbs_grater_than_16_chars(self):
     db = DatabaseManager("usernamegreaterthan16")
     username, password = db.create_user("usernamegreaterthan16", "%")
     sql = "select User, Host FROM mysql.user " +\
           "WHERE User like 'usernamegrea%' AND Host='%'"
     self.cursor.execute(sql)
     row = self.cursor.fetchone()
     self.assertEqual("usernamegrea", row[0][:12])
     db = DatabaseManager(row[0])
     db.drop_user(username, "%")
示例#21
0
文件: views.py 项目: agnhesi/mysqlapi
 def post(self, request, name, *args, **kwargs):
     if not "hostname" in request.POST:
         return HttpResponse("Hostname is missing", status=500)
     hostname = request.POST.get("hostname", None)
     if not hostname:
         return HttpResponse("Hostname is empty", status=500)
     try:
         instance = Instance.objects.get(name=name)
     except Instance.DoesNotExist:
         return HttpResponse("Instance not found", status=404)
     if instance.state != "running":
         return HttpResponse(u"You can't bind to this instance because it's not running.", status=412)
     db = DatabaseManager(name, instance.host)
     try:
         username, password = db.create_user(name, hostname)
     except Exception, e:
         return HttpResponse(e[1], status=500)