Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix jnpr_device.JunosDevice.save NamedTemporaryFile mode. #318

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyntc/devices/jnpr_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ def save(self, filename=None):
self.cu.commit()
return

temp_file = NamedTemporaryFile() # pylint: disable=consider-using-with
temp_file.write(self.show("show config"))
temp_file = NamedTemporaryFile(mode="w") # pylint: disable=consider-using-with
temp_file.write(self.startup_config)
temp_file.flush()

with SCP(self.native) as scp:
Expand Down
22 changes: 11 additions & 11 deletions tests/unit/test_devices/test_jnpr_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,19 @@ def test_show_list(self, mock_show):
self.device.show(commands)
self.device.show.assert_called_with(commands)

@mock.patch("pyntc.devices.jnpr_device.JunosDevice.startup_config", new_callable=mock.PropertyMock)
@mock.patch("pyntc.devices.jnpr_device.SCP", autospec=True)
def test_save(self, mock_scp):
self.device.show = mock.MagicMock()
self.device.show.return_value = b"file contents"
def test_save(self, mock_scp, mock_startup_config):
mock_startup_config.return_value = "file contents"

result = self.device.save(filename="saved_config")

self.assertTrue(result)
self.device.show.assert_called_with("show config")
mock_startup_config.assert_called_once_with()

def test_file_copy_remote_exists(self):
temp_file = NamedTemporaryFile()
temp_file.write(b"file contents")
temp_file = NamedTemporaryFile(mode="w")
temp_file.write("file contents")
temp_file.flush()

local_checksum = "4a8ec4fa5f01b4ab1a0ab8cbccb709f0"
Expand All @@ -189,8 +189,8 @@ def test_file_copy_remote_exists(self):
self.device.fs.checksum.assert_called_with("dest")

def test_file_copy_remote_exists_failure(self):
temp_file = NamedTemporaryFile()
temp_file.write(b"file contents")
temp_file = NamedTemporaryFile(mode="w")
temp_file.write("file contents")
temp_file.flush()

self.device.fs.checksum.return_value = "deadbeef"
Expand All @@ -202,8 +202,8 @@ def test_file_copy_remote_exists_failure(self):

@mock.patch("pyntc.devices.jnpr_device.SCP")
def test_file_copy(self, mock_scp):
temp_file = NamedTemporaryFile()
temp_file.write(b"file contents")
temp_file = NamedTemporaryFile(mode="w")
temp_file.write("file contents")
temp_file.flush()

local_checksum = "4a8ec4fa5f01b4ab1a0ab8cbccb709f0"
Expand Down Expand Up @@ -241,7 +241,7 @@ def test_rollback(self, mock_scp):
@mock.patch("pyntc.devices.jnpr_device.SCP", autospec=True)
def test_checkpoint(self, mock_scp):
self.device.show = mock.MagicMock()
self.device.show.return_value = b"file contents"
self.device.show.return_value = "file contents"
self.device.checkpoint("saved_config")
self.device.show.assert_called_with("show config")

Expand Down
Loading