Ejemplo n.º 1
0
    def test_set_defaults(self):
        """
        Test that the default values are set when set_defaults() is run
        """
        # GIVEN: An initialised FRW and a whole lot of stuff mocked out
        frw = FirstTimeForm(None)
        frw.initialize(MagicMock())
        with patch.object(frw, 'restart') as mocked_restart, \
                patch.object(frw, 'cancel_button') as mocked_cancel_button, \
                patch.object(frw, 'no_internet_finish_button') as mocked_no_internet_finish_btn, \
                patch.object(frw, 'currentIdChanged') as mocked_currentIdChanged, \
                patch.object(Registry, 'register_function') as mocked_register_function, \
                patch('openlp.core.ui.firsttimeform.Settings') as MockedSettings, \
                patch('openlp.core.ui.firsttimeform.gettempdir') as mocked_gettempdir, \
                patch('openlp.core.ui.firsttimeform.create_paths') as mocked_create_paths, \
                patch.object(frw.application, 'set_normal_cursor'):
            mocked_settings = MagicMock()
            mocked_settings.value.return_value = True
            MockedSettings.return_value = mocked_settings
            mocked_gettempdir.return_value = 'temp'
            expected_temp_path = Path('temp', 'openlp')

            # WHEN: The set_defaults() method is run
            frw.set_defaults()

            # THEN: The default values should have been set
            mocked_restart.assert_called_with()
            assert 'http://openlp.org/files/frw/' == frw.web, 'The default URL should be set'
            mocked_cancel_button.clicked.connect.assert_called_with(
                frw.on_cancel_button_clicked)
            mocked_no_internet_finish_btn.clicked.connect.assert_called_with(
                frw.on_no_internet_finish_button_clicked)
            mocked_currentIdChanged.connect.assert_called_with(
                frw.on_current_id_changed)
            mocked_register_function.assert_called_with(
                'config_screen_changed', frw.update_screen_list_combo)
            mocked_no_internet_finish_btn.setVisible.assert_called_with(False)
            mocked_settings.value.assert_called_with('core/has run wizard')
            mocked_gettempdir.assert_called_with()
            mocked_create_paths.assert_called_with(expected_temp_path)
Ejemplo n.º 2
0
    def test_set_defaults(self):
        """
        Test that the default values are set when set_defaults() is run
        """
        # GIVEN: An initialised FRW and a whole lot of stuff mocked out
        frw = FirstTimeForm(None)
        frw.initialize(MagicMock())
        mocked_settings = MagicMock()
        mocked_settings.value.side_effect = lambda key: {
            'core/has run wizard': False
        }[key]
        with patch.object(frw, 'restart') as mocked_restart, \
                patch.object(frw, 'currentIdChanged') as mocked_currentIdChanged, \
                patch.object(frw, 'theme_combo_box') as mocked_theme_combo_box, \
                patch.object(frw, 'songs_check_box') as mocked_songs_check_box, \
                patch.object(Registry, 'register_function') as mocked_register_function, \
                patch('openlp.core.ui.firsttimeform.Settings', return_value=mocked_settings), \
                patch('openlp.core.ui.firsttimeform.gettempdir', return_value='temp') as mocked_gettempdir, \
                patch('openlp.core.ui.firsttimeform.create_paths') as mocked_create_paths, \
                patch.object(frw.application, 'set_normal_cursor'):
            mocked_theme_manager = MagicMock()
            Registry().register('theme_manager', mocked_theme_manager)

            # WHEN: The set_defaults() method is run
            frw.set_defaults()

            # THEN: The default values should have been set
            mocked_restart.assert_called_once()
            assert 'https://get.openlp.org/ftw/' == frw.web, 'The default URL should be set'
            mocked_currentIdChanged.connect.assert_called_once_with(
                frw.on_current_id_changed)
            mocked_register_function.assert_called_once_with(
                'config_screen_changed', frw.screen_selection_widget.load)
            mocked_settings.value.assert_has_calls(
                [call('core/has run wizard')])
            mocked_gettempdir.assert_called_once()
            mocked_create_paths.assert_called_once_with(Path('temp', 'openlp'))
            mocked_theme_combo_box.clear.assert_called_once()
            mocked_theme_manager.assert_not_called()
            mocked_songs_check_box.assert_not_called()
Ejemplo n.º 3
0
    def test_set_defaults(self):
        """
        Test that the default values are set when set_defaults() is run
        """
        # GIVEN: An initialised FRW and a whole lot of stuff mocked out
        frw = FirstTimeForm(None)
        frw.initialize(MagicMock())
        with patch.object(frw, 'restart') as mocked_restart, \
                patch.object(frw, 'cancel_button') as mocked_cancel_button, \
                patch.object(frw, 'no_internet_finish_button') as mocked_no_internet_finish_btn, \
                patch.object(frw, 'currentIdChanged') as mocked_currentIdChanged, \
                patch.object(Registry, 'register_function') as mocked_register_function, \
                patch('openlp.core.ui.firsttimeform.Settings') as MockedSettings, \
                patch('openlp.core.ui.firsttimeform.gettempdir') as mocked_gettempdir, \
                patch('openlp.core.ui.firsttimeform.check_directory_exists') as mocked_check_directory_exists, \
                patch.object(frw.application, 'set_normal_cursor') as mocked_set_normal_cursor:
            mocked_settings = MagicMock()
            mocked_settings.value.return_value = True
            MockedSettings.return_value = mocked_settings
            mocked_gettempdir.return_value = 'temp'
            expected_temp_path = os.path.join('temp', 'openlp')

            # WHEN: The set_defaults() method is run
            frw.set_defaults()

            # THEN: The default values should have been set
            mocked_restart.assert_called_with()
            self.assertEqual('http://openlp.org/files/frw/', frw.web, 'The default URL should be set')
            mocked_cancel_button.clicked.connect.assert_called_with(frw.on_cancel_button_clicked)
            mocked_no_internet_finish_btn.clicked.connect.assert_called_with(frw.on_no_internet_finish_button_clicked)
            mocked_currentIdChanged.connect.assert_called_with(frw.on_current_id_changed)
            mocked_register_function.assert_called_with('config_screen_changed', frw.update_screen_list_combo)
            mocked_no_internet_finish_btn.setVisible.assert_called_with(False)
            mocked_settings.value.assert_called_with('core/has run wizard')
            mocked_gettempdir.assert_called_with()
            mocked_check_directory_exists.assert_called_with(expected_temp_path)
Ejemplo n.º 4
0
    def test_set_defaults_rerun(self):
        """
        Test that the default values are set when set_defaults() is run
        """
        # GIVEN: An initialised FRW and a whole lot of stuff mocked out
        frw = FirstTimeForm(None)
        frw.initialize(MagicMock())
        mocked_settings = MagicMock()
        mocked_settings.value.side_effect = \
            lambda key: {'core/has run wizard': True, 'themes/global theme': 'Default Theme'}[key]
        with patch.object(frw, 'restart') as mocked_restart, \
                patch.object(frw, 'currentIdChanged') as mocked_currentIdChanged, \
                patch.object(frw, 'theme_combo_box', **{'findText.return_value': 3}) as mocked_theme_combo_box, \
                patch.multiple(frw, songs_check_box=DEFAULT, bible_check_box=DEFAULT, presentation_check_box=DEFAULT,
                               image_check_box=DEFAULT, media_check_box=DEFAULT, custom_check_box=DEFAULT,
                               song_usage_check_box=DEFAULT, alert_check_box=DEFAULT), \
                patch.object(Registry, 'register_function') as mocked_register_function, \
                patch('openlp.core.ui.firsttimeform.Settings', return_value=mocked_settings), \
                patch('openlp.core.ui.firsttimeform.gettempdir', return_value='temp') as mocked_gettempdir, \
                patch('openlp.core.ui.firsttimeform.create_paths') as mocked_create_paths, \
                patch.object(frw.application, 'set_normal_cursor'):
            mocked_plugin_manager = MagicMock()
            mocked_theme_manager = MagicMock(
                **{'get_theme_names.return_value': ['b', 'a', 'c']})
            Registry().register('plugin_manager', mocked_plugin_manager)
            Registry().register('theme_manager', mocked_theme_manager)

            # WHEN: The set_defaults() method is run
            frw.set_defaults()

            # THEN: The default values should have been set
            mocked_restart.assert_called_once()
            assert 'https://get.openlp.org/ftw/' == frw.web, 'The default URL should be set'
            mocked_currentIdChanged.connect.assert_called_once_with(
                frw.on_current_id_changed)
            mocked_register_function.assert_called_once_with(
                'config_screen_changed', frw.screen_selection_widget.load)
            mocked_settings.value.assert_has_calls(
                [call('core/has run wizard'),
                 call('themes/global theme')])
            mocked_gettempdir.assert_called_once()
            mocked_create_paths.assert_called_once_with(Path('temp', 'openlp'))
            mocked_theme_manager.get_theme_names.assert_called_once()
            mocked_theme_combo_box.clear.assert_called_once()
            mocked_plugin_manager.get_plugin_by_name.assert_has_calls(
                [
                    call('songs'),
                    call('bibles'),
                    call('presentations'),
                    call('images'),
                    call('media'),
                    call('custom'),
                    call('songusage'),
                    call('alerts')
                ],
                any_order=True)
            mocked_plugin_manager.get_plugin_by_name.assert_has_calls(
                [call().is_active()] * 8, any_order=True)
            mocked_theme_combo_box.addItems.assert_called_once_with(
                ['a', 'b', 'c'])
            mocked_theme_combo_box.findText.assert_called_once_with(
                'Default Theme')
            mocked_theme_combo_box.setCurrentIndex(3)