Skip to content

Commit

Permalink
Mock open to prevent file creation
Browse files Browse the repository at this point in the history
Some unit tests does create files in root of project

Change-Id: I9b9907177ad1d25142d85538a727a5e8eab99df0
  • Loading branch information
Sergey Skripnick committed Aug 5, 2014
1 parent 4fbb79e commit 2d210ff
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions tests/cmd/commands/test_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.

import os

import mock
import six

Expand Down Expand Up @@ -139,32 +137,45 @@ def test_results_verification_not_found(self, mock_db_result_get):

mock_db_result_get.assert_called_once_with(verification_uuid)

@mock.patch('rally.cmd.commands.verify.open', create=True)
@mock.patch('rally.db.verification_result_get', return_value={'data': {}})
def test_results_with_output_json_and_output_file(self,
mock_db_result_get):
mock_db_result_get,
mock_open):
mock_open.return_value = mock.MagicMock()
verification_uuid = '94615cd4-ff45-4123-86bd-4b0741541d09'
self.verify.results(verification_uuid, output_file='results',
output_json=True)

mock_db_result_get.assert_called_once_with(verification_uuid)
self.assertTrue(os.path.isfile('results'))
mock_open.assert_called_once_with('results', 'wb')
fake_file = mock_open.return_value.__enter__.return_value
fake_file.write.assert_called_once_with('{}')

@mock.patch('rally.cmd.commands.verify.open', create=True)
@mock.patch('rally.db.verification_result_get', return_value={'data': {}})
def test_results_with_output_pprint_and_output_file(self,
mock_db_result_get):
mock_db_result_get,
mock_open):
mock_open.return_value = mock.MagicMock()
verification_uuid = 'fa882ccc-153e-4a6e-9001-91fecda6a75c'
self.verify.results(verification_uuid, output_pprint=True,
output_file='results')

mock_db_result_get.assert_called_once_with(verification_uuid)
self.assertTrue(os.path.isfile('results'))
mock_open.assert_called_once_with('results', 'wb')
fake_file = mock_open.return_value.__enter__.return_value
fake_file.write.assert_called_once_with('{}')

@mock.patch('rally.cmd.commands.verify.open', create=True)
@mock.patch('rally.db.verification_result_get')
@mock.patch('rally.verification.verifiers.tempest.json2html.main',
return_value='')
def test_results_with_output_html_and_output_file(self,
mock_json2html_main,
mock_db_result_get):
mock_db_result_get,
mock_open):
mock_open.return_value = mock.MagicMock()
verification_uuid = '7140dd59-3a7b-41fd-a3ef-5e3e615d7dfa'
results = {'data': {}}
mock_db_result_get.return_value = results
Expand All @@ -173,4 +184,6 @@ def test_results_with_output_html_and_output_file(self,

mock_db_result_get.assert_called_once_with(verification_uuid)
mock_json2html_main.assert_called_once()
self.assertTrue(os.path.isfile('results'))
mock_open.assert_called_once_with('results', 'wb')
fake_file = mock_open.return_value.__enter__.return_value
fake_file.write.assert_called_once_with('')

0 comments on commit 2d210ff

Please sign in to comment.