feat: major architectural refactor to 5.1b1 - Service Layer, gRPC & Agent evolution (fragmented secrets)
This commit is contained in:
1 parent
85b23526cd
commit
cb926c2b85
123 files changed
+38189
-4640
No files matched your search
@@ -48,10 +48,6 @@ el.replaceWith(d);
|
||||
<dd>
|
||||
<div class="desc"><p>Tests for connpy.ai module.</p></div>
|
||||
</dd>
|
||||
<dt><code class="name"><a title="connpy.tests.test_api" href="test_api.html">connpy.tests.test_api</a></code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>Tests for connpy.api module — Flask routes.</p></div>
|
||||
</dd>
|
||||
<dt><code class="name"><a title="connpy.tests.test_capture" href="test_capture.html">connpy.tests.test_capture</a></code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>Tests for connpy.core_plugins.capture</p></div>
|
||||
@@ -64,18 +60,26 @@ el.replaceWith(d);
|
||||
<dd>
|
||||
<div class="desc"><p>Tests for connpy.configfile module.</p></div>
|
||||
</dd>
|
||||
<dt><code class="name"><a title="connpy.tests.test_context" href="test_context.html">connpy.tests.test_context</a></code></dt>
|
||||
<dt><code class="name"><a title="connpy.tests.test_connapp" href="test_connapp.html">connpy.tests.test_connapp</a></code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>Tests for connpy.core_plugins.context</p></div>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt><code class="name"><a title="connpy.tests.test_core" href="test_core.html">connpy.tests.test_core</a></code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>Tests for connpy.core module — node and nodes classes.</p></div>
|
||||
</dd>
|
||||
<dt><code class="name"><a title="connpy.tests.test_execution_service" href="test_execution_service.html">connpy.tests.test_execution_service</a></code></dt>
|
||||
<dd>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt><code class="name"><a title="connpy.tests.test_hooks" href="test_hooks.html">connpy.tests.test_hooks</a></code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>Tests for connpy.hooks module — MethodHook and ClassHook.</p></div>
|
||||
</dd>
|
||||
<dt><code class="name"><a title="connpy.tests.test_node_service" href="test_node_service.html">connpy.tests.test_node_service</a></code></dt>
|
||||
<dd>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt><code class="name"><a title="connpy.tests.test_plugins" href="test_plugins.html">connpy.tests.test_plugins</a></code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>Tests for connpy.plugins module.</p></div>
|
||||
@@ -84,9 +88,17 @@ el.replaceWith(d);
|
||||
<dd>
|
||||
<div class="desc"><p>Tests for connpy.printer module.</p></div>
|
||||
</dd>
|
||||
<dt><code class="name"><a title="connpy.tests.test_profile_service" href="test_profile_service.html">connpy.tests.test_profile_service</a></code></dt>
|
||||
<dd>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt><code class="name"><a title="connpy.tests.test_provider" href="test_provider.html">connpy.tests.test_provider</a></code></dt>
|
||||
<dd>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt><code class="name"><a title="connpy.tests.test_sync" href="test_sync.html">connpy.tests.test_sync</a></code></dt>
|
||||
<dd>
|
||||
<div class="desc"><p>Tests for connpy.core_plugins.sync</p></div>
|
||||
<div class="desc"><p>Tests for connpy.services.sync_service</p></div>
|
||||
</dd>
|
||||
</dl>
|
||||
</section>
|
||||
@@ -111,15 +123,18 @@ el.replaceWith(d);
|
||||
<ul>
|
||||
<li><code><a title="connpy.tests.conftest" href="conftest.html">connpy.tests.conftest</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_ai" href="test_ai.html">connpy.tests.test_ai</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_api" href="test_api.html">connpy.tests.test_api</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_capture" href="test_capture.html">connpy.tests.test_capture</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_completion" href="test_completion.html">connpy.tests.test_completion</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_configfile" href="test_configfile.html">connpy.tests.test_configfile</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_context" href="test_context.html">connpy.tests.test_context</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp" href="test_connapp.html">connpy.tests.test_connapp</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_core" href="test_core.html">connpy.tests.test_core</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_execution_service" href="test_execution_service.html">connpy.tests.test_execution_service</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_hooks" href="test_hooks.html">connpy.tests.test_hooks</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_node_service" href="test_node_service.html">connpy.tests.test_node_service</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_plugins" href="test_plugins.html">connpy.tests.test_plugins</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_printer" href="test_printer.html">connpy.tests.test_printer</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_profile_service" href="test_profile_service.html">connpy.tests.test_profile_service</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_provider" href="test_provider.html">connpy.tests.test_provider</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_sync" href="test_sync.html">connpy.tests.test_sync</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
@@ -63,11 +63,13 @@ el.replaceWith(d);
|
||||
assert myai.engineer_model == "test/test-model"
|
||||
assert myai.architect_model == "test/test-architect"
|
||||
|
||||
def test_init_missing_engineer_key(self, config):
|
||||
"""Raises ValueError if engineer key is missing."""
|
||||
def test_ask_missing_engineer_key(self, config):
|
||||
"""Raises ValueError if engineer key is missing when asking."""
|
||||
from connpy.ai import ai
|
||||
with pytest.raises(ValueError, match="Engineer API key"):
|
||||
ai(config)
|
||||
myai = ai(config)
|
||||
with pytest.raises(ValueError) as exc:
|
||||
myai.ask("hello")
|
||||
assert "Engineer API key not configured" in str(exc.value)
|
||||
|
||||
def test_init_missing_architect_key_warns(self, ai_config, capsys, mock_litellm):
|
||||
"""Warns if architect key is missing but doesn't crash."""
|
||||
@@ -104,6 +106,24 @@ el.replaceWith(d);
|
||||
<div class="desc"></div>
|
||||
<h3>Methods</h3>
|
||||
<dl>
|
||||
<dt id="connpy.tests.test_ai.TestAIInit.test_ask_missing_engineer_key"><code class="name flex">
|
||||
<span>def <span class="ident">test_ask_missing_engineer_key</span></span>(<span>self, config)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_ask_missing_engineer_key(self, config):
|
||||
"""Raises ValueError if engineer key is missing when asking."""
|
||||
from connpy.ai import ai
|
||||
myai = ai(config)
|
||||
with pytest.raises(ValueError) as exc:
|
||||
myai.ask("hello")
|
||||
assert "Engineer API key not configured" in str(exc.value)</code></pre>
|
||||
</details>
|
||||
<div class="desc"><p>Raises ValueError if engineer key is missing when asking.</p></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_ai.TestAIInit.test_default_models"><code class="name flex">
|
||||
<span>def <span class="ident">test_default_models</span></span>(<span>self, config)</span>
|
||||
</code></dt>
|
||||
@@ -166,22 +186,6 @@ el.replaceWith(d);
|
||||
</details>
|
||||
<div class="desc"><p>Warns if architect key is missing but doesn't crash.</p></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_ai.TestAIInit.test_init_missing_engineer_key"><code class="name flex">
|
||||
<span>def <span class="ident">test_init_missing_engineer_key</span></span>(<span>self, config)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_init_missing_engineer_key(self, config):
|
||||
"""Raises ValueError if engineer key is missing."""
|
||||
from connpy.ai import ai
|
||||
with pytest.raises(ValueError, match="Engineer API key"):
|
||||
ai(config)</code></pre>
|
||||
</details>
|
||||
<div class="desc"><p>Raises ValueError if engineer key is missing.</p></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_ai.TestAIInit.test_init_with_keys"><code class="name flex">
|
||||
<span>def <span class="ident">test_init_with_keys</span></span>(<span>self, ai_config, mock_litellm)</span>
|
||||
</code></dt>
|
||||
@@ -1615,10 +1619,10 @@ def myai(self, ai_config, mock_litellm):
|
||||
<li>
|
||||
<h4><code><a title="connpy.tests.test_ai.TestAIInit" href="#connpy.tests.test_ai.TestAIInit">TestAIInit</a></code></h4>
|
||||
<ul class="">
|
||||
<li><code><a title="connpy.tests.test_ai.TestAIInit.test_ask_missing_engineer_key" href="#connpy.tests.test_ai.TestAIInit.test_ask_missing_engineer_key">test_ask_missing_engineer_key</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_ai.TestAIInit.test_default_models" href="#connpy.tests.test_ai.TestAIInit.test_default_models">test_default_models</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_ai.TestAIInit.test_init_loads_memory" href="#connpy.tests.test_ai.TestAIInit.test_init_loads_memory">test_init_loads_memory</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_ai.TestAIInit.test_init_missing_architect_key_warns" href="#connpy.tests.test_ai.TestAIInit.test_init_missing_architect_key_warns">test_init_missing_architect_key_warns</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_ai.TestAIInit.test_init_missing_engineer_key" href="#connpy.tests.test_ai.TestAIInit.test_init_missing_engineer_key">test_init_missing_engineer_key</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_ai.TestAIInit.test_init_with_keys" href="#connpy.tests.test_ai.TestAIInit.test_init_with_keys">test_init_with_keys</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
@@ -45,6 +45,20 @@ el.replaceWith(d);
|
||||
<section>
|
||||
<h2 class="section-title" id="header-functions">Functions</h2>
|
||||
<dl>
|
||||
<dt id="connpy.tests.test_capture.RemoteCapture"><code class="name flex">
|
||||
<span>def <span class="ident">RemoteCapture</span></span>(<span>)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@pytest.fixture
|
||||
def RemoteCapture():
|
||||
return Entrypoint.get_remote_capture_class()</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_capture.mock_connapp"><code class="name flex">
|
||||
<span>def <span class="ident">mock_connapp</span></span>(<span>)</span>
|
||||
</code></dt>
|
||||
@@ -56,13 +70,14 @@ el.replaceWith(d);
|
||||
<pre><code class="python">@pytest.fixture
|
||||
def mock_connapp():
|
||||
app = MagicMock()
|
||||
app.nodes_list = ["test_node"]
|
||||
app.config.getitem.return_value = {"host": "127.0.0.1", "protocol": "ssh"}
|
||||
app.services.nodes.list_nodes.return_value = ["test_node"]
|
||||
app.services.nodes.get_node_details.return_value = {"host": "127.0.0.1", "protocol": "ssh"}
|
||||
app.services.config_svc.get_settings().get.return_value = "/fake/ws"
|
||||
|
||||
mock_node = MagicMock()
|
||||
mock_node.protocol = "ssh"
|
||||
mock_node.unique = "test_node"
|
||||
app.node.return_value = mock_node
|
||||
app.config.config = {"wireshark_path": "/fake/ws"}
|
||||
return app</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
@@ -81,34 +96,54 @@ def mock_connapp():
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">class TestRemoteCapture:
|
||||
def test_init_node_not_found(self, mock_connapp):
|
||||
# Attempt to capture a node not in nodes_list
|
||||
mock_connapp.nodes_list = ["other_node"]
|
||||
def test_init_node_not_found(self, mock_connapp, RemoteCapture):
|
||||
# Attempt to capture a node not in inventory
|
||||
mock_connapp.services.nodes.list_nodes.return_value = []
|
||||
with pytest.raises(SystemExit) as exc:
|
||||
RemoteCapture(mock_connapp, "test_node", "eth0")
|
||||
assert exc.value.code == 2
|
||||
|
||||
def test_init_success(self, mock_connapp):
|
||||
def test_init_success(self, mock_connapp, RemoteCapture):
|
||||
rc = RemoteCapture(mock_connapp, "test_node", "eth0")
|
||||
assert rc.node_name == "test_node"
|
||||
assert rc.interface == "eth0"
|
||||
assert rc.wireshark_path == "/fake/ws"
|
||||
|
||||
@patch("connpy.core_plugins.capture.socket")
|
||||
def test_is_port_in_use(self, mock_socket, mock_connapp):
|
||||
def test_is_port_in_use(self, mock_connapp, RemoteCapture):
|
||||
rc = RemoteCapture(mock_connapp, "test_node", "eth0")
|
||||
mock_sock_instance = MagicMock()
|
||||
mock_socket.socket.return_value.__enter__.return_value = mock_sock_instance
|
||||
|
||||
mock_sock_instance.connect_ex.return_value = 0
|
||||
assert rc._is_port_in_use(8080) is True
|
||||
|
||||
mock_sock_instance.connect_ex.return_value = 1
|
||||
assert rc._is_port_in_use(8080) is False
|
||||
with patch("socket.socket") as mock_socket:
|
||||
mock_sock_instance = MagicMock()
|
||||
mock_socket.return_value.__enter__.return_value = mock_sock_instance
|
||||
|
||||
mock_sock_instance.connect_ex.return_value = 0
|
||||
assert rc._is_port_in_use(8080) is True
|
||||
|
||||
mock_sock_instance.connect_ex.return_value = 1
|
||||
assert rc._is_port_in_use(8080) is False
|
||||
|
||||
@patch.object(RemoteCapture, "_is_port_in_use")
|
||||
def test_find_free_port(self, mock_is_in_use, mock_connapp):
|
||||
def test_find_free_port(self, mock_connapp, RemoteCapture):
|
||||
rc = RemoteCapture(mock_connapp, "test_node", "eth0")
|
||||
with patch.object(RemoteCapture, "_is_port_in_use") as mock_is_in_use:
|
||||
# First 2 ports in use, 3rd is free
|
||||
mock_is_in_use.side_effect = [True, True, False]
|
||||
port = rc._find_free_port(20000, 30000)
|
||||
assert 20000 <= port <= 30000
|
||||
assert mock_is_in_use.call_count == 3</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
<h3>Methods</h3>
|
||||
<dl>
|
||||
<dt id="connpy.tests.test_capture.TestRemoteCapture.test_find_free_port"><code class="name flex">
|
||||
<span>def <span class="ident">test_find_free_port</span></span>(<span>self, mock_connapp, RemoteCapture)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_find_free_port(self, mock_connapp, RemoteCapture):
|
||||
rc = RemoteCapture(mock_connapp, "test_node", "eth0")
|
||||
with patch.object(RemoteCapture, "_is_port_in_use") as mock_is_in_use:
|
||||
# First 2 ports in use, 3rd is free
|
||||
mock_is_in_use.side_effect = [True, True, False]
|
||||
port = rc._find_free_port(20000, 30000)
|
||||
@@ -116,38 +151,18 @@ def mock_connapp():
|
||||
assert mock_is_in_use.call_count == 3</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
<h3>Methods</h3>
|
||||
<dl>
|
||||
<dt id="connpy.tests.test_capture.TestRemoteCapture.test_find_free_port"><code class="name flex">
|
||||
<span>def <span class="ident">test_find_free_port</span></span>(<span>self, mock_is_in_use, mock_connapp)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch.object(RemoteCapture, "_is_port_in_use")
|
||||
def test_find_free_port(self, mock_is_in_use, mock_connapp):
|
||||
rc = RemoteCapture(mock_connapp, "test_node", "eth0")
|
||||
# First 2 ports in use, 3rd is free
|
||||
mock_is_in_use.side_effect = [True, True, False]
|
||||
port = rc._find_free_port(20000, 30000)
|
||||
assert 20000 <= port <= 30000
|
||||
assert mock_is_in_use.call_count == 3</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_capture.TestRemoteCapture.test_init_node_not_found"><code class="name flex">
|
||||
<span>def <span class="ident">test_init_node_not_found</span></span>(<span>self, mock_connapp)</span>
|
||||
<span>def <span class="ident">test_init_node_not_found</span></span>(<span>self, mock_connapp, RemoteCapture)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_init_node_not_found(self, mock_connapp):
|
||||
# Attempt to capture a node not in nodes_list
|
||||
mock_connapp.nodes_list = ["other_node"]
|
||||
<pre><code class="python">def test_init_node_not_found(self, mock_connapp, RemoteCapture):
|
||||
# Attempt to capture a node not in inventory
|
||||
mock_connapp.services.nodes.list_nodes.return_value = []
|
||||
with pytest.raises(SystemExit) as exc:
|
||||
RemoteCapture(mock_connapp, "test_node", "eth0")
|
||||
assert exc.value.code == 2</code></pre>
|
||||
@@ -155,14 +170,14 @@ def test_find_free_port(self, mock_is_in_use, mock_connapp):
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_capture.TestRemoteCapture.test_init_success"><code class="name flex">
|
||||
<span>def <span class="ident">test_init_success</span></span>(<span>self, mock_connapp)</span>
|
||||
<span>def <span class="ident">test_init_success</span></span>(<span>self, mock_connapp, RemoteCapture)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_init_success(self, mock_connapp):
|
||||
<pre><code class="python">def test_init_success(self, mock_connapp, RemoteCapture):
|
||||
rc = RemoteCapture(mock_connapp, "test_node", "eth0")
|
||||
assert rc.node_name == "test_node"
|
||||
assert rc.interface == "eth0"
|
||||
@@ -171,24 +186,24 @@ def test_find_free_port(self, mock_is_in_use, mock_connapp):
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_capture.TestRemoteCapture.test_is_port_in_use"><code class="name flex">
|
||||
<span>def <span class="ident">test_is_port_in_use</span></span>(<span>self, mock_socket, mock_connapp)</span>
|
||||
<span>def <span class="ident">test_is_port_in_use</span></span>(<span>self, mock_connapp, RemoteCapture)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.core_plugins.capture.socket")
|
||||
def test_is_port_in_use(self, mock_socket, mock_connapp):
|
||||
<pre><code class="python">def test_is_port_in_use(self, mock_connapp, RemoteCapture):
|
||||
rc = RemoteCapture(mock_connapp, "test_node", "eth0")
|
||||
mock_sock_instance = MagicMock()
|
||||
mock_socket.socket.return_value.__enter__.return_value = mock_sock_instance
|
||||
|
||||
mock_sock_instance.connect_ex.return_value = 0
|
||||
assert rc._is_port_in_use(8080) is True
|
||||
|
||||
mock_sock_instance.connect_ex.return_value = 1
|
||||
assert rc._is_port_in_use(8080) is False</code></pre>
|
||||
with patch("socket.socket") as mock_socket:
|
||||
mock_sock_instance = MagicMock()
|
||||
mock_socket.return_value.__enter__.return_value = mock_sock_instance
|
||||
|
||||
mock_sock_instance.connect_ex.return_value = 0
|
||||
assert rc._is_port_in_use(8080) is True
|
||||
|
||||
mock_sock_instance.connect_ex.return_value = 1
|
||||
assert rc._is_port_in_use(8080) is False</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
@@ -209,6 +224,7 @@ def test_is_port_in_use(self, mock_socket, mock_connapp):
|
||||
</li>
|
||||
<li><h3><a href="#header-functions">Functions</a></h3>
|
||||
<ul class="">
|
||||
<li><code><a title="connpy.tests.test_capture.RemoteCapture" href="#connpy.tests.test_capture.RemoteCapture">RemoteCapture</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_capture.mock_connapp" href="#connpy.tests.test_capture.mock_connapp">mock_connapp</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
@@ -64,7 +64,7 @@ el.replaceWith(d);
|
||||
subdir = tmp_path / "subdir"
|
||||
subdir.mkdir()
|
||||
|
||||
result = _getcwd(["run", "run"], "run")
|
||||
result = get_cwd(["run", "run"])
|
||||
# Should list files
|
||||
assert any("file1.txt" in r for r in result)
|
||||
assert any("subdir/" in r for r in result)
|
||||
@@ -75,7 +75,7 @@ el.replaceWith(d);
|
||||
(tmp_path / "script.yaml").touch()
|
||||
(tmp_path / "script2.yaml").touch()
|
||||
|
||||
result = _getcwd(["run", "script"], "run")
|
||||
result = get_cwd(["run", "script"])
|
||||
assert any("script" in r for r in result)
|
||||
|
||||
def test_folder_only(self, tmp_path, monkeypatch):
|
||||
@@ -85,7 +85,7 @@ el.replaceWith(d);
|
||||
subdir = tmp_path / "mydir"
|
||||
subdir.mkdir()
|
||||
|
||||
result = _getcwd(["export", "export"], "export", folderonly=True)
|
||||
result = get_cwd(["export", "export"], folderonly=True)
|
||||
files_in_result = [r for r in result if "file.txt" in r]
|
||||
assert len(files_in_result) == 0
|
||||
dirs_in_result = [r for r in result if "mydir" in r]
|
||||
@@ -110,7 +110,7 @@ el.replaceWith(d);
|
||||
subdir = tmp_path / "subdir"
|
||||
subdir.mkdir()
|
||||
|
||||
result = _getcwd(["run", "run"], "run")
|
||||
result = get_cwd(["run", "run"])
|
||||
# Should list files
|
||||
assert any("file1.txt" in r for r in result)
|
||||
assert any("subdir/" in r for r in result)</code></pre>
|
||||
@@ -132,7 +132,7 @@ el.replaceWith(d);
|
||||
subdir = tmp_path / "mydir"
|
||||
subdir.mkdir()
|
||||
|
||||
result = _getcwd(["export", "export"], "export", folderonly=True)
|
||||
result = get_cwd(["export", "export"], folderonly=True)
|
||||
files_in_result = [r for r in result if "file.txt" in r]
|
||||
assert len(files_in_result) == 0
|
||||
dirs_in_result = [r for r in result if "mydir" in r]
|
||||
@@ -154,179 +154,13 @@ el.replaceWith(d);
|
||||
(tmp_path / "script.yaml").touch()
|
||||
(tmp_path / "script2.yaml").touch()
|
||||
|
||||
result = _getcwd(["run", "script"], "run")
|
||||
result = get_cwd(["run", "script"])
|
||||
assert any("script" in r for r in result)</code></pre>
|
||||
</details>
|
||||
<div class="desc"><p>Lists files matching a partial path.</p></div>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_completion.TestGetPlugins"><code class="flex name class">
|
||||
<span>class <span class="ident">TestGetPlugins</span></span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">class TestGetPlugins:
|
||||
def test_get_plugins_disable(self, tmp_path):
|
||||
"""--disable returns enabled plugins."""
|
||||
plugin_dir = tmp_path / "plugins"
|
||||
plugin_dir.mkdir()
|
||||
(plugin_dir / "active.py").touch()
|
||||
(plugin_dir / "disabled.py.bkp").touch()
|
||||
|
||||
result = _get_plugins("--disable", str(tmp_path))
|
||||
assert "active" in result
|
||||
assert "disabled" not in result
|
||||
|
||||
def test_get_plugins_enable(self, tmp_path):
|
||||
"""--enable returns disabled plugins."""
|
||||
plugin_dir = tmp_path / "plugins"
|
||||
plugin_dir.mkdir()
|
||||
(plugin_dir / "active.py").touch()
|
||||
(plugin_dir / "disabled.py.bkp").touch()
|
||||
|
||||
result = _get_plugins("--enable", str(tmp_path))
|
||||
assert "disabled" in result
|
||||
assert "active" not in result
|
||||
|
||||
def test_get_plugins_del(self, tmp_path):
|
||||
"""--del returns all plugins."""
|
||||
plugin_dir = tmp_path / "plugins"
|
||||
plugin_dir.mkdir()
|
||||
(plugin_dir / "active.py").touch()
|
||||
(plugin_dir / "disabled.py.bkp").touch()
|
||||
|
||||
result = _get_plugins("--del", str(tmp_path))
|
||||
assert "active" in result
|
||||
assert "disabled" in result
|
||||
|
||||
def test_get_plugins_all(self, tmp_path):
|
||||
"""'all' returns dict with paths."""
|
||||
plugin_dir = tmp_path / "plugins"
|
||||
plugin_dir.mkdir()
|
||||
(plugin_dir / "myplugin.py").touch()
|
||||
|
||||
result = _get_plugins("all", str(tmp_path))
|
||||
assert isinstance(result, dict)
|
||||
assert "myplugin" in result
|
||||
|
||||
def test_get_plugins_empty_dir(self, tmp_path):
|
||||
"""Empty plugins directory returns empty list."""
|
||||
plugin_dir = tmp_path / "plugins"
|
||||
plugin_dir.mkdir()
|
||||
|
||||
result = _get_plugins("--disable", str(tmp_path))
|
||||
assert result == []</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
<h3>Methods</h3>
|
||||
<dl>
|
||||
<dt id="connpy.tests.test_completion.TestGetPlugins.test_get_plugins_all"><code class="name flex">
|
||||
<span>def <span class="ident">test_get_plugins_all</span></span>(<span>self, tmp_path)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_get_plugins_all(self, tmp_path):
|
||||
"""'all' returns dict with paths."""
|
||||
plugin_dir = tmp_path / "plugins"
|
||||
plugin_dir.mkdir()
|
||||
(plugin_dir / "myplugin.py").touch()
|
||||
|
||||
result = _get_plugins("all", str(tmp_path))
|
||||
assert isinstance(result, dict)
|
||||
assert "myplugin" in result</code></pre>
|
||||
</details>
|
||||
<div class="desc"><p>'all' returns dict with paths.</p></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_completion.TestGetPlugins.test_get_plugins_del"><code class="name flex">
|
||||
<span>def <span class="ident">test_get_plugins_del</span></span>(<span>self, tmp_path)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_get_plugins_del(self, tmp_path):
|
||||
"""--del returns all plugins."""
|
||||
plugin_dir = tmp_path / "plugins"
|
||||
plugin_dir.mkdir()
|
||||
(plugin_dir / "active.py").touch()
|
||||
(plugin_dir / "disabled.py.bkp").touch()
|
||||
|
||||
result = _get_plugins("--del", str(tmp_path))
|
||||
assert "active" in result
|
||||
assert "disabled" in result</code></pre>
|
||||
</details>
|
||||
<div class="desc"><p>–del returns all plugins.</p></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_completion.TestGetPlugins.test_get_plugins_disable"><code class="name flex">
|
||||
<span>def <span class="ident">test_get_plugins_disable</span></span>(<span>self, tmp_path)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_get_plugins_disable(self, tmp_path):
|
||||
"""--disable returns enabled plugins."""
|
||||
plugin_dir = tmp_path / "plugins"
|
||||
plugin_dir.mkdir()
|
||||
(plugin_dir / "active.py").touch()
|
||||
(plugin_dir / "disabled.py.bkp").touch()
|
||||
|
||||
result = _get_plugins("--disable", str(tmp_path))
|
||||
assert "active" in result
|
||||
assert "disabled" not in result</code></pre>
|
||||
</details>
|
||||
<div class="desc"><p>–disable returns enabled plugins.</p></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_completion.TestGetPlugins.test_get_plugins_empty_dir"><code class="name flex">
|
||||
<span>def <span class="ident">test_get_plugins_empty_dir</span></span>(<span>self, tmp_path)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_get_plugins_empty_dir(self, tmp_path):
|
||||
"""Empty plugins directory returns empty list."""
|
||||
plugin_dir = tmp_path / "plugins"
|
||||
plugin_dir.mkdir()
|
||||
|
||||
result = _get_plugins("--disable", str(tmp_path))
|
||||
assert result == []</code></pre>
|
||||
</details>
|
||||
<div class="desc"><p>Empty plugins directory returns empty list.</p></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_completion.TestGetPlugins.test_get_plugins_enable"><code class="name flex">
|
||||
<span>def <span class="ident">test_get_plugins_enable</span></span>(<span>self, tmp_path)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_get_plugins_enable(self, tmp_path):
|
||||
"""--enable returns disabled plugins."""
|
||||
plugin_dir = tmp_path / "plugins"
|
||||
plugin_dir.mkdir()
|
||||
(plugin_dir / "active.py").touch()
|
||||
(plugin_dir / "disabled.py.bkp").touch()
|
||||
|
||||
result = _get_plugins("--enable", str(tmp_path))
|
||||
assert "disabled" in result
|
||||
assert "active" not in result</code></pre>
|
||||
</details>
|
||||
<div class="desc"><p>–enable returns disabled plugins.</p></div>
|
||||
</dd>
|
||||
</dl>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_completion.TestLoadTxtCache"><code class="flex name class">
|
||||
<span>class <span class="ident">TestLoadTxtCache</span></span>
|
||||
</code></dt>
|
||||
@@ -411,16 +245,6 @@ el.replaceWith(d);
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<h4><code><a title="connpy.tests.test_completion.TestGetPlugins" href="#connpy.tests.test_completion.TestGetPlugins">TestGetPlugins</a></code></h4>
|
||||
<ul class="">
|
||||
<li><code><a title="connpy.tests.test_completion.TestGetPlugins.test_get_plugins_all" href="#connpy.tests.test_completion.TestGetPlugins.test_get_plugins_all">test_get_plugins_all</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_completion.TestGetPlugins.test_get_plugins_del" href="#connpy.tests.test_completion.TestGetPlugins.test_get_plugins_del">test_get_plugins_del</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_completion.TestGetPlugins.test_get_plugins_disable" href="#connpy.tests.test_completion.TestGetPlugins.test_get_plugins_disable">test_get_plugins_disable</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_completion.TestGetPlugins.test_get_plugins_empty_dir" href="#connpy.tests.test_completion.TestGetPlugins.test_get_plugins_empty_dir">test_get_plugins_empty_dir</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_completion.TestGetPlugins.test_get_plugins_enable" href="#connpy.tests.test_completion.TestGetPlugins.test_get_plugins_enable">test_get_plugins_enable</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<h4><code><a title="connpy.tests.test_completion.TestLoadTxtCache" href="#connpy.tests.test_completion.TestLoadTxtCache">TestLoadTxtCache</a></code></h4>
|
||||
<ul class="">
|
||||
<li><code><a title="connpy.tests.test_completion.TestLoadTxtCache.test_load_existing_cache" href="#connpy.tests.test_completion.TestLoadTxtCache.test_load_existing_cache">test_load_existing_cache</a></code></li>
|
||||
|
||||
@@ -1140,8 +1140,9 @@ el.replaceWith(d);
|
||||
assert "server1@office" not in nodes
|
||||
|
||||
def test_getallnodes_filter_invalid_type(self, populated_config):
|
||||
with pytest.raises(ValueError):
|
||||
with pytest.raises(SystemExit) as exc:
|
||||
populated_config._getallnodes(123)
|
||||
assert exc.value.code == 1
|
||||
|
||||
def test_getallfolders(self, populated_config):
|
||||
folders = populated_config._getallfolders()
|
||||
@@ -1236,8 +1237,9 @@ el.replaceWith(d);
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_getallnodes_filter_invalid_type(self, populated_config):
|
||||
with pytest.raises(ValueError):
|
||||
populated_config._getallnodes(123)</code></pre>
|
||||
with pytest.raises(SystemExit) as exc:
|
||||
populated_config._getallnodes(123)
|
||||
assert exc.value.code == 1</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
|
||||
@@ -0,0 +1,705 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
|
||||
<meta name="generator" content="pdoc3 0.11.5">
|
||||
<title>connpy.tests.test_connapp API documentation</title>
|
||||
<meta name="description" content="">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/sanitize.min.css" integrity="sha512-y1dtMcuvtTMJc1yPgEqF0ZjQbhnc/bFhyvIyVNb9Zk5mIGtqVaAB1Ttl28su8AvFMOY0EwRbAe+HCLqj6W7/KA==" crossorigin>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/typography.min.css" integrity="sha512-Y1DYSb995BAfxobCkKepB1BqJJTPrOp3zPL74AWFugHHmmdcvO+C48WLrUOlhGMc0QG7AE3f7gmvvcrmX2fDoA==" crossorigin>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css" crossorigin>
|
||||
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:1.5em;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:2em 0 .50em 0}h3{font-size:1.4em;margin:1.6em 0 .7em 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .2s ease-in-out}a:visited{color:#503}a:hover{color:#b62}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900;font-weight:bold}pre code{font-size:.8em;line-height:1.4em;padding:1em;display:block}code{background:#f3f3f3;font-family:"DejaVu Sans Mono",monospace;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source > summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible;min-width:max-content}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em 1em;margin:1em 0}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
|
||||
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul ul{padding-left:1em}.toc > ul > li{margin-top:.5em}}</style>
|
||||
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
|
||||
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js" integrity="sha512-D9gUyxqja7hBtkWpPWGt9wfbfaMGVt9gnyCvYa+jojwwPHLCzUm5i8rpk7vD7wNee9bA35eYIjobYPaQuKS1MQ==" crossorigin></script>
|
||||
<script>window.addEventListener('DOMContentLoaded', () => {
|
||||
hljs.configure({languages: ['bash', 'css', 'diff', 'graphql', 'ini', 'javascript', 'json', 'plaintext', 'python', 'python-repl', 'rust', 'shell', 'sql', 'typescript', 'xml', 'yaml']});
|
||||
hljs.highlightAll();
|
||||
/* Collapse source docstrings */
|
||||
setTimeout(() => {
|
||||
[...document.querySelectorAll('.hljs.language-python > .hljs-string')]
|
||||
.filter(el => el.innerHTML.length > 200 && ['"""', "'''"].includes(el.innerHTML.substring(0, 3)))
|
||||
.forEach(el => {
|
||||
let d = document.createElement('details');
|
||||
d.classList.add('hljs-string');
|
||||
d.innerHTML = '<summary>"""</summary>' + el.innerHTML.substring(3);
|
||||
el.replaceWith(d);
|
||||
});
|
||||
}, 100);
|
||||
})</script>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<article id="content">
|
||||
<header>
|
||||
<h1 class="title">Module <code>connpy.tests.test_connapp</code></h1>
|
||||
</header>
|
||||
<section id="section-intro">
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
<h2 class="section-title" id="header-functions">Functions</h2>
|
||||
<dl>
|
||||
<dt id="connpy.tests.test_connapp.app"><code class="name flex">
|
||||
<span>def <span class="ident">app</span></span>(<span>populated_config)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@pytest.fixture
|
||||
def app(populated_config):
|
||||
"""Returns an instance of connapp initialized with the mock config."""
|
||||
return connapp(populated_config)</code></pre>
|
||||
</details>
|
||||
<div class="desc"><p>Returns an instance of connapp initialized with the mock config.</p></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_ai"><code class="name flex">
|
||||
<span>def <span class="ident">test_ai</span></span>(<span>mock_status, mock_ask, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.services.ai_service.AIService.ask")
|
||||
@patch("connpy.connapp.console.status")
|
||||
def test_ai(mock_status, mock_ask, app):
|
||||
mock_ask.return_value = {"response": "AI output", "usage": {"total": 10, "input": 5, "output": 5}}
|
||||
|
||||
app.start(["ai", "--engineer-api-key", "testkey", "how are you"])
|
||||
mock_ask.assert_called_once()</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_ai_list"><code class="name flex">
|
||||
<span>def <span class="ident">test_ai_list</span></span>(<span>mock_list_sessions, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.services.ai_service.AIService.list_sessions")
|
||||
def test_ai_list(mock_list_sessions, app):
|
||||
mock_list_sessions.return_value = [{"id": "1", "title": "t", "created_at": "now", "model": "m"}]
|
||||
app.start(["ai", "--list"])
|
||||
mock_list_sessions.assert_called_once()</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_api_debug"><code class="name flex">
|
||||
<span>def <span class="ident">test_api_debug</span></span>(<span>mock_status, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.services.system_service.SystemService.get_api_status")
|
||||
def test_api_debug(mock_status, app):
|
||||
mock_status.return_value = {"running": False}
|
||||
app.services.system.debug_api = MagicMock()
|
||||
app.start(["api", "-d", "8080"])
|
||||
app.services.system.debug_api.assert_called_once_with(port=8080)</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_api_start"><code class="name flex">
|
||||
<span>def <span class="ident">test_api_start</span></span>(<span>mock_status, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.services.system_service.SystemService.get_api_status")
|
||||
def test_api_start(mock_status, app):
|
||||
mock_status.return_value = {"running": False}
|
||||
app.services.system.start_api = MagicMock()
|
||||
app.start(["api", "-s", "8080"])
|
||||
app.services.system.start_api.assert_called_once_with(port=8080)</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_api_stop"><code class="name flex">
|
||||
<span>def <span class="ident">test_api_stop</span></span>(<span>mock_status, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.services.system_service.SystemService.get_api_status")
|
||||
def test_api_stop(mock_status, app):
|
||||
mock_status.return_value = {"running": True, "pid": "1234"}
|
||||
app.services.system.stop_api = MagicMock(return_value=True)
|
||||
app.start(["api", "-x"])
|
||||
app.services.system.stop_api.assert_called_once()</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_bulk"><code class="name flex">
|
||||
<span>def <span class="ident">test_bulk</span></span>(<span>mock_bulk_add, mock_q_bulk, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.cli.forms.Forms.questions_bulk")
|
||||
@patch("connpy.services.node_service.NodeService.bulk_add")
|
||||
def test_bulk(mock_bulk_add, mock_q_bulk, app):
|
||||
mock_q_bulk.return_value = {"ids": "node1", "host": "host1", "location": ""}
|
||||
mock_bulk_add.return_value = 1
|
||||
app.start(["bulk"])
|
||||
mock_bulk_add.assert_called_once()</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_config"><code class="name flex">
|
||||
<span>def <span class="ident">test_config</span></span>(<span>mock_update_setting, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.services.config_service.ConfigService.update_setting")
|
||||
def test_config(mock_update_setting, app):
|
||||
app.start(["config", "--allow-uppercase", "true"])
|
||||
mock_update_setting.assert_called_with("case", True)</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_config_folder"><code class="name flex">
|
||||
<span>def <span class="ident">test_config_folder</span></span>(<span>mock_set_config_folder, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.services.config_service.ConfigService.set_config_folder")
|
||||
def test_config_folder(mock_set_config_folder, app):
|
||||
app.start(["config", "--configfolder", "/new/path"])
|
||||
mock_set_config_folder.assert_called_once_with("/new/path")</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_config_various"><code class="name flex">
|
||||
<span>def <span class="ident">test_config_various</span></span>(<span>mock_update_setting, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.services.config_service.ConfigService.update_setting")
|
||||
def test_config_various(mock_update_setting, app):
|
||||
app.start(["config", "--fzf", "true"])
|
||||
mock_update_setting.assert_called_with("fzf", True)
|
||||
app.start(["config", "--keepalive", "60"])
|
||||
mock_update_setting.assert_called_with("idletime", 60)</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_connapp_init"><code class="name flex">
|
||||
<span>def <span class="ident">test_connapp_init</span></span>(<span>app, populated_config)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_connapp_init(app, populated_config):
|
||||
"""Test that connapp initializes correctly with config."""
|
||||
assert app.config == populated_config
|
||||
assert app.case == populated_config.config.get("case", False)</code></pre>
|
||||
</details>
|
||||
<div class="desc"><p>Test that connapp initializes correctly with config.</p></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_copy"><code class="name flex">
|
||||
<span>def <span class="ident">test_copy</span></span>(<span>mock_move_node, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.services.node_service.NodeService.move_node")
|
||||
def test_copy(mock_move_node, app):
|
||||
app.start(["copy", "src_node", "dst_node"])
|
||||
mock_move_node.assert_called_once_with("src_node", "dst_node", copy=True)</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_export"><code class="name flex">
|
||||
<span>def <span class="ident">test_export</span></span>(<span>mock_export, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.services.import_export_service.ImportExportService.export_to_file")
|
||||
def test_export(mock_export, app):
|
||||
with pytest.raises(SystemExit):
|
||||
app.start(["export", "file.yml", "@folder1"])
|
||||
mock_export.assert_called_once_with("file.yml", folders=["@folder1"])</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_import"><code class="name flex">
|
||||
<span>def <span class="ident">test_import</span></span>(<span>mock_import, mock_prompt, mock_exists, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("os.path.exists")
|
||||
@patch("inquirer.prompt")
|
||||
@patch("connpy.services.import_export_service.ImportExportService.import_from_file")
|
||||
def test_import(mock_import, mock_prompt, mock_exists, app):
|
||||
mock_exists.return_value = True
|
||||
mock_prompt.return_value = {"import": True}
|
||||
app.start(["import", "file.yml"])
|
||||
mock_import.assert_called_once_with("file.yml")</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_list_folders"><code class="name flex">
|
||||
<span>def <span class="ident">test_list_folders</span></span>(<span>mock_list_folders, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.services.node_service.NodeService.list_folders")
|
||||
def test_list_folders(mock_list_folders, app):
|
||||
mock_list_folders.return_value = ["folder1"]
|
||||
app.start(["list", "folders"])
|
||||
# Called during init and during the list command
|
||||
assert mock_list_folders.call_count >= 2</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_move"><code class="name flex">
|
||||
<span>def <span class="ident">test_move</span></span>(<span>mock_move_node, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.services.node_service.NodeService.move_node")
|
||||
def test_move(mock_move_node, app):
|
||||
app.start(["move", "src_node", "dst_node"])
|
||||
mock_move_node.assert_called_once_with("src_node", "dst_node", copy=False)</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_node_add"><code class="name flex">
|
||||
<span>def <span class="ident">test_node_add</span></span>(<span>mock_func_node, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.cli.node_handler.NodeHandler.dispatch")
|
||||
def test_node_add(mock_func_node, app):
|
||||
"""Test that 'node -a' command correctly parses."""
|
||||
app.start(["node", "-a", "new_router"])
|
||||
mock_func_node.assert_called_once()
|
||||
args = mock_func_node.call_args[0][0]
|
||||
assert args.data == "new_router"
|
||||
assert args.action == "add"</code></pre>
|
||||
</details>
|
||||
<div class="desc"><p>Test that 'node -a' command correctly parses.</p></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_node_default"><code class="name flex">
|
||||
<span>def <span class="ident">test_node_default</span></span>(<span>mock_func_node, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.cli.node_handler.NodeHandler.dispatch")
|
||||
def test_node_default(mock_func_node, app):
|
||||
"""Test that default 'node' command correctly parses and calls _func_node."""
|
||||
app.start(["node", "router1"])
|
||||
mock_func_node.assert_called_once()
|
||||
args = mock_func_node.call_args[0][0]
|
||||
assert args.data == "router1"
|
||||
assert args.action == "connect"</code></pre>
|
||||
</details>
|
||||
<div class="desc"><p>Test that default 'node' command correctly parses and calls _func_node.</p></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_node_del"><code class="name flex">
|
||||
<span>def <span class="ident">test_node_del</span></span>(<span>mock_prompt, mock_delete_node, mock_list_nodes, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.services.node_service.NodeService.list_nodes")
|
||||
@patch("connpy.services.node_service.NodeService.delete_node")
|
||||
@patch("inquirer.prompt")
|
||||
def test_node_del(mock_prompt, mock_delete_node, mock_list_nodes, app):
|
||||
mock_list_nodes.return_value = ["router1"]
|
||||
mock_prompt.return_value = {"delete": True}
|
||||
app.start(["node", "-r", "router1"])
|
||||
mock_delete_node.assert_called_once_with("router1", is_folder=False)</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_node_list"><code class="name flex">
|
||||
<span>def <span class="ident">test_node_list</span></span>(<span>mock_list_nodes, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.services.node_service.NodeService.list_nodes")
|
||||
def test_node_list(mock_list_nodes, app):
|
||||
"""Test 'list nodes' invokes node service."""
|
||||
mock_list_nodes.return_value = ["router1", "server1"]
|
||||
app.start(["list", "nodes"])
|
||||
# Should be called during init and during the list command
|
||||
assert mock_list_nodes.call_count >= 2</code></pre>
|
||||
</details>
|
||||
<div class="desc"><p>Test 'list nodes' invokes node service.</p></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_node_mod"><code class="name flex">
|
||||
<span>def <span class="ident">test_node_mod</span></span>(<span>mock_q_nodes, mock_q_edit, mock_update_node, mock_get_details, mock_list_nodes, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.services.node_service.NodeService.list_nodes")
|
||||
@patch("connpy.services.node_service.NodeService.get_node_details")
|
||||
@patch("connpy.services.node_service.NodeService.update_node")
|
||||
@patch("connpy.cli.forms.Forms.questions_edit")
|
||||
@patch("connpy.cli.forms.Forms.questions_nodes")
|
||||
def test_node_mod(mock_q_nodes, mock_q_edit, mock_update_node, mock_get_details, mock_list_nodes, app):
|
||||
mock_list_nodes.return_value = ["router1"]
|
||||
mock_get_details.return_value = {"host": "1.1.1.1", "port": 22}
|
||||
mock_q_edit.return_value = {"host": True}
|
||||
mock_q_nodes.return_value = {"host": "2.2.2.2", "port": 22}
|
||||
|
||||
app.start(["node", "-e", "router1"])
|
||||
mock_update_node.assert_called_once()</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_node_show"><code class="name flex">
|
||||
<span>def <span class="ident">test_node_show</span></span>(<span>mock_data, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.printer.data")
|
||||
def test_node_show(mock_data, app):
|
||||
app.nodes_list = ["router1"]
|
||||
app.config.getitem = MagicMock(return_value={"host": "1.1.1.1"})
|
||||
app.start(["node", "-s", "router1"])
|
||||
mock_data.assert_called()</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_plugin_add"><code class="name flex">
|
||||
<span>def <span class="ident">test_plugin_add</span></span>(<span>mock_verify, mock_copy, mock_exists, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("os.path.exists")
|
||||
@patch("shutil.copy2")
|
||||
@patch("connpy.plugins.Plugins.verify_script")
|
||||
def test_plugin_add(mock_verify, mock_copy, mock_exists, app):
|
||||
def mock_exists_side_effect(path):
|
||||
if "testplug.py" in path: return False
|
||||
if "testplug.py.bkp" in path: return False
|
||||
if "file.py" in path: return True
|
||||
return True
|
||||
mock_exists.side_effect = mock_exists_side_effect
|
||||
mock_verify.return_value = None
|
||||
app.commands = []
|
||||
app.start(["plugin", "--add", "testplug", "file.py"])
|
||||
mock_copy.assert_called()</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_plugin_delete"><code class="name flex">
|
||||
<span>def <span class="ident">test_plugin_delete</span></span>(<span>mock_delete, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.services.plugin_service.PluginService.delete_plugin")
|
||||
def test_plugin_delete(mock_delete, app):
|
||||
app.start(["plugin", "--del", "testplug"])
|
||||
mock_delete.assert_called_once_with("testplug")</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_plugin_disable"><code class="name flex">
|
||||
<span>def <span class="ident">test_plugin_disable</span></span>(<span>mock_disable, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.services.plugin_service.PluginService.disable_plugin")
|
||||
def test_plugin_disable(mock_disable, app):
|
||||
app.start(["plugin", "--disable", "testplug"])
|
||||
mock_disable.assert_called_once_with("testplug")</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_plugin_enable"><code class="name flex">
|
||||
<span>def <span class="ident">test_plugin_enable</span></span>(<span>mock_enable, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.services.plugin_service.PluginService.enable_plugin")
|
||||
def test_plugin_enable(mock_enable, app):
|
||||
app.start(["plugin", "--enable", "testplug"])
|
||||
mock_enable.assert_called_once_with("testplug")</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_plugin_list"><code class="name flex">
|
||||
<span>def <span class="ident">test_plugin_list</span></span>(<span>mock_list_plugins, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.services.plugin_service.PluginService.list_plugins")
|
||||
def test_plugin_list(mock_list_plugins, app):
|
||||
mock_list_plugins.return_value = {"testplug": {"enabled": True}}
|
||||
app.start(["plugin", "--list"])
|
||||
mock_list_plugins.assert_called_once()</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_profile_add"><code class="name flex">
|
||||
<span>def <span class="ident">test_profile_add</span></span>(<span>mock_q_profiles, mock_add_profile, mock_list_profiles, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.services.profile_service.ProfileService.list_profiles")
|
||||
@patch("connpy.services.profile_service.ProfileService.add_profile")
|
||||
@patch("connpy.cli.forms.Forms.questions_profiles")
|
||||
def test_profile_add(mock_q_profiles, mock_add_profile, mock_list_profiles, app):
|
||||
mock_list_profiles.return_value = ["default"]
|
||||
mock_q_profiles.return_value = {"host": "test"}
|
||||
app.start(["profile", "-a", "new_profile"])
|
||||
mock_add_profile.assert_called_once_with("new_profile", {"host": "test"})</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_profile_del"><code class="name flex">
|
||||
<span>def <span class="ident">test_profile_del</span></span>(<span>mock_prompt, mock_delete_profile, mock_get_profile, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.services.profile_service.ProfileService.get_profile")
|
||||
@patch("connpy.services.profile_service.ProfileService.delete_profile")
|
||||
@patch("inquirer.prompt")
|
||||
def test_profile_del(mock_prompt, mock_delete_profile, mock_get_profile, app):
|
||||
mock_get_profile.return_value = {"host": "test"}
|
||||
mock_prompt.return_value = {"delete": True}
|
||||
app.start(["profile", "-r", "test_profile"])
|
||||
mock_delete_profile.assert_called_once_with("test_profile")</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_profile_list"><code class="name flex">
|
||||
<span>def <span class="ident">test_profile_list</span></span>(<span>mock_print, mock_list_profiles, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.services.profile_service.ProfileService.list_profiles")
|
||||
@patch("connpy.connapp.printer.console.print")
|
||||
def test_profile_list(mock_print, mock_list_profiles, app):
|
||||
"""Test 'profile list' invokes profile service correctly."""
|
||||
mock_list_profiles.return_value = ["default", "office-user"]
|
||||
app.start(["list", "profiles"])
|
||||
assert mock_list_profiles.call_count >= 2</code></pre>
|
||||
</details>
|
||||
<div class="desc"><p>Test 'profile list' invokes profile service correctly.</p></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_profile_mod"><code class="name flex">
|
||||
<span>def <span class="ident">test_profile_mod</span></span>(<span>mock_q_profiles, mock_q_edit, mock_update_profile, mock_get_profile, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.services.profile_service.ProfileService.get_profile")
|
||||
@patch("connpy.services.profile_service.ProfileService.update_profile")
|
||||
@patch("connpy.cli.forms.Forms.questions_edit")
|
||||
@patch("connpy.cli.forms.Forms.questions_profiles")
|
||||
def test_profile_mod(mock_q_profiles, mock_q_edit, mock_update_profile, mock_get_profile, app):
|
||||
mock_get_profile.return_value = {"host": "test", "port": 22}
|
||||
mock_q_edit.return_value = {"host": True}
|
||||
mock_q_profiles.return_value = {"id": "test_profile", "host": "new_host", "port": 22}
|
||||
app.start(["profile", "-e", "test_profile"])
|
||||
mock_update_profile.assert_called_once_with("test_profile", {"id": "test_profile", "host": "new_host", "port": 22})</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_profile_show"><code class="name flex">
|
||||
<span>def <span class="ident">test_profile_show</span></span>(<span>mock_data, mock_get_profile, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.services.profile_service.ProfileService.get_profile")
|
||||
@patch("connpy.printer.data")
|
||||
def test_profile_show(mock_data, mock_get_profile, app):
|
||||
mock_get_profile.return_value = {"host": "test"}
|
||||
app.start(["profile", "-s", "test_profile"])
|
||||
mock_data.assert_called()</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_run"><code class="name flex">
|
||||
<span>def <span class="ident">test_run</span></span>(<span>mock_run_commands, app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.services.execution_service.ExecutionService.run_commands")
|
||||
def test_run(mock_run_commands, app):
|
||||
app.start(["run", "node1", "command1", "command2"])
|
||||
mock_run_commands.assert_called_once()
|
||||
assert mock_run_commands.call_args[1]["nodes_filter"] == "node1"
|
||||
assert mock_run_commands.call_args[1]["commands"] == ["command1 command2"]</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_connapp.test_type_node_reserved_word"><code class="name flex">
|
||||
<span>def <span class="ident">test_type_node_reserved_word</span></span>(<span>app)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_type_node_reserved_word(app):
|
||||
app.commands = ["bulk", "ai", "run"]
|
||||
with patch("sys.argv", ["connpy", "node", "-a", "bulk"]):
|
||||
with pytest.raises(SystemExit) as exc:
|
||||
app._type_node("bulk")
|
||||
assert exc.value.code == 2
|
||||
|
||||
# In move/copy it also raises because destination cannot be reserved
|
||||
with patch("sys.argv", ["connpy", "mv", "test1", "bulk"]):
|
||||
with pytest.raises(SystemExit) as exc:
|
||||
app._type_node("bulk")
|
||||
assert exc.value.code == 2</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
</dl>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
</article>
|
||||
<nav id="sidebar">
|
||||
<div class="toc">
|
||||
<ul></ul>
|
||||
</div>
|
||||
<ul id="index">
|
||||
<li><h3>Super-module</h3>
|
||||
<ul>
|
||||
<li><code><a title="connpy.tests" href="index.html">connpy.tests</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><h3><a href="#header-functions">Functions</a></h3>
|
||||
<ul class="">
|
||||
<li><code><a title="connpy.tests.test_connapp.app" href="#connpy.tests.test_connapp.app">app</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_ai" href="#connpy.tests.test_connapp.test_ai">test_ai</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_ai_list" href="#connpy.tests.test_connapp.test_ai_list">test_ai_list</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_api_debug" href="#connpy.tests.test_connapp.test_api_debug">test_api_debug</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_api_start" href="#connpy.tests.test_connapp.test_api_start">test_api_start</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_api_stop" href="#connpy.tests.test_connapp.test_api_stop">test_api_stop</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_bulk" href="#connpy.tests.test_connapp.test_bulk">test_bulk</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_config" href="#connpy.tests.test_connapp.test_config">test_config</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_config_folder" href="#connpy.tests.test_connapp.test_config_folder">test_config_folder</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_config_various" href="#connpy.tests.test_connapp.test_config_various">test_config_various</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_connapp_init" href="#connpy.tests.test_connapp.test_connapp_init">test_connapp_init</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_copy" href="#connpy.tests.test_connapp.test_copy">test_copy</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_export" href="#connpy.tests.test_connapp.test_export">test_export</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_import" href="#connpy.tests.test_connapp.test_import">test_import</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_list_folders" href="#connpy.tests.test_connapp.test_list_folders">test_list_folders</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_move" href="#connpy.tests.test_connapp.test_move">test_move</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_node_add" href="#connpy.tests.test_connapp.test_node_add">test_node_add</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_node_default" href="#connpy.tests.test_connapp.test_node_default">test_node_default</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_node_del" href="#connpy.tests.test_connapp.test_node_del">test_node_del</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_node_list" href="#connpy.tests.test_connapp.test_node_list">test_node_list</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_node_mod" href="#connpy.tests.test_connapp.test_node_mod">test_node_mod</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_node_show" href="#connpy.tests.test_connapp.test_node_show">test_node_show</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_plugin_add" href="#connpy.tests.test_connapp.test_plugin_add">test_plugin_add</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_plugin_delete" href="#connpy.tests.test_connapp.test_plugin_delete">test_plugin_delete</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_plugin_disable" href="#connpy.tests.test_connapp.test_plugin_disable">test_plugin_disable</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_plugin_enable" href="#connpy.tests.test_connapp.test_plugin_enable">test_plugin_enable</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_plugin_list" href="#connpy.tests.test_connapp.test_plugin_list">test_plugin_list</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_profile_add" href="#connpy.tests.test_connapp.test_profile_add">test_profile_add</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_profile_del" href="#connpy.tests.test_connapp.test_profile_del">test_profile_del</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_profile_list" href="#connpy.tests.test_connapp.test_profile_list">test_profile_list</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_profile_mod" href="#connpy.tests.test_connapp.test_profile_mod">test_profile_mod</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_profile_show" href="#connpy.tests.test_connapp.test_profile_show">test_profile_show</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_run" href="#connpy.tests.test_connapp.test_run">test_run</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_connapp.test_type_node_reserved_word" href="#connpy.tests.test_connapp.test_type_node_reserved_word">test_type_node_reserved_word</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</main>
|
||||
<footer id="footer">
|
||||
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.11.5</a>.</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
@@ -115,8 +115,9 @@ el.replaceWith(d);
|
||||
|
||||
def test_invalid_protocol_raises(self):
|
||||
n = self._make_node(protocol="invalid_proto")
|
||||
with pytest.raises(ValueError, match="Invalid protocol"):
|
||||
with pytest.raises(SystemExit) as exc:
|
||||
n._get_cmd()
|
||||
assert exc.value.code == 1
|
||||
|
||||
def test_ssh_cmd_no_user(self):
|
||||
n = self._make_node(user="")
|
||||
@@ -155,8 +156,9 @@ el.replaceWith(d);
|
||||
</summary>
|
||||
<pre><code class="python">def test_invalid_protocol_raises(self):
|
||||
n = self._make_node(protocol="invalid_proto")
|
||||
with pytest.raises(ValueError, match="Invalid protocol"):
|
||||
n._get_cmd()</code></pre>
|
||||
with pytest.raises(SystemExit) as exc:
|
||||
n._get_cmd()
|
||||
assert exc.value.code == 1</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
|
||||
<meta name="generator" content="pdoc3 0.11.5">
|
||||
<title>connpy.tests.test_execution_service API documentation</title>
|
||||
<meta name="description" content="">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/sanitize.min.css" integrity="sha512-y1dtMcuvtTMJc1yPgEqF0ZjQbhnc/bFhyvIyVNb9Zk5mIGtqVaAB1Ttl28su8AvFMOY0EwRbAe+HCLqj6W7/KA==" crossorigin>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/typography.min.css" integrity="sha512-Y1DYSb995BAfxobCkKepB1BqJJTPrOp3zPL74AWFugHHmmdcvO+C48WLrUOlhGMc0QG7AE3f7gmvvcrmX2fDoA==" crossorigin>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css" crossorigin>
|
||||
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:1.5em;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:2em 0 .50em 0}h3{font-size:1.4em;margin:1.6em 0 .7em 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .2s ease-in-out}a:visited{color:#503}a:hover{color:#b62}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900;font-weight:bold}pre code{font-size:.8em;line-height:1.4em;padding:1em;display:block}code{background:#f3f3f3;font-family:"DejaVu Sans Mono",monospace;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source > summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible;min-width:max-content}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em 1em;margin:1em 0}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
|
||||
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul ul{padding-left:1em}.toc > ul > li{margin-top:.5em}}</style>
|
||||
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
|
||||
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js" integrity="sha512-D9gUyxqja7hBtkWpPWGt9wfbfaMGVt9gnyCvYa+jojwwPHLCzUm5i8rpk7vD7wNee9bA35eYIjobYPaQuKS1MQ==" crossorigin></script>
|
||||
<script>window.addEventListener('DOMContentLoaded', () => {
|
||||
hljs.configure({languages: ['bash', 'css', 'diff', 'graphql', 'ini', 'javascript', 'json', 'plaintext', 'python', 'python-repl', 'rust', 'shell', 'sql', 'typescript', 'xml', 'yaml']});
|
||||
hljs.highlightAll();
|
||||
/* Collapse source docstrings */
|
||||
setTimeout(() => {
|
||||
[...document.querySelectorAll('.hljs.language-python > .hljs-string')]
|
||||
.filter(el => el.innerHTML.length > 200 && ['"""', "'''"].includes(el.innerHTML.substring(0, 3)))
|
||||
.forEach(el => {
|
||||
let d = document.createElement('details');
|
||||
d.classList.add('hljs-string');
|
||||
d.innerHTML = '<summary>"""</summary>' + el.innerHTML.substring(3);
|
||||
el.replaceWith(d);
|
||||
});
|
||||
}, 100);
|
||||
})</script>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<article id="content">
|
||||
<header>
|
||||
<h1 class="title">Module <code>connpy.tests.test_execution_service</code></h1>
|
||||
</header>
|
||||
<section id="section-intro">
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
<h2 class="section-title" id="header-functions">Functions</h2>
|
||||
<dl>
|
||||
<dt id="connpy.tests.test_execution_service.test_run_commands_callback"><code class="name flex">
|
||||
<span>def <span class="ident">test_run_commands_callback</span></span>(<span>populated_config)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_run_commands_callback(populated_config):
|
||||
"""Test that run_commands correctly passes on_node_complete to the executor."""
|
||||
service = ExecutionService(populated_config)
|
||||
|
||||
# Mock the Nodes class in connpy.services.execution_service
|
||||
with patch("connpy.services.execution_service.Nodes") as MockNodes:
|
||||
mock_executor = MockNodes.return_value
|
||||
mock_executor.run.return_value = {"router1": "output"}
|
||||
|
||||
callback = MagicMock()
|
||||
|
||||
service.run_commands(
|
||||
nodes_filter="router1",
|
||||
commands=["show version"],
|
||||
on_node_complete=callback
|
||||
)
|
||||
|
||||
# Verify executor.run was called with on_complete=callback
|
||||
# Note: ExecutionService calls executor.run(..., on_complete=on_node_complete, ...)
|
||||
MockNodes.return_value.run.assert_called_once()
|
||||
args, kwargs = MockNodes.return_value.run.call_args
|
||||
assert kwargs["on_complete"] == callback</code></pre>
|
||||
</details>
|
||||
<div class="desc"><p>Test that run_commands correctly passes on_node_complete to the executor.</p></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_execution_service.test_test_commands_callback_regression"><code class="name flex">
|
||||
<span>def <span class="ident">test_test_commands_callback_regression</span></span>(<span>populated_config)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_test_commands_callback_regression(populated_config):
|
||||
"""
|
||||
Test that test_commands correctly passes on_node_complete to the executor.
|
||||
Regression: ExecutionService.test_commands currently ignores on_node_complete.
|
||||
"""
|
||||
service = ExecutionService(populated_config)
|
||||
|
||||
with patch("connpy.services.execution_service.Nodes") as MockNodes:
|
||||
mock_executor = MockNodes.return_value
|
||||
mock_executor.test.return_value = {"router1": {"PASS": True}}
|
||||
|
||||
callback = MagicMock()
|
||||
|
||||
service.test_commands(
|
||||
nodes_filter="router1",
|
||||
commands=["show version"],
|
||||
expected=["12.4"],
|
||||
on_node_complete=callback
|
||||
)
|
||||
|
||||
# This is expected to FAIL because ExecutionService.test_commands
|
||||
# doesn't pass on_complete to executor.test
|
||||
MockNodes.return_value.test.assert_called_once()
|
||||
args, kwargs = MockNodes.return_value.test.call_args
|
||||
|
||||
# We expect 'on_complete' to be in kwargs and equal to our callback
|
||||
assert "on_complete" in kwargs, "on_complete parameter missing in call to executor.test"
|
||||
assert kwargs["on_complete"] == callback</code></pre>
|
||||
</details>
|
||||
<div class="desc"><p>Test that test_commands correctly passes on_node_complete to the executor.
|
||||
Regression: ExecutionService.test_commands currently ignores on_node_complete.</p></div>
|
||||
</dd>
|
||||
</dl>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
</article>
|
||||
<nav id="sidebar">
|
||||
<div class="toc">
|
||||
<ul></ul>
|
||||
</div>
|
||||
<ul id="index">
|
||||
<li><h3>Super-module</h3>
|
||||
<ul>
|
||||
<li><code><a title="connpy.tests" href="index.html">connpy.tests</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><h3><a href="#header-functions">Functions</a></h3>
|
||||
<ul class="">
|
||||
<li><code><a title="connpy.tests.test_execution_service.test_run_commands_callback" href="#connpy.tests.test_execution_service.test_run_commands_callback">test_run_commands_callback</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_execution_service.test_test_commands_callback_regression" href="#connpy.tests.test_execution_service.test_test_commands_callback_regression">test_test_commands_callback_regression</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</main>
|
||||
<footer id="footer">
|
||||
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.11.5</a>.</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,184 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
|
||||
<meta name="generator" content="pdoc3 0.11.5">
|
||||
<title>connpy.tests.test_node_service API documentation</title>
|
||||
<meta name="description" content="">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/sanitize.min.css" integrity="sha512-y1dtMcuvtTMJc1yPgEqF0ZjQbhnc/bFhyvIyVNb9Zk5mIGtqVaAB1Ttl28su8AvFMOY0EwRbAe+HCLqj6W7/KA==" crossorigin>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/typography.min.css" integrity="sha512-Y1DYSb995BAfxobCkKepB1BqJJTPrOp3zPL74AWFugHHmmdcvO+C48WLrUOlhGMc0QG7AE3f7gmvvcrmX2fDoA==" crossorigin>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css" crossorigin>
|
||||
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:1.5em;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:2em 0 .50em 0}h3{font-size:1.4em;margin:1.6em 0 .7em 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .2s ease-in-out}a:visited{color:#503}a:hover{color:#b62}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900;font-weight:bold}pre code{font-size:.8em;line-height:1.4em;padding:1em;display:block}code{background:#f3f3f3;font-family:"DejaVu Sans Mono",monospace;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source > summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible;min-width:max-content}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em 1em;margin:1em 0}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
|
||||
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul ul{padding-left:1em}.toc > ul > li{margin-top:.5em}}</style>
|
||||
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
|
||||
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js" integrity="sha512-D9gUyxqja7hBtkWpPWGt9wfbfaMGVt9gnyCvYa+jojwwPHLCzUm5i8rpk7vD7wNee9bA35eYIjobYPaQuKS1MQ==" crossorigin></script>
|
||||
<script>window.addEventListener('DOMContentLoaded', () => {
|
||||
hljs.configure({languages: ['bash', 'css', 'diff', 'graphql', 'ini', 'javascript', 'json', 'plaintext', 'python', 'python-repl', 'rust', 'shell', 'sql', 'typescript', 'xml', 'yaml']});
|
||||
hljs.highlightAll();
|
||||
/* Collapse source docstrings */
|
||||
setTimeout(() => {
|
||||
[...document.querySelectorAll('.hljs.language-python > .hljs-string')]
|
||||
.filter(el => el.innerHTML.length > 200 && ['"""', "'''"].includes(el.innerHTML.substring(0, 3)))
|
||||
.forEach(el => {
|
||||
let d = document.createElement('details');
|
||||
d.classList.add('hljs-string');
|
||||
d.innerHTML = '<summary>"""</summary>' + el.innerHTML.substring(3);
|
||||
el.replaceWith(d);
|
||||
});
|
||||
}, 100);
|
||||
})</script>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<article id="content">
|
||||
<header>
|
||||
<h1 class="title">Module <code>connpy.tests.test_node_service</code></h1>
|
||||
</header>
|
||||
<section id="section-intro">
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
<h2 class="section-title" id="header-functions">Functions</h2>
|
||||
<dl>
|
||||
<dt id="connpy.tests.test_node_service.test_list_nodes_case_sensitivity"><code class="name flex">
|
||||
<span>def <span class="ident">test_list_nodes_case_sensitivity</span></span>(<span>populated_config)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_list_nodes_case_sensitivity(populated_config):
|
||||
"""Test that filtering respects the case setting in config."""
|
||||
service = NodeService(populated_config)
|
||||
|
||||
# Default case is False (case-insensitive)
|
||||
nodes = service.list_nodes(filter_str="ROUTER")
|
||||
assert "router1" in nodes</code></pre>
|
||||
</details>
|
||||
<div class="desc"><p>Test that filtering respects the case setting in config.</p></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_node_service.test_list_nodes_dynamic_formatting"><code class="name flex">
|
||||
<span>def <span class="ident">test_list_nodes_dynamic_formatting</span></span>(<span>populated_config)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_list_nodes_dynamic_formatting(populated_config):
|
||||
"""
|
||||
Test that list_nodes supports dynamic formatting for any node attribute.
|
||||
Regression: NodeService currently has hardcoded support for name, location, host.
|
||||
"""
|
||||
service = NodeService(populated_config)
|
||||
|
||||
# Try to format using 'user' and 'protocol' which are NOT in the hardcoded list
|
||||
# (name, location, host)
|
||||
format_str = "{name} -> {user}@{host} ({protocol})"
|
||||
|
||||
# router1: host=10.0.0.1, user=admin, protocol=ssh
|
||||
# Expected: "router1 -> admin@10.0.0.1 (ssh)"
|
||||
|
||||
formatted = service.list_nodes(filter_str="router1", format_str=format_str)
|
||||
|
||||
assert len(formatted) == 1
|
||||
# This will FAIL if it only supports {name}, {location}, {host}
|
||||
assert formatted[0] == "router1 -> admin@10.0.0.1 (ssh)"</code></pre>
|
||||
</details>
|
||||
<div class="desc"><p>Test that list_nodes supports dynamic formatting for any node attribute.
|
||||
Regression: NodeService currently has hardcoded support for name, location, host.</p></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_node_service.test_list_nodes_filtering_parity"><code class="name flex">
|
||||
<span>def <span class="ident">test_list_nodes_filtering_parity</span></span>(<span>populated_config)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_list_nodes_filtering_parity(populated_config):
|
||||
"""
|
||||
Test that list_nodes uses literal 'in' logic instead of re.search.
|
||||
Regression: NodeService currently uses re.search in some versions,
|
||||
but we want to ensure it uses literal 'in' for parity.
|
||||
"""
|
||||
service = NodeService(populated_config)
|
||||
|
||||
# If it uses 'in' logic, '1' should match all nodes containing '1'
|
||||
# router1, server1@office, db1@datacenter@office
|
||||
nodes = service.list_nodes(filter_str="1")
|
||||
assert len(nodes) == 3
|
||||
assert "router1" in nodes
|
||||
assert "server1@office" in nodes
|
||||
assert "db1@datacenter@office" in nodes
|
||||
|
||||
# Test regex-specific characters.
|
||||
# NodeService should use re.search, so '^router' will match 'router1'.
|
||||
nodes_regex = service.list_nodes(filter_str="^router")
|
||||
|
||||
assert "router1" in nodes_regex</code></pre>
|
||||
</details>
|
||||
<div class="desc"><p>Test that list_nodes uses literal 'in' logic instead of re.search.
|
||||
Regression: NodeService currently uses re.search in some versions,
|
||||
but we want to ensure it uses literal 'in' for parity.</p></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_node_service.test_node_editing_parity"><code class="name flex">
|
||||
<span>def <span class="ident">test_node_editing_parity</span></span>(<span>populated_config)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_node_editing_parity(populated_config):
|
||||
"""
|
||||
Test that add_node improperly raises NodeAlreadyExistsError when used for editing.
|
||||
Regression: connapp._mod calls add_node instead of update_node.
|
||||
"""
|
||||
service = NodeService(populated_config)
|
||||
|
||||
# router1 already exists in populated_config
|
||||
# We confirm that calling add_node with an existing ID raises NodeAlreadyExistsError
|
||||
# which is why connapp._mod (which calls add_node) is currently broken for editing.
|
||||
with pytest.raises(NodeAlreadyExistsError):
|
||||
service.add_node("router1", {"host": "1.1.1.1"})</code></pre>
|
||||
</details>
|
||||
<div class="desc"><p>Test that add_node improperly raises NodeAlreadyExistsError when used for editing.
|
||||
Regression: connapp._mod calls add_node instead of update_node.</p></div>
|
||||
</dd>
|
||||
</dl>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
</article>
|
||||
<nav id="sidebar">
|
||||
<div class="toc">
|
||||
<ul></ul>
|
||||
</div>
|
||||
<ul id="index">
|
||||
<li><h3>Super-module</h3>
|
||||
<ul>
|
||||
<li><code><a title="connpy.tests" href="index.html">connpy.tests</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><h3><a href="#header-functions">Functions</a></h3>
|
||||
<ul class="">
|
||||
<li><code><a title="connpy.tests.test_node_service.test_list_nodes_case_sensitivity" href="#connpy.tests.test_node_service.test_list_nodes_case_sensitivity">test_list_nodes_case_sensitivity</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_node_service.test_list_nodes_dynamic_formatting" href="#connpy.tests.test_node_service.test_list_nodes_dynamic_formatting">test_list_nodes_dynamic_formatting</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_node_service.test_list_nodes_filtering_parity" href="#connpy.tests.test_node_service.test_list_nodes_filtering_parity">test_list_nodes_filtering_parity</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_node_service.test_node_editing_parity" href="#connpy.tests.test_node_service.test_node_editing_parity">test_node_editing_parity</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</main>
|
||||
<footer id="footer">
|
||||
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.11.5</a>.</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
@@ -98,11 +98,80 @@ el.replaceWith(d);
|
||||
assert lines[0] == "[i] line1"
|
||||
# Second line should be indented by len("[i] ") = 4 chars
|
||||
assert lines[1].startswith(" line2")
|
||||
assert lines[2].startswith(" line3")</code></pre>
|
||||
assert lines[2].startswith(" line3")
|
||||
|
||||
def test_data_output(self, capsys):
|
||||
printer.data("my title", "key: value")
|
||||
captured = capsys.readouterr()
|
||||
# Rich output is formatted with ansi escape sequences or box drawing chars
|
||||
# Just check that title and content appear in the output stream
|
||||
assert "my title" in captured.out
|
||||
assert "key" in captured.out
|
||||
|
||||
def test_node_panel_pass(self, capsys):
|
||||
printer.node_panel("node1", "output line\n", 0)
|
||||
captured = capsys.readouterr()
|
||||
assert "node1" in captured.out
|
||||
assert "PASS" in captured.out
|
||||
assert "output line" in captured.out
|
||||
|
||||
def test_node_panel_fail(self, capsys):
|
||||
printer.node_panel("node2", "error line\n", 1)
|
||||
captured = capsys.readouterr()
|
||||
assert "node2" in captured.out
|
||||
assert "FAIL" in captured.out
|
||||
assert "error line" in captured.out
|
||||
|
||||
def test_test_panel(self, capsys):
|
||||
printer.test_panel("node1", "output", 0, {"check1": True, "check2": False})
|
||||
captured = capsys.readouterr()
|
||||
assert "node1" in captured.out
|
||||
assert "check1" in captured.out
|
||||
assert "check2" in captured.out
|
||||
|
||||
def test_test_summary(self, capsys):
|
||||
results = {"node1": {"test1": True}, "node2": {"test2": False}}
|
||||
printer.test_summary(results)
|
||||
captured = capsys.readouterr()
|
||||
assert "node1" in captured.out
|
||||
assert "node2" in captured.out
|
||||
assert "test1" in captured.out
|
||||
assert "test2" in captured.out
|
||||
|
||||
def test_header_output(self, capsys):
|
||||
printer.header("My Header")
|
||||
captured = capsys.readouterr()
|
||||
assert "My Header" in captured.out
|
||||
|
||||
def test_kv_output(self, capsys):
|
||||
printer.kv("mykeystring", "myvaluestring")
|
||||
captured = capsys.readouterr()
|
||||
assert "mykeystring" in captured.out
|
||||
assert "myvaluestring" in captured.out
|
||||
|
||||
def test_confirm_action(self, capsys):
|
||||
printer.confirm_action("router1", "delete")
|
||||
captured = capsys.readouterr()
|
||||
assert "[i] delete: router1" in captured.out</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
<h3>Methods</h3>
|
||||
<dl>
|
||||
<dt id="connpy.tests.test_printer.TestPrinter.test_confirm_action"><code class="name flex">
|
||||
<span>def <span class="ident">test_confirm_action</span></span>(<span>self, capsys)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_confirm_action(self, capsys):
|
||||
printer.confirm_action("router1", "delete")
|
||||
captured = capsys.readouterr()
|
||||
assert "[i] delete: router1" in captured.out</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_printer.TestPrinter.test_custom_output"><code class="name flex">
|
||||
<span>def <span class="ident">test_custom_output</span></span>(<span>self, capsys)</span>
|
||||
</code></dt>
|
||||
@@ -118,6 +187,24 @@ el.replaceWith(d);
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_printer.TestPrinter.test_data_output"><code class="name flex">
|
||||
<span>def <span class="ident">test_data_output</span></span>(<span>self, capsys)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_data_output(self, capsys):
|
||||
printer.data("my title", "key: value")
|
||||
captured = capsys.readouterr()
|
||||
# Rich output is formatted with ansi escape sequences or box drawing chars
|
||||
# Just check that title and content appear in the output stream
|
||||
assert "my title" in captured.out
|
||||
assert "key" in captured.out</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_printer.TestPrinter.test_debug_output"><code class="name flex">
|
||||
<span>def <span class="ident">test_debug_output</span></span>(<span>self, capsys)</span>
|
||||
</code></dt>
|
||||
@@ -148,6 +235,21 @@ el.replaceWith(d);
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_printer.TestPrinter.test_header_output"><code class="name flex">
|
||||
<span>def <span class="ident">test_header_output</span></span>(<span>self, capsys)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_header_output(self, capsys):
|
||||
printer.header("My Header")
|
||||
captured = capsys.readouterr()
|
||||
assert "My Header" in captured.out</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_printer.TestPrinter.test_info_output"><code class="name flex">
|
||||
<span>def <span class="ident">test_info_output</span></span>(<span>self, capsys)</span>
|
||||
</code></dt>
|
||||
@@ -163,6 +265,22 @@ el.replaceWith(d);
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_printer.TestPrinter.test_kv_output"><code class="name flex">
|
||||
<span>def <span class="ident">test_kv_output</span></span>(<span>self, capsys)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_kv_output(self, capsys):
|
||||
printer.kv("mykeystring", "myvaluestring")
|
||||
captured = capsys.readouterr()
|
||||
assert "mykeystring" in captured.out
|
||||
assert "myvaluestring" in captured.out</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_printer.TestPrinter.test_multiline_indentation"><code class="name flex">
|
||||
<span>def <span class="ident">test_multiline_indentation</span></span>(<span>self, capsys)</span>
|
||||
</code></dt>
|
||||
@@ -182,6 +300,40 @@ el.replaceWith(d);
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_printer.TestPrinter.test_node_panel_fail"><code class="name flex">
|
||||
<span>def <span class="ident">test_node_panel_fail</span></span>(<span>self, capsys)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_node_panel_fail(self, capsys):
|
||||
printer.node_panel("node2", "error line\n", 1)
|
||||
captured = capsys.readouterr()
|
||||
assert "node2" in captured.out
|
||||
assert "FAIL" in captured.out
|
||||
assert "error line" in captured.out</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_printer.TestPrinter.test_node_panel_pass"><code class="name flex">
|
||||
<span>def <span class="ident">test_node_panel_pass</span></span>(<span>self, capsys)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_node_panel_pass(self, capsys):
|
||||
printer.node_panel("node1", "output line\n", 0)
|
||||
captured = capsys.readouterr()
|
||||
assert "node1" in captured.out
|
||||
assert "PASS" in captured.out
|
||||
assert "output line" in captured.out</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_printer.TestPrinter.test_start_output"><code class="name flex">
|
||||
<span>def <span class="ident">test_start_output</span></span>(<span>self, capsys)</span>
|
||||
</code></dt>
|
||||
@@ -212,6 +364,42 @@ el.replaceWith(d);
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_printer.TestPrinter.test_test_panel"><code class="name flex">
|
||||
<span>def <span class="ident">test_test_panel</span></span>(<span>self, capsys)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_test_panel(self, capsys):
|
||||
printer.test_panel("node1", "output", 0, {"check1": True, "check2": False})
|
||||
captured = capsys.readouterr()
|
||||
assert "node1" in captured.out
|
||||
assert "check1" in captured.out
|
||||
assert "check2" in captured.out</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_printer.TestPrinter.test_test_summary"><code class="name flex">
|
||||
<span>def <span class="ident">test_test_summary</span></span>(<span>self, capsys)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_test_summary(self, capsys):
|
||||
results = {"node1": {"test1": True}, "node2": {"test2": False}}
|
||||
printer.test_summary(results)
|
||||
captured = capsys.readouterr()
|
||||
assert "node1" in captured.out
|
||||
assert "node2" in captured.out
|
||||
assert "test1" in captured.out
|
||||
assert "test2" in captured.out</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_printer.TestPrinter.test_warning_output"><code class="name flex">
|
||||
<span>def <span class="ident">test_warning_output</span></span>(<span>self, capsys)</span>
|
||||
</code></dt>
|
||||
@@ -247,13 +435,21 @@ el.replaceWith(d);
|
||||
<li>
|
||||
<h4><code><a title="connpy.tests.test_printer.TestPrinter" href="#connpy.tests.test_printer.TestPrinter">TestPrinter</a></code></h4>
|
||||
<ul class="">
|
||||
<li><code><a title="connpy.tests.test_printer.TestPrinter.test_confirm_action" href="#connpy.tests.test_printer.TestPrinter.test_confirm_action">test_confirm_action</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_printer.TestPrinter.test_custom_output" href="#connpy.tests.test_printer.TestPrinter.test_custom_output">test_custom_output</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_printer.TestPrinter.test_data_output" href="#connpy.tests.test_printer.TestPrinter.test_data_output">test_data_output</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_printer.TestPrinter.test_debug_output" href="#connpy.tests.test_printer.TestPrinter.test_debug_output">test_debug_output</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_printer.TestPrinter.test_error_output" href="#connpy.tests.test_printer.TestPrinter.test_error_output">test_error_output</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_printer.TestPrinter.test_header_output" href="#connpy.tests.test_printer.TestPrinter.test_header_output">test_header_output</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_printer.TestPrinter.test_info_output" href="#connpy.tests.test_printer.TestPrinter.test_info_output">test_info_output</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_printer.TestPrinter.test_kv_output" href="#connpy.tests.test_printer.TestPrinter.test_kv_output">test_kv_output</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_printer.TestPrinter.test_multiline_indentation" href="#connpy.tests.test_printer.TestPrinter.test_multiline_indentation">test_multiline_indentation</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_printer.TestPrinter.test_node_panel_fail" href="#connpy.tests.test_printer.TestPrinter.test_node_panel_fail">test_node_panel_fail</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_printer.TestPrinter.test_node_panel_pass" href="#connpy.tests.test_printer.TestPrinter.test_node_panel_pass">test_node_panel_pass</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_printer.TestPrinter.test_start_output" href="#connpy.tests.test_printer.TestPrinter.test_start_output">test_start_output</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_printer.TestPrinter.test_success_output" href="#connpy.tests.test_printer.TestPrinter.test_success_output">test_success_output</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_printer.TestPrinter.test_test_panel" href="#connpy.tests.test_printer.TestPrinter.test_test_panel">test_test_panel</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_printer.TestPrinter.test_test_summary" href="#connpy.tests.test_printer.TestPrinter.test_test_summary">test_test_summary</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_printer.TestPrinter.test_warning_output" href="#connpy.tests.test_printer.TestPrinter.test_warning_output">test_warning_output</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
|
||||
<meta name="generator" content="pdoc3 0.11.5">
|
||||
<title>connpy.tests.test_profile_service API documentation</title>
|
||||
<meta name="description" content="">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/sanitize.min.css" integrity="sha512-y1dtMcuvtTMJc1yPgEqF0ZjQbhnc/bFhyvIyVNb9Zk5mIGtqVaAB1Ttl28su8AvFMOY0EwRbAe+HCLqj6W7/KA==" crossorigin>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/typography.min.css" integrity="sha512-Y1DYSb995BAfxobCkKepB1BqJJTPrOp3zPL74AWFugHHmmdcvO+C48WLrUOlhGMc0QG7AE3f7gmvvcrmX2fDoA==" crossorigin>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css" crossorigin>
|
||||
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:1.5em;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:2em 0 .50em 0}h3{font-size:1.4em;margin:1.6em 0 .7em 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .2s ease-in-out}a:visited{color:#503}a:hover{color:#b62}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900;font-weight:bold}pre code{font-size:.8em;line-height:1.4em;padding:1em;display:block}code{background:#f3f3f3;font-family:"DejaVu Sans Mono",monospace;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source > summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible;min-width:max-content}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em 1em;margin:1em 0}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
|
||||
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul ul{padding-left:1em}.toc > ul > li{margin-top:.5em}}</style>
|
||||
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
|
||||
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js" integrity="sha512-D9gUyxqja7hBtkWpPWGt9wfbfaMGVt9gnyCvYa+jojwwPHLCzUm5i8rpk7vD7wNee9bA35eYIjobYPaQuKS1MQ==" crossorigin></script>
|
||||
<script>window.addEventListener('DOMContentLoaded', () => {
|
||||
hljs.configure({languages: ['bash', 'css', 'diff', 'graphql', 'ini', 'javascript', 'json', 'plaintext', 'python', 'python-repl', 'rust', 'shell', 'sql', 'typescript', 'xml', 'yaml']});
|
||||
hljs.highlightAll();
|
||||
/* Collapse source docstrings */
|
||||
setTimeout(() => {
|
||||
[...document.querySelectorAll('.hljs.language-python > .hljs-string')]
|
||||
.filter(el => el.innerHTML.length > 200 && ['"""', "'''"].includes(el.innerHTML.substring(0, 3)))
|
||||
.forEach(el => {
|
||||
let d = document.createElement('details');
|
||||
d.classList.add('hljs-string');
|
||||
d.innerHTML = '<summary>"""</summary>' + el.innerHTML.substring(3);
|
||||
el.replaceWith(d);
|
||||
});
|
||||
}, 100);
|
||||
})</script>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<article id="content">
|
||||
<header>
|
||||
<h1 class="title">Module <code>connpy.tests.test_profile_service</code></h1>
|
||||
</header>
|
||||
<section id="section-intro">
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
<h2 class="section-title" id="header-functions">Functions</h2>
|
||||
<dl>
|
||||
<dt id="connpy.tests.test_profile_service.test_delete_default_profile_fails"><code class="name flex">
|
||||
<span>def <span class="ident">test_delete_default_profile_fails</span></span>(<span>populated_config)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_delete_default_profile_fails(populated_config):
|
||||
"""Test that deleting the 'default' profile is prohibited."""
|
||||
service = ProfileService(populated_config)
|
||||
from connpy.services.exceptions import InvalidConfigurationError
|
||||
|
||||
with pytest.raises(InvalidConfigurationError, match="Cannot delete the 'default' profile"):
|
||||
service.delete_profile("default")</code></pre>
|
||||
</details>
|
||||
<div class="desc"><p>Test that deleting the 'default' profile is prohibited.</p></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_profile_service.test_delete_used_profile_fails"><code class="name flex">
|
||||
<span>def <span class="ident">test_delete_used_profile_fails</span></span>(<span>populated_config)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_delete_used_profile_fails(populated_config):
|
||||
"""Test that deleting a profile used by nodes is prohibited."""
|
||||
service = ProfileService(populated_config)
|
||||
from connpy.services.exceptions import InvalidConfigurationError
|
||||
|
||||
# In populated_config, we need to make sure a node uses a profile
|
||||
# Let's add a node that uses 'office-user'
|
||||
populated_config._connections_add(id="testnode", host="1.1.1.1", user="@office-user")
|
||||
|
||||
with pytest.raises(InvalidConfigurationError, match="is used by nodes"):
|
||||
service.delete_profile("office-user")</code></pre>
|
||||
</details>
|
||||
<div class="desc"><p>Test that deleting a profile used by nodes is prohibited.</p></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_profile_service.test_profile_crud"><code class="name flex">
|
||||
<span>def <span class="ident">test_profile_crud</span></span>(<span>populated_config)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_profile_crud(populated_config):
|
||||
"""Test basic CRUD operations for profiles."""
|
||||
service = ProfileService(populated_config)
|
||||
|
||||
# List
|
||||
profiles = service.list_profiles()
|
||||
assert "default" in profiles
|
||||
assert "office-user" in profiles
|
||||
|
||||
# Get
|
||||
office = service.get_profile("office-user")
|
||||
assert office["user"] == "officeadmin"
|
||||
|
||||
# Add
|
||||
new_data = {
|
||||
"user": "newadmin",
|
||||
"password": "newpassword"
|
||||
}
|
||||
service.add_profile("new-profile", new_data)
|
||||
assert "new-profile" in service.list_profiles()
|
||||
assert service.get_profile("new-profile")["user"] == "newadmin"
|
||||
|
||||
# Update
|
||||
update_data = {
|
||||
"user": "updatedadmin"
|
||||
}
|
||||
service.update_profile("new-profile", update_data)
|
||||
assert service.get_profile("new-profile")["user"] == "updatedadmin"
|
||||
|
||||
# Delete
|
||||
service.delete_profile("new-profile")
|
||||
assert "new-profile" not in service.list_profiles()</code></pre>
|
||||
</details>
|
||||
<div class="desc"><p>Test basic CRUD operations for profiles.</p></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_profile_service.test_profile_inheritance_parity"><code class="name flex">
|
||||
<span>def <span class="ident">test_profile_inheritance_parity</span></span>(<span>populated_config)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_profile_inheritance_parity(populated_config):
|
||||
"""
|
||||
Test that profiles can inherit from other profiles.
|
||||
Regression: ProfileService currently doesn't resolve inheritance within profiles.
|
||||
"""
|
||||
service = ProfileService(populated_config)
|
||||
|
||||
# Create a profile that inherits from 'office-user'
|
||||
# 'office-user' has user='officeadmin', password='officepass'
|
||||
inherited_data = {
|
||||
"user": "@office-user",
|
||||
"options": "-v"
|
||||
}
|
||||
service.add_profile("inherited-profile", inherited_data)
|
||||
|
||||
# When we get the profile, we expect it to be resolved if inheritance is supported
|
||||
# This is a common pattern in connpy for nodes, but should it work for profiles?
|
||||
# The task mentions "profile CRUD and inheritance parity".
|
||||
|
||||
profile = service.get_profile("inherited-profile")
|
||||
|
||||
# If inheritance is resolved, user should be 'officeadmin'
|
||||
# This is expected to FAIL if ProfileService just returns the raw dict.
|
||||
assert profile["user"] == "officeadmin"
|
||||
assert profile["password"] == "officepass"
|
||||
assert profile["options"] == "-v"</code></pre>
|
||||
</details>
|
||||
<div class="desc"><p>Test that profiles can inherit from other profiles.
|
||||
Regression: ProfileService currently doesn't resolve inheritance within profiles.</p></div>
|
||||
</dd>
|
||||
</dl>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
</article>
|
||||
<nav id="sidebar">
|
||||
<div class="toc">
|
||||
<ul></ul>
|
||||
</div>
|
||||
<ul id="index">
|
||||
<li><h3>Super-module</h3>
|
||||
<ul>
|
||||
<li><code><a title="connpy.tests" href="index.html">connpy.tests</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><h3><a href="#header-functions">Functions</a></h3>
|
||||
<ul class="">
|
||||
<li><code><a title="connpy.tests.test_profile_service.test_delete_default_profile_fails" href="#connpy.tests.test_profile_service.test_delete_default_profile_fails">test_delete_default_profile_fails</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_profile_service.test_delete_used_profile_fails" href="#connpy.tests.test_profile_service.test_delete_used_profile_fails">test_delete_used_profile_fails</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_profile_service.test_profile_crud" href="#connpy.tests.test_profile_service.test_profile_crud">test_profile_crud</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_profile_service.test_profile_inheritance_parity" href="#connpy.tests.test_profile_service.test_profile_inheritance_parity">test_profile_inheritance_parity</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</main>
|
||||
<footer id="footer">
|
||||
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.11.5</a>.</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,145 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
|
||||
<meta name="generator" content="pdoc3 0.11.5">
|
||||
<title>connpy.tests.test_provider API documentation</title>
|
||||
<meta name="description" content="">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/sanitize.min.css" integrity="sha512-y1dtMcuvtTMJc1yPgEqF0ZjQbhnc/bFhyvIyVNb9Zk5mIGtqVaAB1Ttl28su8AvFMOY0EwRbAe+HCLqj6W7/KA==" crossorigin>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/typography.min.css" integrity="sha512-Y1DYSb995BAfxobCkKepB1BqJJTPrOp3zPL74AWFugHHmmdcvO+C48WLrUOlhGMc0QG7AE3f7gmvvcrmX2fDoA==" crossorigin>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css" crossorigin>
|
||||
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:1.5em;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:2em 0 .50em 0}h3{font-size:1.4em;margin:1.6em 0 .7em 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .2s ease-in-out}a:visited{color:#503}a:hover{color:#b62}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900;font-weight:bold}pre code{font-size:.8em;line-height:1.4em;padding:1em;display:block}code{background:#f3f3f3;font-family:"DejaVu Sans Mono",monospace;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source > summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible;min-width:max-content}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em 1em;margin:1em 0}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
|
||||
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul ul{padding-left:1em}.toc > ul > li{margin-top:.5em}}</style>
|
||||
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
|
||||
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js" integrity="sha512-D9gUyxqja7hBtkWpPWGt9wfbfaMGVt9gnyCvYa+jojwwPHLCzUm5i8rpk7vD7wNee9bA35eYIjobYPaQuKS1MQ==" crossorigin></script>
|
||||
<script>window.addEventListener('DOMContentLoaded', () => {
|
||||
hljs.configure({languages: ['bash', 'css', 'diff', 'graphql', 'ini', 'javascript', 'json', 'plaintext', 'python', 'python-repl', 'rust', 'shell', 'sql', 'typescript', 'xml', 'yaml']});
|
||||
hljs.highlightAll();
|
||||
/* Collapse source docstrings */
|
||||
setTimeout(() => {
|
||||
[...document.querySelectorAll('.hljs.language-python > .hljs-string')]
|
||||
.filter(el => el.innerHTML.length > 200 && ['"""', "'''"].includes(el.innerHTML.substring(0, 3)))
|
||||
.forEach(el => {
|
||||
let d = document.createElement('details');
|
||||
d.classList.add('hljs-string');
|
||||
d.innerHTML = '<summary>"""</summary>' + el.innerHTML.substring(3);
|
||||
el.replaceWith(d);
|
||||
});
|
||||
}, 100);
|
||||
})</script>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<article id="content">
|
||||
<header>
|
||||
<h1 class="title">Module <code>connpy.tests.test_provider</code></h1>
|
||||
</header>
|
||||
<section id="section-intro">
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
<section>
|
||||
<h2 class="section-title" id="header-functions">Functions</h2>
|
||||
<dl>
|
||||
<dt id="connpy.tests.test_provider.test_service_provider_local_mode"><code class="name flex">
|
||||
<span>def <span class="ident">test_service_provider_local_mode</span></span>(<span>)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_service_provider_local_mode():
|
||||
config_mock = MagicMock()
|
||||
with patch("connpy.services.provider.NodeService", create=True) as MockNodeService, \
|
||||
patch("connpy.services.provider.ProfileService", create=True), \
|
||||
patch("connpy.services.provider.ConfigService", create=True), \
|
||||
patch("connpy.services.provider.PluginService", create=True), \
|
||||
patch("connpy.services.provider.AIService", create=True), \
|
||||
patch("connpy.services.provider.SystemService", create=True), \
|
||||
patch("connpy.services.provider.ExecutionService", create=True), \
|
||||
patch("connpy.services.provider.ImportExportService", create=True):
|
||||
|
||||
provider = ServiceProvider(config_mock, mode="local")
|
||||
|
||||
assert provider.mode == "local"
|
||||
assert provider.config == config_mock
|
||||
# Verify that an attribute was created
|
||||
assert provider.nodes is not None</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_provider.test_service_provider_remote_mode"><code class="name flex">
|
||||
<span>def <span class="ident">test_service_provider_remote_mode</span></span>(<span>)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_service_provider_remote_mode():
|
||||
config_mock = MagicMock()
|
||||
with patch("connpy.services.provider.ConfigService", create=True) as MockConfigService, \
|
||||
patch("grpc.insecure_channel", create=True) as MockChannel:
|
||||
|
||||
provider = ServiceProvider(config_mock, mode="remote", remote_host="localhost:50051")
|
||||
|
||||
# Verify ConfigService is initialized locally
|
||||
assert provider.config_svc is not None
|
||||
|
||||
# Verify grpc channel was created
|
||||
MockChannel.assert_called_once_with("localhost:50051")
|
||||
|
||||
# Verify a stub was assigned
|
||||
assert provider.nodes is not None</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_provider.test_service_provider_unknown_mode"><code class="name flex">
|
||||
<span>def <span class="ident">test_service_provider_unknown_mode</span></span>(<span>)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_service_provider_unknown_mode():
|
||||
config_mock = MagicMock()
|
||||
with pytest.raises(ValueError, match="Unknown service mode: invalid_mode"):
|
||||
ServiceProvider(config_mock, mode="invalid_mode")</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
</dl>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
</article>
|
||||
<nav id="sidebar">
|
||||
<div class="toc">
|
||||
<ul></ul>
|
||||
</div>
|
||||
<ul id="index">
|
||||
<li><h3>Super-module</h3>
|
||||
<ul>
|
||||
<li><code><a title="connpy.tests" href="index.html">connpy.tests</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><h3><a href="#header-functions">Functions</a></h3>
|
||||
<ul class="">
|
||||
<li><code><a title="connpy.tests.test_provider.test_service_provider_local_mode" href="#connpy.tests.test_provider.test_service_provider_local_mode">test_service_provider_local_mode</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_provider.test_service_provider_remote_mode" href="#connpy.tests.test_provider.test_service_provider_remote_mode">test_service_provider_remote_mode</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_provider.test_service_provider_unknown_mode" href="#connpy.tests.test_provider.test_service_provider_unknown_mode">test_service_provider_unknown_mode</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</main>
|
||||
<footer id="footer">
|
||||
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.11.5</a>.</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
+156
-192
@@ -5,7 +5,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
|
||||
<meta name="generator" content="pdoc3 0.11.5">
|
||||
<title>connpy.tests.test_sync API documentation</title>
|
||||
<meta name="description" content="Tests for connpy.core_plugins.sync">
|
||||
<meta name="description" content="Tests for connpy.services.sync_service">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/sanitize.min.css" integrity="sha512-y1dtMcuvtTMJc1yPgEqF0ZjQbhnc/bFhyvIyVNb9Zk5mIGtqVaAB1Ttl28su8AvFMOY0EwRbAe+HCLqj6W7/KA==" crossorigin>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/typography.min.css" integrity="sha512-Y1DYSb995BAfxobCkKepB1BqJJTPrOp3zPL74AWFugHHmmdcvO+C48WLrUOlhGMc0QG7AE3f7gmvvcrmX2fDoA==" crossorigin>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css" crossorigin>
|
||||
@@ -36,7 +36,7 @@ el.replaceWith(d);
|
||||
<h1 class="title">Module <code>connpy.tests.test_sync</code></h1>
|
||||
</header>
|
||||
<section id="section-intro">
|
||||
<p>Tests for connpy.core_plugins.sync</p>
|
||||
<p>Tests for connpy.services.sync_service</p>
|
||||
</section>
|
||||
<section>
|
||||
</section>
|
||||
@@ -45,8 +45,8 @@ el.replaceWith(d);
|
||||
<section>
|
||||
<h2 class="section-title" id="header-functions">Functions</h2>
|
||||
<dl>
|
||||
<dt id="connpy.tests.test_sync.mock_connapp"><code class="name flex">
|
||||
<span>def <span class="ident">mock_connapp</span></span>(<span>)</span>
|
||||
<dt id="connpy.tests.test_sync.mock_config"><code class="name flex">
|
||||
<span>def <span class="ident">mock_config</span></span>(<span>)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
@@ -54,13 +54,15 @@ el.replaceWith(d);
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@pytest.fixture
|
||||
def mock_connapp():
|
||||
app = MagicMock()
|
||||
app.config.defaultdir = "/fake/dir"
|
||||
app.config.file = "/fake/dir/config.yaml"
|
||||
app.config.key = "/fake/dir/.osk"
|
||||
app.config.config = {"sync": True}
|
||||
return app</code></pre>
|
||||
def mock_config():
|
||||
config = MagicMock()
|
||||
config.defaultdir = "/fake/dir"
|
||||
config.file = "/fake/dir/config.yaml"
|
||||
config.key = "/fake/dir/.osk"
|
||||
config.cachefile = "/fake/dir/.cache"
|
||||
config.fzf_cachefile = "/fake/dir/.fzf_cache"
|
||||
config.config = {"sync": True, "sync_remote": False}
|
||||
return config</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
@@ -69,79 +71,85 @@ def mock_connapp():
|
||||
<section>
|
||||
<h2 class="section-title" id="header-classes">Classes</h2>
|
||||
<dl>
|
||||
<dt id="connpy.tests.test_sync.TestSyncPlugin"><code class="flex name class">
|
||||
<span>class <span class="ident">TestSyncPlugin</span></span>
|
||||
<dt id="connpy.tests.test_sync.TestSyncService"><code class="flex name class">
|
||||
<span>class <span class="ident">TestSyncService</span></span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">class TestSyncPlugin:
|
||||
def test_init(self, mock_connapp):
|
||||
s = sync(mock_connapp)
|
||||
assert s.sync is True
|
||||
assert s.file == "/fake/dir/config.yaml"
|
||||
assert s.token_file == "/fake/dir/gtoken.json"
|
||||
<pre><code class="python">class TestSyncService:
|
||||
def test_init(self, mock_config):
|
||||
s = SyncService(mock_config)
|
||||
assert s.sync_enabled is True
|
||||
assert s.token_file == os.path.join("/fake/dir", "gtoken.json")
|
||||
|
||||
@patch("connpy.core_plugins.sync.os.path.exists")
|
||||
@patch("connpy.core_plugins.sync.Credentials")
|
||||
def test_get_credentials_success(self, MockCreds, mock_exists, mock_connapp):
|
||||
@patch("connpy.services.sync_service.os.path.exists")
|
||||
@patch("connpy.services.sync_service.Credentials")
|
||||
def test_get_credentials_success(self, MockCreds, mock_exists, mock_config):
|
||||
mock_exists.return_value = True
|
||||
mock_cred_instance = MagicMock()
|
||||
mock_cred_instance.valid = True
|
||||
MockCreds.from_authorized_user_file.return_value = mock_cred_instance
|
||||
|
||||
s = sync(mock_connapp)
|
||||
s = SyncService(mock_config)
|
||||
creds = s.get_credentials()
|
||||
assert creds == mock_cred_instance
|
||||
|
||||
@patch("connpy.core_plugins.sync.os.path.exists")
|
||||
def test_get_credentials_not_found(self, mock_exists, mock_connapp):
|
||||
@patch("connpy.services.sync_service.os.path.exists")
|
||||
def test_get_credentials_not_found(self, mock_exists, mock_config):
|
||||
mock_exists.return_value = False
|
||||
s = sync(mock_connapp)
|
||||
assert s.get_credentials() == 0
|
||||
s = SyncService(mock_config)
|
||||
assert s.get_credentials() is None
|
||||
|
||||
@patch("connpy.core_plugins.sync.zipfile.ZipFile")
|
||||
@patch("connpy.core_plugins.sync.os.path.basename")
|
||||
def test_compress_specific_files(self, mock_basename, MockZipFile, mock_connapp):
|
||||
@patch("connpy.services.sync_service.zipfile.ZipFile")
|
||||
@patch("connpy.services.sync_service.os.path.exists")
|
||||
@patch("connpy.services.sync_service.os.path.basename")
|
||||
def test_compress_and_upload_local(self, mock_basename, mock_exists, MockZipFile, mock_config):
|
||||
mock_basename.return_value = "config.yaml"
|
||||
s = sync(mock_connapp)
|
||||
mock_exists.return_value = True
|
||||
s = SyncService(mock_config)
|
||||
|
||||
# Mocking list_backups and upload_file to avoid real API calls
|
||||
s.list_backups = MagicMock(return_value=[])
|
||||
s.upload_file = MagicMock(return_value=True)
|
||||
|
||||
zip_mock = MagicMock()
|
||||
MockZipFile.return_value.__enter__.return_value = zip_mock
|
||||
|
||||
s.compress_specific_files("/fake/zip.zip")
|
||||
zip_mock.write.assert_any_call(s.file, "config.yaml")
|
||||
zip_mock.write.assert_any_call(s.key, ".osk")
|
||||
s.compress_and_upload()
|
||||
# Verify zip was created with local config and key
|
||||
zip_mock.write.assert_any_call(s.config.file, "config.yaml")
|
||||
zip_mock.write.assert_any_call(s.config.key, ".osk")
|
||||
|
||||
@patch("connpy.core_plugins.sync.zipfile.ZipFile")
|
||||
@patch("connpy.core_plugins.sync.os.path.dirname")
|
||||
def test_decompress_zip_yaml(self, mock_dirname, MockZipFile, mock_connapp):
|
||||
@patch("connpy.services.sync_service.zipfile.ZipFile")
|
||||
@patch("connpy.services.sync_service.os.path.exists")
|
||||
@patch("connpy.services.sync_service.os.path.dirname")
|
||||
@patch("connpy.services.sync_service.os.remove")
|
||||
def test_perform_restore(self, mock_remove, mock_dirname, mock_exists, MockZipFile, mock_config):
|
||||
mock_dirname.return_value = "/fake/dir"
|
||||
s = sync(mock_connapp)
|
||||
# Mock exists to return True for key and zip, but False for caches during the cleanup phase
|
||||
def exists_side_effect(path):
|
||||
if ".cache" in path or ".fzf_cache" in path:
|
||||
return False
|
||||
return True
|
||||
mock_exists.side_effect = exists_side_effect
|
||||
|
||||
s = SyncService(mock_config)
|
||||
zip_mock = MagicMock()
|
||||
zip_mock.namelist.return_value = ["config.yaml", ".osk"]
|
||||
MockZipFile.return_value.__enter__.return_value = zip_mock
|
||||
|
||||
assert s.decompress_zip("/fake/zip.zip") == 0
|
||||
zip_mock.extract.assert_any_call("config.yaml", "/fake/dir")
|
||||
with patch("connpy.services.sync_service.yaml.safe_load") as mock_load:
|
||||
mock_load.return_value = {"connections": {}, "profiles": {}, "config": {}}
|
||||
assert s.perform_restore("/fake/zip.zip") is True
|
||||
|
||||
zip_mock.extract.assert_any_call(".osk", "/fake/dir")
|
||||
|
||||
@patch("connpy.core_plugins.sync.zipfile.ZipFile")
|
||||
@patch("connpy.core_plugins.sync.os.path.dirname")
|
||||
def test_decompress_zip_json_fallback(self, mock_dirname, MockZipFile, mock_connapp):
|
||||
mock_dirname.return_value = "/fake/dir"
|
||||
s = sync(mock_connapp)
|
||||
zip_mock = MagicMock()
|
||||
zip_mock.namelist.return_value = ["config.json", ".osk"]
|
||||
MockZipFile.return_value.__enter__.return_value = zip_mock
|
||||
|
||||
assert s.decompress_zip("/fake/old_zip.zip") == 0
|
||||
zip_mock.extract.assert_any_call("config.json", "/fake/dir")
|
||||
|
||||
@patch.object(sync, "get_credentials")
|
||||
@patch("connpy.core_plugins.sync.build")
|
||||
def test_get_appdata_files(self, mock_build, mock_get_credentials, mock_connapp):
|
||||
@patch.object(SyncService, "get_credentials")
|
||||
@patch("connpy.services.sync_service.build")
|
||||
def test_list_backups(self, mock_build, mock_get_credentials, mock_config):
|
||||
mock_get_credentials.return_value = MagicMock()
|
||||
mock_service = MagicMock()
|
||||
mock_build.return_value = mock_service
|
||||
@@ -152,131 +160,109 @@ def mock_connapp():
|
||||
]
|
||||
}
|
||||
|
||||
s = sync(mock_connapp)
|
||||
files = s.get_appdata_files()
|
||||
s = SyncService(mock_config)
|
||||
files = s.list_backups()
|
||||
assert len(files) == 1
|
||||
assert files[0]["id"] == "1"
|
||||
assert files[0]["timestamp"] == "1000"
|
||||
|
||||
@patch.object(sync, "get_credentials")
|
||||
@patch("connpy.core_plugins.sync.build")
|
||||
@patch("connpy.core_plugins.sync.MediaFileUpload")
|
||||
@patch("connpy.core_plugins.sync.os.path.basename")
|
||||
def test_backup_file_to_drive(self, mock_basename, mock_media, mock_build, mock_get_credentials, mock_connapp):
|
||||
mock_get_credentials.return_value = MagicMock()
|
||||
mock_basename.return_value = "backup.zip"
|
||||
mock_service = MagicMock()
|
||||
mock_build.return_value = mock_service
|
||||
|
||||
s = sync(mock_connapp)
|
||||
assert s.backup_file_to_drive("/fake/backup.zip", 1234567890000) == 0
|
||||
mock_service.files().create.assert_called_once()</code></pre>
|
||||
assert files[0]["timestamp"] == "1000"</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
<h3>Methods</h3>
|
||||
<dl>
|
||||
<dt id="connpy.tests.test_sync.TestSyncPlugin.test_backup_file_to_drive"><code class="name flex">
|
||||
<span>def <span class="ident">test_backup_file_to_drive</span></span>(<span>self, mock_basename, mock_media, mock_build, mock_get_credentials, mock_connapp)</span>
|
||||
<dt id="connpy.tests.test_sync.TestSyncService.test_compress_and_upload_local"><code class="name flex">
|
||||
<span>def <span class="ident">test_compress_and_upload_local</span></span>(<span>self, mock_basename, mock_exists, MockZipFile, mock_config)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch.object(sync, "get_credentials")
|
||||
@patch("connpy.core_plugins.sync.build")
|
||||
@patch("connpy.core_plugins.sync.MediaFileUpload")
|
||||
@patch("connpy.core_plugins.sync.os.path.basename")
|
||||
def test_backup_file_to_drive(self, mock_basename, mock_media, mock_build, mock_get_credentials, mock_connapp):
|
||||
mock_get_credentials.return_value = MagicMock()
|
||||
mock_basename.return_value = "backup.zip"
|
||||
mock_service = MagicMock()
|
||||
mock_build.return_value = mock_service
|
||||
|
||||
s = sync(mock_connapp)
|
||||
assert s.backup_file_to_drive("/fake/backup.zip", 1234567890000) == 0
|
||||
mock_service.files().create.assert_called_once()</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_sync.TestSyncPlugin.test_compress_specific_files"><code class="name flex">
|
||||
<span>def <span class="ident">test_compress_specific_files</span></span>(<span>self, mock_basename, MockZipFile, mock_connapp)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.core_plugins.sync.zipfile.ZipFile")
|
||||
@patch("connpy.core_plugins.sync.os.path.basename")
|
||||
def test_compress_specific_files(self, mock_basename, MockZipFile, mock_connapp):
|
||||
<pre><code class="python">@patch("connpy.services.sync_service.zipfile.ZipFile")
|
||||
@patch("connpy.services.sync_service.os.path.exists")
|
||||
@patch("connpy.services.sync_service.os.path.basename")
|
||||
def test_compress_and_upload_local(self, mock_basename, mock_exists, MockZipFile, mock_config):
|
||||
mock_basename.return_value = "config.yaml"
|
||||
s = sync(mock_connapp)
|
||||
mock_exists.return_value = True
|
||||
s = SyncService(mock_config)
|
||||
|
||||
# Mocking list_backups and upload_file to avoid real API calls
|
||||
s.list_backups = MagicMock(return_value=[])
|
||||
s.upload_file = MagicMock(return_value=True)
|
||||
|
||||
zip_mock = MagicMock()
|
||||
MockZipFile.return_value.__enter__.return_value = zip_mock
|
||||
|
||||
s.compress_specific_files("/fake/zip.zip")
|
||||
zip_mock.write.assert_any_call(s.file, "config.yaml")
|
||||
zip_mock.write.assert_any_call(s.key, ".osk")</code></pre>
|
||||
s.compress_and_upload()
|
||||
# Verify zip was created with local config and key
|
||||
zip_mock.write.assert_any_call(s.config.file, "config.yaml")
|
||||
zip_mock.write.assert_any_call(s.config.key, ".osk")</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_sync.TestSyncPlugin.test_decompress_zip_json_fallback"><code class="name flex">
|
||||
<span>def <span class="ident">test_decompress_zip_json_fallback</span></span>(<span>self, mock_dirname, MockZipFile, mock_connapp)</span>
|
||||
<dt id="connpy.tests.test_sync.TestSyncService.test_get_credentials_not_found"><code class="name flex">
|
||||
<span>def <span class="ident">test_get_credentials_not_found</span></span>(<span>self, mock_exists, mock_config)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.core_plugins.sync.zipfile.ZipFile")
|
||||
@patch("connpy.core_plugins.sync.os.path.dirname")
|
||||
def test_decompress_zip_json_fallback(self, mock_dirname, MockZipFile, mock_connapp):
|
||||
mock_dirname.return_value = "/fake/dir"
|
||||
s = sync(mock_connapp)
|
||||
zip_mock = MagicMock()
|
||||
zip_mock.namelist.return_value = ["config.json", ".osk"]
|
||||
MockZipFile.return_value.__enter__.return_value = zip_mock
|
||||
|
||||
assert s.decompress_zip("/fake/old_zip.zip") == 0
|
||||
zip_mock.extract.assert_any_call("config.json", "/fake/dir")</code></pre>
|
||||
<pre><code class="python">@patch("connpy.services.sync_service.os.path.exists")
|
||||
def test_get_credentials_not_found(self, mock_exists, mock_config):
|
||||
mock_exists.return_value = False
|
||||
s = SyncService(mock_config)
|
||||
assert s.get_credentials() is None</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_sync.TestSyncPlugin.test_decompress_zip_yaml"><code class="name flex">
|
||||
<span>def <span class="ident">test_decompress_zip_yaml</span></span>(<span>self, mock_dirname, MockZipFile, mock_connapp)</span>
|
||||
<dt id="connpy.tests.test_sync.TestSyncService.test_get_credentials_success"><code class="name flex">
|
||||
<span>def <span class="ident">test_get_credentials_success</span></span>(<span>self, MockCreds, mock_exists, mock_config)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.core_plugins.sync.zipfile.ZipFile")
|
||||
@patch("connpy.core_plugins.sync.os.path.dirname")
|
||||
def test_decompress_zip_yaml(self, mock_dirname, MockZipFile, mock_connapp):
|
||||
mock_dirname.return_value = "/fake/dir"
|
||||
s = sync(mock_connapp)
|
||||
zip_mock = MagicMock()
|
||||
zip_mock.namelist.return_value = ["config.yaml", ".osk"]
|
||||
MockZipFile.return_value.__enter__.return_value = zip_mock
|
||||
<pre><code class="python">@patch("connpy.services.sync_service.os.path.exists")
|
||||
@patch("connpy.services.sync_service.Credentials")
|
||||
def test_get_credentials_success(self, MockCreds, mock_exists, mock_config):
|
||||
mock_exists.return_value = True
|
||||
mock_cred_instance = MagicMock()
|
||||
mock_cred_instance.valid = True
|
||||
MockCreds.from_authorized_user_file.return_value = mock_cred_instance
|
||||
|
||||
assert s.decompress_zip("/fake/zip.zip") == 0
|
||||
zip_mock.extract.assert_any_call("config.yaml", "/fake/dir")
|
||||
zip_mock.extract.assert_any_call(".osk", "/fake/dir")</code></pre>
|
||||
s = SyncService(mock_config)
|
||||
creds = s.get_credentials()
|
||||
assert creds == mock_cred_instance</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_sync.TestSyncPlugin.test_get_appdata_files"><code class="name flex">
|
||||
<span>def <span class="ident">test_get_appdata_files</span></span>(<span>self, mock_build, mock_get_credentials, mock_connapp)</span>
|
||||
<dt id="connpy.tests.test_sync.TestSyncService.test_init"><code class="name flex">
|
||||
<span>def <span class="ident">test_init</span></span>(<span>self, mock_config)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch.object(sync, "get_credentials")
|
||||
@patch("connpy.core_plugins.sync.build")
|
||||
def test_get_appdata_files(self, mock_build, mock_get_credentials, mock_connapp):
|
||||
<pre><code class="python">def test_init(self, mock_config):
|
||||
s = SyncService(mock_config)
|
||||
assert s.sync_enabled is True
|
||||
assert s.token_file == os.path.join("/fake/dir", "gtoken.json")</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_sync.TestSyncService.test_list_backups"><code class="name flex">
|
||||
<span>def <span class="ident">test_list_backups</span></span>(<span>self, mock_build, mock_get_credentials, mock_config)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch.object(SyncService, "get_credentials")
|
||||
@patch("connpy.services.sync_service.build")
|
||||
def test_list_backups(self, mock_build, mock_get_credentials, mock_config):
|
||||
mock_get_credentials.return_value = MagicMock()
|
||||
mock_service = MagicMock()
|
||||
mock_build.return_value = mock_service
|
||||
@@ -287,65 +273,45 @@ def test_get_appdata_files(self, mock_build, mock_get_credentials, mock_connapp)
|
||||
]
|
||||
}
|
||||
|
||||
s = sync(mock_connapp)
|
||||
files = s.get_appdata_files()
|
||||
s = SyncService(mock_config)
|
||||
files = s.list_backups()
|
||||
assert len(files) == 1
|
||||
assert files[0]["id"] == "1"
|
||||
assert files[0]["timestamp"] == "1000"</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_sync.TestSyncPlugin.test_get_credentials_not_found"><code class="name flex">
|
||||
<span>def <span class="ident">test_get_credentials_not_found</span></span>(<span>self, mock_exists, mock_connapp)</span>
|
||||
<dt id="connpy.tests.test_sync.TestSyncService.test_perform_restore"><code class="name flex">
|
||||
<span>def <span class="ident">test_perform_restore</span></span>(<span>self, mock_remove, mock_dirname, mock_exists, MockZipFile, mock_config)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.core_plugins.sync.os.path.exists")
|
||||
def test_get_credentials_not_found(self, mock_exists, mock_connapp):
|
||||
mock_exists.return_value = False
|
||||
s = sync(mock_connapp)
|
||||
assert s.get_credentials() == 0</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_sync.TestSyncPlugin.test_get_credentials_success"><code class="name flex">
|
||||
<span>def <span class="ident">test_get_credentials_success</span></span>(<span>self, MockCreds, mock_exists, mock_connapp)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">@patch("connpy.core_plugins.sync.os.path.exists")
|
||||
@patch("connpy.core_plugins.sync.Credentials")
|
||||
def test_get_credentials_success(self, MockCreds, mock_exists, mock_connapp):
|
||||
mock_exists.return_value = True
|
||||
mock_cred_instance = MagicMock()
|
||||
mock_cred_instance.valid = True
|
||||
MockCreds.from_authorized_user_file.return_value = mock_cred_instance
|
||||
<pre><code class="python">@patch("connpy.services.sync_service.zipfile.ZipFile")
|
||||
@patch("connpy.services.sync_service.os.path.exists")
|
||||
@patch("connpy.services.sync_service.os.path.dirname")
|
||||
@patch("connpy.services.sync_service.os.remove")
|
||||
def test_perform_restore(self, mock_remove, mock_dirname, mock_exists, MockZipFile, mock_config):
|
||||
mock_dirname.return_value = "/fake/dir"
|
||||
# Mock exists to return True for key and zip, but False for caches during the cleanup phase
|
||||
def exists_side_effect(path):
|
||||
if ".cache" in path or ".fzf_cache" in path:
|
||||
return False
|
||||
return True
|
||||
mock_exists.side_effect = exists_side_effect
|
||||
|
||||
s = sync(mock_connapp)
|
||||
creds = s.get_credentials()
|
||||
assert creds == mock_cred_instance</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
<dt id="connpy.tests.test_sync.TestSyncPlugin.test_init"><code class="name flex">
|
||||
<span>def <span class="ident">test_init</span></span>(<span>self, mock_connapp)</span>
|
||||
</code></dt>
|
||||
<dd>
|
||||
<details class="source">
|
||||
<summary>
|
||||
<span>Expand source code</span>
|
||||
</summary>
|
||||
<pre><code class="python">def test_init(self, mock_connapp):
|
||||
s = sync(mock_connapp)
|
||||
assert s.sync is True
|
||||
assert s.file == "/fake/dir/config.yaml"
|
||||
assert s.token_file == "/fake/dir/gtoken.json"</code></pre>
|
||||
s = SyncService(mock_config)
|
||||
zip_mock = MagicMock()
|
||||
zip_mock.namelist.return_value = ["config.yaml", ".osk"]
|
||||
MockZipFile.return_value.__enter__.return_value = zip_mock
|
||||
|
||||
with patch("connpy.services.sync_service.yaml.safe_load") as mock_load:
|
||||
mock_load.return_value = {"connections": {}, "profiles": {}, "config": {}}
|
||||
assert s.perform_restore("/fake/zip.zip") is True
|
||||
|
||||
zip_mock.extract.assert_any_call(".osk", "/fake/dir")</code></pre>
|
||||
</details>
|
||||
<div class="desc"></div>
|
||||
</dd>
|
||||
@@ -366,22 +332,20 @@ def test_get_credentials_success(self, MockCreds, mock_exists, mock_connapp):
|
||||
</li>
|
||||
<li><h3><a href="#header-functions">Functions</a></h3>
|
||||
<ul class="">
|
||||
<li><code><a title="connpy.tests.test_sync.mock_connapp" href="#connpy.tests.test_sync.mock_connapp">mock_connapp</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_sync.mock_config" href="#connpy.tests.test_sync.mock_config">mock_config</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><h3><a href="#header-classes">Classes</a></h3>
|
||||
<ul>
|
||||
<li>
|
||||
<h4><code><a title="connpy.tests.test_sync.TestSyncPlugin" href="#connpy.tests.test_sync.TestSyncPlugin">TestSyncPlugin</a></code></h4>
|
||||
<h4><code><a title="connpy.tests.test_sync.TestSyncService" href="#connpy.tests.test_sync.TestSyncService">TestSyncService</a></code></h4>
|
||||
<ul class="">
|
||||
<li><code><a title="connpy.tests.test_sync.TestSyncPlugin.test_backup_file_to_drive" href="#connpy.tests.test_sync.TestSyncPlugin.test_backup_file_to_drive">test_backup_file_to_drive</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_sync.TestSyncPlugin.test_compress_specific_files" href="#connpy.tests.test_sync.TestSyncPlugin.test_compress_specific_files">test_compress_specific_files</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_sync.TestSyncPlugin.test_decompress_zip_json_fallback" href="#connpy.tests.test_sync.TestSyncPlugin.test_decompress_zip_json_fallback">test_decompress_zip_json_fallback</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_sync.TestSyncPlugin.test_decompress_zip_yaml" href="#connpy.tests.test_sync.TestSyncPlugin.test_decompress_zip_yaml">test_decompress_zip_yaml</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_sync.TestSyncPlugin.test_get_appdata_files" href="#connpy.tests.test_sync.TestSyncPlugin.test_get_appdata_files">test_get_appdata_files</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_sync.TestSyncPlugin.test_get_credentials_not_found" href="#connpy.tests.test_sync.TestSyncPlugin.test_get_credentials_not_found">test_get_credentials_not_found</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_sync.TestSyncPlugin.test_get_credentials_success" href="#connpy.tests.test_sync.TestSyncPlugin.test_get_credentials_success">test_get_credentials_success</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_sync.TestSyncPlugin.test_init" href="#connpy.tests.test_sync.TestSyncPlugin.test_init">test_init</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_sync.TestSyncService.test_compress_and_upload_local" href="#connpy.tests.test_sync.TestSyncService.test_compress_and_upload_local">test_compress_and_upload_local</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_sync.TestSyncService.test_get_credentials_not_found" href="#connpy.tests.test_sync.TestSyncService.test_get_credentials_not_found">test_get_credentials_not_found</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_sync.TestSyncService.test_get_credentials_success" href="#connpy.tests.test_sync.TestSyncService.test_get_credentials_success">test_get_credentials_success</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_sync.TestSyncService.test_init" href="#connpy.tests.test_sync.TestSyncService.test_init">test_init</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_sync.TestSyncService.test_list_backups" href="#connpy.tests.test_sync.TestSyncService.test_list_backups">test_list_backups</a></code></li>
|
||||
<li><code><a title="connpy.tests.test_sync.TestSyncService.test_perform_restore" href="#connpy.tests.test_sync.TestSyncService.test_perform_restore">test_perform_restore</a></code></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
Reference in new issue
Block a user