feat: major architectural refactor to 5.1b1 - Service Layer, gRPC & Agent evolution (fragmented secrets)

This commit is contained in:
fluzzi32 committed 2026-04-17 18:42:08 -03:00
1 parent 85b23526cd
commit cb926c2b85
123 files changed
+38189 -4640

No files matched your search

+24 -9
View File
@@ -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>
+25 -21
View File
@@ -63,11 +63,13 @@ el.replaceWith(d);
assert myai.engineer_model == &#34;test/test-model&#34;
assert myai.architect_model == &#34;test/test-architect&#34;
def test_init_missing_engineer_key(self, config):
&#34;&#34;&#34;Raises ValueError if engineer key is missing.&#34;&#34;&#34;
def test_ask_missing_engineer_key(self, config):
&#34;&#34;&#34;Raises ValueError if engineer key is missing when asking.&#34;&#34;&#34;
from connpy.ai import ai
with pytest.raises(ValueError, match=&#34;Engineer API key&#34;):
ai(config)
myai = ai(config)
with pytest.raises(ValueError) as exc:
myai.ask(&#34;hello&#34;)
assert &#34;Engineer API key not configured&#34; in str(exc.value)
def test_init_missing_architect_key_warns(self, ai_config, capsys, mock_litellm):
&#34;&#34;&#34;Warns if architect key is missing but doesn&#39;t crash.&#34;&#34;&#34;
@@ -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):
&#34;&#34;&#34;Raises ValueError if engineer key is missing when asking.&#34;&#34;&#34;
from connpy.ai import ai
myai = ai(config)
with pytest.raises(ValueError) as exc:
myai.ask(&#34;hello&#34;)
assert &#34;Engineer API key not configured&#34; 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):
&#34;&#34;&#34;Raises ValueError if engineer key is missing.&#34;&#34;&#34;
from connpy.ai import ai
with pytest.raises(ValueError, match=&#34;Engineer API key&#34;):
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>
+72 -56
View File
@@ -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 = [&#34;test_node&#34;]
app.config.getitem.return_value = {&#34;host&#34;: &#34;127.0.0.1&#34;, &#34;protocol&#34;: &#34;ssh&#34;}
app.services.nodes.list_nodes.return_value = [&#34;test_node&#34;]
app.services.nodes.get_node_details.return_value = {&#34;host&#34;: &#34;127.0.0.1&#34;, &#34;protocol&#34;: &#34;ssh&#34;}
app.services.config_svc.get_settings().get.return_value = &#34;/fake/ws&#34;
mock_node = MagicMock()
mock_node.protocol = &#34;ssh&#34;
mock_node.unique = &#34;test_node&#34;
app.node.return_value = mock_node
app.config.config = {&#34;wireshark_path&#34;: &#34;/fake/ws&#34;}
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 = [&#34;other_node&#34;]
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, &#34;test_node&#34;, &#34;eth0&#34;)
assert exc.value.code == 2
def test_init_success(self, mock_connapp):
def test_init_success(self, mock_connapp, RemoteCapture):
rc = RemoteCapture(mock_connapp, &#34;test_node&#34;, &#34;eth0&#34;)
assert rc.node_name == &#34;test_node&#34;
assert rc.interface == &#34;eth0&#34;
assert rc.wireshark_path == &#34;/fake/ws&#34;
@patch(&#34;connpy.core_plugins.capture.socket&#34;)
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, &#34;test_node&#34;, &#34;eth0&#34;)
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(&#34;socket.socket&#34;) 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, &#34;_is_port_in_use&#34;)
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, &#34;test_node&#34;, &#34;eth0&#34;)
with patch.object(RemoteCapture, &#34;_is_port_in_use&#34;) 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 &lt;= port &lt;= 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, &#34;test_node&#34;, &#34;eth0&#34;)
with patch.object(RemoteCapture, &#34;_is_port_in_use&#34;) 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, &#34;_is_port_in_use&#34;)
def test_find_free_port(self, mock_is_in_use, mock_connapp):
rc = RemoteCapture(mock_connapp, &#34;test_node&#34;, &#34;eth0&#34;)
# 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 &lt;= port &lt;= 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 = [&#34;other_node&#34;]
<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, &#34;test_node&#34;, &#34;eth0&#34;)
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, &#34;test_node&#34;, &#34;eth0&#34;)
assert rc.node_name == &#34;test_node&#34;
assert rc.interface == &#34;eth0&#34;
@@ -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(&#34;connpy.core_plugins.capture.socket&#34;)
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, &#34;test_node&#34;, &#34;eth0&#34;)
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(&#34;socket.socket&#34;) 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>
+6 -182
View File
@@ -64,7 +64,7 @@ el.replaceWith(d);
subdir = tmp_path / &#34;subdir&#34;
subdir.mkdir()
result = _getcwd([&#34;run&#34;, &#34;run&#34;], &#34;run&#34;)
result = get_cwd([&#34;run&#34;, &#34;run&#34;])
# Should list files
assert any(&#34;file1.txt&#34; in r for r in result)
assert any(&#34;subdir/&#34; in r for r in result)
@@ -75,7 +75,7 @@ el.replaceWith(d);
(tmp_path / &#34;script.yaml&#34;).touch()
(tmp_path / &#34;script2.yaml&#34;).touch()
result = _getcwd([&#34;run&#34;, &#34;script&#34;], &#34;run&#34;)
result = get_cwd([&#34;run&#34;, &#34;script&#34;])
assert any(&#34;script&#34; in r for r in result)
def test_folder_only(self, tmp_path, monkeypatch):
@@ -85,7 +85,7 @@ el.replaceWith(d);
subdir = tmp_path / &#34;mydir&#34;
subdir.mkdir()
result = _getcwd([&#34;export&#34;, &#34;export&#34;], &#34;export&#34;, folderonly=True)
result = get_cwd([&#34;export&#34;, &#34;export&#34;], folderonly=True)
files_in_result = [r for r in result if &#34;file.txt&#34; in r]
assert len(files_in_result) == 0
dirs_in_result = [r for r in result if &#34;mydir&#34; in r]
@@ -110,7 +110,7 @@ el.replaceWith(d);
subdir = tmp_path / &#34;subdir&#34;
subdir.mkdir()
result = _getcwd([&#34;run&#34;, &#34;run&#34;], &#34;run&#34;)
result = get_cwd([&#34;run&#34;, &#34;run&#34;])
# Should list files
assert any(&#34;file1.txt&#34; in r for r in result)
assert any(&#34;subdir/&#34; in r for r in result)</code></pre>
@@ -132,7 +132,7 @@ el.replaceWith(d);
subdir = tmp_path / &#34;mydir&#34;
subdir.mkdir()
result = _getcwd([&#34;export&#34;, &#34;export&#34;], &#34;export&#34;, folderonly=True)
result = get_cwd([&#34;export&#34;, &#34;export&#34;], folderonly=True)
files_in_result = [r for r in result if &#34;file.txt&#34; in r]
assert len(files_in_result) == 0
dirs_in_result = [r for r in result if &#34;mydir&#34; in r]
@@ -154,179 +154,13 @@ el.replaceWith(d);
(tmp_path / &#34;script.yaml&#34;).touch()
(tmp_path / &#34;script2.yaml&#34;).touch()
result = _getcwd([&#34;run&#34;, &#34;script&#34;], &#34;run&#34;)
result = get_cwd([&#34;run&#34;, &#34;script&#34;])
assert any(&#34;script&#34; 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):
&#34;&#34;&#34;--disable returns enabled plugins.&#34;&#34;&#34;
plugin_dir = tmp_path / &#34;plugins&#34;
plugin_dir.mkdir()
(plugin_dir / &#34;active.py&#34;).touch()
(plugin_dir / &#34;disabled.py.bkp&#34;).touch()
result = _get_plugins(&#34;--disable&#34;, str(tmp_path))
assert &#34;active&#34; in result
assert &#34;disabled&#34; not in result
def test_get_plugins_enable(self, tmp_path):
&#34;&#34;&#34;--enable returns disabled plugins.&#34;&#34;&#34;
plugin_dir = tmp_path / &#34;plugins&#34;
plugin_dir.mkdir()
(plugin_dir / &#34;active.py&#34;).touch()
(plugin_dir / &#34;disabled.py.bkp&#34;).touch()
result = _get_plugins(&#34;--enable&#34;, str(tmp_path))
assert &#34;disabled&#34; in result
assert &#34;active&#34; not in result
def test_get_plugins_del(self, tmp_path):
&#34;&#34;&#34;--del returns all plugins.&#34;&#34;&#34;
plugin_dir = tmp_path / &#34;plugins&#34;
plugin_dir.mkdir()
(plugin_dir / &#34;active.py&#34;).touch()
(plugin_dir / &#34;disabled.py.bkp&#34;).touch()
result = _get_plugins(&#34;--del&#34;, str(tmp_path))
assert &#34;active&#34; in result
assert &#34;disabled&#34; in result
def test_get_plugins_all(self, tmp_path):
&#34;&#34;&#34;&#39;all&#39; returns dict with paths.&#34;&#34;&#34;
plugin_dir = tmp_path / &#34;plugins&#34;
plugin_dir.mkdir()
(plugin_dir / &#34;myplugin.py&#34;).touch()
result = _get_plugins(&#34;all&#34;, str(tmp_path))
assert isinstance(result, dict)
assert &#34;myplugin&#34; in result
def test_get_plugins_empty_dir(self, tmp_path):
&#34;&#34;&#34;Empty plugins directory returns empty list.&#34;&#34;&#34;
plugin_dir = tmp_path / &#34;plugins&#34;
plugin_dir.mkdir()
result = _get_plugins(&#34;--disable&#34;, 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):
&#34;&#34;&#34;&#39;all&#39; returns dict with paths.&#34;&#34;&#34;
plugin_dir = tmp_path / &#34;plugins&#34;
plugin_dir.mkdir()
(plugin_dir / &#34;myplugin.py&#34;).touch()
result = _get_plugins(&#34;all&#34;, str(tmp_path))
assert isinstance(result, dict)
assert &#34;myplugin&#34; 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):
&#34;&#34;&#34;--del returns all plugins.&#34;&#34;&#34;
plugin_dir = tmp_path / &#34;plugins&#34;
plugin_dir.mkdir()
(plugin_dir / &#34;active.py&#34;).touch()
(plugin_dir / &#34;disabled.py.bkp&#34;).touch()
result = _get_plugins(&#34;--del&#34;, str(tmp_path))
assert &#34;active&#34; in result
assert &#34;disabled&#34; in result</code></pre>
</details>
<div class="desc"><p>&ndash;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):
&#34;&#34;&#34;--disable returns enabled plugins.&#34;&#34;&#34;
plugin_dir = tmp_path / &#34;plugins&#34;
plugin_dir.mkdir()
(plugin_dir / &#34;active.py&#34;).touch()
(plugin_dir / &#34;disabled.py.bkp&#34;).touch()
result = _get_plugins(&#34;--disable&#34;, str(tmp_path))
assert &#34;active&#34; in result
assert &#34;disabled&#34; not in result</code></pre>
</details>
<div class="desc"><p>&ndash;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):
&#34;&#34;&#34;Empty plugins directory returns empty list.&#34;&#34;&#34;
plugin_dir = tmp_path / &#34;plugins&#34;
plugin_dir.mkdir()
result = _get_plugins(&#34;--disable&#34;, 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):
&#34;&#34;&#34;--enable returns disabled plugins.&#34;&#34;&#34;
plugin_dir = tmp_path / &#34;plugins&#34;
plugin_dir.mkdir()
(plugin_dir / &#34;active.py&#34;).touch()
(plugin_dir / &#34;disabled.py.bkp&#34;).touch()
result = _get_plugins(&#34;--enable&#34;, str(tmp_path))
assert &#34;disabled&#34; in result
assert &#34;active&#34; not in result</code></pre>
</details>
<div class="desc"><p>&ndash;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>
+5 -3
View File
@@ -1140,8 +1140,9 @@ el.replaceWith(d);
assert &#34;server1@office&#34; 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>
+705
View File
@@ -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):
&#34;&#34;&#34;Returns an instance of connapp initialized with the mock config.&#34;&#34;&#34;
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(&#34;connpy.services.ai_service.AIService.ask&#34;)
@patch(&#34;connpy.connapp.console.status&#34;)
def test_ai(mock_status, mock_ask, app):
mock_ask.return_value = {&#34;response&#34;: &#34;AI output&#34;, &#34;usage&#34;: {&#34;total&#34;: 10, &#34;input&#34;: 5, &#34;output&#34;: 5}}
app.start([&#34;ai&#34;, &#34;--engineer-api-key&#34;, &#34;testkey&#34;, &#34;how are you&#34;])
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(&#34;connpy.services.ai_service.AIService.list_sessions&#34;)
def test_ai_list(mock_list_sessions, app):
mock_list_sessions.return_value = [{&#34;id&#34;: &#34;1&#34;, &#34;title&#34;: &#34;t&#34;, &#34;created_at&#34;: &#34;now&#34;, &#34;model&#34;: &#34;m&#34;}]
app.start([&#34;ai&#34;, &#34;--list&#34;])
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(&#34;connpy.services.system_service.SystemService.get_api_status&#34;)
def test_api_debug(mock_status, app):
mock_status.return_value = {&#34;running&#34;: False}
app.services.system.debug_api = MagicMock()
app.start([&#34;api&#34;, &#34;-d&#34;, &#34;8080&#34;])
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(&#34;connpy.services.system_service.SystemService.get_api_status&#34;)
def test_api_start(mock_status, app):
mock_status.return_value = {&#34;running&#34;: False}
app.services.system.start_api = MagicMock()
app.start([&#34;api&#34;, &#34;-s&#34;, &#34;8080&#34;])
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(&#34;connpy.services.system_service.SystemService.get_api_status&#34;)
def test_api_stop(mock_status, app):
mock_status.return_value = {&#34;running&#34;: True, &#34;pid&#34;: &#34;1234&#34;}
app.services.system.stop_api = MagicMock(return_value=True)
app.start([&#34;api&#34;, &#34;-x&#34;])
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(&#34;connpy.cli.forms.Forms.questions_bulk&#34;)
@patch(&#34;connpy.services.node_service.NodeService.bulk_add&#34;)
def test_bulk(mock_bulk_add, mock_q_bulk, app):
mock_q_bulk.return_value = {&#34;ids&#34;: &#34;node1&#34;, &#34;host&#34;: &#34;host1&#34;, &#34;location&#34;: &#34;&#34;}
mock_bulk_add.return_value = 1
app.start([&#34;bulk&#34;])
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(&#34;connpy.services.config_service.ConfigService.update_setting&#34;)
def test_config(mock_update_setting, app):
app.start([&#34;config&#34;, &#34;--allow-uppercase&#34;, &#34;true&#34;])
mock_update_setting.assert_called_with(&#34;case&#34;, 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(&#34;connpy.services.config_service.ConfigService.set_config_folder&#34;)
def test_config_folder(mock_set_config_folder, app):
app.start([&#34;config&#34;, &#34;--configfolder&#34;, &#34;/new/path&#34;])
mock_set_config_folder.assert_called_once_with(&#34;/new/path&#34;)</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(&#34;connpy.services.config_service.ConfigService.update_setting&#34;)
def test_config_various(mock_update_setting, app):
app.start([&#34;config&#34;, &#34;--fzf&#34;, &#34;true&#34;])
mock_update_setting.assert_called_with(&#34;fzf&#34;, True)
app.start([&#34;config&#34;, &#34;--keepalive&#34;, &#34;60&#34;])
mock_update_setting.assert_called_with(&#34;idletime&#34;, 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):
&#34;&#34;&#34;Test that connapp initializes correctly with config.&#34;&#34;&#34;
assert app.config == populated_config
assert app.case == populated_config.config.get(&#34;case&#34;, 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(&#34;connpy.services.node_service.NodeService.move_node&#34;)
def test_copy(mock_move_node, app):
app.start([&#34;copy&#34;, &#34;src_node&#34;, &#34;dst_node&#34;])
mock_move_node.assert_called_once_with(&#34;src_node&#34;, &#34;dst_node&#34;, 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(&#34;connpy.services.import_export_service.ImportExportService.export_to_file&#34;)
def test_export(mock_export, app):
with pytest.raises(SystemExit):
app.start([&#34;export&#34;, &#34;file.yml&#34;, &#34;@folder1&#34;])
mock_export.assert_called_once_with(&#34;file.yml&#34;, folders=[&#34;@folder1&#34;])</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(&#34;os.path.exists&#34;)
@patch(&#34;inquirer.prompt&#34;)
@patch(&#34;connpy.services.import_export_service.ImportExportService.import_from_file&#34;)
def test_import(mock_import, mock_prompt, mock_exists, app):
mock_exists.return_value = True
mock_prompt.return_value = {&#34;import&#34;: True}
app.start([&#34;import&#34;, &#34;file.yml&#34;])
mock_import.assert_called_once_with(&#34;file.yml&#34;)</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(&#34;connpy.services.node_service.NodeService.list_folders&#34;)
def test_list_folders(mock_list_folders, app):
mock_list_folders.return_value = [&#34;folder1&#34;]
app.start([&#34;list&#34;, &#34;folders&#34;])
# Called during init and during the list command
assert mock_list_folders.call_count &gt;= 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(&#34;connpy.services.node_service.NodeService.move_node&#34;)
def test_move(mock_move_node, app):
app.start([&#34;move&#34;, &#34;src_node&#34;, &#34;dst_node&#34;])
mock_move_node.assert_called_once_with(&#34;src_node&#34;, &#34;dst_node&#34;, 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(&#34;connpy.cli.node_handler.NodeHandler.dispatch&#34;)
def test_node_add(mock_func_node, app):
&#34;&#34;&#34;Test that &#39;node -a&#39; command correctly parses.&#34;&#34;&#34;
app.start([&#34;node&#34;, &#34;-a&#34;, &#34;new_router&#34;])
mock_func_node.assert_called_once()
args = mock_func_node.call_args[0][0]
assert args.data == &#34;new_router&#34;
assert args.action == &#34;add&#34;</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(&#34;connpy.cli.node_handler.NodeHandler.dispatch&#34;)
def test_node_default(mock_func_node, app):
&#34;&#34;&#34;Test that default &#39;node&#39; command correctly parses and calls _func_node.&#34;&#34;&#34;
app.start([&#34;node&#34;, &#34;router1&#34;])
mock_func_node.assert_called_once()
args = mock_func_node.call_args[0][0]
assert args.data == &#34;router1&#34;
assert args.action == &#34;connect&#34;</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(&#34;connpy.services.node_service.NodeService.list_nodes&#34;)
@patch(&#34;connpy.services.node_service.NodeService.delete_node&#34;)
@patch(&#34;inquirer.prompt&#34;)
def test_node_del(mock_prompt, mock_delete_node, mock_list_nodes, app):
mock_list_nodes.return_value = [&#34;router1&#34;]
mock_prompt.return_value = {&#34;delete&#34;: True}
app.start([&#34;node&#34;, &#34;-r&#34;, &#34;router1&#34;])
mock_delete_node.assert_called_once_with(&#34;router1&#34;, 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(&#34;connpy.services.node_service.NodeService.list_nodes&#34;)
def test_node_list(mock_list_nodes, app):
&#34;&#34;&#34;Test &#39;list nodes&#39; invokes node service.&#34;&#34;&#34;
mock_list_nodes.return_value = [&#34;router1&#34;, &#34;server1&#34;]
app.start([&#34;list&#34;, &#34;nodes&#34;])
# Should be called during init and during the list command
assert mock_list_nodes.call_count &gt;= 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(&#34;connpy.services.node_service.NodeService.list_nodes&#34;)
@patch(&#34;connpy.services.node_service.NodeService.get_node_details&#34;)
@patch(&#34;connpy.services.node_service.NodeService.update_node&#34;)
@patch(&#34;connpy.cli.forms.Forms.questions_edit&#34;)
@patch(&#34;connpy.cli.forms.Forms.questions_nodes&#34;)
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 = [&#34;router1&#34;]
mock_get_details.return_value = {&#34;host&#34;: &#34;1.1.1.1&#34;, &#34;port&#34;: 22}
mock_q_edit.return_value = {&#34;host&#34;: True}
mock_q_nodes.return_value = {&#34;host&#34;: &#34;2.2.2.2&#34;, &#34;port&#34;: 22}
app.start([&#34;node&#34;, &#34;-e&#34;, &#34;router1&#34;])
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(&#34;connpy.printer.data&#34;)
def test_node_show(mock_data, app):
app.nodes_list = [&#34;router1&#34;]
app.config.getitem = MagicMock(return_value={&#34;host&#34;: &#34;1.1.1.1&#34;})
app.start([&#34;node&#34;, &#34;-s&#34;, &#34;router1&#34;])
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(&#34;os.path.exists&#34;)
@patch(&#34;shutil.copy2&#34;)
@patch(&#34;connpy.plugins.Plugins.verify_script&#34;)
def test_plugin_add(mock_verify, mock_copy, mock_exists, app):
def mock_exists_side_effect(path):
if &#34;testplug.py&#34; in path: return False
if &#34;testplug.py.bkp&#34; in path: return False
if &#34;file.py&#34; in path: return True
return True
mock_exists.side_effect = mock_exists_side_effect
mock_verify.return_value = None
app.commands = []
app.start([&#34;plugin&#34;, &#34;--add&#34;, &#34;testplug&#34;, &#34;file.py&#34;])
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(&#34;connpy.services.plugin_service.PluginService.delete_plugin&#34;)
def test_plugin_delete(mock_delete, app):
app.start([&#34;plugin&#34;, &#34;--del&#34;, &#34;testplug&#34;])
mock_delete.assert_called_once_with(&#34;testplug&#34;)</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(&#34;connpy.services.plugin_service.PluginService.disable_plugin&#34;)
def test_plugin_disable(mock_disable, app):
app.start([&#34;plugin&#34;, &#34;--disable&#34;, &#34;testplug&#34;])
mock_disable.assert_called_once_with(&#34;testplug&#34;)</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(&#34;connpy.services.plugin_service.PluginService.enable_plugin&#34;)
def test_plugin_enable(mock_enable, app):
app.start([&#34;plugin&#34;, &#34;--enable&#34;, &#34;testplug&#34;])
mock_enable.assert_called_once_with(&#34;testplug&#34;)</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(&#34;connpy.services.plugin_service.PluginService.list_plugins&#34;)
def test_plugin_list(mock_list_plugins, app):
mock_list_plugins.return_value = {&#34;testplug&#34;: {&#34;enabled&#34;: True}}
app.start([&#34;plugin&#34;, &#34;--list&#34;])
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(&#34;connpy.services.profile_service.ProfileService.list_profiles&#34;)
@patch(&#34;connpy.services.profile_service.ProfileService.add_profile&#34;)
@patch(&#34;connpy.cli.forms.Forms.questions_profiles&#34;)
def test_profile_add(mock_q_profiles, mock_add_profile, mock_list_profiles, app):
mock_list_profiles.return_value = [&#34;default&#34;]
mock_q_profiles.return_value = {&#34;host&#34;: &#34;test&#34;}
app.start([&#34;profile&#34;, &#34;-a&#34;, &#34;new_profile&#34;])
mock_add_profile.assert_called_once_with(&#34;new_profile&#34;, {&#34;host&#34;: &#34;test&#34;})</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(&#34;connpy.services.profile_service.ProfileService.get_profile&#34;)
@patch(&#34;connpy.services.profile_service.ProfileService.delete_profile&#34;)
@patch(&#34;inquirer.prompt&#34;)
def test_profile_del(mock_prompt, mock_delete_profile, mock_get_profile, app):
mock_get_profile.return_value = {&#34;host&#34;: &#34;test&#34;}
mock_prompt.return_value = {&#34;delete&#34;: True}
app.start([&#34;profile&#34;, &#34;-r&#34;, &#34;test_profile&#34;])
mock_delete_profile.assert_called_once_with(&#34;test_profile&#34;)</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(&#34;connpy.services.profile_service.ProfileService.list_profiles&#34;)
@patch(&#34;connpy.connapp.printer.console.print&#34;)
def test_profile_list(mock_print, mock_list_profiles, app):
&#34;&#34;&#34;Test &#39;profile list&#39; invokes profile service correctly.&#34;&#34;&#34;
mock_list_profiles.return_value = [&#34;default&#34;, &#34;office-user&#34;]
app.start([&#34;list&#34;, &#34;profiles&#34;])
assert mock_list_profiles.call_count &gt;= 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(&#34;connpy.services.profile_service.ProfileService.get_profile&#34;)
@patch(&#34;connpy.services.profile_service.ProfileService.update_profile&#34;)
@patch(&#34;connpy.cli.forms.Forms.questions_edit&#34;)
@patch(&#34;connpy.cli.forms.Forms.questions_profiles&#34;)
def test_profile_mod(mock_q_profiles, mock_q_edit, mock_update_profile, mock_get_profile, app):
mock_get_profile.return_value = {&#34;host&#34;: &#34;test&#34;, &#34;port&#34;: 22}
mock_q_edit.return_value = {&#34;host&#34;: True}
mock_q_profiles.return_value = {&#34;id&#34;: &#34;test_profile&#34;, &#34;host&#34;: &#34;new_host&#34;, &#34;port&#34;: 22}
app.start([&#34;profile&#34;, &#34;-e&#34;, &#34;test_profile&#34;])
mock_update_profile.assert_called_once_with(&#34;test_profile&#34;, {&#34;id&#34;: &#34;test_profile&#34;, &#34;host&#34;: &#34;new_host&#34;, &#34;port&#34;: 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(&#34;connpy.services.profile_service.ProfileService.get_profile&#34;)
@patch(&#34;connpy.printer.data&#34;)
def test_profile_show(mock_data, mock_get_profile, app):
mock_get_profile.return_value = {&#34;host&#34;: &#34;test&#34;}
app.start([&#34;profile&#34;, &#34;-s&#34;, &#34;test_profile&#34;])
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(&#34;connpy.services.execution_service.ExecutionService.run_commands&#34;)
def test_run(mock_run_commands, app):
app.start([&#34;run&#34;, &#34;node1&#34;, &#34;command1&#34;, &#34;command2&#34;])
mock_run_commands.assert_called_once()
assert mock_run_commands.call_args[1][&#34;nodes_filter&#34;] == &#34;node1&#34;
assert mock_run_commands.call_args[1][&#34;commands&#34;] == [&#34;command1 command2&#34;]</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 = [&#34;bulk&#34;, &#34;ai&#34;, &#34;run&#34;]
with patch(&#34;sys.argv&#34;, [&#34;connpy&#34;, &#34;node&#34;, &#34;-a&#34;, &#34;bulk&#34;]):
with pytest.raises(SystemExit) as exc:
app._type_node(&#34;bulk&#34;)
assert exc.value.code == 2
# In move/copy it also raises because destination cannot be reserved
with patch(&#34;sys.argv&#34;, [&#34;connpy&#34;, &#34;mv&#34;, &#34;test1&#34;, &#34;bulk&#34;]):
with pytest.raises(SystemExit) as exc:
app._type_node(&#34;bulk&#34;)
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>
+5 -3
View File
@@ -115,8 +115,9 @@ el.replaceWith(d);
def test_invalid_protocol_raises(self):
n = self._make_node(protocol=&#34;invalid_proto&#34;)
with pytest.raises(ValueError, match=&#34;Invalid protocol&#34;):
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=&#34;&#34;)
@@ -155,8 +156,9 @@ el.replaceWith(d);
</summary>
<pre><code class="python">def test_invalid_protocol_raises(self):
n = self._make_node(protocol=&#34;invalid_proto&#34;)
with pytest.raises(ValueError, match=&#34;Invalid protocol&#34;):
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):
&#34;&#34;&#34;Test that run_commands correctly passes on_node_complete to the executor.&#34;&#34;&#34;
service = ExecutionService(populated_config)
# Mock the Nodes class in connpy.services.execution_service
with patch(&#34;connpy.services.execution_service.Nodes&#34;) as MockNodes:
mock_executor = MockNodes.return_value
mock_executor.run.return_value = {&#34;router1&#34;: &#34;output&#34;}
callback = MagicMock()
service.run_commands(
nodes_filter=&#34;router1&#34;,
commands=[&#34;show version&#34;],
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[&#34;on_complete&#34;] == 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):
&#34;&#34;&#34;
Test that test_commands correctly passes on_node_complete to the executor.
Regression: ExecutionService.test_commands currently ignores on_node_complete.
&#34;&#34;&#34;
service = ExecutionService(populated_config)
with patch(&#34;connpy.services.execution_service.Nodes&#34;) as MockNodes:
mock_executor = MockNodes.return_value
mock_executor.test.return_value = {&#34;router1&#34;: {&#34;PASS&#34;: True}}
callback = MagicMock()
service.test_commands(
nodes_filter=&#34;router1&#34;,
commands=[&#34;show version&#34;],
expected=[&#34;12.4&#34;],
on_node_complete=callback
)
# This is expected to FAIL because ExecutionService.test_commands
# doesn&#39;t pass on_complete to executor.test
MockNodes.return_value.test.assert_called_once()
args, kwargs = MockNodes.return_value.test.call_args
# We expect &#39;on_complete&#39; to be in kwargs and equal to our callback
assert &#34;on_complete&#34; in kwargs, &#34;on_complete parameter missing in call to executor.test&#34;
assert kwargs[&#34;on_complete&#34;] == 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>
+184
View File
@@ -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):
&#34;&#34;&#34;Test that filtering respects the case setting in config.&#34;&#34;&#34;
service = NodeService(populated_config)
# Default case is False (case-insensitive)
nodes = service.list_nodes(filter_str=&#34;ROUTER&#34;)
assert &#34;router1&#34; 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):
&#34;&#34;&#34;
Test that list_nodes supports dynamic formatting for any node attribute.
Regression: NodeService currently has hardcoded support for name, location, host.
&#34;&#34;&#34;
service = NodeService(populated_config)
# Try to format using &#39;user&#39; and &#39;protocol&#39; which are NOT in the hardcoded list
# (name, location, host)
format_str = &#34;{name} -&gt; {user}@{host} ({protocol})&#34;
# router1: host=10.0.0.1, user=admin, protocol=ssh
# Expected: &#34;router1 -&gt; admin@10.0.0.1 (ssh)&#34;
formatted = service.list_nodes(filter_str=&#34;router1&#34;, format_str=format_str)
assert len(formatted) == 1
# This will FAIL if it only supports {name}, {location}, {host}
assert formatted[0] == &#34;router1 -&gt; admin@10.0.0.1 (ssh)&#34;</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):
&#34;&#34;&#34;
Test that list_nodes uses literal &#39;in&#39; logic instead of re.search.
Regression: NodeService currently uses re.search in some versions,
but we want to ensure it uses literal &#39;in&#39; for parity.
&#34;&#34;&#34;
service = NodeService(populated_config)
# If it uses &#39;in&#39; logic, &#39;1&#39; should match all nodes containing &#39;1&#39;
# router1, server1@office, db1@datacenter@office
nodes = service.list_nodes(filter_str=&#34;1&#34;)
assert len(nodes) == 3
assert &#34;router1&#34; in nodes
assert &#34;server1@office&#34; in nodes
assert &#34;db1@datacenter@office&#34; in nodes
# Test regex-specific characters.
# NodeService should use re.search, so &#39;^router&#39; will match &#39;router1&#39;.
nodes_regex = service.list_nodes(filter_str=&#34;^router&#34;)
assert &#34;router1&#34; 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):
&#34;&#34;&#34;
Test that add_node improperly raises NodeAlreadyExistsError when used for editing.
Regression: connapp._mod calls add_node instead of update_node.
&#34;&#34;&#34;
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(&#34;router1&#34;, {&#34;host&#34;: &#34;1.1.1.1&#34;})</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>
+197 -1
View File
@@ -98,11 +98,80 @@ el.replaceWith(d);
assert lines[0] == &#34;[i] line1&#34;
# Second line should be indented by len(&#34;[i] &#34;) = 4 chars
assert lines[1].startswith(&#34; line2&#34;)
assert lines[2].startswith(&#34; line3&#34;)</code></pre>
assert lines[2].startswith(&#34; line3&#34;)
def test_data_output(self, capsys):
printer.data(&#34;my title&#34;, &#34;key: value&#34;)
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 &#34;my title&#34; in captured.out
assert &#34;key&#34; in captured.out
def test_node_panel_pass(self, capsys):
printer.node_panel(&#34;node1&#34;, &#34;output line\n&#34;, 0)
captured = capsys.readouterr()
assert &#34;node1&#34; in captured.out
assert &#34;PASS&#34; in captured.out
assert &#34;output line&#34; in captured.out
def test_node_panel_fail(self, capsys):
printer.node_panel(&#34;node2&#34;, &#34;error line\n&#34;, 1)
captured = capsys.readouterr()
assert &#34;node2&#34; in captured.out
assert &#34;FAIL&#34; in captured.out
assert &#34;error line&#34; in captured.out
def test_test_panel(self, capsys):
printer.test_panel(&#34;node1&#34;, &#34;output&#34;, 0, {&#34;check1&#34;: True, &#34;check2&#34;: False})
captured = capsys.readouterr()
assert &#34;node1&#34; in captured.out
assert &#34;check1&#34; in captured.out
assert &#34;check2&#34; in captured.out
def test_test_summary(self, capsys):
results = {&#34;node1&#34;: {&#34;test1&#34;: True}, &#34;node2&#34;: {&#34;test2&#34;: False}}
printer.test_summary(results)
captured = capsys.readouterr()
assert &#34;node1&#34; in captured.out
assert &#34;node2&#34; in captured.out
assert &#34;test1&#34; in captured.out
assert &#34;test2&#34; in captured.out
def test_header_output(self, capsys):
printer.header(&#34;My Header&#34;)
captured = capsys.readouterr()
assert &#34;My Header&#34; in captured.out
def test_kv_output(self, capsys):
printer.kv(&#34;mykeystring&#34;, &#34;myvaluestring&#34;)
captured = capsys.readouterr()
assert &#34;mykeystring&#34; in captured.out
assert &#34;myvaluestring&#34; in captured.out
def test_confirm_action(self, capsys):
printer.confirm_action(&#34;router1&#34;, &#34;delete&#34;)
captured = capsys.readouterr()
assert &#34;[i] delete: router1&#34; 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(&#34;router1&#34;, &#34;delete&#34;)
captured = capsys.readouterr()
assert &#34;[i] delete: router1&#34; 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(&#34;my title&#34;, &#34;key: value&#34;)
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 &#34;my title&#34; in captured.out
assert &#34;key&#34; 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(&#34;My Header&#34;)
captured = capsys.readouterr()
assert &#34;My Header&#34; 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(&#34;mykeystring&#34;, &#34;myvaluestring&#34;)
captured = capsys.readouterr()
assert &#34;mykeystring&#34; in captured.out
assert &#34;myvaluestring&#34; 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(&#34;node2&#34;, &#34;error line\n&#34;, 1)
captured = capsys.readouterr()
assert &#34;node2&#34; in captured.out
assert &#34;FAIL&#34; in captured.out
assert &#34;error line&#34; 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(&#34;node1&#34;, &#34;output line\n&#34;, 0)
captured = capsys.readouterr()
assert &#34;node1&#34; in captured.out
assert &#34;PASS&#34; in captured.out
assert &#34;output line&#34; 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(&#34;node1&#34;, &#34;output&#34;, 0, {&#34;check1&#34;: True, &#34;check2&#34;: False})
captured = capsys.readouterr()
assert &#34;node1&#34; in captured.out
assert &#34;check1&#34; in captured.out
assert &#34;check2&#34; 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 = {&#34;node1&#34;: {&#34;test1&#34;: True}, &#34;node2&#34;: {&#34;test2&#34;: False}}
printer.test_summary(results)
captured = capsys.readouterr()
assert &#34;node1&#34; in captured.out
assert &#34;node2&#34; in captured.out
assert &#34;test1&#34; in captured.out
assert &#34;test2&#34; 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>
+198
View File
@@ -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):
&#34;&#34;&#34;Test that deleting the &#39;default&#39; profile is prohibited.&#34;&#34;&#34;
service = ProfileService(populated_config)
from connpy.services.exceptions import InvalidConfigurationError
with pytest.raises(InvalidConfigurationError, match=&#34;Cannot delete the &#39;default&#39; profile&#34;):
service.delete_profile(&#34;default&#34;)</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):
&#34;&#34;&#34;Test that deleting a profile used by nodes is prohibited.&#34;&#34;&#34;
service = ProfileService(populated_config)
from connpy.services.exceptions import InvalidConfigurationError
# In populated_config, we need to make sure a node uses a profile
# Let&#39;s add a node that uses &#39;office-user&#39;
populated_config._connections_add(id=&#34;testnode&#34;, host=&#34;1.1.1.1&#34;, user=&#34;@office-user&#34;)
with pytest.raises(InvalidConfigurationError, match=&#34;is used by nodes&#34;):
service.delete_profile(&#34;office-user&#34;)</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):
&#34;&#34;&#34;Test basic CRUD operations for profiles.&#34;&#34;&#34;
service = ProfileService(populated_config)
# List
profiles = service.list_profiles()
assert &#34;default&#34; in profiles
assert &#34;office-user&#34; in profiles
# Get
office = service.get_profile(&#34;office-user&#34;)
assert office[&#34;user&#34;] == &#34;officeadmin&#34;
# Add
new_data = {
&#34;user&#34;: &#34;newadmin&#34;,
&#34;password&#34;: &#34;newpassword&#34;
}
service.add_profile(&#34;new-profile&#34;, new_data)
assert &#34;new-profile&#34; in service.list_profiles()
assert service.get_profile(&#34;new-profile&#34;)[&#34;user&#34;] == &#34;newadmin&#34;
# Update
update_data = {
&#34;user&#34;: &#34;updatedadmin&#34;
}
service.update_profile(&#34;new-profile&#34;, update_data)
assert service.get_profile(&#34;new-profile&#34;)[&#34;user&#34;] == &#34;updatedadmin&#34;
# Delete
service.delete_profile(&#34;new-profile&#34;)
assert &#34;new-profile&#34; 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):
&#34;&#34;&#34;
Test that profiles can inherit from other profiles.
Regression: ProfileService currently doesn&#39;t resolve inheritance within profiles.
&#34;&#34;&#34;
service = ProfileService(populated_config)
# Create a profile that inherits from &#39;office-user&#39;
# &#39;office-user&#39; has user=&#39;officeadmin&#39;, password=&#39;officepass&#39;
inherited_data = {
&#34;user&#34;: &#34;@office-user&#34;,
&#34;options&#34;: &#34;-v&#34;
}
service.add_profile(&#34;inherited-profile&#34;, 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 &#34;profile CRUD and inheritance parity&#34;.
profile = service.get_profile(&#34;inherited-profile&#34;)
# If inheritance is resolved, user should be &#39;officeadmin&#39;
# This is expected to FAIL if ProfileService just returns the raw dict.
assert profile[&#34;user&#34;] == &#34;officeadmin&#34;
assert profile[&#34;password&#34;] == &#34;officepass&#34;
assert profile[&#34;options&#34;] == &#34;-v&#34;</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>
+145
View File
@@ -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(&#34;connpy.services.provider.NodeService&#34;, create=True) as MockNodeService, \
patch(&#34;connpy.services.provider.ProfileService&#34;, create=True), \
patch(&#34;connpy.services.provider.ConfigService&#34;, create=True), \
patch(&#34;connpy.services.provider.PluginService&#34;, create=True), \
patch(&#34;connpy.services.provider.AIService&#34;, create=True), \
patch(&#34;connpy.services.provider.SystemService&#34;, create=True), \
patch(&#34;connpy.services.provider.ExecutionService&#34;, create=True), \
patch(&#34;connpy.services.provider.ImportExportService&#34;, create=True):
provider = ServiceProvider(config_mock, mode=&#34;local&#34;)
assert provider.mode == &#34;local&#34;
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(&#34;connpy.services.provider.ConfigService&#34;, create=True) as MockConfigService, \
patch(&#34;grpc.insecure_channel&#34;, create=True) as MockChannel:
provider = ServiceProvider(config_mock, mode=&#34;remote&#34;, remote_host=&#34;localhost:50051&#34;)
# Verify ConfigService is initialized locally
assert provider.config_svc is not None
# Verify grpc channel was created
MockChannel.assert_called_once_with(&#34;localhost:50051&#34;)
# 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=&#34;Unknown service mode: invalid_mode&#34;):
ServiceProvider(config_mock, mode=&#34;invalid_mode&#34;)</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
View File
@@ -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 = &#34;/fake/dir&#34;
app.config.file = &#34;/fake/dir/config.yaml&#34;
app.config.key = &#34;/fake/dir/.osk&#34;
app.config.config = {&#34;sync&#34;: True}
return app</code></pre>
def mock_config():
config = MagicMock()
config.defaultdir = &#34;/fake/dir&#34;
config.file = &#34;/fake/dir/config.yaml&#34;
config.key = &#34;/fake/dir/.osk&#34;
config.cachefile = &#34;/fake/dir/.cache&#34;
config.fzf_cachefile = &#34;/fake/dir/.fzf_cache&#34;
config.config = {&#34;sync&#34;: True, &#34;sync_remote&#34;: 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 == &#34;/fake/dir/config.yaml&#34;
assert s.token_file == &#34;/fake/dir/gtoken.json&#34;
<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(&#34;/fake/dir&#34;, &#34;gtoken.json&#34;)
@patch(&#34;connpy.core_plugins.sync.os.path.exists&#34;)
@patch(&#34;connpy.core_plugins.sync.Credentials&#34;)
def test_get_credentials_success(self, MockCreds, mock_exists, mock_connapp):
@patch(&#34;connpy.services.sync_service.os.path.exists&#34;)
@patch(&#34;connpy.services.sync_service.Credentials&#34;)
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(&#34;connpy.core_plugins.sync.os.path.exists&#34;)
def test_get_credentials_not_found(self, mock_exists, mock_connapp):
@patch(&#34;connpy.services.sync_service.os.path.exists&#34;)
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(&#34;connpy.core_plugins.sync.zipfile.ZipFile&#34;)
@patch(&#34;connpy.core_plugins.sync.os.path.basename&#34;)
def test_compress_specific_files(self, mock_basename, MockZipFile, mock_connapp):
@patch(&#34;connpy.services.sync_service.zipfile.ZipFile&#34;)
@patch(&#34;connpy.services.sync_service.os.path.exists&#34;)
@patch(&#34;connpy.services.sync_service.os.path.basename&#34;)
def test_compress_and_upload_local(self, mock_basename, mock_exists, MockZipFile, mock_config):
mock_basename.return_value = &#34;config.yaml&#34;
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(&#34;/fake/zip.zip&#34;)
zip_mock.write.assert_any_call(s.file, &#34;config.yaml&#34;)
zip_mock.write.assert_any_call(s.key, &#34;.osk&#34;)
s.compress_and_upload()
# Verify zip was created with local config and key
zip_mock.write.assert_any_call(s.config.file, &#34;config.yaml&#34;)
zip_mock.write.assert_any_call(s.config.key, &#34;.osk&#34;)
@patch(&#34;connpy.core_plugins.sync.zipfile.ZipFile&#34;)
@patch(&#34;connpy.core_plugins.sync.os.path.dirname&#34;)
def test_decompress_zip_yaml(self, mock_dirname, MockZipFile, mock_connapp):
@patch(&#34;connpy.services.sync_service.zipfile.ZipFile&#34;)
@patch(&#34;connpy.services.sync_service.os.path.exists&#34;)
@patch(&#34;connpy.services.sync_service.os.path.dirname&#34;)
@patch(&#34;connpy.services.sync_service.os.remove&#34;)
def test_perform_restore(self, mock_remove, mock_dirname, mock_exists, MockZipFile, mock_config):
mock_dirname.return_value = &#34;/fake/dir&#34;
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 &#34;.cache&#34; in path or &#34;.fzf_cache&#34; 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 = [&#34;config.yaml&#34;, &#34;.osk&#34;]
MockZipFile.return_value.__enter__.return_value = zip_mock
assert s.decompress_zip(&#34;/fake/zip.zip&#34;) == 0
zip_mock.extract.assert_any_call(&#34;config.yaml&#34;, &#34;/fake/dir&#34;)
with patch(&#34;connpy.services.sync_service.yaml.safe_load&#34;) as mock_load:
mock_load.return_value = {&#34;connections&#34;: {}, &#34;profiles&#34;: {}, &#34;config&#34;: {}}
assert s.perform_restore(&#34;/fake/zip.zip&#34;) is True
zip_mock.extract.assert_any_call(&#34;.osk&#34;, &#34;/fake/dir&#34;)
@patch(&#34;connpy.core_plugins.sync.zipfile.ZipFile&#34;)
@patch(&#34;connpy.core_plugins.sync.os.path.dirname&#34;)
def test_decompress_zip_json_fallback(self, mock_dirname, MockZipFile, mock_connapp):
mock_dirname.return_value = &#34;/fake/dir&#34;
s = sync(mock_connapp)
zip_mock = MagicMock()
zip_mock.namelist.return_value = [&#34;config.json&#34;, &#34;.osk&#34;]
MockZipFile.return_value.__enter__.return_value = zip_mock
assert s.decompress_zip(&#34;/fake/old_zip.zip&#34;) == 0
zip_mock.extract.assert_any_call(&#34;config.json&#34;, &#34;/fake/dir&#34;)
@patch.object(sync, &#34;get_credentials&#34;)
@patch(&#34;connpy.core_plugins.sync.build&#34;)
def test_get_appdata_files(self, mock_build, mock_get_credentials, mock_connapp):
@patch.object(SyncService, &#34;get_credentials&#34;)
@patch(&#34;connpy.services.sync_service.build&#34;)
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][&#34;id&#34;] == &#34;1&#34;
assert files[0][&#34;timestamp&#34;] == &#34;1000&#34;
@patch.object(sync, &#34;get_credentials&#34;)
@patch(&#34;connpy.core_plugins.sync.build&#34;)
@patch(&#34;connpy.core_plugins.sync.MediaFileUpload&#34;)
@patch(&#34;connpy.core_plugins.sync.os.path.basename&#34;)
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 = &#34;backup.zip&#34;
mock_service = MagicMock()
mock_build.return_value = mock_service
s = sync(mock_connapp)
assert s.backup_file_to_drive(&#34;/fake/backup.zip&#34;, 1234567890000) == 0
mock_service.files().create.assert_called_once()</code></pre>
assert files[0][&#34;timestamp&#34;] == &#34;1000&#34;</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, &#34;get_credentials&#34;)
@patch(&#34;connpy.core_plugins.sync.build&#34;)
@patch(&#34;connpy.core_plugins.sync.MediaFileUpload&#34;)
@patch(&#34;connpy.core_plugins.sync.os.path.basename&#34;)
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 = &#34;backup.zip&#34;
mock_service = MagicMock()
mock_build.return_value = mock_service
s = sync(mock_connapp)
assert s.backup_file_to_drive(&#34;/fake/backup.zip&#34;, 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(&#34;connpy.core_plugins.sync.zipfile.ZipFile&#34;)
@patch(&#34;connpy.core_plugins.sync.os.path.basename&#34;)
def test_compress_specific_files(self, mock_basename, MockZipFile, mock_connapp):
<pre><code class="python">@patch(&#34;connpy.services.sync_service.zipfile.ZipFile&#34;)
@patch(&#34;connpy.services.sync_service.os.path.exists&#34;)
@patch(&#34;connpy.services.sync_service.os.path.basename&#34;)
def test_compress_and_upload_local(self, mock_basename, mock_exists, MockZipFile, mock_config):
mock_basename.return_value = &#34;config.yaml&#34;
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(&#34;/fake/zip.zip&#34;)
zip_mock.write.assert_any_call(s.file, &#34;config.yaml&#34;)
zip_mock.write.assert_any_call(s.key, &#34;.osk&#34;)</code></pre>
s.compress_and_upload()
# Verify zip was created with local config and key
zip_mock.write.assert_any_call(s.config.file, &#34;config.yaml&#34;)
zip_mock.write.assert_any_call(s.config.key, &#34;.osk&#34;)</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(&#34;connpy.core_plugins.sync.zipfile.ZipFile&#34;)
@patch(&#34;connpy.core_plugins.sync.os.path.dirname&#34;)
def test_decompress_zip_json_fallback(self, mock_dirname, MockZipFile, mock_connapp):
mock_dirname.return_value = &#34;/fake/dir&#34;
s = sync(mock_connapp)
zip_mock = MagicMock()
zip_mock.namelist.return_value = [&#34;config.json&#34;, &#34;.osk&#34;]
MockZipFile.return_value.__enter__.return_value = zip_mock
assert s.decompress_zip(&#34;/fake/old_zip.zip&#34;) == 0
zip_mock.extract.assert_any_call(&#34;config.json&#34;, &#34;/fake/dir&#34;)</code></pre>
<pre><code class="python">@patch(&#34;connpy.services.sync_service.os.path.exists&#34;)
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(&#34;connpy.core_plugins.sync.zipfile.ZipFile&#34;)
@patch(&#34;connpy.core_plugins.sync.os.path.dirname&#34;)
def test_decompress_zip_yaml(self, mock_dirname, MockZipFile, mock_connapp):
mock_dirname.return_value = &#34;/fake/dir&#34;
s = sync(mock_connapp)
zip_mock = MagicMock()
zip_mock.namelist.return_value = [&#34;config.yaml&#34;, &#34;.osk&#34;]
MockZipFile.return_value.__enter__.return_value = zip_mock
<pre><code class="python">@patch(&#34;connpy.services.sync_service.os.path.exists&#34;)
@patch(&#34;connpy.services.sync_service.Credentials&#34;)
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(&#34;/fake/zip.zip&#34;) == 0
zip_mock.extract.assert_any_call(&#34;config.yaml&#34;, &#34;/fake/dir&#34;)
zip_mock.extract.assert_any_call(&#34;.osk&#34;, &#34;/fake/dir&#34;)</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, &#34;get_credentials&#34;)
@patch(&#34;connpy.core_plugins.sync.build&#34;)
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(&#34;/fake/dir&#34;, &#34;gtoken.json&#34;)</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, &#34;get_credentials&#34;)
@patch(&#34;connpy.services.sync_service.build&#34;)
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][&#34;id&#34;] == &#34;1&#34;
assert files[0][&#34;timestamp&#34;] == &#34;1000&#34;</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(&#34;connpy.core_plugins.sync.os.path.exists&#34;)
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(&#34;connpy.core_plugins.sync.os.path.exists&#34;)
@patch(&#34;connpy.core_plugins.sync.Credentials&#34;)
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(&#34;connpy.services.sync_service.zipfile.ZipFile&#34;)
@patch(&#34;connpy.services.sync_service.os.path.exists&#34;)
@patch(&#34;connpy.services.sync_service.os.path.dirname&#34;)
@patch(&#34;connpy.services.sync_service.os.remove&#34;)
def test_perform_restore(self, mock_remove, mock_dirname, mock_exists, MockZipFile, mock_config):
mock_dirname.return_value = &#34;/fake/dir&#34;
# Mock exists to return True for key and zip, but False for caches during the cleanup phase
def exists_side_effect(path):
if &#34;.cache&#34; in path or &#34;.fzf_cache&#34; 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 == &#34;/fake/dir/config.yaml&#34;
assert s.token_file == &#34;/fake/dir/gtoken.json&#34;</code></pre>
s = SyncService(mock_config)
zip_mock = MagicMock()
zip_mock.namelist.return_value = [&#34;config.yaml&#34;, &#34;.osk&#34;]
MockZipFile.return_value.__enter__.return_value = zip_mock
with patch(&#34;connpy.services.sync_service.yaml.safe_load&#34;) as mock_load:
mock_load.return_value = {&#34;connections&#34;: {}, &#34;profiles&#34;: {}, &#34;config&#34;: {}}
assert s.perform_restore(&#34;/fake/zip.zip&#34;) is True
zip_mock.extract.assert_any_call(&#34;.osk&#34;, &#34;/fake/dir&#34;)</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>