From a2d60e789c6f780d4284a554944c4513c845de0c Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Wed, 13 Feb 2019 13:50:12 -0500 Subject: [PATCH] tests: more verifications for remote execution of module Signed-off-by: Alfredo Deza --- remoto/tests/backends/test_backends.py | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/remoto/tests/backends/test_backends.py b/remoto/tests/backends/test_backends.py index 550e7b0..9911e8e 100644 --- a/remoto/tests/backends/test_backends.py +++ b/remoto/tests/backends/test_backends.py @@ -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): -- 2.47.3