← Back to team overview

openlp-core team mailing list archive

Re: [Merge] lp:~alisonken1/openlp/bug-1407445 into lp:openlp

 

I had refactored the setup - on first try
Registry().get('service_manager') returned None.
Fixed.

On Thu, Jan 8, 2015 at 10:46 AM, Tim Bentley <tim.bentley@xxxxxxxxx> wrote:
> Review: Needs Information
>
>
>
> Diff comments:
>
>> === modified file 'openlp/core/ui/servicemanager.py'
>> --- openlp/core/ui/servicemanager.py  2014-12-31 10:58:13 +0000
>> +++ openlp/core/ui/servicemanager.py  2015-01-08 18:35:24 +0000
>> @@ -338,6 +338,8 @@
>>          self.setup_ui(self)
>>          # Need to use event as called across threads and UI is updated
>>          QtCore.QObject.connect(self, QtCore.SIGNAL('servicemanager_set_item'), self.on_set_item)
>> +        QtCore.QObject.connect(self, QtCore.SIGNAL('servicemanager_next_item'), self.next_item)
>> +        QtCore.QObject.connect(self, QtCore.SIGNAL('servicemanager_previous_item'), self.previous_item)
>>
>>      def bootstrap_post_set_up(self):
>>          """
>>
>> === modified file 'openlp/plugins/remotes/lib/httprouter.py'
>> --- openlp/plugins/remotes/lib/httprouter.py  2014-12-31 10:58:13 +0000
>> +++ openlp/plugins/remotes/lib/httprouter.py  2015-01-08 18:35:24 +0000
>> @@ -582,7 +582,7 @@
>>                  return self.do_http_error()
>>              self.service_manager.emit(QtCore.SIGNAL(event), data)
>>          else:
>> -            Registry().execute(event)
>> +            self.service_manager.emit(QtCore.SIGNAL(event))
>>          self.do_json_header()
>>          return json.dumps({'results': {'success': True}}).encode()
>>
>>
>> === modified file 'tests/functional/openlp_plugins/remotes/test_router.py'
>> --- tests/functional/openlp_plugins/remotes/test_router.py    2014-12-31 10:58:13 +0000
>> +++ tests/functional/openlp_plugins/remotes/test_router.py    2015-01-08 18:35:24 +0000
>> @@ -32,8 +32,9 @@
>>  import os
>>  import urllib.request
>>  from unittest import TestCase
>> -
>> +from PyQt4 import QtCore
>>  from openlp.core.common import Settings, Registry
>> +from openlp.core.ui import ServiceManager
>>  from openlp.plugins.remotes.lib.httpserver import HttpRouter
>>  from urllib.parse import urlparse
>>  from tests.functional import MagicMock, patch, mock_open
>> @@ -61,9 +62,12 @@
>>          """
>>          Create the UI
>>          """
>> +        Registry.create()
>>          self.setup_application()
>>          self.build_settings()
>>          Settings().extend_default_settings(__default_settings__)
>> +        self.service_manager = ServiceManager()
>> +        self.service_manager = Registry().service_list['service_manager'] = self.service_manager
>
> Why do you need this the previous line should have created and registered a valid servicemanager object.
>
>>          self.router = HttpRouter()
>>
>>      def tearDown(self):
>> @@ -299,3 +303,41 @@
>>              mocked_image_manager.assert_called_any(os.path.normpath('thumbnails\\another test'),
>>                                                     'slide1.png', None, '120x90')
>>              mocked_image_manager.assert_called_any(os.path.normpath('thumbnails\\another test'), 'slide1.png', '120x90')
>> +
>> +    def remote_next_test(self):
>> +        """
>> +        Test service manager receives remote next click properly (bug 1407445)
>> +        """
>> +        # GIVEN: initial setup and mocks
>> +        self.router.routes = [(r'^/api/service/(.*)$', {'function': self.router.service, 'secure': False})]
>> +        self.router.request_data = False
>> +        mocked_next_item = MagicMock()
>> +        self.service_manager.next_item = mocked_next_item
>> +        with patch.object(self.service_manager, 'setup_ui'), \
>> +                patch.object(self.router, 'do_json_header'):
>> +            self.service_manager.bootstrap_initialise()
>> +            self.app.processEvents()
>> +            # WHEN: Remote next is received
>> +            self.router.service(action='next')
>> +            self.app.processEvents()
>> +            # THEN: service_manager.next_item() should have been called
>> +            self.assertTrue(mocked_next_item.called, 'next_item() should have been called in service_manager')
>> +
>> +    def remote_previous_test(self):
>> +        """
>> +        Test service manager receives remote previous click properly (bug 1407445)
>> +        """
>> +        # GIVEN: initial setup and mocks
>> +        self.router.routes = [(r'^/api/service/(.*)$', {'function': self.router.service, 'secure': False})]
>> +        self.router.request_data = False
>> +        mocked_previous_item = MagicMock()
>> +        self.service_manager.previous_item = mocked_previous_item
>> +        with patch.object(self.service_manager, 'setup_ui'), \
>> +                patch.object(self.router, 'do_json_header'):
>> +            self.service_manager.bootstrap_initialise()
>> +            self.app.processEvents()
>> +            # WHEN: Remote next is received
>> +            self.router.service(action='previous')
>> +            self.app.processEvents()
>> +            # THEN: service_manager.next_item() should have been called
>> +            self.assertTrue(mocked_previous_item.called, 'previous_item() should have been called in service_manager')
>>
>
>
> --
> https://code.launchpad.net/~alisonken1/openlp/bug-1407445/+merge/245894
> You are the owner of lp:~alisonken1/openlp/bug-1407445.



-- 
- Ken
Registered Linux user 296561
Slackin' since 1993
Slackware Linux (http://www.slackware.com)

https://code.launchpad.net/~alisonken1/openlp/bug-1407445/+merge/245894
Your team OpenLP Core is subscribed to branch lp:openlp.


References