1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
#!/usr/bin/python3
import unittest
from unittest.mock import patch
from keyman_config import KeymanComUrl, __tier__
from keyman_config.handle_install import download_and_install_package
class HandleInstallTests(unittest.TestCase):
@patch('keyman_config.handle_install.is_zipfile')
@patch('keyman_config.handle_install._install_package')
def test_downloadAndInstallPackage_file(self, installPackageMethod, mockIsZipfile):
# Setup
mockIsZipfile.return_value = True
# Execute
download_and_install_package('/tmp/keyboard/sil_euro_latin.kmp')
# Verify
installPackageMethod.assert_called_with('/tmp/keyboard/sil_euro_latin.kmp', '')
@patch('keyman_config.handle_install.is_zipfile')
@patch('keyman_config.handle_install._install_package')
def test_downloadAndInstallPackage_fileUrl(self, installPackageMethod, mockIsZipfile):
# Setup
mockIsZipfile.return_value = True
# Execute
download_and_install_package('file:///tmp/keyboard/sil_euro_latin.kmp')
# Verify
installPackageMethod.assert_called_with('/tmp/keyboard/sil_euro_latin.kmp', '')
@patch('keyman_config.handle_install.is_zipfile')
@patch('keyman_config.handle_install._install_package')
def test_downloadAndInstallPackage_fileUrlWithBcp47(self, installPackageMethod,
mockIsZipfile):
# Setup
mockIsZipfile.return_value = True
# Execute
download_and_install_package('file:///tmp/keyboard/sil_euro_latin.kmp?bcp47=dyo')
# Verify
installPackageMethod.assert_called_with('/tmp/keyboard/sil_euro_latin.kmp', 'dyo')
@patch('keyman_config.handle_install.is_zipfile')
@patch('keyman_config.handle_install._install_package')
def test_downloadAndInstallPackage_fileUrlWithBcp47AndVersion(self, installPackageMethod,
mockIsZipfile):
# Setup
mockIsZipfile.return_value = True
# Execute
download_and_install_package('file:///tmp/keyboard/sil_euro_latin.kmp?bcp47=dyo&version=1')
# Verify
installPackageMethod.assert_called_with('/tmp/keyboard/sil_euro_latin.kmp', 'dyo')
@patch('keyman_config.handle_install.is_zipfile')
@patch('keyman_config.handle_install._install_package')
def test_downloadAndInstallPackage_InvalidUrl(self, installPackageMethod, mockIsZipfile):
# Setup
mockIsZipfile.return_value = True
# Execute
download_and_install_package('http://localhost/keyboard/sil_euro_latin.kmp')
# Verify
installPackageMethod.assert_not_called()
@patch('keyman_config.handle_install.is_zipfile')
@patch('keyman_config.handle_install._install_package')
@patch('keyman_config.get_kmp.download_kmp_file')
def test_downloadAndInstallPackage_invalidUrl(self, downloadKmpFileMethod,
installPackageMethod, mockIsZipfile):
for url in ['foo://download/keyboard/sil_euro_latin', 'keyman://keyboard/sil_euro_latin',
'keyman://download/sil_euro_latin', 'keyman://download/keyboard/']:
with self.subTest(url=url):
# Setup
mockIsZipfile.return_value = True
# Execute
download_and_install_package(url)
# Verify
downloadKmpFileMethod.assert_not_called()
installPackageMethod.assert_not_called()
@patch('keyman_config.handle_install.is_zipfile')
@patch('keyman_config.handle_install._install_package')
@patch('keyman_config.get_kmp.keyman_cache_dir')
@patch('keyman_config.handle_install.download_kmp_file')
def test_downloadAndInstallPackage_keymanUrl(self, downloadKmpFileMethod,
keymanCacheDirMethod, installPackageMethod,
mockIsZipfile):
# Setup
mockPackagePath = '/tmp/sil_euro_latin'
keymanCacheDirMethod.return_value = '/tmp'
downloadKmpFileMethod.return_value = mockPackagePath
mockIsZipfile.return_value = True
# Execute
download_and_install_package('keyman://download/keyboard/sil_euro_latin')
# Verify
downloadKmpFileMethod.assert_called_with(
KeymanComUrl + '/go/package/download/sil_euro_latin?platform=linux&tier=' + __tier__,
mockPackagePath)
installPackageMethod.assert_called_with(mockPackagePath, '')
@patch('keyman_config.handle_install.is_zipfile')
@patch('keyman_config.handle_install._install_package')
@patch('keyman_config.get_kmp.keyman_cache_dir')
@patch('keyman_config.handle_install.download_kmp_file')
def test_downloadAndInstallPackage_keymanUrlWithBcp47(self, downloadKmpFileMethod,
keymanCacheDirMethod,
installPackageMethod, mockIsZipfile):
# Setup
mockPackagePath = '/tmp/sil_euro_latin'
keymanCacheDirMethod.return_value = '/tmp'
downloadKmpFileMethod.return_value = mockPackagePath
mockIsZipfile.return_value = True
# Execute
download_and_install_package('keyman://download/keyboard/sil_euro_latin?bcp47=de')
# Verify
downloadKmpFileMethod.assert_called_with(
KeymanComUrl + '/go/package/download/sil_euro_latin?platform=linux&tier=' + __tier__,
mockPackagePath)
installPackageMethod.assert_called_with(mockPackagePath, 'de')
if __name__ == '__main__':
unittest.main()
|