Пример #1
0
 def test_drop(self):
     self.create_ciclops()
     request = RequestFactory().delete("/ciclops")
     self.fake = mocks.FakeEC2Client()
     view = DropDatabase()
     view._client = self.fake
     response = view.delete(request, "ciclops")
     self.assertEqual(200, response.status_code)
     with self.assertRaises(Instance.DoesNotExist):
         Instance.objects.get(name="ciclops")
Пример #2
0
 def test_drop(self):
     self.create_ciclops()
     request = RequestFactory().delete("/ciclops")
     self.fake = mocks.FakeEC2Client()
     view = DropDatabase()
     view._client = self.fake
     response = view.delete(request, "ciclops")
     self.assertEqual(200, response.status_code)
     with self.assertRaises(Instance.DoesNotExist):
         Instance.objects.get(name="ciclops")
Пример #3
0
    def test_should_remove_ec2_instance(self):
        self.create_ciclops()
        self.fake = mocks.FakeEC2Client()
        view = DropDatabase()
        view._client = self.fake

        request = RequestFactory().delete("/ciclops", {"service_host": "127.0.0.1"})
        resp = view.delete(request, "ciclops")

        self.assertEqual(200, resp.status_code)
        self.assertEqual(["terminate instance ciclops"], self.fake.actions)
Пример #4
0
 def test_should_unauthorize_ec2_instance_before_terminate_it(self):
     self.create_ciclops()
     fake = mocks.FakeEC2Client()
     view = DropDatabase()
     view._client = fake
     request = RequestFactory().delete("/ciclops")
     resp = view.delete(request, "ciclops")
     self.assertEqual(200, resp.status_code)
     actions = [u"unauthorize instance ciclops",
                u"terminate instance ciclops"]
     self.assertEqual(actions, fake.actions)
Пример #5
0
 def test_should_unauthorize_ec2_instance_before_terminate_it(self):
     self.create_ciclops()
     fake = mocks.FakeEC2Client()
     view = DropDatabase()
     view._client = fake
     request = RequestFactory().delete("/ciclops")
     resp = view.delete(request, "ciclops")
     self.assertEqual(200, resp.status_code)
     actions = [u"unauthorize instance ciclops",
                u"terminate instance ciclops"]
     self.assertEqual(actions, fake.actions)
Пример #6
0
    def test_drop_from_a_custom_service_host(self):
        self.create_ciclops()
        request = RequestFactory().delete("/ciclops", {"service_host": "127.0.0.1"})
        self.fake = mocks.FakeEC2Client()
        view = DropDatabase()
        view._client = self.fake
        response = view.delete(request, "ciclops")
        self.assertEqual(200, response.status_code)

        self.cursor.execute("select SCHEMA_NAME from information_schema.SCHEMATA where SCHEMA_NAME = 'ciclops'")
        row = self.cursor.fetchone()
        self.assertFalse(row)
Пример #7
0
    def test_drop_should_returns_405_when_method_is_not_delete(self):
        request = RequestFactory().get("/")
        response = DropDatabase.as_view()(request, name="foo")
        self.assertEqual(405, response.status_code)

        request = RequestFactory().put("/")
        response = DropDatabase.as_view()(request, name="foo")
        self.assertEqual(405, response.status_code)

        request = RequestFactory().post("/")
        response = DropDatabase.as_view()(request, name="foo")
        self.assertEqual(405, response.status_code)
Пример #8
0
 def test_drop_database_with_shared_server(self):
     settings.SHARED_SERVER = "127.0.0.1"
     self.create_fandango_shared()
     view = DropDatabase()
     request = RequestFactory().delete("/fandango")
     resp = view.delete(request, "fandango")
     self.assertEqual(200, resp.status_code)
     sql = "select SCHEMA_NAME from information_schema.SCHEMATA " +\
           "where SCHEMA_NAME = 'fandango'"
     self.cursor.execute(sql)
     row = self.cursor.fetchone()
     self.assertIsNone(row)
Пример #9
0
 def test_drop_database_with_shared_server(self):
     settings.SHARED_SERVER = "127.0.0.1"
     self.create_fandango_shared()
     view = DropDatabase()
     request = RequestFactory().delete("/fandango")
     resp = view.delete(request, "fandango")
     self.assertEqual(200, resp.status_code)
     sql = "select SCHEMA_NAME from information_schema.SCHEMATA " +\
           "where SCHEMA_NAME = 'fandango'"
     self.cursor.execute(sql)
     row = self.cursor.fetchone()
     self.assertIsNone(row)
Пример #10
0
    def test_drop_should_returns_405_when_method_is_not_delete(self):
        request = RequestFactory().get("/")
        response = DropDatabase.as_view()(request, name="foo")
        self.assertEqual(405, response.status_code)

        request = RequestFactory().put("/")
        response = DropDatabase.as_view()(request, name="foo")
        self.assertEqual(405, response.status_code)

        request = RequestFactory().post("/")
        response = DropDatabase.as_view()(request, name="foo")
        self.assertEqual(405, response.status_code)
Пример #11
0
 def test_drop(self):
     self.create_ciclops()
     request = RequestFactory().delete("/ciclops")
     self.fake = mocks.FakeEC2Client()
     view = DropDatabase()
     view._client = self.fake
     response = view.delete(request, "ciclops")
     self.assertEqual(200, response.status_code)
     self.cursor.execute("select SCHEMA_NAME from information_schema.SCHEMATA where SCHEMA_NAME = 'ciclops'")
     row = self.cursor.fetchone()
     self.assertFalse(row)
     with self.assertRaises(Instance.DoesNotExist):
         Instance.objects.get(name="ciclops")
Пример #12
0
    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)
Пример #13
0
    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)
Пример #14
0
 def test_drop_database_from_pool(self):
     instance = Instance(name="presto")
     pi = ProvisionedInstance.objects.create(host="127.0.0.1",
                                             port=3306,
                                             admin_user="******")
     self.addCleanup(pi.delete)
     pi.alloc(instance)
     self.addCleanup(instance.delete)
     view = DropDatabase()
     request = RequestFactory().delete("/presto")
     resp = view.delete(request, "presto")
     self.assertEqual(200, resp.status_code)
     sql = "select SCHEMA_NAME from information_schema.SCHEMATA " +\
           "where SCHEMA_NAME = 'presto'"
     self.cursor.execute(sql)
     row = self.cursor.fetchone()
     self.assertIsNone(row)
     pi = ProvisionedInstance.objects.get(pk=pi.pk)
     self.assertEqual(None, pi.instance)
Пример #15
0
# Copyright 2014 mysqlapi authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

from django.conf.urls import patterns, url

from mysqlapi.api.decorators import basic_auth_required
from mysqlapi.api.views import (BindApp, BindUnit, CreateDatabase,
                                DropDatabase, Healthcheck)

urlpatterns = patterns('',
                       url(r'^resources$',
                           basic_auth_required(CreateDatabase.as_view())),
                       url(r'^resources/(?P<name>[\w-]+)$',
                           basic_auth_required(DropDatabase.as_view())),
                       url(r'^resources/(?P<name>[\w-]+)/bind$',
                           basic_auth_required(BindUnit.as_view())),
                       url(r'^resources/(?P<name>[\w-]+)/bind-app$',
                           basic_auth_required(BindApp.as_view())),
                       url(r'^resources/(?P<name>[\w-]+)/export$',
                           'mysqlapi.api.views.export'),
                       url(r'^resources/(?P<name>[\w-]+)/status$',
                           basic_auth_required(Healthcheck.as_view())),
                       )
Пример #16
0
# Copyright 2014 mysqlapi authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

from django.conf.urls import patterns, url

from mysqlapi.api.decorators import basic_auth_required
from mysqlapi.api.views import (BindApp, BindUnit, CreateDatabase,
                                DropDatabase, Healthcheck)

urlpatterns = patterns(
    '',
    url(r'^resources$', basic_auth_required(CreateDatabase.as_view())),
    url(r'^resources/(?P<name>[\w-]+)$',
        basic_auth_required(DropDatabase.as_view())),
    url(r'^resources/(?P<name>[\w-]+)/bind$',
        basic_auth_required(BindUnit.as_view())),
    url(r'^resources/(?P<name>[\w-]+)/bind-app$',
        basic_auth_required(BindApp.as_view())),
    url(r'^resources/(?P<name>[\w-]+)/export$', 'mysqlapi.api.views.export'),
    url(r'^resources/(?P<name>[\w-]+)/status$',
        basic_auth_required(Healthcheck.as_view())),
)
Пример #17
0
 def test_drop_returns_404_and_error_msg_when_instance_does_not_exist(self):
     request = RequestFactory().delete("/")
     response = DropDatabase().delete(request, name="doesnotexists")
     self.assertEqual(404, response.status_code)
     msg = "Can't drop database 'doesnotexists'; database doesn't exist"
     self.assertEqual(msg, response.content)