Add scaffolding for Glue service, including create_database and get_database for the Glue Data Catalog
This commit is contained in:
parent
2e5e7e7f5e
commit
77f0a61c9f
@ -24,6 +24,7 @@ from .elbv2 import mock_elbv2 # flake8: noqa
|
|||||||
from .emr import mock_emr, mock_emr_deprecated # flake8: noqa
|
from .emr import mock_emr, mock_emr_deprecated # flake8: noqa
|
||||||
from .events import mock_events # flake8: noqa
|
from .events import mock_events # flake8: noqa
|
||||||
from .glacier import mock_glacier, mock_glacier_deprecated # flake8: noqa
|
from .glacier import mock_glacier, mock_glacier_deprecated # flake8: noqa
|
||||||
|
from .glue import mock_glue # flake8: noqa
|
||||||
from .iam import mock_iam, mock_iam_deprecated # flake8: noqa
|
from .iam import mock_iam, mock_iam_deprecated # flake8: noqa
|
||||||
from .kinesis import mock_kinesis, mock_kinesis_deprecated # flake8: noqa
|
from .kinesis import mock_kinesis, mock_kinesis_deprecated # flake8: noqa
|
||||||
from .kms import mock_kms, mock_kms_deprecated # flake8: noqa
|
from .kms import mock_kms, mock_kms_deprecated # flake8: noqa
|
||||||
|
5
moto/glue/__init__.py
Normal file
5
moto/glue/__init__.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
from .models import glue_backend
|
||||||
|
|
||||||
|
glue_backends = {"global": glue_backend}
|
||||||
|
mock_glue = glue_backend.decorator
|
9
moto/glue/exceptions.py
Normal file
9
moto/glue/exceptions.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
from moto.core.exceptions import RESTError
|
||||||
|
|
||||||
|
|
||||||
|
class GlueClientError(RESTError):
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
kwargs.setdefault('template', 'single_error')
|
||||||
|
super(GlueClientError, self).__init__(*args, **kwargs)
|
27
moto/glue/models.py
Normal file
27
moto/glue/models.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from moto.core import BaseBackend, BaseModel
|
||||||
|
from moto.compat import OrderedDict
|
||||||
|
|
||||||
|
|
||||||
|
class GlueBackend(BaseBackend):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.databases = OrderedDict()
|
||||||
|
|
||||||
|
def create_database(self, database_name):
|
||||||
|
database = FakeDatabase(database_name)
|
||||||
|
self.databases[database_name] = database
|
||||||
|
return database
|
||||||
|
|
||||||
|
def get_database(self, database_name):
|
||||||
|
return self.databases[database_name]
|
||||||
|
|
||||||
|
|
||||||
|
class FakeDatabase(BaseModel):
|
||||||
|
|
||||||
|
def __init__(self, database_name):
|
||||||
|
self.name = database_name
|
||||||
|
|
||||||
|
|
||||||
|
glue_backend = GlueBackend()
|
27
moto/glue/responses.py
Normal file
27
moto/glue/responses.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
|
from moto.core.responses import BaseResponse
|
||||||
|
from .models import glue_backend
|
||||||
|
|
||||||
|
|
||||||
|
class GlueResponse(BaseResponse):
|
||||||
|
|
||||||
|
@property
|
||||||
|
def glue_backend(self):
|
||||||
|
return glue_backend
|
||||||
|
|
||||||
|
@property
|
||||||
|
def parameters(self):
|
||||||
|
return json.loads(self.body)
|
||||||
|
|
||||||
|
def create_database(self):
|
||||||
|
database_name = self.parameters['DatabaseInput']['Name']
|
||||||
|
self.glue_backend.create_database(database_name)
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def get_database(self):
|
||||||
|
database_name = self.parameters.get('Name')
|
||||||
|
database = self.glue_backend.get_database(database_name)
|
||||||
|
return json.dumps({'Database': {'Name': database.name}})
|
11
moto/glue/urls.py
Normal file
11
moto/glue/urls.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from .responses import GlueResponse
|
||||||
|
|
||||||
|
url_bases = [
|
||||||
|
"https?://glue(.*).amazonaws.com"
|
||||||
|
]
|
||||||
|
|
||||||
|
url_paths = {
|
||||||
|
'{0}/$': GlueResponse.dispatch
|
||||||
|
}
|
1
moto/glue/utils.py
Normal file
1
moto/glue/utils.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from __future__ import unicode_literals
|
30
tests/test_glue/test_datacatalog.py
Normal file
30
tests/test_glue/test_datacatalog.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import sure # noqa
|
||||||
|
import boto3
|
||||||
|
|
||||||
|
from moto import mock_glue
|
||||||
|
|
||||||
|
|
||||||
|
def create_database(client, database_name):
|
||||||
|
return client.create_database(
|
||||||
|
DatabaseInput={
|
||||||
|
'Name': database_name
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def get_database(client, database_name):
|
||||||
|
return client.get_database(Name=database_name)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_glue
|
||||||
|
def test_create_database():
|
||||||
|
client = boto3.client('glue', region_name='us-east-1')
|
||||||
|
database_name = 'myspecialdatabase'
|
||||||
|
create_database(client, database_name)
|
||||||
|
|
||||||
|
response = get_database(client, database_name)
|
||||||
|
database = response['Database']
|
||||||
|
|
||||||
|
database.should.equal({'Name': database_name})
|
@ -101,6 +101,3 @@ def test_s3_default_storage_class():
|
|||||||
|
|
||||||
# tests that the default storage class is still STANDARD
|
# tests that the default storage class is still STANDARD
|
||||||
list_of_objects["Contents"][0]["StorageClass"].should.equal("STANDARD")
|
list_of_objects["Contents"][0]["StorageClass"].should.equal("STANDARD")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ def test_force_ignore_subdomain_for_bucketnames():
|
|||||||
os.environ['S3_IGNORE_SUBDOMAIN_BUCKETNAME'] = '1'
|
os.environ['S3_IGNORE_SUBDOMAIN_BUCKETNAME'] = '1'
|
||||||
expect(bucket_name_from_url('https://subdomain.localhost:5000/abc/resource')).should.equal(None)
|
expect(bucket_name_from_url('https://subdomain.localhost:5000/abc/resource')).should.equal(None)
|
||||||
del(os.environ['S3_IGNORE_SUBDOMAIN_BUCKETNAME'])
|
del(os.environ['S3_IGNORE_SUBDOMAIN_BUCKETNAME'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_versioned_key_store():
|
def test_versioned_key_store():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user