2016-12-23 16:11:47 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2017-03-04 19:17:59 +00:00
|
|
|
# Copyright (c) 2008-2017 OpenLP Developers #
|
2016-12-23 16:11:47 +00:00
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
|
|
|
|
2017-03-04 17:32:47 +00:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
|
|
|
|
from tempfile import mkdtemp
|
|
|
|
from unittest import TestCase
|
2017-06-08 21:36:17 +00:00
|
|
|
from unittest.mock import MagicMock
|
2017-03-04 17:32:47 +00:00
|
|
|
|
2017-03-05 09:23:28 +00:00
|
|
|
from openlp.core.common import Registry
|
|
|
|
from openlp.core.common.httputils import url_get_file
|
2017-06-08 21:36:17 +00:00
|
|
|
from openlp.plugins.remotes.deploy import download_sha256, download_and_check
|
|
|
|
|
2017-03-04 17:32:47 +00:00
|
|
|
|
2017-03-05 09:23:28 +00:00
|
|
|
from tests.helpers.testmixin import TestMixin
|
2017-03-04 17:32:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources'))
|
|
|
|
|
|
|
|
|
2017-03-05 09:23:28 +00:00
|
|
|
class TestRemoteDeploy(TestCase, TestMixin):
|
2017-03-04 17:32:47 +00:00
|
|
|
"""
|
|
|
|
Test the Remote plugin deploy functions
|
|
|
|
"""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Setup for tests
|
|
|
|
"""
|
|
|
|
self.app_root = mkdtemp()
|
2017-03-05 09:23:28 +00:00
|
|
|
self.setup_application()
|
|
|
|
self.app.setApplicationVersion('0.0')
|
|
|
|
self.app.process_events = lambda: None
|
|
|
|
Registry.create()
|
|
|
|
Registry().register('application', self.app)
|
2017-03-04 17:32:47 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
"""
|
|
|
|
Clean up after tests
|
|
|
|
"""
|
|
|
|
shutil.rmtree(self.app_root)
|
|
|
|
|
|
|
|
def test_download_and_check_size(self):
|
|
|
|
"""
|
|
|
|
Remote Deploy tests - Test hosted sites file matches the config file
|
|
|
|
"""
|
|
|
|
# GIVEN: a hosted configuration file
|
|
|
|
web = 'https://get.openlp.org/webclient/'
|
2017-06-08 21:36:17 +00:00
|
|
|
sha, version = download_sha256()
|
2017-03-04 17:32:47 +00:00
|
|
|
callback = MagicMock()
|
|
|
|
callback.was_cancelled = False
|
|
|
|
f = os.path.join(self.app_root, 'sites.zip')
|
|
|
|
# WHEN: I download the sites file
|
|
|
|
# THEN: the file will download and match the sha256 from the config file
|
|
|
|
url_get_file(callback, web + 'site.zip', f, sha256=sha)
|
|
|
|
|
2017-03-05 09:23:28 +00:00
|
|
|
def test_download_and_deploy(self):
|
|
|
|
"""
|
|
|
|
Remote Deploy tests - Test hosted sites file matches the config file
|
|
|
|
"""
|
|
|
|
# GIVEN: a hosted configuration file
|
|
|
|
callback = MagicMock()
|
|
|
|
callback.was_cancelled = False
|
|
|
|
download_and_check(callback)
|