def test_detail_repository_abstraction_actions(self): """ Tests that repo detail component's abstractions changes are correctly reported to GUI. """ site = SiteConfigurationManager.get_blank_site() repo = site.repository control_agent = DetailRepositoryControlAgent(repo) presentation_agent = control_agent.get_presentation_agent() repo.enabled = True refresh_gui() # All widgets should be enabled flags = { 'enabled': True, 'type': True, 'name': True, } self.assert_widgets_sensitive_flag(presentation_agent, flags) # Enabled widget should be activated self.assert_widgets_active_flag(presentation_agent, {'enabled': True}) # When a name, username or password is set, correpsonding widget # should follow for name in ('name',): setattr(repo, name, 'abc') refresh_gui() self.assertEquals(presentation_agent[name].get_text(), 'abc', 'repo %s widget is wrong' % name) # Comboboxes value should reflect abstraction changes repotype = SiteDefaultsManager.get_repository_types().keys()[0] for name, value in {'type': repotype}.items(): setattr(repo, name, value) refresh_gui() self.assertEquals(presentation_agent.get_combobox_selection( presentation_agent[name]), value, 'repo %s widget selection is wrong' % name) # Tests that when done flag is set, allw widgets are disabled repo.done = True refresh_gui() # Tests widgets sensitivity after enablement flags = { 'enabled': False, 'type': False, 'name': False, } self.assert_widgets_sensitive_flag(presentation_agent, flags)
def test_detail_repository_read_only(self): """ Tests that database detail component's abstractions changes are correctly reported to GUI. """ site = SiteConfigurationManager.get_blank_site() repo = site.repository control_agent = DetailRepositoryControlAgent(repo, read_only=True) presentation_agent = control_agent.get_presentation_agent() refresh_gui() # Ine read-only mode, all widgets should be disabled flags = { 'enabled': False, 'name': False, 'type': False } self.assert_widgets_sensitive_flag(presentation_agent, flags)
def test_detail_repository_validity_flag(self): """ Tests that the validity flag is correctly set and unset when a component's widget value is set to a correct and incorrect value. """ site = SiteConfigurationManager.get_blank_site() repo = site.repository control_agent = DetailRepositoryControlAgent(repo, read_only=True) presentation_agent = control_agent.get_presentation_agent() repo.enabled = True refresh_gui() observer = ValidityObserver() control_agent.get_event_bus().subscribe( DataValidityEvent, observer.validity_changed) presentation_agent['name'].set_text('abc') refresh_gui() self.assertTrue(observer.notified, 'validity observer has not been notified') self.assertTrue(observer.flag, 'reopsitory validity should be true') presentation_agent['name'].set_text('ab c') refresh_gui() self.assertTrue(observer.notified, 'validity observer has not been notified') self.assertFalse(observer.flag, 'repository validity should be false') control_agent.get_event_bus().unsubscribe( DataValidityEvent, observer.validity_changed)
def test_detail_repository_gui_actions(self): """ Tests that repo detail component's presentation_agent works as expected, and that abstraction attributes are set correspondingly to GUI actions. """ site = SiteConfigurationManager.get_blank_site() repo = site.repository control_agent = DetailRepositoryControlAgent(repo) presentation_agent = control_agent.get_presentation_agent() refresh_gui() # Enables component presentation_agent['enabled'].set_active(True) refresh_gui() # Tests widgets sensitivity after enablement flags = { 'enabled': True, 'type': True, 'name': True, } self.assert_widgets_sensitive_flag(presentation_agent, flags) # When a checkbox is enabled, the corresponding attribute should follow for name in ('enabled',): presentation_agent[name].set_active(True) refresh_gui() self.assertTrue(getattr(repo, name), 'repo %s attribute is not enabled' % name) # Comboboxes value should be reported to abstraction repotype = SiteDefaultsManager.get_repository_types().keys()[0] for name, value in {'type': repotype}.items(): presentation_agent.set_value(name, value) refresh_gui() self.assertEquals(getattr(repo, name), value, 'repo %s attribute is wrong' % name)
def detail_repository_state_test(self, repo): """ Tests repo detail component's presentation_agent state """ control_agent = DetailRepositoryControlAgent(repo) presentation_agent = control_agent.get_presentation_agent() done = repo.done enabled = repo.enabled refresh_gui() # Tests checkboxes state flags = { 'enabled': enabled, } self.assert_widgets_active_flag(presentation_agent, flags) # Tests widgets sensitivity flags = { 'enabled': not done, 'type': not done and enabled, 'name': not done and enabled, } self.assert_widgets_sensitive_flag(presentation_agent, flags)