def test_add_known_host_exists_outdated( self, check_output, host_key, rm, known_hosts): check_output.return_value = '|1|= fookey' host_key.return_value = '|1|= fookey_old' with patch_open() as (_open, _file): utils.add_known_host('foohost', None, None) rm.assert_called_with('foohost', None, None)
def test_add_known_host_exists(self, check_output, host_key, rm): check_output.return_value = '|1|= fookey' host_key.return_value = '|1|= fookey' with patch_open() as (_open, _file): utils.add_known_host('foohost') self.assertFalse(rm.called) self.assertFalse(_file.write.called)
def test_add_known_host_exists_added( self, check_output, host_key, rm, known_hosts): check_output.return_value = '|1|= fookey' host_key.return_value = None with patch_open() as (_open, _file): _file.write = MagicMock() utils.add_known_host('foohost') self.assertFalse(rm.called) _file.write.assert_called_with('|1|= fookey\n')