forked from openlp/openlp
Add tests
This commit is contained in:
parent
126c5462a0
commit
fe3014fc66
@ -23,13 +23,17 @@
|
|||||||
import os
|
import os
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
file_name = "/home/tim/Projects/OpenLP/openlp/remoteweb/deploy.zip"
|
|
||||||
|
|
||||||
|
def deploy_zipfile(zip_file, app_root):
|
||||||
|
"""
|
||||||
|
Process the downloaded zip file and add to the correct directory
|
||||||
|
|
||||||
def deploy_zipfile(file_name):
|
:param zip_file: the zip file to be processed
|
||||||
|
:param app_root: the directory where the zip get expanded to
|
||||||
|
|
||||||
app_root = "/home/tim/.openlp/data/remotes/"
|
:return: None
|
||||||
web_zip = zipfile.ZipFile(file_name)
|
"""
|
||||||
|
web_zip = zipfile.ZipFile(zip_file)
|
||||||
for web_file in web_zip.namelist():
|
for web_file in web_zip.namelist():
|
||||||
(dir_name, filename) = os.path.split(web_file)
|
(dir_name, filename) = os.path.split(web_file)
|
||||||
real_path = os.path.join(app_root, web_file[4:])
|
real_path = os.path.join(app_root, web_file[4:])
|
||||||
@ -37,14 +41,20 @@ def deploy_zipfile(file_name):
|
|||||||
if not os.path.exists(real_path):
|
if not os.path.exists(real_path):
|
||||||
os.makedirs(real_path)
|
os.makedirs(real_path)
|
||||||
else:
|
else:
|
||||||
file_web = str(web_zip.read(web_file))
|
file_web = web_zip.read(web_file)
|
||||||
out_file = open(real_path, 'w')
|
out_file = open(real_path, 'w')
|
||||||
out_file.write(file_web)
|
# extract the file from the zip. If an image then the exception will be used.
|
||||||
|
try:
|
||||||
|
out_file.write(file_web.decode("utf-8"))
|
||||||
|
except UnicodeDecodeError as ude:
|
||||||
|
out_file.close()
|
||||||
|
out_file = open(real_path, 'wb')
|
||||||
|
out_file.write(file_web)
|
||||||
|
out_file.close()
|
||||||
web_zip.close()
|
web_zip.close()
|
||||||
|
|
||||||
|
|
||||||
def check_for_previous_deployment(create=False):
|
def check_for_previous_deployment(app_root, create=False):
|
||||||
app_root = "/home/tim/.openlp/data/remotes/"
|
|
||||||
marker_file = os.path.join(app_root, "marker.txt")
|
marker_file = os.path.join(app_root, "marker.txt")
|
||||||
if os.path.isfile(marker_file):
|
if os.path.isfile(marker_file):
|
||||||
return True
|
return True
|
||||||
@ -52,24 +62,12 @@ def check_for_previous_deployment(create=False):
|
|||||||
if create:
|
if create:
|
||||||
os.mknod(marker_file)
|
os.mknod(marker_file)
|
||||||
return False
|
return False
|
||||||
a=1
|
|
||||||
|
|
||||||
|
|
||||||
deploy_zipfile(file_name)
|
#file_name = "/home/tim/Projects/OpenLP/openlp/remoteweb/deploy.zip"
|
||||||
#print(check_for_previous_deployment())
|
#app_root = "/home/tim/.openlp/data/remotes/"
|
||||||
#print(check_for_previous_deployment(True))
|
|
||||||
#print(check_for_previous_deployment())
|
|
||||||
|
|
||||||
|
#deploy_zipfile(file_name)
|
||||||
# xml_file = [name for name in theme_zip.namelist() if os.path.splitext(name)[1].lower() == '.xml']
|
#print(check_for_previous_deployment(app_root))
|
||||||
# if len(xml_file) != 1:
|
#print(check_for_previous_deployment(app_root, True))
|
||||||
# self.log_error('Theme contains "{val:d}" XML files'.format(val=len(xml_file)))
|
#print(check_for_previous_deployment(app_root))
|
||||||
# raise ValidationError
|
|
||||||
# xml_tree = ElementTree(element=XML(theme_zip.read(xml_file[0]))).getroot()
|
|
||||||
# theme_version = xml_tree.get('version', default=None)
|
|
||||||
# if not theme_version or float(theme_version) < 2.0:
|
|
||||||
# self.log_error('Theme version is less than 2.0')
|
|
||||||
# raise ValidationError
|
|
||||||
# theme_name = xml_tree.find('name').text.strip()
|
|
||||||
# theme_folder = os.path.join(directory, theme_name)
|
|
||||||
# theme_exists = os.path.exists(theme_folder)
|
|
||||||
|
49
tests/functional/openlp_core_api_http/test_init.py
Normal file
49
tests/functional/openlp_core_api_http/test_init.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# OpenLP - Open Source Lyrics Projection #
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# Copyright (c) 2008-2016 OpenLP Developers #
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# 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 #
|
||||||
|
###############################################################################
|
||||||
|
"""
|
||||||
|
Functional tests to test the Http Server Class.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from unittest import TestCase
|
||||||
|
|
||||||
|
from openlp.core.api.http.server import HttpServer
|
||||||
|
|
||||||
|
from tests.functional import patch
|
||||||
|
|
||||||
|
|
||||||
|
class TestHttpServer(TestCase):
|
||||||
|
"""
|
||||||
|
A test suite to test starting the http server
|
||||||
|
"""
|
||||||
|
@patch('openlp.core.api.http.server.HttpWorker')
|
||||||
|
@patch('openlp.core.api.http.server.QtCore.QThread')
|
||||||
|
def test_serverstart(self, mock_qthread, mock_thread):
|
||||||
|
"""
|
||||||
|
Test the starting of the Waitress Server
|
||||||
|
"""
|
||||||
|
# GIVEN: A new httpserver
|
||||||
|
# WHEN: I start the server
|
||||||
|
server = HttpServer()
|
||||||
|
|
||||||
|
# THEN: the api environment should have been created
|
||||||
|
self.assertEquals(1, mock_qthread.call_count, 'The qthread should have been called once')
|
||||||
|
self.assertEquals(1, mock_thread.call_count, 'The http thread should have been called once')
|
21
tests/functional/openlp_plugins/remotes/__init__.py
Normal file
21
tests/functional/openlp_plugins/remotes/__init__.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# OpenLP - Open Source Lyrics Projection #
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# Copyright (c) 2008-2016 OpenLP Developers #
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# 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 #
|
||||||
|
###############################################################################
|
103
tests/functional/openlp_plugins/remotes/test_deploy.py
Normal file
103
tests/functional/openlp_plugins/remotes/test_deploy.py
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# OpenLP - Open Source Lyrics Projection #
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# Copyright (c) 2008-2016 OpenLP Developers #
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# 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 #
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
from tempfile import mkdtemp
|
||||||
|
from unittest import TestCase
|
||||||
|
|
||||||
|
from openlp.core.api.http.server import HttpServer
|
||||||
|
from openlp.plugins.remotes.deploy import check_for_previous_deployment
|
||||||
|
|
||||||
|
from tests.functional import patch
|
||||||
|
|
||||||
|
|
||||||
|
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'resources'))
|
||||||
|
|
||||||
|
|
||||||
|
class TestDeploy(TestCase):
|
||||||
|
"""
|
||||||
|
Test the Remote deploy functions
|
||||||
|
"""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
"""
|
||||||
|
Setup for tests
|
||||||
|
"""
|
||||||
|
self.app_root = mkdtemp()
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
"""
|
||||||
|
Clean up after tests
|
||||||
|
"""
|
||||||
|
shutil.rmtree(self.app_root)
|
||||||
|
|
||||||
|
@patch('openlp.plugins.remotes.deploy.os.path.isfile')
|
||||||
|
@patch('openlp.plugins.remotes.deploy.os.mknod')
|
||||||
|
def test_check_for_previous_deployment_false(self, mocked_mknod, mocked_isfile):
|
||||||
|
"""
|
||||||
|
Remote Deploy tests - Test when the marker file is missing
|
||||||
|
"""
|
||||||
|
# GIVEN: A new setup with not market file
|
||||||
|
# WHEN: I check for a deployment which does not create the marker file
|
||||||
|
mocked_isfile.return_value = False
|
||||||
|
processed = check_for_previous_deployment(self.app_root)
|
||||||
|
|
||||||
|
# THEN test the see if marker is present and has not been created
|
||||||
|
self.assertFalse(processed, "should return False as marker does not exist")
|
||||||
|
mocked_isfile.assert_called_once_with(os.path.join(self.app_root, "marker.txt"))
|
||||||
|
mocked_mknod.assert_not_called()
|
||||||
|
|
||||||
|
@patch('openlp.plugins.remotes.deploy.os.path.isfile')
|
||||||
|
@patch('openlp.plugins.remotes.deploy.os.mknod')
|
||||||
|
def test_check_for_previous_deployment_true(self, mocked_mknod, mocked_isfile):
|
||||||
|
"""
|
||||||
|
Remote Deploy tests - Test when the marker file is missing
|
||||||
|
"""
|
||||||
|
# GIVEN: A new setup with not market file
|
||||||
|
# WHEN: I check for a deployment which does not create the marker file
|
||||||
|
mocked_isfile.return_value = False
|
||||||
|
processed = check_for_previous_deployment(self.app_root, True)
|
||||||
|
|
||||||
|
# THEN test the see if marker is present and has not been created
|
||||||
|
marker_file = os.path.join(self.app_root, "marker.txt")
|
||||||
|
self.assertFalse(processed, "should return False as marker does not exist")
|
||||||
|
mocked_isfile.assert_called_once_with(marker_file)
|
||||||
|
mocked_mknod.assert_called_once_with(marker_file)
|
||||||
|
|
||||||
|
@patch('openlp.plugins.remotes.deploy.os.path.isfile')
|
||||||
|
@patch('openlp.plugins.remotes.deploy.os.mknod')
|
||||||
|
def test_check_for_previous_deployment_true(self, mocked_mknod, mocked_isfile):
|
||||||
|
"""
|
||||||
|
Remote Deploy tests - Test when the marker file is missing
|
||||||
|
"""
|
||||||
|
# GIVEN: A new setup with not market file
|
||||||
|
# WHEN: I check for a deployment which does not create the marker file
|
||||||
|
mocked_isfile.return_value = True
|
||||||
|
processed = check_for_previous_deployment(self.app_root, True)
|
||||||
|
|
||||||
|
# THEN test the see if marker is present and has not been created
|
||||||
|
marker_file = os.path.join(self.app_root, "marker.txt")
|
||||||
|
self.assertTrue(processed, "should return True as marker does exist")
|
||||||
|
mocked_isfile.assert_called_once_with(marker_file)
|
||||||
|
mocked_mknod.assert_not_called()
|
BIN
tests/resources/remotes/deploy.zip
Normal file
BIN
tests/resources/remotes/deploy.zip
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user