Fix PY3 compatibility

* Change iteritems to items
* Use six.string_types instead of basestring
* Use open instead of file
* encode to utf-8 before writing to file in tests
* fix minor relative import in mistralclient.utils

Also, this is blocking the port of Heat to use Python 3.

Change-Id: Ie82975482754246d9761dd2cf9693fb852024a9b
This commit is contained in:
Sirushti Murugesan
2015-08-01 01:27:05 +05:30
parent fc140dbe05
commit 54041d4f3a
7 changed files with 19 additions and 17 deletions

View File

@@ -41,7 +41,7 @@ class TestCLITriggersV2(base.BaseCommandTest):
@mock.patch('mistralclient.api.v2.cron_triggers.CronTriggerManager.create')
def test_create(self, mock, mock_open):
mock.return_value = TRIGGER
mock_open.return_value = mock.MagicMock(spec=file)
mock_open.return_value = mock.MagicMock(spec=open)
result = self.call(
cron_triggers_cmd.Create,

View File

@@ -56,7 +56,7 @@ class TestCLIEnvironmentsV2(base.BaseCommandTest):
mock.return_value = ENVIRONMENT
with tempfile.NamedTemporaryFile() as f:
f.write(content)
f.write(content.encode('utf-8'))
f.flush()
file_path = os.path.abspath(f.name)
result = self.call(environment_cmd.Create, app_args=[file_path])
@@ -74,7 +74,7 @@ class TestCLIEnvironmentsV2(base.BaseCommandTest):
mock.return_value = ENVIRONMENT
with tempfile.NamedTemporaryFile() as f:
f.write(content)
f.write(content.encode('utf-8'))
f.flush()
file_path = os.path.abspath(f.name)
result = self.call(environment_cmd.Update, app_args=[file_path])

View File

@@ -53,7 +53,7 @@ class TestCLIWorkbooksV2(base.BaseCommandTest):
@mock.patch('mistralclient.api.v2.workbooks.WorkbookManager.create')
def test_create(self, mock, mock_open):
mock.return_value = WORKBOOK
mock_open.return_value = mock.MagicMock(spec=file)
mock_open.return_value = mock.MagicMock(spec=open)
result = self.call(workbook_cmd.Create, app_args=['wb.yaml'])
@@ -63,7 +63,7 @@ class TestCLIWorkbooksV2(base.BaseCommandTest):
@mock.patch('mistralclient.api.v2.workbooks.WorkbookManager.update')
def test_update(self, mock, mock_open):
mock.return_value = WORKBOOK
mock_open.return_value = mock.MagicMock(spec=file)
mock_open.return_value = mock.MagicMock(spec=open)
result = self.call(workbook_cmd.Update, app_args=['definition'])
@@ -113,7 +113,7 @@ class TestCLIWorkbooksV2(base.BaseCommandTest):
@mock.patch('mistralclient.api.v2.workbooks.WorkbookManager.validate')
def test_validate(self, mock, mock_open):
mock.return_value = {'valid': True}
mock_open.return_value = mock.MagicMock(spec=file)
mock_open.return_value = mock.MagicMock(spec=open)
result = self.call(workbook_cmd.Validate, app_args=['wb.yaml'])
@@ -124,7 +124,7 @@ class TestCLIWorkbooksV2(base.BaseCommandTest):
@mock.patch('mistralclient.api.v2.workbooks.WorkbookManager.validate')
def test_validate_failed(self, mock, mock_open):
mock.return_value = {'valid': False, 'error': 'Invalid DSL...'}
mock_open.return_value = mock.MagicMock(spec=file)
mock_open.return_value = mock.MagicMock(spec=open)
self.assertRaises(exc.MistralClientException,
self.call,

View File

@@ -128,7 +128,7 @@ class TestCLIWorkflowsV2(base.BaseCommandTest):
@mock.patch('mistralclient.api.v2.workflows.WorkflowManager.validate')
def test_validate(self, mock, mock_open):
mock.return_value = {'valid': True}
mock_open.return_value = mock.MagicMock(spec=file)
mock_open.return_value = mock.MagicMock(spec=open)
result = self.call(workflow_cmd.Validate, app_args=['wf.yaml'])
@@ -139,7 +139,7 @@ class TestCLIWorkflowsV2(base.BaseCommandTest):
@mock.patch('mistralclient.api.v2.workflows.WorkflowManager.validate')
def test_validate_failed(self, mock, mock_open):
mock.return_value = {'valid': False, 'error': 'Invalid DSL...'}
mock_open.return_value = mock.MagicMock(spec=file)
mock_open.return_value = mock.MagicMock(spec=open)
self.assertRaises(exc.MistralClientException,
self.call,