From: Andrew Schoen Date: Wed, 3 Dec 2014 20:26:34 +0000 (-0600) Subject: moved all the cluster.write_file tests into their own class; rewrote the existing... X-Git-Tag: 1.1.0~1061^2~18^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=e4e34e2f7b34d2cc96bf5eb2dc9bdf9a29247fe1;p=teuthology.git moved all the cluster.write_file tests into their own class; rewrote the existing test to have one assertion per test case Signed-off-by: Andrew Schoen --- diff --git a/teuthology/orchestra/test/test_cluster.py b/teuthology/orchestra/test/test_cluster.py index 8f1a23f69d..6b3a9836d3 100644 --- a/teuthology/orchestra/test/test_cluster.py +++ b/teuthology/orchestra/test/test_cluster.py @@ -1,7 +1,7 @@ import fudge import pytest -from mock import patch +from mock import patch, Mock from .. import cluster, remote @@ -208,20 +208,33 @@ class TestCluster(object): c_foo = c.exclude('foo', lambda role: role.startswith('b')) assert c_foo.remotes == {r2: ['bar'], r3: ['foo']} - @patch("teuthology.misc.write_file") - @patch("teuthology.misc.sudo_write_file") - def test_write_file(self, m_sudo_write_file, m_write_file): - r1 = remote.Remote('r1', ssh=fudge.Fake('SSH')) - c = cluster.Cluster( + +class TestWriteFile(object): + """ Tests for cluster.write_file """ + def setup(self): + self.r1 = remote.Remote('r1', ssh=Mock()) + self.c = cluster.Cluster( remotes=[ - (r1, ['foo', 'bar']), - ], - ) - c.write_file("filename", "content", sudo=True) - m_sudo_write_file.assert_called_with(r1, "filename", "content", owner=None, perms=None) + (self.r1, ['foo', 'bar']), + ], + ) + + @patch("teuthology.misc.write_file") + def test_write_file(self, m_write_file): + self.c.write_file("filename", "content") + m_write_file.assert_called_with(self.r1, "filename", "content") + + @patch("teuthology.misc.write_file") + def test_fails_with_invalid_perms(self, m_write_file): with pytest.raises(ValueError): - c.write_file("filename", "content", sudo=False, perms="perms") - c.write_file("filename", "content") - m_write_file.assert_called_with(r1, "filename", "content") + self.c.write_file("filename", "content", sudo=False, perms="invalid") + @patch("teuthology.misc.write_file") + def test_fails_with_invalid_owner(self, m_write_file): + with pytest.raises(ValueError): + self.c.write_file("filename", "content", sudo=False, owner="invalid") + @patch("teuthology.misc.sudo_write_file") + def test_with_sudo(self, m_sudo_write_file): + self.c.write_file("filename", "content", sudo=True) + m_sudo_write_file.assert_called_with(self.r1, "filename", "content", owner=None, perms=None)