Skip to content

Commit f2c76e7

Browse files
author
Alexandre Vincent
committed
[change] Use PropertyMock for stdout.channel.exit_status on exec_command
1 parent 8c5a06e commit f2c76e7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

openwisp_controller/connection/tests/test_models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import socket
22
from unittest import mock
3+
from unittest.mock import PropertyMock
34

45
import paramiko
56
from django.contrib.auth.models import ContentType
@@ -46,7 +47,7 @@ def _exec_command_return_value(
4647
stderr_ = mock.Mock()
4748
stdin_.read().decode.return_value = stdin
4849
stdout_.read().decode.return_value = stdout
49-
stdout_.channel.exit_status = exit_code
50+
type(stdout_.channel).exit_status = PropertyMock(return_value=exit_code)
5051
stderr_.read().decode.return_value = stderr
5152
return (stdin_, stdout_, stderr_)
5253

@@ -1009,7 +1010,7 @@ def _assert_applying_conf_test_command(mocked_exec):
10091010
# 1. Checking openwisp_config returns with 0
10101011
# 2. Testing presence of /tmp/openwisp/applying_conf returns with 1
10111012
# 3. Restarting openwisp_config returns with 0 exit code
1012-
stdout.channel.recv_exit_status.side_effect = [0, 1, 1]
1013+
type(stdout.channel).exit_status = PropertyMock(side_effect=[0, 1, 1])
10131014
mocked_exec_command.return_value = (stdin, stdout, stderr)
10141015
conf.save()
10151016
self.assertEqual(mocked_exec_command.call_count, 3)

0 commit comments

Comments
 (0)