Fix order of arguments in assertEqual - Part1

Some tests used incorrect order assertEqual(observed, expected).
The correct order expected by testtools is:
    def assertEqual(self, expected, observed, message='')
Changed to use the right order. Also if the order is wrong and
expected value is None, change it to assertIsNone instead.

It requires big changes and some tests change frequently.
So I would do it in series of small CR.
This part contains all changes except tests of plugins and service.

Partial-Bug: #1259292

Change-Id: Iefbb5f4b9efca35f7a2298f9f7f5b9de73fc260f
changes/71/165271/3
Jacob Bin Wang 8 years ago
parent 9f709c912a
commit cb480679a1
  1. 2
      sahara/tests/tempest/scenario/data_processing/client_tests/test_job_executions.py
  2. 24
      sahara/tests/unit/conductor/manager/test_clusters.py
  3. 110
      sahara/tests/unit/conductor/manager/test_edp.py
  4. 26
      sahara/tests/unit/conductor/manager/test_templates.py
  5. 8
      sahara/tests/unit/conductor/test_api.py
  6. 31
      sahara/tests/unit/conductor/test_resource.py
  7. 2
      sahara/tests/unit/db/migration/test_migrations.py
  8. 8
      sahara/tests/unit/test_context.py
  9. 20
      sahara/tests/unit/topology/test_topology.py
  10. 2
      sahara/tests/unit/utils/test_cluster_progress_ops.py
  11. 8
      sahara/tests/unit/utils/test_edp.py
  12. 4
      sahara/tests/unit/utils/test_general.py
  13. 5
      sahara/tests/unit/utils/test_patches.py
  14. 2
      sahara/tests/unit/utils/test_ssh_remote.py
  15. 74
      sahara/tests/unit/utils/test_xml_utils.py

@ -178,7 +178,7 @@ class JobExecutionTest(base.BaseDataProcessingTest):
# check that cluster moved to deleting state
cluster = self.client.clusters.get(cluster_id)
self.assertEqual(cluster.status, 'Deleting')
self.assertEqual('Deleting', cluster.status)
timeout = CONF.data_processing.cluster_timeout
s_time = timeutils.utcnow()

@ -73,12 +73,12 @@ class ClusterTest(test_base.ConductorManagerTestCase):
self.assertIsInstance(cluster_db_obj, dict)
lst = self.api.cluster_get_all(ctx)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
cl_id = lst[0]["id"]
self.api.cluster_destroy(ctx, cl_id)
lst = self.api.cluster_get_all(ctx)
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
with testtools.ExpectedException(ex.NotFoundException):
self.api.cluster_destroy(ctx, cl_id)
@ -106,9 +106,9 @@ class ClusterTest(test_base.ConductorManagerTestCase):
ng.pop("created_at")
ng.pop("updated_at")
ng.pop("id")
self.assertEqual(ng.pop("cluster_id"), cl_db_obj["id"])
self.assertEqual(cl_db_obj["id"], ng.pop("cluster_id"))
ng.pop("image_id")
self.assertEqual(ng.pop("instances"), [])
self.assertEqual([], ng.pop("instances"))
ng.pop("node_configs")
ng.pop("node_group_template_id")
ng.pop("volume_mount_prefix")
@ -139,7 +139,7 @@ class ClusterTest(test_base.ConductorManagerTestCase):
self.assertEqual(val, cl_db_obj.get(key),
"Key not found %s" % key)
self.assertEqual(cl_db_obj["node_groups"], [])
self.assertEqual([], cl_db_obj["node_groups"])
def test_cluster_update_status(self):
ctx = context.ctx()
@ -148,7 +148,7 @@ class ClusterTest(test_base.ConductorManagerTestCase):
updated_cl = self.api.cluster_update(ctx, _id, {"status": "Active"})
self.assertIsInstance(updated_cl, dict)
self.assertEqual(updated_cl["status"], "Active")
self.assertEqual("Active", updated_cl["status"])
get_cl_obj = self.api.cluster_get(ctx, _id)
self.assertEqual(updated_cl, get_cl_obj)
@ -186,7 +186,7 @@ class ClusterTest(test_base.ConductorManagerTestCase):
cluster_db_obj = self.api.cluster_create(ctx, SAMPLE_CLUSTER)
_id = cluster_db_obj["id"]
self.assertEqual(len(cluster_db_obj["node_groups"]), 2)
self.assertEqual(2, len(cluster_db_obj["node_groups"]))
ng_id = cluster_db_obj["node_groups"][-1]["id"]
self.api.node_group_update(ctx, ng_id, {"image_id": "test_image"})
@ -200,7 +200,7 @@ class ClusterTest(test_base.ConductorManagerTestCase):
if ng["id"] != ng_id:
continue
self.assertEqual(ng["image_id"], "test_image")
self.assertEqual("test_image", ng["image_id"])
def test_delete_node_group(self):
ctx = context.ctx()
@ -298,18 +298,18 @@ class ClusterTest(test_base.ConductorManagerTestCase):
self.api.cluster_create(ctx, SAMPLE_CLUSTER)
lst = self.api.cluster_get_all(ctx)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
kwargs = {'name': SAMPLE_CLUSTER['name'],
'plugin_name': SAMPLE_CLUSTER['plugin_name']}
lst = self.api.cluster_get_all(ctx, **kwargs)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
# Valid field but no matching value
kwargs = {'name': SAMPLE_CLUSTER['name']+'foo'}
lst = self.api.cluster_get_all(ctx, **kwargs)
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
# Invalid field
lst = self.api.cluster_get_all(ctx, **{'badfield': 'somevalue'})
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))

@ -98,13 +98,13 @@ class DataSourceTest(test_base.ConductorManagerTestCase):
self.api.data_source_create(ctx, SAMPLE_DATA_SOURCE)
lst = self.api.data_source_get_all(ctx)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
ds_id = lst[0]['id']
self.api.data_source_destroy(ctx, ds_id)
lst = self.api.data_source_get_all(ctx)
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
def test_duplicate_data_source_create(self):
ctx = context.ctx()
@ -141,21 +141,21 @@ class DataSourceTest(test_base.ConductorManagerTestCase):
self.api.data_source_create(ctx, SAMPLE_DATA_SOURCE)
lst = self.api.data_source_get_all(ctx)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
kwargs = {'name': SAMPLE_DATA_SOURCE['name'],
'tenant_id': SAMPLE_DATA_SOURCE['tenant_id']}
lst = self.api.data_source_get_all(ctx, **kwargs)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
# Valid field but no matching value
kwargs = {'name': SAMPLE_DATA_SOURCE['name']+"foo"}
lst = self.api.data_source_get_all(ctx, **kwargs)
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
# Invalid field
lst = self.api.data_source_get_all(ctx, **{'badfield': 'somevalue'})
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
def test_data_source_count_in(self):
ctx = context.ctx()
@ -164,27 +164,27 @@ class DataSourceTest(test_base.ConductorManagerTestCase):
self.api.data_source_create(ctx, src)
cnt = self.api.data_source_count(ctx, name='ngt_test')
self.assertEqual(cnt, 1)
self.assertEqual(1, cnt)
cnt = self.api.data_source_count(ctx, name=('ngt_test',
'test2', 'test3'))
self.assertEqual(cnt, 1)
self.assertEqual(1, cnt)
cnt = self.api.data_source_count(ctx, name=('test1',
'test2', 'test3'))
self.assertEqual(cnt, 0)
self.assertEqual(0, cnt)
lst = self.api.data_source_get_all(ctx, name='ngt_test')
myid = lst[0]['id']
cnt = self.api.data_source_count(ctx,
name=('ngt_test', 'test2', 'test3'),
id=myid)
self.assertEqual(cnt, 1)
self.assertEqual(1, cnt)
cnt = self.api.data_source_count(ctx,
name=('ngt_test', 'test2', 'test3'),
id=(myid, '2'))
self.assertEqual(cnt, 1)
self.assertEqual(1, cnt)
def test_data_source_count_like(self):
ctx = context.ctx()
@ -193,20 +193,20 @@ class DataSourceTest(test_base.ConductorManagerTestCase):
self.api.data_source_create(ctx, src)
cnt = self.api.data_source_count(ctx, name='ngt_test')
self.assertEqual(cnt, 1)
self.assertEqual(1, cnt)
cnt = self.api.data_source_count(ctx, name='ngt%')
self.assertEqual(cnt, 1)
self.assertEqual(1, cnt)
cnt = self.api.data_source_count(ctx,
name=('ngt_test',),
url='localhost%')
self.assertEqual(cnt, 1)
self.assertEqual(1, cnt)
cnt = self.api.data_source_count(ctx,
name=('ngt_test',),
url='localhost')
self.assertEqual(cnt, 0)
self.assertEqual(0, cnt)
class JobExecutionTest(test_base.ConductorManagerTestCase):
@ -225,10 +225,10 @@ class JobExecutionTest(test_base.ConductorManagerTestCase):
self.api.job_execution_create(ctx, SAMPLE_JOB_EXECUTION)
lst = self.api.job_execution_get_all(ctx)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
count = self.api.job_execution_count(ctx)
self.assertEqual(count, 1)
self.assertEqual(1, count)
job_ex_id = lst[0]['id']
@ -236,9 +236,9 @@ class JobExecutionTest(test_base.ConductorManagerTestCase):
new_info = {"status": edp.JOB_STATUS_PENDING}
self.api.job_execution_update(ctx, job_ex_id, {'info': new_info})
updated_job = self.api.job_execution_get(ctx, job_ex_id)
self.assertEqual(updated_job['info'], new_info)
self.assertEqual(updated_job['start_time'],
SAMPLE_JOB_EXECUTION['start_time'])
self.assertEqual(new_info, updated_job['info'])
self.assertEqual(SAMPLE_JOB_EXECUTION['start_time'],
updated_job['start_time'])
self.api.job_execution_destroy(ctx, job_ex_id)
@ -249,7 +249,7 @@ class JobExecutionTest(test_base.ConductorManagerTestCase):
self.api.job_execution_destroy(ctx, job_ex_id)
lst = self.api.job_execution_get_all(ctx)
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
def test_crud_operation_on_configured_jobs(self):
ctx = context.ctx()
@ -266,7 +266,7 @@ class JobExecutionTest(test_base.ConductorManagerTestCase):
self.api.job_execution_create(ctx, SAMPLE_CONF_JOB_EXECUTION)
lst = self.api.job_execution_get_all(ctx)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
job_ex = lst[0]
configs = {
@ -312,20 +312,20 @@ class JobExecutionTest(test_base.ConductorManagerTestCase):
self.api.job_execution_create(ctx, SAMPLE_JOB_EXECUTION)
lst = self.api.job_execution_get_all(ctx)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
kwargs = {'tenant_id': SAMPLE_JOB_EXECUTION['tenant_id']}
lst = self.api.job_execution_get_all(ctx, **kwargs)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
# Valid field but no matching value
kwargs = {'job_id': SAMPLE_JOB_EXECUTION['job_id']+"foo"}
lst = self.api.job_execution_get_all(ctx, **kwargs)
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
# Invalid field
lst = self.api.job_execution_get_all(ctx, **{'badfield': 'somevalue'})
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
def test_job_execution_advanced_search(self):
ctx = context.ctx()
@ -360,20 +360,20 @@ class JobExecutionTest(test_base.ConductorManagerTestCase):
# Search only with job exeuction fields (finds both)
lst = self.api.job_execution_get_all(ctx, **{'return_code': 1})
self.assertEqual(len(lst), 2)
self.assertEqual(2, len(lst))
# Search on cluster name
kwargs = {'cluster.name': cl1['name'],
'return_code': 1}
lst = self.api.job_execution_get_all(ctx, **kwargs)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
# Search on cluster name and job name
kwargs = {'cluster.name': cl1['name'],
'job.name': SAMPLE_JOB['name'],
'return_code': 1}
lst = self.api.job_execution_get_all(ctx, **kwargs)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
# Search on cluster name, job name, and status
kwargs = {'cluster.name': cl2['name'],
@ -381,31 +381,31 @@ class JobExecutionTest(test_base.ConductorManagerTestCase):
'status': 'killed',
'return_code': 1}
lst = self.api.job_execution_get_all(ctx, **kwargs)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
# Search on job name (finds both)
kwargs = {'job.name': SAMPLE_JOB['name'],
'return_code': 1}
lst = self.api.job_execution_get_all(ctx, **kwargs)
self.assertEqual(len(lst), 2)
self.assertEqual(2, len(lst))
# invalid cluster name value
kwargs = {'cluster.name': cl1['name']+'foo',
'job.name': SAMPLE_JOB['name']}
lst = self.api.job_execution_get_all(ctx, **kwargs)
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
# invalid job name value
kwargs = {'cluster.name': cl1['name'],
'job.name': SAMPLE_JOB['name']+'foo'}
lst = self.api.job_execution_get_all(ctx, **kwargs)
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
# invalid status value
kwargs = {'cluster.name': cl1['name'],
'status': 'PENDING'}
lst = self.api.job_execution_get_all(ctx, **kwargs)
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
class JobTest(test_base.ConductorManagerTestCase):
@ -421,18 +421,18 @@ class JobTest(test_base.ConductorManagerTestCase):
self.api.job_create(ctx, SAMPLE_JOB)
lst = self.api.job_get_all(ctx)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
jo_id = lst[0]['id']
update_jo = self.api.job_update(ctx, jo_id,
{'description': 'update'})
self.assertEqual(update_jo['description'], 'update')
self.assertEqual('update', update_jo['description'])
self.api.job_destroy(ctx, jo_id)
lst = self.api.job_get_all(ctx)
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
with testtools.ExpectedException(ex.NotFoundException):
self.api.job_destroy(ctx, jo_id)
@ -455,20 +455,20 @@ class JobTest(test_base.ConductorManagerTestCase):
self.api.job_create(ctx, SAMPLE_JOB)
lst = self.api.job_get_all(ctx)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
kwargs = {'name': SAMPLE_JOB['name'],
'tenant_id': SAMPLE_JOB['tenant_id']}
lst = self.api.job_get_all(ctx, **kwargs)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
# Valid field but no matching value
lst = self.api.job_get_all(ctx, **{'name': SAMPLE_JOB['name']+"foo"})
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
# Invalid field
lst = self.api.job_get_all(ctx, **{'badfield': 'somevalue'})
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
class JobBinaryInternalTest(test_base.ConductorManagerTestCase):
@ -484,13 +484,13 @@ class JobBinaryInternalTest(test_base.ConductorManagerTestCase):
self.api.job_binary_internal_create(ctx, SAMPLE_JOB_BINARY_INTERNAL)
lst = self.api.job_binary_internal_get_all(ctx)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
job_bin_int_id = lst[0]['id']
self.api.job_binary_internal_destroy(ctx, job_bin_int_id)
lst = self.api.job_binary_internal_get_all(ctx)
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
with testtools.ExpectedException(ex.NotFoundException):
self.api.job_binary_internal_destroy(ctx, job_bin_int_id)
@ -509,7 +509,7 @@ class JobBinaryInternalTest(test_base.ConductorManagerTestCase):
SAMPLE_JOB_BINARY_INTERNAL
)['id']
data = self.api.job_binary_internal_get_raw_data(ctx, id)
self.assertEqual(data, SAMPLE_JOB_BINARY_INTERNAL["data"])
self.assertEqual(SAMPLE_JOB_BINARY_INTERNAL["data"], data)
self.api.job_binary_internal_destroy(ctx, id)
@ -541,21 +541,21 @@ class JobBinaryInternalTest(test_base.ConductorManagerTestCase):
self.api.job_binary_internal_create(ctx, SAMPLE_JOB_BINARY_INTERNAL)
lst = self.api.job_binary_internal_get_all(ctx)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
kwargs = {'name': SAMPLE_JOB_BINARY_INTERNAL['name'],
'tenant_id': SAMPLE_JOB_BINARY_INTERNAL['tenant_id']}
lst = self.api.job_binary_internal_get_all(ctx, **kwargs)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
# Valid field but no matching value
kwargs = {'name': SAMPLE_JOB_BINARY_INTERNAL['name']+"foo"}
lst = self.api.job_binary_internal_get_all(ctx, **kwargs)
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
# Invalid field
lst = self.api.job_binary_internal_get_all(ctx, **{'badfield': 'junk'})
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
class JobBinaryTest(test_base.ConductorManagerTestCase):
@ -571,13 +571,13 @@ class JobBinaryTest(test_base.ConductorManagerTestCase):
self.api.job_binary_create(ctx, SAMPLE_JOB_BINARY)
lst = self.api.job_binary_get_all(ctx)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
job_binary_id = lst[0]['id']
self.api.job_binary_destroy(ctx, job_binary_id)
lst = self.api.job_binary_get_all(ctx)
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
with testtools.ExpectedException(ex.NotFoundException):
self.api.job_binary_destroy(ctx, job_binary_id)
@ -612,7 +612,7 @@ class JobBinaryTest(test_base.ConductorManagerTestCase):
self.api.job_destroy(ctx, job_id)
self.api.job_binary_destroy(ctx, job_binary_id)
lst = self.api.job_binary_get_all(ctx)
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
def test_job_binary_referenced_mains(self):
self._test_job_binary_referenced("mains")
@ -633,18 +633,18 @@ class JobBinaryTest(test_base.ConductorManagerTestCase):
self.api.job_binary_create(ctx, SAMPLE_JOB_BINARY)
lst = self.api.job_binary_get_all(ctx)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
kwargs = {'name': SAMPLE_JOB_BINARY['name'],
'tenant_id': SAMPLE_JOB_BINARY['tenant_id']}
lst = self.api.job_binary_get_all(ctx, **kwargs)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
# Valid field but no matching value
kwargs = {'name': SAMPLE_JOB_BINARY['name']+"foo"}
lst = self.api.job_binary_get_all(ctx, **kwargs)
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
# Invalid field
lst = self.api.job_binary_get_all(ctx, **{'badfield': 'somevalue'})
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))

@ -96,13 +96,13 @@ class NodeGroupTemplates(test_base.ConductorManagerTestCase):
self.api.node_group_template_create(ctx, SAMPLE_NGT)
lst = self.api.node_group_template_get_all(ctx)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
ngt_id = lst[0]['id']
self.api.node_group_template_destroy(ctx, ngt_id)
lst = self.api.node_group_template_get_all(ctx)
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
def test_duplicate_ngt_create(self):
ctx = context.ctx()
@ -152,21 +152,21 @@ class NodeGroupTemplates(test_base.ConductorManagerTestCase):
self.api.node_group_template_create(ctx, SAMPLE_NGT)
lst = self.api.node_group_template_get_all(ctx)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
kwargs = {'name': SAMPLE_NGT['name'],
'plugin_name': SAMPLE_NGT['plugin_name']}
lst = self.api.node_group_template_get_all(ctx, **kwargs)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
# Valid field but no matching value
kwargs = {'name': SAMPLE_NGT['name']+"foo"}
lst = self.api.node_group_template_get_all(ctx, **kwargs)
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
# Invalid field
lst = self.api.node_group_template_get_all(ctx, **{'badfield': 'junk'})
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
def test_ngt_update(self):
ctx = context.ctx()
@ -228,13 +228,13 @@ class ClusterTemplates(test_base.ConductorManagerTestCase):
self.api.cluster_template_create(ctx, SAMPLE_CLT)
lst = self.api.cluster_template_get_all(ctx)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
clt_id = lst[0]['id']
self.api.cluster_template_destroy(ctx, clt_id)
lst = self.api.cluster_template_get_all(ctx)
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
with testtools.ExpectedException(ex.NotFoundException):
self.api.cluster_template_destroy(ctx, clt_id)
@ -264,7 +264,7 @@ class ClusterTemplates(test_base.ConductorManagerTestCase):
ng.pop("updated_at")
ng.pop("id")
ng.pop("tenant_id")
self.assertEqual(ng.pop("cluster_template_id"), clt_db_obj_id)
self.assertEqual(clt_db_obj_id, ng.pop("cluster_template_id"))
ng.pop("image_id")
ng.pop("node_configs")
ng.pop("node_group_template_id")
@ -310,21 +310,21 @@ class ClusterTemplates(test_base.ConductorManagerTestCase):
self.api.cluster_template_create(ctx, SAMPLE_CLT)
lst = self.api.cluster_template_get_all(ctx)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
kwargs = {'name': SAMPLE_CLT['name'],
'plugin_name': SAMPLE_CLT['plugin_name']}
lst = self.api.cluster_template_get_all(ctx, **kwargs)
self.assertEqual(len(lst), 1)
self.assertEqual(1, len(lst))
# Valid field but no matching value
kwargs = {'name': SAMPLE_CLT['name']+"foo"}
lst = self.api.cluster_template_get_all(ctx, **kwargs)
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
# Invalid field
lst = self.api.cluster_template_get_all(ctx, **{'badfield': 'junk'})
self.assertEqual(len(lst), 0)
self.assertEqual(0, len(lst))
def test_clt_update(self):
ctx = context.ctx()

@ -83,11 +83,11 @@ class TestConductorClusterApi(base.SaharaWithDbTestCase):
self.api.cluster_update(ctx, cluster.id, {'name': 'changed'})
updated_cluster = self.api.cluster_get(ctx, cluster.id)
self.assertEqual(updated_cluster['name'], 'changed')
self.assertEqual('changed', updated_cluster['name'])
self.api.cluster_destroy(ctx, updated_cluster.id)
cluster_list = self.api.cluster_get_all(ctx)
self.assertEqual(len(cluster_list), 0)
self.assertEqual(0, len(cluster_list))
def test_add_node_group_to_cluster_id(self):
ctx, cluster = self._make_sample()
@ -101,7 +101,7 @@ class TestConductorClusterApi(base.SaharaWithDbTestCase):
cluster = self.api.cluster_get(ctx, cluster.id)
ng = gu.get_by_id(cluster.node_groups, ng_id)
self.assertEqual(ng.name, 'changed_ng')
self.assertEqual('changed_ng', ng.name)
def test_add_instance_to_node_group_id(self):
ctx, cluster = self._make_sample()
@ -118,7 +118,7 @@ class TestConductorClusterApi(base.SaharaWithDbTestCase):
cluster = self.api.cluster_get(ctx, cluster.id)
ng = gu.get_by_id(cluster.node_groups, ng_id)
self.assertEqual(ng.instances[0].instance_name, 'tst123')
self.assertEqual('tst123', ng.instances[0].instance_name)
def _get_events(self, ctx, cluster_id, step_id=None):
cluster = self.api.cluster_get(ctx, cluster_id, show_progress=True)

@ -139,10 +139,10 @@ class TestResource(testtools.TestCase):
res = r.Resource(SAMPLE_DICT)
self.assertIsInstance(res.first, list)
self.assertEqual(res.first, [1, 2])
self.assertEqual([1, 2], res.first)
self.assertIsInstance(res.second, r.Resource)
self.assertEqual(res.second.a, 1)
self.assertEqual(res.second.b, 2)
self.assertEqual(1, res.second.a)
self.assertEqual(2, res.second.b)
def test_resource_immutability(self):
res = r.Resource(SAMPLE_DICT)
@ -158,28 +158,27 @@ class TestResource(testtools.TestCase):
def test_nested_lists(self):
res = r.Resource(SAMPLE_NESTED_LISTS_DICT)
self.assertEqual(res.a[0][0].b, 123)
self.assertEqual(123, res.a[0][0].b)
def test_cluster_resource(self):
cluster = r.ClusterResource(SAMPLE_CLUSTER_DICT)
self.assertEqual(cluster.name, 'test-cluster')
self.assertEqual('test-cluster', cluster.name)
self.assertEqual(cluster.node_groups[0].name, 'master')
self.assertEqual('master', cluster.node_groups[0].name)
self.assertIsInstance(cluster.node_groups[0], r.NodeGroupResource)
self.assertEqual(cluster.node_groups[0].cluster.name, 'test-cluster')
self.assertEqual('test-cluster', cluster.node_groups[0].cluster.name)
self.assertEqual(cluster.node_groups[1].instances[0].name,
'test-cluster-001')
self.assertEqual('test-cluster-001',
cluster.node_groups[1].instances[0].name)
self.assertIsInstance(cluster.node_groups[1].instances[0],
r.InstanceResource)
self.assertEqual(
cluster.node_groups[1].instances[0].node_group.name,
'worker')
self.assertEqual('worker',
cluster.node_groups[1].instances[0].node_group.name)
def test_to_dict(self):
cluster = r.ClusterResource(SAMPLE_CLUSTER_DICT)
self.assertEqual(cluster.to_dict(), SAMPLE_CLUSTER_DICT)
self.assertEqual(SAMPLE_CLUSTER_DICT, cluster.to_dict())
def test_to_dict_filtering(self):
cluster_dict = copy.deepcopy(SAMPLE_CLUSTER_DICT)
@ -187,13 +186,13 @@ class TestResource(testtools.TestCase):
cluster_dict['node_groups'][0]['id'] = 'some_id'
cluster = r.ClusterResource(cluster_dict)
self.assertEqual(cluster.to_dict(), SAMPLE_CLUSTER_DICT)
self.assertEqual(SAMPLE_CLUSTER_DICT, cluster.to_dict())
def test_to_wrapped_dict(self):
cluster = r.ClusterResource(SAMPLE_CLUSTER_DICT)
wrapped_dict = cluster.to_wrapped_dict()
self.assertEqual(len(wrapped_dict), 1)
self.assertEqual(wrapped_dict['cluster'], SAMPLE_CLUSTER_DICT)
self.assertEqual(1, len(wrapped_dict))
self.assertEqual(SAMPLE_CLUSTER_DICT, wrapped_dict['cluster'])
def test_job_binary_filter_extra(self):
job_binary = r.JobBinary(SAMPLE_JOB_BINARY_DICT)

@ -52,7 +52,7 @@ class SaharaMigrationsCheckers(object):
def assertColumnCount(self, engine, table, columns):
t = db_utils.get_table(engine, table)
self.assertEqual(len(t.columns), len(columns))
self.assertEqual(len(columns), len(t.columns))
def assertColumnNotExists(self, engine, table, column):
t = db_utils.get_table(engine, table)

@ -55,7 +55,7 @@ class ContextTest(testtools.TestCase):
for i in six.moves.range(400):
tg.spawn('add %i' % i, self._add_element, lst, i)
self.assertEqual(len(lst), 400)
self.assertEqual(400, len(lst))
def test_thread_group_waits_threads_if_spawning_exception(self):
lst = []
@ -67,7 +67,7 @@ class ContextTest(testtools.TestCase):
raise RuntimeError()
self.assertEqual(len(lst), 400)
self.assertEqual(400, len(lst))
def test_thread_group_waits_threads_if_child_exception(self):
lst = []
@ -79,7 +79,7 @@ class ContextTest(testtools.TestCase):
for i in six.moves.range(400):
tg.spawn('add %i' % i, self._add_element, lst, i)
self.assertEqual(len(lst), 400)
self.assertEqual(400, len(lst))
def test_thread_group_handles_spawning_exception(self):
with testtools.ExpectedException(TestException):
@ -119,7 +119,7 @@ class ContextTest(testtools.TestCase):
context._wrapper(None, 'test thread', tg, func)
self.assertIsNotNone(tg.exc)
self.assertEqual(tg.failed_thread, 'test thread')
self.assertEqual('test thread', tg.failed_thread)
def test_is_auth_capable_for_admin_ctx(self):
ctx = context.ctx()

@ -114,7 +114,7 @@ class TopologyTestCase(base.SaharaTestCase):
cluster.node_groups = [ng1, ng2]
top = th.generate_topology_map(cluster, False)
self.assertEqual(top, {
self.assertEqual({
"i1": "/r1",
"1.1.1.1": "/r1",
"0.0.1.1": "/r1",
@ -125,10 +125,10 @@ class TopologyTestCase(base.SaharaTestCase):
"1.1.1.3": "/r2",
"0.0.1.3": "/r2",
"s1": "/r1"
})
}, top)
top = th.generate_topology_map(cluster, True)
self.assertEqual(top, {
self.assertEqual({
"i1": "/r1/o1",
"1.1.1.1": "/r1/o1",
"0.0.1.1": "/r1/o1",
@ -139,7 +139,7 @@ class TopologyTestCase(base.SaharaTestCase):
"1.1.1.3": "/r2/o2",
"0.0.1.3": "/r2/o2",
"s1": "/r1"
})
}, top)
def _read_swift_topology(self, content):
temp_file = tempfile.NamedTemporaryFile()
@ -153,17 +153,17 @@ class TopologyTestCase(base.SaharaTestCase):
def test_read_swift_topology(self):
topology = self._read_swift_topology("")
self.assertEqual(topology, {})
self.assertEqual({}, topology)
topology = self._read_swift_topology(
"192.168.1.1 /rack1\n192.168.1.2 /rack2")
self.assertEqual(
topology, {"192.168.1.1": "/rack1", "192.168.1.2": "/rack2"})
{"192.168.1.1": "/rack1", "192.168.1.2": "/rack2"}, topology)
topology = self._read_swift_topology(
"192.168.1.1 /rack1\n192.168.1.2 /rack2\n\n")
self.assertEqual(
topology, {"192.168.1.1": "/rack1", "192.168.1.2": "/rack2"})
{"192.168.1.1": "/rack1", "192.168.1.2": "/rack2"}, topology)
def _read_compute_topology(self, content):
temp_file = tempfile.NamedTemporaryFile()
@ -177,12 +177,12 @@ class TopologyTestCase(base.SaharaTestCase):
def test_read_compute_topology(self):
topology = self._read_swift_topology("")
self.assertEqual(topology, {})
self.assertEqual({}, topology)
topology = self._read_swift_topology(
"192.168.1.1 /rack1\n192.168.1.2 /rack2")
self.assertEqual(len(topology), 2)
self.assertEqual(2, len(topology))
topology = self._read_swift_topology(
"192.168.1.1 /rack1\n192.168.1.2 /rack2\n\n")
self.assertEqual(len(topology), 2)
self.assertEqual(2, len(topology))

@ -61,7 +61,7 @@ class ClusterProgressOpsTest(base.SaharaWithDbTestCase):
result_cluster = self.api.cluster_get(ctx, cluster.id)
result_step = result_cluster.provision_progress[0]
self.assertEqual(None, result_step.successful)
self.assertIsNone(result_step.successful)
# check updating in case of successful provision step

@ -21,12 +21,12 @@ from sahara.utils import edp
class SplitJobTypeTest(testtools.TestCase):
def test_split_job_type(self):
jtype, stype = edp.split_job_type(edp.JOB_TYPE_MAPREDUCE)
self.assertEqual(jtype, edp.JOB_TYPE_MAPREDUCE)
self.assertEqual(stype, edp.JOB_SUBTYPE_NONE)
self.assertEqual(edp.JOB_TYPE_MAPREDUCE, jtype)
self.assertEqual(edp.JOB_SUBTYPE_NONE, stype)
jtype, stype = edp.split_job_type(edp.JOB_TYPE_MAPREDUCE_STREAMING)
self.assertEqual(jtype, edp.JOB_TYPE_MAPREDUCE)
self.assertEqual(stype, edp.JOB_SUBTYPE_STREAMING)
self.assertEqual(edp.JOB_TYPE_MAPREDUCE, jtype)
self.assertEqual(edp.JOB_SUBTYPE_STREAMING, stype)
def test_compare_job_type(self):
self.assertTrue(edp.compare_job_type(

@ -43,6 +43,6 @@ class UtilsGeneralTest(testtools.TestCase):
def test_generate_instance_name(self):
inst_name = "cluster-worker-001"
self.assertEqual(
general.generate_instance_name("cluster", "worker", 1), inst_name)
inst_name, general.generate_instance_name("cluster", "worker", 1))
self.assertEqual(
general.generate_instance_name("CLUSTER", "WORKER", 1), inst_name)
inst_name, general.generate_instance_name("CLUSTER", "WORKER", 1))

@ -49,8 +49,7 @@ class MinidomPatchesTest(testtools.TestCase):
return doc.toprettyxml(indent=" ")
def test_minidom_toprettyxml(self):
self.assertEqual(self._generate_n_prettify_xml(),
"""<?xml version="1.0" ?>
self.assertEqual("""<?xml version="1.0" ?>
<?xml-smth type="text/smth" href="test.smth"?>
<root>
<element>
@ -74,4 +73,4 @@ class MinidomPatchesTest(testtools.TestCase):
<value>value-4</value>
</element>
</root>
""")
""", self._generate_n_prettify_xml())

@ -26,7 +26,7 @@ from sahara.utils import ssh_remote
class TestEscapeQuotes(testtools.TestCase):
def test_escape_quotes(self):
s = ssh_remote._escape_quotes('echo "\\"Hello, world!\\""')
self.assertEqual(s, r'echo \"\\\"Hello, world!\\\"\"')
self.assertEqual(r'echo \"\\\"Hello, world!\\\"\"', s)
class FakeCluster(object):

@ -38,18 +38,16 @@ class XMLUtilsTestCase(testtools.TestCase):
'tests/unit/resources/test-default.xml'))
def test_adjust_description(self):
self.assertEqual(x._adjust_field("\n"), "")
self.assertEqual(x._adjust_field("\n "), "")
self.assertEqual(x._adjust_field(u"abc\n def\n "), "abcdef")
self.assertEqual(x._adjust_field("abc d\n e f\n"), "abc de f")
self.assertEqual(x._adjust_field("a\tb\t\nc"), "abc")
self.assertEqual("", x._adjust_field("\n"))
self.assertEqual("", x._adjust_field("\n "))
self.assertEqual("abcdef", x._adjust_field(u"abc\n def\n "))
self.assertEqual("abc de f", x._adjust_field("abc d\n e f\n"))
self.assertEqual("abc", x._adjust_field("a\tb\t\nc"))
def test_create_hadoop_xml(self):
conf = x.load_hadoop_xml_defaults(
'tests/unit/resources/test-default.xml')
self.assertEqual(x.create_hadoop_xml({'name1': 'some_val1',
'name2': 2}, conf),
"""<?xml version="1.0" ?>
self.assertEqual("""<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
@ -61,24 +59,25 @@ class XMLUtilsTestCase(testtools.TestCase):
<value>2</value>
</property>
</configuration>
""")
""",
x.create_hadoop_xml({'name1': 'some_val1',
'name2': 2}, conf),)
def test_add_property_to_configuration(self):
doc = self.create_default_doc()
x.add_properties_to_configuration(doc, 'test', {'': 'empty1',
None: 'empty2'})
self.assertEqual(doc.toprettyxml(indent=" "),
"""<?xml version="1.0" ?>
self.assertEqual("""<?xml version="1.0" ?>
<test>
<configuration/>
</test>
""")
""",
doc.toprettyxml(indent=" "))
test_conf = {'name1': 'value1', 'name2': 'value2'}
x.add_properties_to_configuration(doc, 'test', test_conf)
self.assertEqual(doc.toprettyxml(indent=" "),
"""<?xml version="1.0" ?>
self.assertEqual("""<?xml version="1.0" ?>
<test>
<configuration>
<property>
@ -91,10 +90,10 @@ class XMLUtilsTestCase(testtools.TestCase):
</property>
</configuration>
</test>
""")
""",
doc.toprettyxml(indent=" "))
x.add_property_to_configuration(doc, 'name3', 'value3')
self.assertEqual(doc.toprettyxml(indent=" "),
"""<?xml version="1.0" ?>
self.assertEqual("""<?xml version="1.0" ?>
<test>
<configuration>
<property>
@ -111,71 +110,72 @@ class XMLUtilsTestCase(testtools.TestCase):
</property>
</configuration>
</test>
""")
""",
doc.toprettyxml(indent=" "))
def test_get_if_not_exist_and_add_text_element(self):
doc = self.create_default_doc()
x.get_and_create_if_not_exist(doc, 'test', 'tag_to_add')
self.assertEqual(doc.toprettyxml(indent=" "),
"""<?xml version="1.0" ?>
self.assertEqual("""<?xml version="1.0" ?>
<test>
<tag_to_add/>
</test>
""")
""",
doc.toprettyxml(indent=" "))
x.add_text_element_to_tag(doc, 'tag_to_add', 'p', 'v')
self.assertEqual(doc.toprettyxml(indent=" "),
"""<?xml version="1.0" ?>
self.assertEqual("""<?xml version="1.0" ?>
<test>
<tag_to_add>
<p>v</p>
</tag_to_add>
</test>
""")
""",
doc.toprettyxml(indent=" "))
def test_get_if_not_exist_and_add_to_element(self):
doc = self.create_default_doc()
elem = x.get_and_create_if_not_exist(doc, 'test', 'tag_to_add')
x.add_text_element_to_element(doc, elem, 'p', 'v')
self.assertEqual(doc.toprettyxml(indent=" "),
"""<?xml version="1.0" ?>
self.assertEqual("""<?xml version="1.0" ?>
<test>
<tag_to_add>
<p>v</p>
</tag_to_add>
</test>
""")
""",
doc.toprettyxml(indent=" "))
def test_add_tagged_list(self):
doc = self.create_default_doc()
x.add_tagged_list(doc, 'test', 'list_item', ['a', 'b'])
self.assertEqual(doc.toprettyxml(indent=" "),
"""<?xml version="1.0" ?>
self.assertEqual("""<?xml version="1.0" ?>
<test>
<list_item>a</list_item>
<list_item>b</list_item>
</test>
""")
""",
doc.toprettyxml(indent=" "))
def test_add_equal_separated_dict(self):
doc = self.create_default_doc()
x.add_equal_separated_dict(doc, 'test', 'dict_item',
{'': 'empty1', None: 'empty2'})
self.assertEqual(doc.toprettyxml(indent=" "),
"""<?xml version="1.0" ?>
self.assertEqual("""<?xml version="1.0" ?>
<test/>
""")
""",
doc.toprettyxml(indent=" "))
x.add_equal_separated_dict(doc, 'test', 'dict_item',
{'a': 'b', 'c': 'd'})
self.assertEqual(doc.toprettyxml(indent=" "),
"""<?xml version="1.0" ?>
self.assertEqual("""<?xml version="1.0" ?>
<test>
<dict_item>a=b</dict_item>
<dict_item>c=d</dict_item>
</test>
""")
""",
doc.toprettyxml(indent=" "))
def create_default_doc(self):
doc = xml.Document()
@ -200,4 +200,4 @@ class XMLUtilsTestCase(testtools.TestCase):
# Prove the differences are only blank lines
non_blank_diffs = [l for l in diff if not l.isspace()]
self.assertEqual(len(non_blank_diffs), 0)
self.assertEqual(0, len(non_blank_diffs))

Loading…
Cancel
Save