Ejemplo n.º 1
0
class TestImageMediaItem(TestCase, TestMixin):
    """
    This is a test case to test various methods in the ImageTab.
    """
    def setUp(self):
        """
        Create the UI
        """
        Registry.create()
        Registry().register('settings_form', MagicMock())
        self.setup_application()
        self.build_settings()
        Settings().extend_default_settings(__default_settings__)
        self.parent = QtWidgets.QMainWindow()
        self.form = ImageTab(self.parent, 'Images', None, None)
        self.form.settings_form.register_post_process = MagicMock()

    def tearDown(self):
        """
        Delete all the C++ objects at the end so that we don't have a segfault
        """
        del self.parent
        del self.form
        self.destroy_settings()

    def test_save_tab_nochange(self):
        """
        Test no changes does not trigger post processing
        """
        # GIVEN: No changes on the form.
        self.initial_color = '#999999'
        # WHEN: the save is invoked
        self.form.save()
        # THEN: the post process should not be requested
        self.assertEqual(
            0, self.form.settings_form.register_post_process.call_count,
            'Image Post processing should not have been requested')

    def test_save_tab_change(self):
        """
        Test a color change is applied and triggers post processing.
        """
        # GIVEN: Apply a change to the form.
        self.form.on_background_color_changed('#999999')
        # WHEN: the save is invoked
        self.form.save()
        # THEN: the post process should be requested
        self.assertEqual(
            1, self.form.settings_form.register_post_process.call_count,
            'Image Post processing should have been requested')
        # THEN: The color should be set
        self.assertEqual(self.form.background_color, '#999999',
                         'The updated color should have been saved')
Ejemplo n.º 2
0
class TestImageMediaItem(TestCase, TestMixin):
    """
    This is a test case to test various methods in the ImageTab.
    """

    def setUp(self):
        """
        Create the UI
        """
        Registry.create()
        Registry().register('settings_form', MagicMock())
        self.setup_application()
        self.build_settings()
        Settings().extend_default_settings(__default_settings__)
        self.parent = QtWidgets.QMainWindow()
        self.form = ImageTab(self.parent, 'Images', None, None)
        self.form.settings_form.register_post_process = MagicMock()

    def tearDown(self):
        """
        Delete all the C++ objects at the end so that we don't have a segfault
        """
        del self.parent
        del self.form
        self.destroy_settings()

    def test_save_tab_nochange(self):
        """
        Test no changes does not trigger post processing
        """
        # GIVEN: No changes on the form.
        self.initial_color = '#999999'
        # WHEN: the save is invoked
        self.form.save()
        # THEN: the post process should not be requested
        self.assertEqual(0, self.form.settings_form.register_post_process.call_count,
                         'Image Post processing should not have been requested')

    def test_save_tab_change(self):
        """
        Test a color change is applied and triggers post processing.
        """
        # GIVEN: Apply a change to the form.
        self.form.on_background_color_changed('#999999')
        # WHEN: the save is invoked
        self.form.save()
        # THEN: the post process should be requested
        self.assertEqual(1, self.form.settings_form.register_post_process.call_count,
                         'Image Post processing should have been requested')
        # THEN: The color should be set
        self.assertEqual(self.form.background_color, '#999999', 'The updated color should have been saved')