46
47
self.app_root_path.rmtree()
48
def test_deploy_zipfile(self):
49
@patch('openlp.core.api.deploy.ZipFile')
50
def test_deploy_zipfile(self, MockZipFile):
50
52
Remote Deploy tests - test the dummy zip file is processed correctly
52
54
# GIVEN: A new downloaded zip file
53
zip_path = TEST_PATH / 'remotes' / 'site.zip'
54
app_root_path = self.app_root_path / 'site.zip'
55
copyfile(zip_path, app_root_path)
57
# WHEN: I process the zipfile
58
deploy_zipfile(self.app_root_path, 'site.zip')
60
# THEN: test if www directory has been created
61
assert (self.app_root_path / 'www').is_dir(), 'We should have a www directory'
55
mocked_zipfile = MagicMock()
56
MockZipFile.return_value = mocked_zipfile
57
root_path = Path('/tmp/remotes')
59
# WHEN: deploy_zipfile() is called
60
deploy_zipfile(root_path, 'site.zip')
62
# THEN: the zip file should have been extracted to the right location
63
MockZipFile.assert_called_once_with('/tmp/remotes/site.zip')
64
mocked_zipfile.extractall.assert_called_once_with('/tmp/remotes')
66
@patch('openlp.core.api.deploy.Registry')
67
@patch('openlp.core.api.deploy.get_web_page')
68
def test_download_sha256_connection_error(self, mocked_get_web_page, MockRegistry):
70
Test that if a ConnectionError occurs while downloading a sha256 False is returned
72
# GIVEN: A bunch of mocks
73
MockRegistry.return_value.get.return_value.applicationVersion.return_value = '1.0'
74
mocked_get_web_page.side_effect = ConnectionError()
76
# WHEN: download_sha256() is called
77
result = download_sha256()
79
# THEN: The result should be False
80
assert result is False, 'download_sha256() should return False when encountering ConnectionError'
82
@patch('openlp.core.api.deploy.Registry')
83
@patch('openlp.core.api.deploy.get_web_page')
84
def test_download_sha256_no_config(self, mocked_get_web_page, MockRegistry):
86
Test that if there's no config when downloading a sha256 None is returned
88
# GIVEN: A bunch of mocks
89
MockRegistry.return_value.get.return_value.applicationVersion.return_value = '1.0'
90
mocked_get_web_page.return_value = None
92
# WHEN: download_sha256() is called
93
result = download_sha256()
95
# THEN: The result should be Nonw
96
assert result is None, 'download_sha256() should return None when there is a problem downloading the page'
98
@patch('openlp.core.api.deploy.Registry')
99
@patch('openlp.core.api.deploy.get_web_page')
100
def test_download_sha256(self, mocked_get_web_page, MockRegistry):
102
Test that the sha256 and the version are returned
104
# GIVEN: A bunch of mocks
105
MockRegistry.return_value.get.return_value.applicationVersion.return_value = '1.0'
106
mocked_get_web_page.return_value = CONFIG_FILE
108
# WHEN: download_sha256() is called
109
result = download_sha256()
111
# THEN: The result should be Nonw
112
assert result == ('2c266badff1e3d140664c50fd1460a2b332b24d5ad8c267fa62e506b5eb6d894', '2017_06_27'), \
113
'download_sha256() should return a tuple of sha256 and version'
115
@patch('openlp.core.api.deploy.Registry')
116
@patch('openlp.core.api.deploy.download_sha256')
117
@patch('openlp.core.api.deploy.get_url_file_size')
118
@patch('openlp.core.api.deploy.download_file')
119
@patch('openlp.core.api.deploy.AppLocation.get_section_data_path')
120
@patch('openlp.core.api.deploy.deploy_zipfile')
121
def test_download_and_check(self, mocked_deploy_zipfile, mocked_get_data_path, mocked_download_file,
122
mocked_get_url_file_size, mocked_download_sha256, MockRegistry):
123
# GIVEN: A bunch of mocks
124
mocked_get_data_path.return_value = Path('/tmp/remotes')
125
mocked_download_file.return_value = True
126
mocked_get_url_file_size.return_value = 5
127
mocked_download_sha256.return_value = ('asdfgh', '0.1')
128
MockRegistry.return_value.get.return_value.applicationVersion.return_value = '1.0'
129
mocked_callback = MagicMock()
131
# WHEN: download_and_check() is called
132
download_and_check(mocked_callback)
134
# THEN: The correct things should have been done
135
mocked_download_sha256.assert_called_once_with()
136
mocked_get_url_file_size.assert_called_once_with('https://get.openlp.org/webclient/site.zip')
137
mocked_callback.setRange.assert_called_once_with(0, 5)
138
mocked_download_file.assert_called_once_with(mocked_callback, 'https://get.openlp.org/webclient/site.zip',
139
Path('/tmp/remotes/site.zip'), sha256='asdfgh')
140
mocked_deploy_zipfile.assert_called_once_with(Path('/tmp/remotes'), 'site.zip')