Added unit tests for python bindings
Change-Id: I6ca2af79cc8e915de12985cacccc173cd6cdbc71 implements bp: python-saharaclient-unit-tests
This commit is contained in:
committed by
Andrey Pavlov
parent
eadb40ccb6
commit
d535d2fd6e
41
saharaclient/tests/unit/base.py
Normal file
41
saharaclient/tests/unit/base.py
Normal file
@@ -0,0 +1,41 @@
|
||||
# Copyright (c) 2014 Mirantis Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import six
|
||||
import testtools
|
||||
|
||||
from saharaclient.api import client
|
||||
|
||||
|
||||
class BaseTestCase(testtools.TestCase):
|
||||
client = client.Client(sahara_url='http://localhost:8386',
|
||||
input_auth_token='token')
|
||||
|
||||
def assertFields(self, body, obj):
|
||||
for key, value in six.iteritems(body):
|
||||
self.assertEqual(value, getattr(obj, key))
|
||||
|
||||
|
||||
class FakeResponse(object):
|
||||
def __init__(self, status_code, content=None, response_key=None):
|
||||
self.status_code = status_code
|
||||
self.content = content or {}
|
||||
self.response_key = response_key
|
||||
self.name = 'name'
|
||||
|
||||
def json(self):
|
||||
if self.response_key:
|
||||
return {self.response_key: self.content}
|
||||
else:
|
||||
return self.content
|
||||
81
saharaclient/tests/unit/test_cluster_templates.py
Normal file
81
saharaclient/tests/unit/test_cluster_templates.py
Normal file
@@ -0,0 +1,81 @@
|
||||
# Copyright (c) 2014 Mirantis Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
|
||||
from saharaclient.api import cluster_templates as ct
|
||||
from saharaclient.tests.unit import base
|
||||
|
||||
import json
|
||||
|
||||
|
||||
class ClusterTemplateTest(base.BaseTestCase):
|
||||
body = {
|
||||
'name': 'name',
|
||||
'description': 'description',
|
||||
'plugin_name': 'plugin',
|
||||
'hadoop_version': '1',
|
||||
'node_groups': {
|
||||
'name': 'master-node',
|
||||
'flavor_id': '2',
|
||||
'node_processes': ['namenode'],
|
||||
'count': 1
|
||||
}
|
||||
}
|
||||
|
||||
@mock.patch('requests.post')
|
||||
def test_create_cluster_template(self, mpost):
|
||||
mpost.return_value = base.FakeResponse(
|
||||
202, self.body, 'cluster_template')
|
||||
|
||||
resp = self.client.cluster_templates.create(**self.body)
|
||||
|
||||
self.assertEqual('http://localhost:8386/cluster-templates',
|
||||
mpost.call_args[0][0])
|
||||
self.assertEqual(self.body, json.loads(mpost.call_args[0][1]))
|
||||
self.assertIsInstance(resp, ct.ClusterTemplate)
|
||||
self.assertFields(self.body, resp)
|
||||
|
||||
@mock.patch('requests.get')
|
||||
def test_cluster_template_list(self, mget):
|
||||
mget.return_value = base.FakeResponse(
|
||||
200, [self.body], 'cluster_templates')
|
||||
|
||||
resp = self.client.cluster_templates.list()
|
||||
|
||||
self.assertEqual('http://localhost:8386/cluster-templates',
|
||||
mget.call_args[0][0])
|
||||
self.assertIsInstance(resp[0], ct.ClusterTemplate)
|
||||
self.assertFields(self.body, resp[0])
|
||||
|
||||
@mock.patch('requests.get')
|
||||
def test_cluster_template_get(self, mget):
|
||||
mget.return_value = base.FakeResponse(
|
||||
200, self.body, 'cluster_template')
|
||||
|
||||
resp = self.client.cluster_templates.get('id')
|
||||
|
||||
self.assertEqual('http://localhost:8386/cluster-templates/id',
|
||||
mget.call_args[0][0])
|
||||
self.assertIsInstance(resp, ct.ClusterTemplate)
|
||||
self.assertFields(self.body, resp)
|
||||
|
||||
@mock.patch('requests.delete')
|
||||
def test_cluster_template_delete(self, mdelete):
|
||||
mdelete.return_value = base.FakeResponse(204)
|
||||
|
||||
self.client.cluster_templates.delete('id')
|
||||
|
||||
self.assertEqual('http://localhost:8386/cluster-templates/id',
|
||||
mdelete.call_args[0][0])
|
||||
120
saharaclient/tests/unit/test_clusters.py
Normal file
120
saharaclient/tests/unit/test_clusters.py
Normal file
@@ -0,0 +1,120 @@
|
||||
# Copyright (c) 2014 Mirantis Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
|
||||
from saharaclient.api import clusters as cl
|
||||
from saharaclient.tests.unit import base
|
||||
|
||||
import json
|
||||
|
||||
|
||||
class ClusterTest(base.BaseTestCase):
|
||||
body = {
|
||||
'name': 'name',
|
||||
'plugin_name': 'fake',
|
||||
'hadoop_version': '0.1',
|
||||
'cluster_template_id': 'id',
|
||||
}
|
||||
|
||||
@mock.patch('requests.post')
|
||||
def test_create_cluster_with_template(self, mpost):
|
||||
mpost.return_value = base.FakeResponse(
|
||||
202, self.body, 'cluster')
|
||||
|
||||
resp = self.client.clusters.create(**self.body)
|
||||
|
||||
self.assertEqual('http://localhost:8386/clusters',
|
||||
mpost.call_args[0][0])
|
||||
self.assertEqual(self.body, json.loads(mpost.call_args[0][1]))
|
||||
self.assertIsInstance(resp, cl.Cluster)
|
||||
self.assertFields(self.body, resp)
|
||||
|
||||
@mock.patch('requests.post')
|
||||
def test_create_cluster_without_template(self, mpost):
|
||||
body = self.body.copy()
|
||||
del body['cluster_template_id']
|
||||
body.update({'default_image_id': 'image_id', 'cluster_configs': {},
|
||||
'node_groups': ['ng1', 'ng2']})
|
||||
mpost.return_value = base.FakeResponse(
|
||||
202, body, 'cluster')
|
||||
|
||||
resp = self.client.clusters.create(**body)
|
||||
|
||||
self.assertEqual('http://localhost:8386/clusters',
|
||||
mpost.call_args[0][0])
|
||||
self.assertEqual(body, json.loads(mpost.call_args[0][1]))
|
||||
self.assertIsInstance(resp, cl.Cluster)
|
||||
self.assertFields(body, resp)
|
||||
|
||||
@mock.patch('requests.get')
|
||||
def test_clusters_list(self, mget):
|
||||
mget.return_value = base.FakeResponse(
|
||||
200, [self.body], 'clusters')
|
||||
|
||||
resp = self.client.clusters.list()
|
||||
|
||||
self.assertEqual('http://localhost:8386/clusters',
|
||||
mget.call_args[0][0])
|
||||
self.assertIsInstance(resp[0], cl.Cluster)
|
||||
self.assertFields(self.body, resp[0])
|
||||
|
||||
@mock.patch('requests.get')
|
||||
def test_clusters_get(self, mget):
|
||||
mget.return_value = base.FakeResponse(
|
||||
200, self.body, 'cluster')
|
||||
|
||||
resp = self.client.clusters.get('id')
|
||||
|
||||
self.assertEqual('http://localhost:8386/clusters/id',
|
||||
mget.call_args[0][0])
|
||||
self.assertIsInstance(resp, cl.Cluster)
|
||||
self.assertFields(self.body, resp)
|
||||
|
||||
@mock.patch('requests.put')
|
||||
def test_clusters_scale(self, mput):
|
||||
mput.return_value = base.FakeResponse(202, self.body)
|
||||
|
||||
scale_body = {
|
||||
'resize_node_groups': [
|
||||
{
|
||||
'count': 2,
|
||||
'name': 'name1'
|
||||
},
|
||||
],
|
||||
'add_node_groups': [
|
||||
{
|
||||
'count': 1,
|
||||
'name': 'name2',
|
||||
'node_group_template_id': 'id'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
resp = self.client.clusters.scale('id', scale_body)
|
||||
|
||||
self.assertEqual('http://localhost:8386/clusters/id',
|
||||
mput.call_args[0][0])
|
||||
self.assertEqual(scale_body, json.loads(mput.call_args[0][1]))
|
||||
self.assertIsInstance(resp, cl.Cluster)
|
||||
self.assertFields(self.body, resp)
|
||||
|
||||
@mock.patch('requests.delete')
|
||||
def test_clusters_delete(self, mdelete):
|
||||
mdelete.return_value = base.FakeResponse(204)
|
||||
|
||||
self.client.clusters.delete('id')
|
||||
|
||||
self.assertEqual('http://localhost:8386/clusters/id',
|
||||
mdelete.call_args[0][0])
|
||||
88
saharaclient/tests/unit/test_data_sources.py
Normal file
88
saharaclient/tests/unit/test_data_sources.py
Normal file
@@ -0,0 +1,88 @@
|
||||
# Copyright (c) 2014 Mirantis Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
|
||||
from saharaclient.api import data_sources as ds
|
||||
from saharaclient.tests.unit import base
|
||||
|
||||
import json
|
||||
|
||||
|
||||
class DataSourceTest(base.BaseTestCase):
|
||||
body = {
|
||||
'name': 'name',
|
||||
'url': 'url',
|
||||
'description': 'descr',
|
||||
'data_source_type': 'hdfs',
|
||||
'credential_user': 'user',
|
||||
'credential_pass': '123'
|
||||
}
|
||||
|
||||
response = {
|
||||
'name': 'name',
|
||||
'url': 'url',
|
||||
'description': 'descr',
|
||||
'type': 'hdfs',
|
||||
'credentials': {
|
||||
'user': 'user',
|
||||
'password': '123'
|
||||
}
|
||||
}
|
||||
|
||||
@mock.patch('requests.post')
|
||||
def test_create_data_sources(self, mpost):
|
||||
mpost.return_value = base.FakeResponse(202, self.response,
|
||||
'data_source')
|
||||
|
||||
resp = self.client.data_sources.create(**self.body)
|
||||
|
||||
self.assertEqual('http://localhost:8386/data-sources',
|
||||
mpost.call_args[0][0])
|
||||
self.assertEqual(self.response, json.loads(mpost.call_args[0][1]))
|
||||
self.assertIsInstance(resp, ds.DataSources)
|
||||
self.assertFields(self.response, resp)
|
||||
|
||||
@mock.patch('requests.get')
|
||||
def test_data_sources_list(self, mget):
|
||||
mget.return_value = base.FakeResponse(200, [self.response],
|
||||
'data_sources')
|
||||
|
||||
resp = self.client.data_sources.list()
|
||||
|
||||
self.assertEqual('http://localhost:8386/data-sources',
|
||||
mget.call_args[0][0])
|
||||
self.assertIsInstance(resp[0], ds.DataSources)
|
||||
self.assertFields(self.response, resp[0])
|
||||
|
||||
@mock.patch('requests.get')
|
||||
def test_data_sources_get(self, mget):
|
||||
mget.return_value = base.FakeResponse(200, self.response,
|
||||
'data_source')
|
||||
|
||||
resp = self.client.data_sources.get('id')
|
||||
|
||||
self.assertEqual('http://localhost:8386/data-sources/id',
|
||||
mget.call_args[0][0])
|
||||
self.assertIsInstance(resp, ds.DataSources)
|
||||
self.assertFields(self.response, resp)
|
||||
|
||||
@mock.patch('requests.delete')
|
||||
def test_data_sources_delete(self, mdelete):
|
||||
mdelete.return_value = base.FakeResponse(204)
|
||||
|
||||
self.client.data_sources.delete('id')
|
||||
|
||||
self.assertEqual('http://localhost:8386/data-sources/id',
|
||||
mdelete.call_args[0][0])
|
||||
87
saharaclient/tests/unit/test_images.py
Normal file
87
saharaclient/tests/unit/test_images.py
Normal file
@@ -0,0 +1,87 @@
|
||||
# Copyright (c) 2014 Mirantis Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
|
||||
from saharaclient.api import images
|
||||
from saharaclient.tests.unit import base
|
||||
|
||||
import json
|
||||
|
||||
|
||||
class ImageTest(base.BaseTestCase):
|
||||
body = {
|
||||
'username': 'name',
|
||||
'description': 'descr'
|
||||
}
|
||||
|
||||
@mock.patch('requests.get')
|
||||
def test_images_list(self, mget):
|
||||
mget.return_value = base.FakeResponse(200, [self.body], 'images')
|
||||
|
||||
resp = self.client.images.list()
|
||||
|
||||
self.assertEqual('http://localhost:8386/images',
|
||||
mget.call_args[0][0])
|
||||
self.assertIsInstance(resp[0], images.Image)
|
||||
self.assertFields(self.body, resp[0])
|
||||
|
||||
@mock.patch('requests.get')
|
||||
def test_images_get(self, mget):
|
||||
mget.return_value = base.FakeResponse(
|
||||
200, self.body, 'image', )
|
||||
|
||||
resp = self.client.images.get('id')
|
||||
|
||||
self.assertEqual('http://localhost:8386/images/id',
|
||||
mget.call_args[0][0])
|
||||
self.assertIsInstance(resp, images.Image)
|
||||
self.assertFields(self.body, resp)
|
||||
|
||||
@mock.patch('requests.delete')
|
||||
def test_unregister_image(self, mdelete):
|
||||
mdelete.return_value = base.FakeResponse(204)
|
||||
|
||||
self.client.images.unregister_image('id')
|
||||
|
||||
self.assertEqual('http://localhost:8386/images/id',
|
||||
mdelete.call_args[0][0])
|
||||
|
||||
@mock.patch('requests.post')
|
||||
def test_update_image(self, mpost):
|
||||
mpost.return_value = base.FakeResponse(
|
||||
202, self.body, 'image')
|
||||
|
||||
self.client.images.update_image('id', 'name', 'descr')
|
||||
|
||||
self.assertEqual('http://localhost:8386/images/id',
|
||||
mpost.call_args[0][0])
|
||||
self.assertEqual(self.body, json.loads(mpost.call_args[0][1]))
|
||||
|
||||
@mock.patch('saharaclient.api.images.ImageManager.get')
|
||||
@mock.patch('requests.post')
|
||||
def test_update_tags(self, mpost, mget):
|
||||
mpost.return_value = base.FakeResponse(202)
|
||||
image = mock.Mock()
|
||||
mget.return_value = image
|
||||
|
||||
image.tags = []
|
||||
self.client.images.update_tags('id', ['username', 'tag'])
|
||||
self.assertEqual('http://localhost:8386/images/id/tag',
|
||||
mpost.call_args[0][0])
|
||||
|
||||
image.tags = ['username', 'tag']
|
||||
self.client.images.update_tags('id', ['username'])
|
||||
self.assertEqual('http://localhost:8386/images/id/untag',
|
||||
mpost.call_args[0][0])
|
||||
85
saharaclient/tests/unit/test_job_binaries.py
Normal file
85
saharaclient/tests/unit/test_job_binaries.py
Normal file
@@ -0,0 +1,85 @@
|
||||
# Copyright (c) 2014 Mirantis Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
|
||||
from saharaclient.api import job_binaries as jb
|
||||
from saharaclient.tests.unit import base
|
||||
|
||||
import json
|
||||
|
||||
|
||||
class JobBinaryTest(base.BaseTestCase):
|
||||
body = {
|
||||
'name': 'name',
|
||||
'url': 'url',
|
||||
'description': 'descr',
|
||||
'extra': {
|
||||
'user': 'user',
|
||||
'password': '123'
|
||||
}
|
||||
}
|
||||
|
||||
@mock.patch('requests.post')
|
||||
def test_create_job_binary(self, mpost):
|
||||
mpost.return_value = base.FakeResponse(202, self.body, 'job_binary')
|
||||
|
||||
resp = self.client.job_binaries.create(**self.body)
|
||||
|
||||
self.assertEqual('http://localhost:8386/job-binaries',
|
||||
mpost.call_args[0][0])
|
||||
self.assertEqual(self.body, json.loads(mpost.call_args[0][1]))
|
||||
self.assertIsInstance(resp, jb.JobBinaries)
|
||||
self.assertFields(self.body, resp)
|
||||
|
||||
@mock.patch('requests.get')
|
||||
def test_job_binary_list(self, mget):
|
||||
mget.return_value = base.FakeResponse(200, [self.body], 'binaries')
|
||||
|
||||
resp = self.client.job_binaries.list()
|
||||
|
||||
self.assertEqual('http://localhost:8386/job-binaries',
|
||||
mget.call_args[0][0])
|
||||
self.assertIsInstance(resp[0], jb.JobBinaries)
|
||||
self.assertFields(self.body, resp[0])
|
||||
|
||||
@mock.patch('requests.get')
|
||||
def test_job_binary_get(self, mget):
|
||||
mget.return_value = base.FakeResponse(200, self.body, 'job_binary')
|
||||
|
||||
resp = self.client.job_binaries.get('id')
|
||||
|
||||
self.assertEqual('http://localhost:8386/job-binaries/id',
|
||||
mget.call_args[0][0])
|
||||
self.assertIsInstance(resp, jb.JobBinaries)
|
||||
self.assertFields(self.body, resp)
|
||||
|
||||
@mock.patch('requests.delete')
|
||||
def test_job_binary_delete(self, mdelete):
|
||||
mdelete.return_value = base.FakeResponse(204)
|
||||
|
||||
self.client.job_binaries.delete('id')
|
||||
|
||||
self.assertEqual('http://localhost:8386/job-binaries/id',
|
||||
mdelete.call_args[0][0])
|
||||
|
||||
@mock.patch('requests.get')
|
||||
def test_job_binary_get_file(self, mget):
|
||||
mget.return_value = base.FakeResponse(200, 'data')
|
||||
|
||||
resp = self.client.job_binaries.get_file('id')
|
||||
|
||||
self.assertEqual('http://localhost:8386/job-binaries/id/data',
|
||||
mget.call_args[0][0])
|
||||
self.assertEqual('data', resp)
|
||||
72
saharaclient/tests/unit/test_job_binary_internals.py
Normal file
72
saharaclient/tests/unit/test_job_binary_internals.py
Normal file
@@ -0,0 +1,72 @@
|
||||
# Copyright (c) 2014 Mirantis Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
|
||||
from saharaclient.api import job_binary_internals as jbi
|
||||
from saharaclient.tests.unit import base
|
||||
|
||||
|
||||
class JobBinaryInternalTest(base.BaseTestCase):
|
||||
body = {
|
||||
'name': 'name',
|
||||
'datasize': '123',
|
||||
'id': 'id'
|
||||
}
|
||||
|
||||
@mock.patch('requests.put')
|
||||
def test_create_job_binary_internal(self, mput):
|
||||
mput.return_value = base.FakeResponse(202, self.body,
|
||||
'job_binary_internal')
|
||||
|
||||
resp = self.client.job_binary_internals.create('name', 'data')
|
||||
|
||||
self.assertEqual('http://localhost:8386/job-binary-internals/name',
|
||||
mput.call_args[0][0])
|
||||
|
||||
self.assertEqual('data', mput.call_args[0][1])
|
||||
self.assertIsInstance(resp, jbi.JobBinaryInternal)
|
||||
self.assertFields(self.body, resp)
|
||||
|
||||
@mock.patch('requests.get')
|
||||
def test_job_binary_internal_list(self, mget):
|
||||
mget.return_value = base.FakeResponse(200, [self.body], 'binaries')
|
||||
|
||||
resp = self.client.job_binary_internals.list()
|
||||
|
||||
self.assertEqual('http://localhost:8386/job-binary-internals',
|
||||
mget.call_args[0][0])
|
||||
self.assertIsInstance(resp[0], jbi.JobBinaryInternal)
|
||||
self.assertFields(self.body, resp[0])
|
||||
|
||||
@mock.patch('requests.get')
|
||||
def test_job_binary_get(self, mget):
|
||||
mget.return_value = base.FakeResponse(200, self.body,
|
||||
'job_binary_internal')
|
||||
|
||||
resp = self.client.job_binary_internals.get('id')
|
||||
|
||||
self.assertEqual('http://localhost:8386/job-binary-internals/id',
|
||||
mget.call_args[0][0])
|
||||
self.assertIsInstance(resp, jbi.JobBinaryInternal)
|
||||
self.assertFields(self.body, resp)
|
||||
|
||||
@mock.patch('requests.delete')
|
||||
def test_job_binary_delete(self, mdelete):
|
||||
mdelete.return_value = base.FakeResponse(204)
|
||||
|
||||
self.client.job_binary_internals.delete('id')
|
||||
|
||||
self.assertEqual('http://localhost:8386/job-binary-internals/id',
|
||||
mdelete.call_args[0][0])
|
||||
98
saharaclient/tests/unit/test_job_executions.py
Normal file
98
saharaclient/tests/unit/test_job_executions.py
Normal file
@@ -0,0 +1,98 @@
|
||||
# Copyright (c) 2014 Mirantis Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
|
||||
from saharaclient.api import job_executions as je
|
||||
from saharaclient.tests.unit import base
|
||||
|
||||
import json
|
||||
|
||||
|
||||
class JobExecutionTest(base.BaseTestCase):
|
||||
body = {
|
||||
'job_id': 'job_id',
|
||||
'cluster_id': 'cluster_id',
|
||||
'configs': {},
|
||||
'input_id': None,
|
||||
'output_id': None
|
||||
}
|
||||
response = {
|
||||
'cluster_id': 'cluster_id',
|
||||
'job_configs': {},
|
||||
}
|
||||
|
||||
@mock.patch('requests.post')
|
||||
def test_create_job_execution_with_io(self, mpost):
|
||||
body = self.body.copy()
|
||||
body.update({'input_id': 'input_id', 'output_id': 'output_id'})
|
||||
response = self.response.copy()
|
||||
response.update({'input_id': 'input_id', 'output_id': 'output_id'})
|
||||
|
||||
mpost.return_value = base.FakeResponse(202, response,
|
||||
'job_execution')
|
||||
|
||||
resp = self.client.job_executions.create(**body)
|
||||
|
||||
self.assertEqual('http://localhost:8386/jobs/job_id/execute',
|
||||
mpost.call_args[0][0])
|
||||
self.assertEqual(response, json.loads(mpost.call_args[0][1]))
|
||||
self.assertIsInstance(resp, je.JobExecution)
|
||||
self.assertFields(response, resp)
|
||||
|
||||
@mock.patch('requests.post')
|
||||
def test_create_job_execution_without_io(self, mpost):
|
||||
mpost.return_value = base.FakeResponse(202, self.response,
|
||||
'job_execution')
|
||||
|
||||
resp = self.client.job_executions.create(**self.body)
|
||||
|
||||
self.assertEqual('http://localhost:8386/jobs/job_id/execute',
|
||||
mpost.call_args[0][0])
|
||||
self.assertEqual(self.response, json.loads(mpost.call_args[0][1]))
|
||||
self.assertIsInstance(resp, je.JobExecution)
|
||||
self.assertFields(self.response, resp)
|
||||
|
||||
@mock.patch('requests.get')
|
||||
def test_job_executions_list(self, mget):
|
||||
mget.return_value = base.FakeResponse(200, [self.response],
|
||||
'job_executions')
|
||||
|
||||
resp = self.client.job_executions.list()
|
||||
|
||||
self.assertEqual('http://localhost:8386/job-executions',
|
||||
mget.call_args[0][0])
|
||||
self.assertIsInstance(resp[0], je.JobExecution)
|
||||
self.assertFields(self.response, resp[0])
|
||||
|
||||
@mock.patch('requests.get')
|
||||
def test_job_executions_get(self, mget):
|
||||
mget.return_value = base.FakeResponse(200, self.response,
|
||||
'job_execution')
|
||||
|
||||
resp = self.client.job_executions.get('id')
|
||||
|
||||
self.assertEqual('http://localhost:8386/job-executions/id',
|
||||
mget.call_args[0][0])
|
||||
self.assertIsInstance(resp, je.JobExecution)
|
||||
self.assertFields(self.response, resp)
|
||||
|
||||
@mock.patch('requests.delete')
|
||||
def test_job_executions_delete(self, mdelete):
|
||||
mdelete.return_value = base.FakeResponse(204)
|
||||
|
||||
self.client.job_executions.delete('id')
|
||||
|
||||
self.assertEqual('http://localhost:8386/job-executions/id',
|
||||
mdelete.call_args[0][0])
|
||||
91
saharaclient/tests/unit/test_jobs.py
Normal file
91
saharaclient/tests/unit/test_jobs.py
Normal file
@@ -0,0 +1,91 @@
|
||||
# Copyright (c) 2014 Mirantis Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
|
||||
from saharaclient.api import jobs
|
||||
from saharaclient.tests.unit import base
|
||||
|
||||
import json
|
||||
|
||||
|
||||
class JobTest(base.BaseTestCase):
|
||||
body = {
|
||||
'name': 'name',
|
||||
'type': 'pig',
|
||||
'mains': ['job_binary_id'],
|
||||
'libs': [],
|
||||
'description': 'descr'
|
||||
}
|
||||
|
||||
@mock.patch('requests.post')
|
||||
def test_create_job(self, mpost):
|
||||
mpost.return_value = base.FakeResponse(202, self.body, 'job')
|
||||
|
||||
resp = self.client.jobs.create(**self.body)
|
||||
|
||||
self.assertEqual('http://localhost:8386/jobs',
|
||||
mpost.call_args[0][0])
|
||||
self.assertEqual(self.body, json.loads(mpost.call_args[0][1]))
|
||||
self.assertIsInstance(resp, jobs.Job)
|
||||
self.assertFields(self.body, resp)
|
||||
|
||||
@mock.patch('requests.get')
|
||||
def test_jobs_list(self, mget):
|
||||
mget.return_value = base.FakeResponse(200, [self.body], 'jobs')
|
||||
|
||||
resp = self.client.jobs.list()
|
||||
|
||||
self.assertEqual('http://localhost:8386/jobs',
|
||||
mget.call_args[0][0])
|
||||
self.assertIsInstance(resp[0], jobs.Job)
|
||||
self.assertFields(self.body, resp[0])
|
||||
|
||||
@mock.patch('requests.get')
|
||||
def test_jobs_get(self, mget):
|
||||
mget.return_value = base.FakeResponse(200, self.body, 'job')
|
||||
|
||||
resp = self.client.jobs.get('id')
|
||||
|
||||
self.assertEqual('http://localhost:8386/jobs/id',
|
||||
mget.call_args[0][0])
|
||||
self.assertIsInstance(resp, jobs.Job)
|
||||
self.assertFields(self.body, resp)
|
||||
|
||||
@mock.patch('requests.get')
|
||||
def test_jobs_get_configs(self, mget):
|
||||
response = {
|
||||
"job_config": {
|
||||
"args": [],
|
||||
"configs": []
|
||||
}
|
||||
}
|
||||
|
||||
mget.return_value = base.FakeResponse(200, response)
|
||||
|
||||
resp = self.client.jobs.get_configs('Pig')
|
||||
|
||||
self.assertEqual('http://localhost:8386/jobs/config-hints/Pig',
|
||||
mget.call_args[0][0])
|
||||
self.assertIsInstance(resp, jobs.Job)
|
||||
self.assertFields(response, resp)
|
||||
|
||||
@mock.patch('requests.delete')
|
||||
def test_jobs_delete(self, mdelete):
|
||||
mdelete.return_value = base.FakeResponse(204)
|
||||
|
||||
self.client.jobs.delete('id')
|
||||
|
||||
self.assertEqual('http://localhost:8386/jobs/id',
|
||||
mdelete.call_args[0][0])
|
||||
79
saharaclient/tests/unit/test_node_group_templates.py
Normal file
79
saharaclient/tests/unit/test_node_group_templates.py
Normal file
@@ -0,0 +1,79 @@
|
||||
# Copyright (c) 2014 Mirantis Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
|
||||
from saharaclient.api import node_group_templates as ng
|
||||
from saharaclient.tests.unit import base
|
||||
|
||||
import json
|
||||
|
||||
|
||||
class NodeGroupTemplateTest(base.BaseTestCase):
|
||||
body = {
|
||||
"name": "name",
|
||||
"plugin_name": "plugin",
|
||||
"hadoop_version": "1",
|
||||
"flavor_id": "2",
|
||||
"description": "description",
|
||||
"volumes_per_node": "3",
|
||||
"volumes_size": "4",
|
||||
"node_processes": ["datanode"]
|
||||
}
|
||||
|
||||
@mock.patch('requests.post')
|
||||
def test_create_node_group_template(self, mpost):
|
||||
mpost.return_value = base.FakeResponse(202, self.body,
|
||||
'node_group_template')
|
||||
|
||||
resp = self.client.node_group_templates.create(**self.body)
|
||||
|
||||
self.assertEqual('http://localhost:8386/node-group-templates',
|
||||
mpost.call_args[0][0])
|
||||
self.assertEqual(self.body, json.loads(mpost.call_args[0][1]))
|
||||
self.assertIsInstance(resp, ng.NodeGroupTemplate)
|
||||
self.assertFields(self.body, resp)
|
||||
|
||||
@mock.patch('requests.get')
|
||||
def test_node_group_template_list(self, mget):
|
||||
mget.return_value = base.FakeResponse(200, [self.body],
|
||||
'node_group_templates')
|
||||
|
||||
resp = self.client.node_group_templates.list()
|
||||
|
||||
self.assertEqual('http://localhost:8386/node-group-templates',
|
||||
mget.call_args[0][0])
|
||||
self.assertIsInstance(resp[0], ng.NodeGroupTemplate)
|
||||
self.assertFields(self.body, resp[0])
|
||||
|
||||
@mock.patch('requests.get')
|
||||
def test_node_group_template_get(self, mget):
|
||||
mget.return_value = base.FakeResponse(200, self.body,
|
||||
'node_group_template')
|
||||
|
||||
resp = self.client.node_group_templates.get('id')
|
||||
|
||||
self.assertEqual('http://localhost:8386/node-group-templates/id',
|
||||
mget.call_args[0][0])
|
||||
self.assertIsInstance(resp, ng.NodeGroupTemplate)
|
||||
self.assertFields(self.body, resp)
|
||||
|
||||
@mock.patch('requests.delete')
|
||||
def test_node_group_template_delete(self, mdelete):
|
||||
mdelete.return_value = base.FakeResponse(204)
|
||||
|
||||
self.client.node_group_templates.delete('id')
|
||||
|
||||
self.assertEqual('http://localhost:8386/node-group-templates/id',
|
||||
mdelete.call_args[0][0])
|
||||
75
saharaclient/tests/unit/test_plugins.py
Normal file
75
saharaclient/tests/unit/test_plugins.py
Normal file
@@ -0,0 +1,75 @@
|
||||
# Copyright (c) 2014 Mirantis Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
|
||||
from saharaclient.api import plugins
|
||||
from saharaclient.tests.unit import base
|
||||
|
||||
|
||||
class PluginTest(base.BaseTestCase):
|
||||
body = {
|
||||
'description': 'description',
|
||||
'name': 'name',
|
||||
'version': '1'
|
||||
}
|
||||
|
||||
@mock.patch('requests.get')
|
||||
def test_plugins_list(self, mget):
|
||||
mget.return_value = base.FakeResponse(200, [self.body], 'plugins')
|
||||
|
||||
resp = self.client.plugins.list()
|
||||
self.assertEqual('http://localhost:8386/plugins',
|
||||
mget.call_args[0][0])
|
||||
self.assertIsInstance(resp[0], plugins.Plugin)
|
||||
self.assertFields(self.body, resp[0])
|
||||
|
||||
@mock.patch('requests.get')
|
||||
def test_plugins_get(self, mget):
|
||||
mget.return_value = base.FakeResponse(200, self.body, 'plugin')
|
||||
|
||||
resp = self.client.plugins.get('name')
|
||||
self.assertEqual('http://localhost:8386/plugins/name',
|
||||
mget.call_args[0][0])
|
||||
self.assertIsInstance(resp, plugins.Plugin)
|
||||
self.assertFields(self.body, resp)
|
||||
|
||||
@mock.patch('requests.get')
|
||||
def test_plugins_get_version_details(self, mget):
|
||||
mget.return_value = base.FakeResponse(200, self.body, 'plugin')
|
||||
|
||||
resp = self.client.plugins.get_version_details('name', '1')
|
||||
self.assertEqual('http://localhost:8386/plugins/name/1',
|
||||
mget.call_args[0][0])
|
||||
self.assertIsInstance(resp, plugins.Plugin)
|
||||
self.assertFields(self.body, resp)
|
||||
|
||||
@mock.patch('requests.post')
|
||||
def test_convert_to_cluster_template(self, mpost):
|
||||
response = {
|
||||
'name': 'name',
|
||||
'description': 'description',
|
||||
'plugin_name': 'plugin',
|
||||
'hadoop_version': '1',
|
||||
}
|
||||
mpost.return_value = base.FakeResponse(202, response,
|
||||
'cluster_template')
|
||||
|
||||
resp = self.client.plugins.convert_to_cluster_template(
|
||||
'plugin', 1, 'template', 'file')
|
||||
|
||||
self.assertEqual(
|
||||
'http://localhost:8386/plugins/plugin/1/convert-config/template',
|
||||
mpost.call_args[0][0])
|
||||
self.assertEqual(response, resp)
|
||||
Reference in New Issue
Block a user