From 285f54711a81603e04d93a19f96eea2969611cc8 Mon Sep 17 00:00:00 2001 From: Andrew Schoen Date: Wed, 3 Dec 2014 13:06:30 -0600 Subject: [PATCH] added a test for teuthology.orchestra.cluster.write_file Signed-off-by: Andrew Schoen --- teuthology/orchestra/test/test_cluster.py | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/teuthology/orchestra/test/test_cluster.py b/teuthology/orchestra/test/test_cluster.py index 7596583cc7..dcc5c697a2 100644 --- a/teuthology/orchestra/test/test_cluster.py +++ b/teuthology/orchestra/test/test_cluster.py @@ -1,4 +1,7 @@ import fudge +import pytest + +from mock import patch from .. import cluster, remote @@ -204,3 +207,25 @@ class TestCluster(object): ) c_foo = c.exclude('foo', lambda role: role.startswith('b')) assert c_foo.remotes == {r2: ['bar'], r3: ['foo']} + + @fudge.with_fakes + @patch("teuthology.misc.write_file") + @patch("teuthology.misc.sudo_write_file") + def test_write_file(self, m_sudo_write_file, m_write_file): + fudge.clear_expectations() + r1 = remote.Remote('r1', ssh=fudge.Fake('SSH')) + c = cluster.Cluster( + remotes=[ + (r1, ['foo', 'bar']), + ], + ) + c.write_file("filename", "content", sudo=True) + assert m_sudo_write_file.called + m_sudo_write_file.assert_called_with(r1, "filename", "content", owner=None, perms=None) + with pytest.raises(ValueError): + c.write_file("filename", "content", sudo=False, perms="perms") + c.write_file("filename", "content") + assert m_write_file.called + m_write_file.assert_called_with(r1, "filename", "content") + + -- 2.39.5