• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python models.DatabaseManager类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mysqlapi.api.models.DatabaseManager的典型用法代码示例。如果您正苦于以下问题:Python DatabaseManager类的具体用法?Python DatabaseManager怎么用?Python DatabaseManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了DatabaseManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_drop

 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)
开发者ID:agnhesi,项目名称:mysqlapi,代码行数:7,代码来源:test_database_manager.py


示例2: test_create

 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()
开发者ID:agnhesi,项目名称:mysqlapi,代码行数:7,代码来源:test_database_manager.py


示例3: test_create_user_in_shared_instance_with_public_host

 def test_create_user_in_shared_instance_with_public_host(self):
     settings.SHARED_SERVER = "localhost"
     settings.SHARED_SERVER_PUBLIC_HOST = "10.10.10.10"
     instance = Instance.objects.create(
         name="inside_out",
         shared=True,
         state="running",
     )
     try:
         request = RequestFactory().post("/", {"unit-host": "192.168.1.10"})
         response = CreateUser.as_view()(request, "inside_out")
         self.assertEqual(201, response.status_code)
         content = json.loads(response.content)
         expected = {
             u"MYSQL_HOST": u"10.10.10.10",
             u"MYSQL_PORT": u"3306",
             u"MYSQL_DATABASE_NAME": "inside_out",
             u"MYSQL_USER": u"inside_out",
             u"MYSQL_PASSWORD": content["MYSQL_PASSWORD"],
         }
         self.assertEqual(expected, content)
         sql = "select User, Host FROM mysql.user " +\
               "WHERE User='inside_out' AND Host='%'"
         self.cursor.execute(sql)
         row = self.cursor.fetchone()
         self.assertIsNotNone(row)
     finally:
         db = DatabaseManager("inside_out")
         db.drop_user("inside_out", "%")
         instance.delete()
开发者ID:pombredanne,项目名称:mysqlapi,代码行数:30,代码来源:test_create_user.py


示例4: drop_user

def drop_user(request, name, hostname):
    host = _get_service_host(request.GET)
    db = DatabaseManager(name, host)
    try:
        db.drop_user(name, hostname)
    except Exception, e:
        return HttpResponse(e[1], status=500)
开发者ID:agnhesi,项目名称:mysqlapi,代码行数:7,代码来源:views.py


示例5: test_create_user_in_a_custom_service_host

    def test_create_user_in_a_custom_service_host(self):
        instance = Instance.objects.create(
            name="ciclops",
            host="127.0.0.1",
            ec2_id="i-009",
            state="running",
        )
        try:
            request = RequestFactory().post("/", {"hostname": "192.168.1.1", "service_host": "127.0.0.1"})
            response = CreateUser.as_view()(request, "ciclops")
            self.assertEqual(201, response.status_code)
            content = json.loads(response.content)
            expected = {
                u"MYSQL_USER": u"ciclops",
                u"MYSQL_PASSWORD": content["MYSQL_PASSWORD"],
            }
            self.assertDictEqual(expected, content)

            self.cursor.execute("select User, Host FROM mysql.user WHERE User='ciclops' AND Host='192.168.1.1'")
            row = self.cursor.fetchone()
            self.assertEqual("ciclops", row[0])
            self.assertEqual("192.168.1.1", row[1])
        finally:
            db = DatabaseManager("ciclops")
            db.drop_user("ciclops", "192.168.1.1")
            instance.delete()
开发者ID:agnhesi,项目名称:mysqlapi,代码行数:26,代码来源:test_create_user.py


示例6: export

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)
开发者ID:pombredanne,项目名称:mysqlapi,代码行数:7,代码来源:views.py


示例7: test_create_user

 def test_create_user(self):
     instance = Instance.objects.create(
         name="ciclops",
         host="127.0.0.1",
         ec2_id="i-009",
         state="running",
     )
     try:
         request = RequestFactory().post("/", {"unit-host": "192.168.1.1"})
         response = CreateUser.as_view()(request, "ciclops")
         self.assertEqual(201, response.status_code)
         content = json.loads(response.content)
         expected = {
             u"MYSQL_HOST": u"127.0.0.1",
             u"MYSQL_PORT": u"3306",
             u"MYSQL_DATABASE_NAME": "ciclops",
             u"MYSQL_USER": u"ciclops",
             u"MYSQL_PASSWORD": content["MYSQL_PASSWORD"],
         }
         self.assertDictEqual(expected, content)
         sql = "select User, Host FROM mysql.user " +\
               "WHERE User='ciclops' AND Host='%'"
         self.cursor.execute(sql)
         row = self.cursor.fetchone()
         self.assertEqual("ciclops", row[0])
     finally:
         db = DatabaseManager("ciclops")
         db.drop_user("ciclops", "%")
         instance.delete()
开发者ID:pombredanne,项目名称:mysqlapi,代码行数:29,代码来源:test_create_user.py


示例8: test_drop_user

 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='wolverine' AND Host='localhost'")
     row = self.cursor.fetchone()
     self.assertFalse(row)
开发者ID:agnhesi,项目名称:mysqlapi,代码行数:7,代码来源:test_database_manager.py


示例9: test_create_user_should_generate_an_username_when_username_length_is_greater_than_16

 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")
开发者ID:agnhesi,项目名称:mysqlapi,代码行数:8,代码来源:test_database_manager.py


示例10: test_create_user

 def test_create_user(self):
     db = DatabaseManager("wolverine")
     db.create_user("wolverine", "localhost")
     self.cursor.execute("select User, Host FROM mysql.user WHERE User='wolverine' AND Host='localhost'")
     row = self.cursor.fetchone()
     self.assertEqual("wolverine", row[0])
     self.assertEqual("localhost", row[1])
     db.drop_user("wolverine", "localhost")
开发者ID:agnhesi,项目名称:mysqlapi,代码行数:8,代码来源:test_database_manager.py


示例11: test_drop_user

 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='wolverine' AND Host='%'"
     self.cursor.execute(sql)
     row = self.cursor.fetchone()
     self.assertFalse(row)
开发者ID:digideskio,项目名称:mysqlapi,代码行数:9,代码来源:test_database_manager.py


示例12: test_create__and_drop_user_username_greater_than_16_chars

 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)
开发者ID:digideskio,项目名称:mysqlapi,代码行数:9,代码来源:test_database_manager.py


示例13: test_create_database_with_custom_hostname

 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()
开发者ID:digideskio,项目名称:mysqlapi,代码行数:9,代码来源:test_database_manager.py


示例14: test_create_user

 def test_create_user(self):
     db = DatabaseManager("wolverine")
     db.create_user("wolverine", "%")
     sql = "select User, Host FROM mysql.user " +\
           "WHERE User='wolverine' AND Host='%'"
     self.cursor.execute(sql)
     row = self.cursor.fetchone()
     self.assertEqual("wolverine", row[0])
     self.assertEqual("%", row[1])
     db.drop_user("wolverine", "%")
开发者ID:digideskio,项目名称:mysqlapi,代码行数:10,代码来源:test_database_manager.py


示例15: test_create_user_generates_username_for_dbs_grater_than_16_chars

 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, "%")
开发者ID:digideskio,项目名称:mysqlapi,代码行数:10,代码来源:test_database_manager.py


示例16: test_drop_user_fom_custom_service_host

    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='ciclops' AND Host='localhost'")
        row = self.cursor.fetchone()
        self.assertFalse(row)
开发者ID:agnhesi,项目名称:mysqlapi,代码行数:11,代码来源:test_drop_user.py


示例17: delete

 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)
开发者ID:agnhesi,项目名称:mysqlapi,代码行数:13,代码来源:views.py


示例18: test_create_database

 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()
开发者ID:agnhesi,项目名称:mysqlapi,代码行数:15,代码来源:test_create_database.py


示例19: test_unbind_app_drops_the_user_on_shared_instance

 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='used' AND Host='%'"
         self.cursor.execute(sql)
         row = self.cursor.fetchone()
         self.assertIsNone(row)
     finally:
         instance.delete()
开发者ID:caio-nas,项目名称:tsuru-mysql,代码行数:16,代码来源:test_bind.py


示例20: test_export

    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")
开发者ID:agnhesi,项目名称:mysqlapi,代码行数:16,代码来源:test_database_manager.py



注:本文中的mysqlapi.api.models.DatabaseManager类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mysqlconf.MySQL类代码示例发布时间:2022-05-27
下一篇:
Python mysql_tools.mysqlQuery函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap