Skip to content

Commit

Permalink
Fix jnpr_device.JunosDevice.save NamedTemporaryFile mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
pszulczewski committed Dec 20, 2024
1 parent 33355bb commit 874f817
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
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

0 comments on commit 874f817

Please sign in to comment.