fix tests

This commit is contained in:
Tim Bentley 2017-03-05 16:36:16 +00:00
parent 71f91e5d15
commit 9c3195d166
3 changed files with 46 additions and 49 deletions

View File

@ -23,7 +23,7 @@
import json import json
from openlp.core.common import RegistryProperties, Settings from openlp.core.common import RegistryProperties, Settings
from openlp.core.common.httputils import get_web_page
class Poller(RegistryProperties): class Poller(RegistryProperties):
""" """
@ -34,6 +34,8 @@ class Poller(RegistryProperties):
Constructor for the poll builder class. Constructor for the poll builder class.
""" """
super(Poller, self).__init__() super(Poller, self).__init__()
self.live_cache = None
self.stage_cache = None
def raw_poll(self): def raw_poll(self):
return { return {
@ -47,8 +49,8 @@ class Poller(RegistryProperties):
'version': 3, 'version': 3,
'isSecure': Settings().value('api/authentication enabled'), 'isSecure': Settings().value('api/authentication enabled'),
'isAuthorised': False, 'isAuthorised': False,
'isStagedActive': self.plugin_manager.get_plugin_by_name('remotes').is_stage_active(), 'isStagedActive': self.is_stage_active(),
'isLiveActive': self.plugin_manager.get_plugin_by_name('remotes').is_live_active() 'isLiveActive': self.is_live_active()
} }
def poll(self): def poll(self):
@ -65,3 +67,43 @@ class Poller(RegistryProperties):
'slide_count': self.live_controller.slide_count 'slide_count': self.live_controller.slide_count
} }
return json.dumps({'results': result}).encode() return json.dumps({'results': result}).encode()
def reset_cache(self):
"""
Reset the caches as the web has changed
:return:
"""
self.stage_cache = None
self.live_cache = None
def is_stage_active(self):
"""
Is stage active - call it and see but only once
:return: if stage is active or not
"""
if self.stage_cache is None:
try:
page = get_web_page("http://localhost:4316/stage")
except:
page = None
if page:
self.stage_cache = True
else:
self.stage_cache = False
return self.stage_cache
def is_live_active(self):
"""
Is main active - call it and see but only once
:return: if live is active or not
"""
if self.live_cache is None:
try:
page = get_web_page("http://localhost:4316/main")
except:
page = None
if page:
self.live_cache = True
else:
self.live_cache = False
return self.live_cache

View File

@ -25,7 +25,6 @@ import os
from openlp.core.api.http import register_endpoint from openlp.core.api.http import register_endpoint
from openlp.core.common import AppLocation, Registry, OpenLPMixin, check_directory_exists from openlp.core.common import AppLocation, Registry, OpenLPMixin, check_directory_exists
from openlp.core.common.httputils import get_web_page
from openlp.core.lib import Plugin, StringContent, translate, build_icon from openlp.core.lib import Plugin, StringContent, translate, build_icon
from openlp.plugins.remotes.endpoint import remote_endpoint from openlp.plugins.remotes.endpoint import remote_endpoint
from openlp.core.api.deploy import download_and_check from openlp.core.api.deploy import download_and_check
@ -44,8 +43,6 @@ class RemotesPlugin(Plugin, OpenLPMixin):
self.icon_path = ':/plugins/plugin_remote.png' self.icon_path = ':/plugins/plugin_remote.png'
self.icon = build_icon(self.icon_path) self.icon = build_icon(self.icon_path)
self.weight = -1 self.weight = -1
self.live_cache = None
self.stage_cache = None
register_endpoint(remote_endpoint) register_endpoint(remote_endpoint)
Registry().register_function('download_website', self.manage_download) Registry().register_function('download_website', self.manage_download)
@ -59,7 +56,6 @@ class RemotesPlugin(Plugin, OpenLPMixin):
check_directory_exists(os.path.join(AppLocation.get_section_data_path('remotes'), 'static')) check_directory_exists(os.path.join(AppLocation.get_section_data_path('remotes'), 'static'))
check_directory_exists(os.path.join(AppLocation.get_section_data_path('remotes'), 'templates')) check_directory_exists(os.path.join(AppLocation.get_section_data_path('remotes'), 'templates'))
@staticmethod @staticmethod
def about(): def about():
""" """
@ -85,46 +81,5 @@ class RemotesPlugin(Plugin, OpenLPMixin):
'title': translate('RemotePlugin', 'Web Remote', 'container title') 'title': translate('RemotePlugin', 'Web Remote', 'container title')
} }
def reset_cache(self):
"""
Reset the caches as the web has changed
:return:
"""
self.stage_cache = None
self.live_cache = None
def is_stage_active(self):
"""
Is stage active - call it and see buy only once
:return: if stage is active or not
"""
if self.stage_cache is None:
try:
page = get_web_page("http://localhost:4316/stage")
except:
page = None
if page:
self.stage_cache = True
else:
self.stage_cache = False
return self.stage_cache
def is_live_active(self):
"""
Is main active - call it and see buy only once
:return: if stage is active or not
"""
if self.live_cache is None:
try:
page = get_web_page("http://localhost:4316/main")
except:
page = None
if page:
self.live_cache = True
else:
self.live_cache = False
return self.live_cache
def manage_download(self): def manage_download(self):
download_and_check() download_and_check()
print("manage downlaod")

View File

@ -22,7 +22,7 @@
""" """
Functional tests to test the Http Server Class. Functional tests to test the Http Server Class.
""" """
import json
from unittest import TestCase from unittest import TestCase
from openlp.core.common import Registry, Settings from openlp.core.common import Registry, Settings