]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Add missing unit test for Remote._sftp_open_file
authorZack Cerza <zack@redhat.com>
Wed, 18 May 2016 17:38:25 +0000 (11:38 -0600)
committerZack Cerza <zack@redhat.com>
Wed, 18 May 2016 17:40:53 +0000 (11:40 -0600)
Signed-off-by: Zack Cerza <zack@redhat.com>
teuthology/orchestra/test/test_remote.py

index 714f8b100b73831a5fe4c5abb81bdd3cb33e18c8..612a0ca4008e615a060e84da7bb78f14ac6a4105 100644 (file)
@@ -147,3 +147,19 @@ class TestRemote(object):
             ssh_pub_key='host_key',
             up=True,
         )
+
+    def test_sftp_open_file(self):
+        m_file_obj = MagicMock()
+        m_stat = Mock()
+        m_stat.st_size = 42
+        m_file_obj.stat.return_value = m_stat
+        m_open = MagicMock()
+        m_open.return_value = m_file_obj
+        m_open.return_value.__enter__.return_value = m_file_obj
+        with patch.object(remote.Remote, '_sftp_open_file', new=m_open):
+            rem = remote.Remote(name='jdoe@xyzzy.example.com', ssh=self.m_ssh)
+            assert rem._sftp_open_file('x') is m_file_obj
+            assert rem._sftp_open_file('x').stat() is m_stat
+            assert rem._sftp_open_file('x').stat().st_size == 42
+            with rem._sftp_open_file('x') as f:
+                assert f == m_file_obj