Skip to content

Commit c3e0f05

Browse files
authored
Merge pull request #318 from networktocode/fix_jnpr_device_NamedTemporaryFile
Fix jnpr_device.JunosDevice.save NamedTemporaryFile mode.
2 parents 33355bb + 874f817 commit c3e0f05

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

pyntc/devices/jnpr_device.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,8 @@ def save(self, filename=None):
408408
self.cu.commit()
409409
return
410410

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

415415
with SCP(self.native) as scp:

tests/unit/test_devices/test_jnpr_device.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,19 +165,19 @@ def test_show_list(self, mock_show):
165165
self.device.show(commands)
166166
self.device.show.assert_called_with(commands)
167167

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

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

175175
self.assertTrue(result)
176-
self.device.show.assert_called_with("show config")
176+
mock_startup_config.assert_called_once_with()
177177

178178
def test_file_copy_remote_exists(self):
179-
temp_file = NamedTemporaryFile()
180-
temp_file.write(b"file contents")
179+
temp_file = NamedTemporaryFile(mode="w")
180+
temp_file.write("file contents")
181181
temp_file.flush()
182182

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

191191
def test_file_copy_remote_exists_failure(self):
192-
temp_file = NamedTemporaryFile()
193-
temp_file.write(b"file contents")
192+
temp_file = NamedTemporaryFile(mode="w")
193+
temp_file.write("file contents")
194194
temp_file.flush()
195195

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

203203
@mock.patch("pyntc.devices.jnpr_device.SCP")
204204
def test_file_copy(self, mock_scp):
205-
temp_file = NamedTemporaryFile()
206-
temp_file.write(b"file contents")
205+
temp_file = NamedTemporaryFile(mode="w")
206+
temp_file.write("file contents")
207207
temp_file.flush()
208208

209209
local_checksum = "4a8ec4fa5f01b4ab1a0ab8cbccb709f0"
@@ -241,7 +241,7 @@ def test_rollback(self, mock_scp):
241241
@mock.patch("pyntc.devices.jnpr_device.SCP", autospec=True)
242242
def test_checkpoint(self, mock_scp):
243243
self.device.show = mock.MagicMock()
244-
self.device.show.return_value = b"file contents"
244+
self.device.show.return_value = "file contents"
245245
self.device.checkpoint("saved_config")
246246
self.device.show.assert_called_with("show config")
247247

0 commit comments

Comments
 (0)