def setUp(self): self.view = Mock(spec=ApplicationView) self.undertest = ImageLoadingDialogManager(self.view)
class ImageLoadingDialogManagerTest(unittest.TestCase): def setUp(self): self.view = Mock(spec=ApplicationView) self.undertest = ImageLoadingDialogManager(self.view) def test_wait_for_source_shows_dialog(self): source_reading = Mock(spec=SourceReading) assert_that(self.view.show_image_loading_dialog.called, equal_to(False)) self.undertest.wait_for_item(source_reading) self.view.show_image_loading_dialog.assert_called_once_with() def test_dialog_hidden_when_all_sources_ready(self): source_reading1 = Mock(spec=SourceReading) source_reading2 = Mock(spec=SourceReading) self.undertest.wait_for_item(source_reading1) self.undertest.wait_for_item(source_reading2) self.view.show_image_loading_dialog.assert_called_once_with() assert_that(self.view.hide_image_loading_dialog.called, equal_to(False)) self.undertest.set_item_done(source_reading1) assert_that(self.view.hide_image_loading_dialog.called, equal_to(False)) self.undertest.set_item_done(source_reading2) self.view.hide_image_loading_dialog.assert_called_once_with() def test_set_item_done_that_wasnt_in_wait_list_gets_ignored(self): source_reading1 = Mock(spec=SourceReading) source_reading2 = Mock(spec=SourceReading) self.undertest.wait_for_item(source_reading1) self.undertest.set_item_done(source_reading2) self.view.show_image_loading_dialog.assert_called_once_with() assert_that(self.view.hide_image_loading_dialog.called, equal_to(False)) def test_wait_on_item_twice_only_requires_setting_done_once(self): source_reading1 = Mock(spec=SourceReading) self.undertest.wait_for_item(source_reading1) self.undertest.wait_for_item(source_reading1) self.view.show_image_loading_dialog.assert_called_once_with() self.undertest.set_item_done(source_reading1) self.view.hide_image_loading_dialog.assert_called_once_with()