← Back to team overview

openlp-core team mailing list archive

Re: [Merge] lp:~suutari-olli/openlp/fix-advanced-bible-search-clear-button-giving-focus-to-quick into lp:openlp

 

your test 'test_on_lock_button_toggled_search_tab' is only really testing the last two lines of on_lock_button_toggled

As, you've gone to all the trouble of setting this test up it would be easy to test the if condition which sets the appropriate icon. In your current test add:

    # GIVEN:
    self.media_item.lock_icon = 'lock icon'
    sender_instance_mock = MagicMock()
    self.media_item.sender = MagicMock(return_value=sender_instance_mock)

    # THEN:
    sender_instance_mock.setIcon.assert_called_once_with('lock icon')

Then you can just copy and paste your test, make a few modifications calling self.media_item.on_lock_button_toggled with False and you've provided 100% coverage for the on_lock_button_toggled method, for not too much extra effort.

See also my inline comment for one small issue with your current test.





Diff comments:

> 
> === modified file 'tests/functional/openlp_plugins/bibles/test_mediaitem.py'
> --- tests/functional/openlp_plugins/bibles/test_mediaitem.py	2016-06-14 21:55:37 +0000
> +++ tests/functional/openlp_plugins/bibles/test_mediaitem.py	2016-09-16 21:53:08 +0000
> @@ -150,3 +150,36 @@
>          self.assertEqual(2, self.media_item.quickSearchButton.setEnabled.call_count, 'Disable and Enable the button')
>          self.assertEqual(1, self.media_item.check_search_result.call_count, 'Check results Should had been called once')
>          self.assertEqual(1, self.app.set_normal_cursor.call_count, 'Normal cursor should had been called once')
> +
> +    def test_on_clear_button_clicked(self):
> +        """
> +        Test that the on_clear_button_clicked works properly. (Used by Bible search tab)
> +        """
> +        # GIVEN: Mocked list_view, check_search_results & quick_search_edit.
> +        self.media_item.list_view = MagicMock()
> +        self.media_item.check_search_result = MagicMock()
> +        self.media_item.quick_search_edit = MagicMock()
> +
> +        # WHEN: on_clear_button_clicked is called
> +        self.media_item.on_clear_button_clicked()
> +
> +        # THEN: Search result should be reset and search field should receive focus.
> +        self.media_item.list_view.clear.assert_called_once_with(),
> +        self.media_item.check_search_result.assert_called_once_with(),
> +        self.media_item.quick_search_edit.clear.assert_called_once_with(),
> +        self.media_item.quick_search_edit.setFocus.assert_called_once_with()
> +
> +    def test_on_lock_button_toggled_search_tab(self):
> +        """
> +        Test that "on_lock_button_toggled" gives focus to the right field.
> +        """
> +        # GIVEN: Mocked functions
> +        self.media_item.sender = MagicMock()
> +        self.media_item.quickTab = MagicMock()
> +        self.media_item.quick_search_edit = MagicMock()
> +
> +        # WHEN: on_lock_button_toggled is called and quickTab.isVisible() returns = True.

quickTab.isVisible() isn't returning True, its returning an instance of MagicMock. For it to return True, you need to set the return_value on isVisable to True.

You could do it like this:
    self.media_item.quickTab = MagicMock()
    self.media_item.quickTab.isVisable = MagicMock(return_value=True)

but a as MagicMock automatically creates mocks for every method you call, you could also do it like:
    self.media_item.quickTab = MagicMock(**{'isVisible.return_value': True})

note in the above example we're unpacking a dictionary, because an keyword argument with a '.' in it isn't valid

> +        self.media_item.on_lock_button_toggled(True)
> +
> +        # THEN: on_quick_search_edit should receive focus.
> +        self.media_item.quick_search_edit.setFocus.assert_called_once_with()


-- 
https://code.launchpad.net/~suutari-olli/openlp/fix-advanced-bible-search-clear-button-giving-focus-to-quick/+merge/306015
Your team OpenLP Core is subscribed to branch lp:openlp.


Follow ups

References