def test_replace_file(self):
    with mock.patch('tempfile.NamedTemporaryFile') as ntf:
        ntf.return_value.name = '/baz'
        with mock.patch('os.chmod') as chmod:
            with mock.patch('os.rename') as rename:
                utils.replace_file('/foo', 'bar')
                expected = [mock.call('w+', dir='/', delete=False), mock.call().write('bar'), mock.call().close()]
                ntf.assert_has_calls(expected)
                chmod.assert_called_once_with('/baz', 420)
                rename.assert_called_once_with('/baz', '/foo')
def test_replace_file(self):
    with mock.patch('tempfile.NamedTemporaryFile') as ntf:
        ntf.return_value.name = '/baz'
        with mock.patch('os.chmod') as chmod:
            with mock.patch('os.rename') as rename:
                utils.replace_file('/foo', 'bar')
                expected = [mock.call('w+', dir='/', delete=False), mock.call().write('bar'), mock.call().close()]
                ntf.assert_has_calls(expected)
                chmod.assert_called_once_with('/baz', 420)
                rename.assert_called_once_with('/baz', '/foo')