def test_constructor___View_fires_right_click_event___Show_menu_at_correct_coordinates( self): right_click_event = Event() menu = self.mocks.CreateMock(MockQMenu) menu.popup('screen coordinates') job_models = [ JobModel(Job('eric', pyjenkins.job.JobStatus.DISABLED), False), JobModel(Job('john', pyjenkins.job.JobStatus.FAILING), False), JobModel(Job('terry', pyjenkins.job.JobStatus.OK), False) ] self._stub_out_set_jobs() self.menu_factory.create(job_models[1], mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(menu) self.view.right_click_event().InAnyOrder().AndReturn(right_click_event) self.mocks.ReplayAll() adapter = gui.jobs.ListViewAdapter(self.view, self.media, self.menu_factory, self.qtgui) # @UnusedVariable adapter.set_jobs(job_models) right_click_event.fire('john', 'screen coordinates') mox.Verify(menu)
def __init__(self, view, media_files, menu_factory, qtgui=QtGuiFactory()): """ @type view: gui.jobs.ListView @type media_files: gui.media.MediaFiles @type menu_factory: gui.jobs.ContextMenuFactory @type qtgui: QtGuiFactory """ self._view = view self._qtgui = qtgui self._menu_factory = menu_factory self._ignored_event = Event() self._unignored_event = Event() self._enabled_event = Event() self._disabled_event = Event() self._job_models = [] view.right_click_event().register(self._on_view_right_click) self._ignored_icon = media_files.ignored_icon() self._status_icons = {JobStatus.DISABLED: media_files.disabled_icon(), JobStatus.FAILING: media_files.failing_icon(), JobStatus.OK: media_files.ok_icon(), JobStatus.UNKNOWN: media_files.unknown_icon()}
def setUp(self): self.mocks = mox.Mox() self.jobs_filter = self.mocks.CreateMock(IFilter) self.messageComposer = self.mocks.CreateMock(IMessageComposer) self.statusReader = self.mocks.CreateMock(IStatusReader) self.statusEvent = self.mocks.CreateMock(IEvent) self.jobsModel = self.mocks.CreateMock(JobsModel) self.jobsEvent = Event() self.jobsModel.jobs_updated_event().AndReturn(self.jobsEvent) self.jobs = [Job('who', 'cares?')] self.job_models = [JobModel(self.jobs[0], False)]
def __init__(self): QtGui.QGroupBox.__init__(self, "Jobs") self._right_click_event = Event() self._jobs = QtGui.QListWidget(self) self._jobs.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self._jobs.customContextMenuRequested.connect( self._on_custom_context_menu_requested) layout = QtGui.QVBoxLayout() layout.addWidget(self._jobs) self.setLayout(layout)
def __init__(self, view, media_files, menu_factory, qtgui=QtGuiFactory()): """ @type view: gui.jobs.ListView @type media_files: gui.media.MediaFiles @type menu_factory: gui.jobs.ContextMenuFactory @type qtgui: QtGuiFactory """ self._view = view self._qtgui = qtgui self._menu_factory = menu_factory self._ignored_event = Event() self._unignored_event = Event() self._enabled_event = Event() self._disabled_event = Event() self._job_models = [] view.right_click_event().register(self._on_view_right_click) self._ignored_icon = media_files.ignored_icon() self._status_icons = { JobStatus.DISABLED: media_files.disabled_icon(), JobStatus.FAILING: media_files.failing_icon(), JobStatus.OK: media_files.ok_icon(), JobStatus.UNKNOWN: media_files.unknown_icon() }
def test___set_jobs___Four_jobs___List_with_correct_names_and_statuses_passed_to_view( self): jobs = [ JobModel(Job('eric', pyjenkins.job.JobStatus.DISABLED), False), JobModel(Job('john', pyjenkins.job.JobStatus.FAILING), False), JobModel(Job('terry', pyjenkins.job.JobStatus.OK), False), JobModel(Job('graham', pyjenkins.job.JobStatus.UNKNOWN), False) ] self.qtgui.QListWidgetItem('disabled icon', 'eric').AndReturn('item for eric') self.qtgui.QListWidgetItem('failing icon', 'john').AndReturn('item for john') self.qtgui.QListWidgetItem('ok icon', 'terry').AndReturn('item for terry') self.qtgui.QListWidgetItem('unknown icon', 'graham').AndReturn('item for graham') self.view.right_click_event().InAnyOrder().AndReturn(Event()) self.view.set_list([ 'item for eric', 'item for john', 'item for terry', 'item for graham' ]) self.mocks.ReplayAll() adapter = gui.jobs.ListViewAdapter(self.view, self.media, self.menu_factory, self.qtgui) adapter.set_jobs(jobs) mox.Verify(self.view)
def __init__(self, jenkins, error_logger, jobs_updated_event=Event()): self._jenkins = jenkins self._error_logger = error_logger self._jobs_updated_event = jobs_updated_event self._models = [] self._ignore = set()
def test_Constructor_ModelFiresStatusChangedEvent_ViewSetStatusCalled(self): mocks = mox.Mox() model = mocks.CreateMock(IModel) view = mocks.CreateMock(IView) event = Event() model.status_changed_event().AndReturn(event) view.set_status('some status string', 'status message') mocks.ReplayAll() presenter = Presenter(model, view) # @UnusedVariable event.fire('some status string', 'status message') mox.Verify(view)
def test_Constructor_ModelFiresStatusChangedEvent_ViewSetStatusCalled( self): mocks = mox.Mox() model = mocks.CreateMock(IModel) view = mocks.CreateMock(IView) event = Event() model.status_changed_event().AndReturn(event) view.set_status('some status string', 'status message') mocks.ReplayAll() presenter = Presenter(model, view) # @UnusedVariable event.fire('some status string', 'status message') mox.Verify(view)
def test_constructor___View_fires_right_click_event___Show_menu_at_correct_coordinates(self): right_click_event = Event() menu = self.mocks.CreateMock(MockQMenu) menu.popup('screen coordinates') job_models = [JobModel(Job('eric', pyjenkins.job.JobStatus.DISABLED), False), JobModel(Job('john', pyjenkins.job.JobStatus.FAILING), False), JobModel(Job('terry', pyjenkins.job.JobStatus.OK), False)] self._stub_out_set_jobs() self.menu_factory.create(job_models[1], mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(menu) self.view.right_click_event().InAnyOrder().AndReturn(right_click_event) self.mocks.ReplayAll() adapter = gui.jobs.ListViewAdapter(self.view, self.media, self.menu_factory, self.qtgui) # @UnusedVariable adapter.set_jobs(job_models) right_click_event.fire('john', 'screen coordinates') mox.Verify(menu)
def test_constructor___User_clicks_disable_menu_item___Fire_job_disabled_event(self): job_models = [JobModel(Job('eric', pyjenkins.job.JobStatus.FAILING), False)] right_click_event = Event() menu = self.mocks.CreateMock(MockQMenu) menu_factory = MockMenuFactory(menu) mock_event_handler = MockEventHandler() self.view.right_click_event().InAnyOrder().AndReturn(right_click_event) self._stub_out_set_jobs() menu.popup(mox.IgnoreArg()) self.mocks.ReplayAll() adapter = gui.jobs.ListViewAdapter(self.view, self.media, menu_factory, self.qtgui) # @UnusedVariable adapter.job_disabled_event().register(mock_event_handler) adapter.set_jobs(job_models) right_click_event.fire('eric', 'screen coordinates') menu_factory.disable_callback() self.assertEqual('eric', mock_event_handler.argument)
def test___set_jobs___Empty_list___Empty_list_passed_to_view_set_list( self): self.view.right_click_event().InAnyOrder().AndReturn(Event()) self.view.set_list([]) self.mocks.ReplayAll() adapter = gui.jobs.ListViewAdapter(self.view, self.media, self.menu_factory, self.qtgui) adapter.set_jobs([]) mox.Verify(self.view)
def __init__(self): QtGui.QGroupBox.__init__(self, "Jobs") self._right_click_event = Event() self._jobs = QtGui.QListWidget(self) self._jobs.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self._jobs.customContextMenuRequested.connect(self._on_custom_context_menu_requested) layout = QtGui.QVBoxLayout() layout.addWidget(self._jobs) self.setLayout(layout)
class ListView(QtGui.QGroupBox): def right_click_event(self): """ Listeners receive Event.fire(job_name:str, pos:PySide.QtCore.QPoint) @rtype: trayjenkins.event.IEvent """ return self._right_click_event def __init__(self): QtGui.QGroupBox.__init__(self, "Jobs") self._right_click_event = Event() self._jobs = QtGui.QListWidget(self) self._jobs.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self._jobs.customContextMenuRequested.connect( self._on_custom_context_menu_requested) layout = QtGui.QVBoxLayout() layout.addWidget(self._jobs) self.setLayout(layout) def _on_custom_context_menu_requested(self, point): """ @type point: PySide.QtCore.QPoint """ item = self._jobs.itemAt(point) if item is not None: self._right_click_event.fire(item.text(), self._jobs.mapToGlobal(point)) def set_list(self, items): """ @type items: [PySide.QtGui.QListWidgetItem] """ self._jobs.clear() for item in items: self._jobs.addItem(item)
class ListView(QtGui.QGroupBox): def right_click_event(self): """ Listeners receive Event.fire(job_name:str, pos:PySide.QtCore.QPoint) @rtype: trayjenkins.event.IEvent """ return self._right_click_event def __init__(self): QtGui.QGroupBox.__init__(self, "Jobs") self._right_click_event = Event() self._jobs = QtGui.QListWidget(self) self._jobs.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self._jobs.customContextMenuRequested.connect(self._on_custom_context_menu_requested) layout = QtGui.QVBoxLayout() layout.addWidget(self._jobs) self.setLayout(layout) def _on_custom_context_menu_requested(self, point): """ @type point: PySide.QtCore.QPoint """ item = self._jobs.itemAt(point) if item is not None: self._right_click_event.fire(item.text(), self._jobs.mapToGlobal(point)) def set_list(self, items): """ @type items: [PySide.QtGui.QListWidgetItem] """ self._jobs.clear() for item in items: self._jobs.addItem(item)
def test_constructor___User_clicks_disable_menu_item___Fire_job_disabled_event( self): job_models = [ JobModel(Job('eric', pyjenkins.job.JobStatus.FAILING), False) ] right_click_event = Event() menu = self.mocks.CreateMock(MockQMenu) menu_factory = MockMenuFactory(menu) mock_event_handler = MockEventHandler() self.view.right_click_event().InAnyOrder().AndReturn(right_click_event) self._stub_out_set_jobs() menu.popup(mox.IgnoreArg()) self.mocks.ReplayAll() adapter = gui.jobs.ListViewAdapter(self.view, self.media, menu_factory, self.qtgui) # @UnusedVariable adapter.job_disabled_event().register(mock_event_handler) adapter.set_jobs(job_models) right_click_event.fire('eric', 'screen coordinates') menu_factory.disable_callback() self.assertEqual('eric', mock_event_handler.argument)
def test_fire_SingleHandlerSingleArgument_HandlerCalledAsFunctionWithArgument(self): handler = SingleArgumentHandler() event = Event() event.register(handler) event.fire('arg 1') self.assertEqual('arg 1', handler.argument)
def test_fire_TwoHandlers_BothHandlersCalledAsFunction(self): handlerOne = SingleArgumentHandler() handlerTwo = SingleArgumentHandler() event = Event() event.register(handlerOne) event.register(handlerTwo) event.fire('arg 1') self.assertEqual('arg 1', handlerOne.argument) self.assertEqual('arg 1', handlerTwo.argument)
def test_Constructor___View_fires_job_ignored_event___Model_ignore_job_called(self): mocks = mox.Mox() model = mocks.CreateMock(IModel) view = mocks.CreateMock(IView) job_ignored_event = Event() model.jobs_updated_event().AndReturn(Event()) view.job_ignored_event().InAnyOrder().AndReturn(job_ignored_event) view.job_unignored_event().InAnyOrder().AndReturn(Event()) view.job_enabled_event().InAnyOrder().AndReturn(Event()) view.job_disabled_event().InAnyOrder().AndReturn(Event()) model.ignore_job('spam') mocks.ReplayAll() presenter = Presenter(model, view) # @UnusedVariable job_ignored_event.fire('spam') mox.Verify(model)
def test_Constructor_ModelFiresJobsUpdatedEvent_ViewSetJobsCalled(self): mocks = mox.Mox() jobs = 'list of jobs' model = mocks.CreateMock(IModel) view = mocks.CreateMock(IView) jobs_updated_event = Event() model.jobs_updated_event().AndReturn(jobs_updated_event) view.job_ignored_event().InAnyOrder().AndReturn(Event()) view.job_unignored_event().InAnyOrder().AndReturn(Event()) view.job_enabled_event().InAnyOrder().AndReturn(Event()) view.job_disabled_event().InAnyOrder().AndReturn(Event()) view.set_jobs(jobs) mocks.ReplayAll() presenter = Presenter(model, view) # @UnusedVariable jobs_updated_event.fire(jobs) mox.Verify(view)
def test___set_jobs___Ignored_job___Ignored_job_gets_ignored_icon(self): jobs = [ JobModel(Job('john', pyjenkins.job.JobStatus.FAILING), False), JobModel(Job('terry', pyjenkins.job.JobStatus.OK), True) ] self.qtgui.QListWidgetItem('failing icon', 'john').AndReturn('item for john') self.qtgui.QListWidgetItem('ignored icon', 'terry').AndReturn('item for terry') self.view.right_click_event().InAnyOrder().AndReturn(Event()) self.view.set_list(['item for john', 'item for terry']) self.mocks.ReplayAll() adapter = gui.jobs.ListViewAdapter(self.view, self.media, self.menu_factory, self.qtgui) adapter.set_jobs(jobs) mox.Verify(self.view)
def __init__(self, jobs_model, jobs_filter, message_composer=DefaultMessageComposer(), status_reader=StatusReader(), status_changed_event=Event()): """ @type jobs_model: trayjenkins.jobs.IModel @type jobs_filter: trayjenkins.jobs.IFilter @type message_composer: trayjenkins.status.IMessageComposer @type status_reader: trayjenkins.status.IStatusReader @type status_changed_event: trayjenkins.event.Event """ self._jobs_filter = jobs_filter self._message_composer = message_composer self._status_reader = status_reader self._status_changed_event = status_changed_event self._lastStatus = JobStatus.UNKNOWN self._lastMessage = None jobs_model.jobs_updated_event().register(self._on_jobs_updated)
def test_fire_SingleHandlerTwoArguments_HandlerCalledAsFunctionWithBothArguments(self): class Handler: def __init__(self): self.arguments = [] def __call__(self, argumentOne, argumentTwo): self.arguments.append(argumentOne) self.arguments.append(argumentTwo) handler = Handler() event = Event() event.register(handler) event.fire('arg 1', 'arg 2') self.assertEqual(['arg 1', 'arg 2'], handler.arguments)
def test_fire_SameHandlerRegisteredTwice_HandlerOnlyCalledOnce(self): class CallCountHandler: def __init__(self): self.callCount = 0 def __call__(self, argument): self.callCount += 1 handler = CallCountHandler() event = Event() event.register(handler) event.register(handler) event.fire('arg 1') self.assertEqual(1, handler.callCount)
class StatusModelTests(TestCase): def setUp(self): self.mocks = mox.Mox() self.jobs_filter = self.mocks.CreateMock(IFilter) self.messageComposer = self.mocks.CreateMock(IMessageComposer) self.statusReader = self.mocks.CreateMock(IStatusReader) self.statusEvent = self.mocks.CreateMock(IEvent) self.jobsModel = self.mocks.CreateMock(JobsModel) self.jobsEvent = Event() self.jobsModel.jobs_updated_event().AndReturn(self.jobsEvent) self.jobs = [Job('who', 'cares?')] self.job_models = [JobModel(self.jobs[0], False)] def test_updateStatus_JobsModelFiresFirstUpdateEventStatusUnknownAndMessageNone_StatusChangedEventNotFired( self): self.jobs_filter.filter_jobs(self.job_models).AndReturn( self.job_models) self.messageComposer.message(self.jobs).AndReturn(None) self.statusReader.status(self.jobs).AndReturn(JobStatus.UNKNOWN) self.mocks.ReplayAll() model = Model( self.jobsModel, # @UnusedVariable self.jobs_filter, self.messageComposer, self.statusReader, self.statusEvent) self.jobsEvent.fire(self.job_models) mox.Verify(self.statusEvent) def test_updateStatus_JobsModelFiresFirstUpdateEvent_StatusChangedEventFired( self): self.jobs_filter.filter_jobs(self.job_models).AndReturn( self.job_models) self.messageComposer.message(self.jobs).AndReturn('message') self.statusReader.status(self.jobs).AndReturn(JobStatus.FAILING) self.statusEvent.fire(JobStatus.FAILING, 'message') self.mocks.ReplayAll() model = Model( self.jobsModel, # @UnusedVariable self.jobs_filter, self.messageComposer, self.statusReader, self.statusEvent) self.jobsEvent.fire(self.job_models) mox.Verify(self.statusEvent) def test_updateStatus_TwoJobsModelUpdatesWithSameStatusAndMessage_StatusChangedEventFiredOnce( self): self.jobs_filter.filter_jobs(self.job_models).AndReturn( self.job_models) self.jobs_filter.filter_jobs(self.job_models).AndReturn( self.job_models) self.messageComposer.message(self.jobs).AndReturn('message') self.messageComposer.message(self.jobs).AndReturn('message') self.statusReader.status(self.jobs).AndReturn(JobStatus.FAILING) self.statusReader.status(self.jobs).AndReturn(JobStatus.FAILING) self.statusEvent.fire(JobStatus.FAILING, 'message') self.mocks.ReplayAll() model = Model( self.jobsModel, # @UnusedVariable self.jobs_filter, self.messageComposer, self.statusReader, self.statusEvent) self.jobsEvent.fire(self.job_models) self.jobsEvent.fire(self.job_models) mox.Verify(self.statusEvent) def test_updateStatus_TwoJobsModelUpdatesWithDifferentStatus_StatusChangedEventFiredTwice( self): self.jobs_filter.filter_jobs(self.job_models).AndReturn( self.job_models) self.jobs_filter.filter_jobs(self.job_models).AndReturn( self.job_models) self.messageComposer.message(self.jobs).AndReturn('message') self.messageComposer.message(self.jobs).AndReturn('message') self.statusReader.status(self.jobs).AndReturn(JobStatus.FAILING) self.statusReader.status(self.jobs).AndReturn(JobStatus.OK) self.statusEvent.fire(JobStatus.FAILING, 'message') self.statusEvent.fire(JobStatus.OK, 'message') self.mocks.ReplayAll() model = Model( self.jobsModel, # @UnusedVariable self.jobs_filter, self.messageComposer, self.statusReader, self.statusEvent) self.jobsEvent.fire(self.job_models) self.jobsEvent.fire(self.job_models) mox.Verify(self.statusEvent) def test_updateStatus_TwoJobsModelUpdatesWithDifferentMessage_StatusChangedEventFiredTwice( self): self.jobs_filter.filter_jobs(self.job_models).AndReturn( self.job_models) self.jobs_filter.filter_jobs(self.job_models).AndReturn( self.job_models) self.messageComposer.message(self.jobs).AndReturn('message one') self.messageComposer.message(self.jobs).AndReturn('message two') self.statusReader.status(self.jobs).AndReturn(JobStatus.FAILING) self.statusReader.status(self.jobs).AndReturn(JobStatus.FAILING) self.statusEvent.fire(JobStatus.FAILING, 'message one') self.statusEvent.fire(JobStatus.FAILING, 'message two') self.mocks.ReplayAll() model = Model( self.jobsModel, # @UnusedVariable self.jobs_filter, self.messageComposer, self.statusReader, self.statusEvent) self.jobsEvent.fire(self.job_models) self.jobsEvent.fire(self.job_models) mox.Verify(self.statusEvent) def test_updateStatus_JobsFilterReturnsModifiedList_ModifiedListPassedTo( self): filtered_jobs = [Job('completely', 'different')] filtered_models = [JobModel(filtered_jobs[0], True)] self.jobs_filter.filter_jobs( self.job_models).AndReturn(filtered_models) self.messageComposer.message(filtered_jobs).AndReturn('message') self.statusReader.status(filtered_jobs).AndReturn(JobStatus.OK) self.statusEvent.fire(JobStatus.OK, 'message') self.mocks.ReplayAll() model = Model( self.jobsModel, # @UnusedVariable self.jobs_filter, self.messageComposer, self.statusReader, self.statusEvent) self.jobsEvent.fire(self.job_models) mox.Verify(self.statusEvent)
class StatusModelTests(TestCase): def setUp(self): self.mocks = mox.Mox() self.jobs_filter = self.mocks.CreateMock(IFilter) self.messageComposer = self.mocks.CreateMock(IMessageComposer) self.statusReader = self.mocks.CreateMock(IStatusReader) self.statusEvent = self.mocks.CreateMock(IEvent) self.jobsModel = self.mocks.CreateMock(JobsModel) self.jobsEvent = Event() self.jobsModel.jobs_updated_event().AndReturn(self.jobsEvent) self.jobs = [Job('who', 'cares?')] self.job_models = [JobModel(self.jobs[0], False)] def test_updateStatus_JobsModelFiresFirstUpdateEventStatusUnknownAndMessageNone_StatusChangedEventNotFired(self): self.jobs_filter.filter_jobs(self.job_models).AndReturn(self.job_models) self.messageComposer.message(self.jobs).AndReturn(None) self.statusReader.status(self.jobs).AndReturn(JobStatus.UNKNOWN) self.mocks.ReplayAll() model = Model(self.jobsModel, # @UnusedVariable self.jobs_filter, self.messageComposer, self.statusReader, self.statusEvent) self.jobsEvent.fire(self.job_models) mox.Verify(self.statusEvent) def test_updateStatus_JobsModelFiresFirstUpdateEvent_StatusChangedEventFired(self): self.jobs_filter.filter_jobs(self.job_models).AndReturn(self.job_models) self.messageComposer.message(self.jobs).AndReturn('message') self.statusReader.status(self.jobs).AndReturn(JobStatus.FAILING) self.statusEvent.fire(JobStatus.FAILING, 'message') self.mocks.ReplayAll() model = Model(self.jobsModel, # @UnusedVariable self.jobs_filter, self.messageComposer, self.statusReader, self.statusEvent) self.jobsEvent.fire(self.job_models) mox.Verify(self.statusEvent) def test_updateStatus_TwoJobsModelUpdatesWithSameStatusAndMessage_StatusChangedEventFiredOnce(self): self.jobs_filter.filter_jobs(self.job_models).AndReturn(self.job_models) self.jobs_filter.filter_jobs(self.job_models).AndReturn(self.job_models) self.messageComposer.message(self.jobs).AndReturn('message') self.messageComposer.message(self.jobs).AndReturn('message') self.statusReader.status(self.jobs).AndReturn(JobStatus.FAILING) self.statusReader.status(self.jobs).AndReturn(JobStatus.FAILING) self.statusEvent.fire(JobStatus.FAILING, 'message') self.mocks.ReplayAll() model = Model(self.jobsModel, # @UnusedVariable self.jobs_filter, self.messageComposer, self.statusReader, self.statusEvent) self.jobsEvent.fire(self.job_models) self.jobsEvent.fire(self.job_models) mox.Verify(self.statusEvent) def test_updateStatus_TwoJobsModelUpdatesWithDifferentStatus_StatusChangedEventFiredTwice(self): self.jobs_filter.filter_jobs(self.job_models).AndReturn(self.job_models) self.jobs_filter.filter_jobs(self.job_models).AndReturn(self.job_models) self.messageComposer.message(self.jobs).AndReturn('message') self.messageComposer.message(self.jobs).AndReturn('message') self.statusReader.status(self.jobs).AndReturn(JobStatus.FAILING) self.statusReader.status(self.jobs).AndReturn(JobStatus.OK) self.statusEvent.fire(JobStatus.FAILING, 'message') self.statusEvent.fire(JobStatus.OK, 'message') self.mocks.ReplayAll() model = Model(self.jobsModel, # @UnusedVariable self.jobs_filter, self.messageComposer, self.statusReader, self.statusEvent) self.jobsEvent.fire(self.job_models) self.jobsEvent.fire(self.job_models) mox.Verify(self.statusEvent) def test_updateStatus_TwoJobsModelUpdatesWithDifferentMessage_StatusChangedEventFiredTwice(self): self.jobs_filter.filter_jobs(self.job_models).AndReturn(self.job_models) self.jobs_filter.filter_jobs(self.job_models).AndReturn(self.job_models) self.messageComposer.message(self.jobs).AndReturn('message one') self.messageComposer.message(self.jobs).AndReturn('message two') self.statusReader.status(self.jobs).AndReturn(JobStatus.FAILING) self.statusReader.status(self.jobs).AndReturn(JobStatus.FAILING) self.statusEvent.fire(JobStatus.FAILING, 'message one') self.statusEvent.fire(JobStatus.FAILING, 'message two') self.mocks.ReplayAll() model = Model(self.jobsModel, # @UnusedVariable self.jobs_filter, self.messageComposer, self.statusReader, self.statusEvent) self.jobsEvent.fire(self.job_models) self.jobsEvent.fire(self.job_models) mox.Verify(self.statusEvent) def test_updateStatus_JobsFilterReturnsModifiedList_ModifiedListPassedTo(self): filtered_jobs = [Job('completely', 'different')] filtered_models = [JobModel(filtered_jobs[0], True)] self.jobs_filter.filter_jobs(self.job_models).AndReturn(filtered_models) self.messageComposer.message(filtered_jobs).AndReturn('message') self.statusReader.status(filtered_jobs).AndReturn(JobStatus.OK) self.statusEvent.fire(JobStatus.OK, 'message') self.mocks.ReplayAll() model = Model(self.jobsModel, # @UnusedVariable self.jobs_filter, self.messageComposer, self.statusReader, self.statusEvent) self.jobsEvent.fire(self.job_models) mox.Verify(self.statusEvent)
class ListViewAdapter(IView): def job_ignored_event(self): """ Listeners receive Event.fire(job_name:str) @rtype: trayjenkins.event.IEvent """ return self._ignored_event def job_unignored_event(self): """ Listeners receive Event.fire(job_name:str) @rtype: trayjenkins.event.IEvent """ return self._unignored_event def job_enabled_event(self): """ Listeners receive Event.fire(job_name:str) @rtype: trayjenkins.event.IEvent """ return self._enabled_event def job_disabled_event(self): """ Listeners receive Event.fire(job_name:str) @rtype: trayjenkins.event.IEvent """ return self._disabled_event def __init__(self, view, media_files, menu_factory, qtgui=QtGuiFactory()): """ @type view: gui.jobs.ListView @type media_files: gui.media.MediaFiles @type menu_factory: gui.jobs.ContextMenuFactory @type qtgui: QtGuiFactory """ self._view = view self._qtgui = qtgui self._menu_factory = menu_factory self._ignored_event = Event() self._unignored_event = Event() self._enabled_event = Event() self._disabled_event = Event() self._job_models = [] view.right_click_event().register(self._on_view_right_click) self._ignored_icon = media_files.ignored_icon() self._status_icons = {JobStatus.DISABLED: media_files.disabled_icon(), JobStatus.FAILING: media_files.failing_icon(), JobStatus.OK: media_files.ok_icon(), JobStatus.UNKNOWN: media_files.unknown_icon()} def set_jobs(self, job_models): """ @type jobs: [trayjenkins.jobs.JobModel] """ items = [] for model in job_models: if model.ignored: icon = self._ignored_icon else: icon = self._status_icons[model.job.status] items.append(self._qtgui.QListWidgetItem(icon, model.job.name)) self._view.set_list(items) self._job_models = job_models def _on_view_ignored(self, job_name): self._ignored_event.fire(job_name) def _on_view_unignored(self, job_name): self._unignored_event.fire(job_name) def _on_view_right_click(self, job_name, pos): """ @type job_name: str @param pos: Absolute screen coordinates @type pos: PySide.QtCore.QPoint """ menu = self._menu_factory.create(self._find_model(job_name), lambda: self._ignored_event.fire(job_name), lambda: self._unignored_event.fire(job_name), lambda: self._enabled_event.fire(job_name), lambda: self._disabled_event.fire(job_name)) menu.popup(pos) def _find_model(self, job_name): result = None for model in self._job_models: if model.job.name == job_name: result = model break return result
class ListViewAdapter(IView): def job_ignored_event(self): """ Listeners receive Event.fire(job_name:str) @rtype: trayjenkins.event.IEvent """ return self._ignored_event def job_unignored_event(self): """ Listeners receive Event.fire(job_name:str) @rtype: trayjenkins.event.IEvent """ return self._unignored_event def job_enabled_event(self): """ Listeners receive Event.fire(job_name:str) @rtype: trayjenkins.event.IEvent """ return self._enabled_event def job_disabled_event(self): """ Listeners receive Event.fire(job_name:str) @rtype: trayjenkins.event.IEvent """ return self._disabled_event def __init__(self, view, media_files, menu_factory, qtgui=QtGuiFactory()): """ @type view: gui.jobs.ListView @type media_files: gui.media.MediaFiles @type menu_factory: gui.jobs.ContextMenuFactory @type qtgui: QtGuiFactory """ self._view = view self._qtgui = qtgui self._menu_factory = menu_factory self._ignored_event = Event() self._unignored_event = Event() self._enabled_event = Event() self._disabled_event = Event() self._job_models = [] view.right_click_event().register(self._on_view_right_click) self._ignored_icon = media_files.ignored_icon() self._status_icons = { JobStatus.DISABLED: media_files.disabled_icon(), JobStatus.FAILING: media_files.failing_icon(), JobStatus.OK: media_files.ok_icon(), JobStatus.UNKNOWN: media_files.unknown_icon() } def set_jobs(self, job_models): """ @type jobs: [trayjenkins.jobs.JobModel] """ items = [] for model in job_models: if model.ignored: icon = self._ignored_icon else: icon = self._status_icons[model.job.status] items.append(self._qtgui.QListWidgetItem(icon, model.job.name)) self._view.set_list(items) self._job_models = job_models def _on_view_ignored(self, job_name): self._ignored_event.fire(job_name) def _on_view_unignored(self, job_name): self._unignored_event.fire(job_name) def _on_view_right_click(self, job_name, pos): """ @type job_name: str @param pos: Absolute screen coordinates @type pos: PySide.QtCore.QPoint """ menu = self._menu_factory.create( self._find_model(job_name), lambda: self._ignored_event.fire(job_name), lambda: self._unignored_event.fire(job_name), lambda: self._enabled_event.fire(job_name), lambda: self._disabled_event.fire(job_name)) menu.popup(pos) def _find_model(self, job_name): result = None for model in self._job_models: if model.job.name == job_name: result = model break return result