]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
moved all the cluster.write_file tests into their own class; rewrote the existing... 374/head
authorAndrew Schoen <aschoen@redhat.com>
Wed, 3 Dec 2014 20:26:34 +0000 (14:26 -0600)
committerAndrew Schoen <aschoen@redhat.com>
Wed, 3 Dec 2014 20:36:23 +0000 (14:36 -0600)
Signed-off-by: Andrew Schoen <aschoen@redhat.com>
teuthology/orchestra/test/test_cluster.py

index 8f1a23f69d2b7ff1b77cc3060df304d970e9c502..6b3a9836d328e7ab1d0fa3a82050e0f2a7ffedcf 100644 (file)
@@ -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)