]> git-server-git.apps.pok.os.sepia.ceph.com Git - remoto.git/commitdiff
tests: more verifications for remote execution of module
authorAlfredo Deza <alfredo@deza.pe>
Wed, 13 Feb 2019 18:50:12 +0000 (13:50 -0500)
committerAlfredo Deza <alfredo@deza.pe>
Wed, 13 Feb 2019 20:14:36 +0000 (15:14 -0500)
Signed-off-by: Alfredo Deza <alfredo@deza.pe>
remoto/tests/backends/test_backends.py

index 550e7b0436b2cfaba83643db376addc658b40fba..9911e8ef0187e92ab498f2fcf69a7d2928960eba 100644 (file)
@@ -2,6 +2,7 @@ import sys
 from mock import Mock, patch
 import pytest
 from remoto import backends
+from remoto.backends import local
 from remoto.tests import fake_module
 from remoto.tests.conftest import Capture, Factory
 
@@ -13,6 +14,44 @@ class FakeSocket(object):
         self.getfqdn = lambda: getfqdn or gethostname
 
 
+class TestJsonModuleExecute(object):
+
+    def test_execute_returns_casted_boolean(self):
+        conn = local.LocalConnection()
+        conn.remote_import_system = 'json'
+        remote_fake_module = conn.import_module(fake_module)
+        assert remote_fake_module.function(None) is True
+
+    def test_execute_can_raise_remote_exceptions(self):
+        conn = local.LocalConnection()
+        conn.remote_import_system = 'json'
+        remote_fake_module = conn.import_module(fake_module)
+        with pytest.raises(Exception) as error:
+            assert remote_fake_module.fails()
+        assert 'Exception: failure from fails() function' in str(error.value)
+
+    def test_execute_can_raise_unexpected_remote_exceptions(self):
+        conn = local.LocalConnection()
+        conn.remote_import_system = 'json'
+        remote_fake_module = conn.import_module(fake_module)
+        with pytest.raises(Exception) as error:
+            remote_fake_module.unexpected_fail()
+        assert 'error calling "unexpected_fail"' in str(error.value)
+        assert 'Unexpected remote exception' in str(error.value)
+
+    def test_execute_noop(self):
+        conn = local.LocalConnection()
+        conn.remote_import_system = 'json'
+        remote_fake_module = conn.import_module(fake_module)
+        assert remote_fake_module.noop() is None
+
+    def test_execute_passes_is_none(self):
+        conn = local.LocalConnection()
+        conn.remote_import_system = 'json'
+        remote_fake_module = conn.import_module(fake_module)
+        assert remote_fake_module.passes() is None
+
+
 class TestNeedsSsh(object):
 
     def test_short_hostname_matches(self):