def test_detail_dnshost_gui_actions(self): """ Tests that repository detail component's presentation_agent works as expected, and that abstraction attributes are set correspondingly to GUI actions. """ site = SiteConfigurationManager.get_blank_site() dnshost = site.dnshost control_agent = DetailDNSHostControlAgent(dnshost) presentation_agent = control_agent.get_presentation_agent() refresh_gui() # When name entry is set, the abstraction should have corresponding # value set for name in ('name', 'description'): presentation_agent[name].set_text('abc') refresh_gui() self.assertEquals(getattr(dnshost, name), 'abc', 'dnshost %s attribute is wrong: %s' % (name, getattr(dnshost, name))) # Comboboxes value should be reported to abstraction domain = SiteDefaultsManager.get_domains().keys()[0] platform = SiteDefaultsManager.get_platforms().keys()[0] for name, value in {'domain': domain, 'platform': platform}.items(): presentation_agent.set_value(name, value) refresh_gui() self.assertEquals(getattr(dnshost, name), value, 'dnshost %s attribute is wrong' % name)
def test_detail_website_abstraction_actions(self): """ Tests that site detail component's abstractions changes are correctly reported to GUI. """ site = SiteConfigurationManager.get_blank_site() website = site.website control_agent = DetailSiteControlAgent(website) presentation_agent = control_agent.get_presentation_agent() refresh_gui() # Enables component website.enabled = True refresh_gui() # Tests widgets sensitivity after enablement flags = { 'enabled': True, 'maintenance': True, 'template': True, 'access': True, } self.assert_widgets_sensitive_flag(presentation_agent, flags) # When a widget is enabled, the corresponding attribute should follow for name in ('enabled', 'maintenance'): setattr(website, name, True) refresh_gui() self.assert_widgets_active_flag(presentation_agent, {name: True}) # Comboboxes value should reflect abstraction changes template = SiteDefaultsManager.get_site_templates().keys()[0] access = SiteDefaultsManager.get_site_accesses().keys()[0] for name, value in {'template': template, 'access': access}.items(): setattr(website, name, value) refresh_gui() self.assertEquals(presentation_agent.get_combobox_selection( presentation_agent[name]), value, 'site %s: %s/%s widget selection is wrong' % (name, value, presentation_agent.get_combobox_selection(presentation_agent[name]))) # Tests that when done flag is set, sentivity is disabled on enabled # and template widgets. Maintenance and access should remain sensitive website.done = True refresh_gui() # Tests final widgets sensitivity flags = { 'enabled': False, 'template': False, 'maintenance': True, 'access': True, } self.assert_widgets_sensitive_flag(presentation_agent, flags)
def __init__(self, site, read_only=False): DetailBaseControlAgent.__init__(self) site.get_event_bus().subscribe(DataChangeEvent, self.load_widgets_data) self.set_site(site) self.set_read_only_flag(read_only) pa = DetailDNSHostPresentationAgent(self) self.set_presentation_agent(pa) # Loads comboboxes items pa.set_items('domain', SiteDefaultsManager.get_domains()) pa.set_items('platform', SiteDefaultsManager.get_platforms()) pa.get_event_bus().subscribe(UIWidgetEvent, self.widget_evt_callback) # Initializes widget values self.load_widgets_data()
def test_detail_dnshost_abstraction_actions(self): """ Tests that database detail component's abstractions changes are correctly reported to GUI. """ site = SiteConfigurationManager.get_blank_site() dnshost = site.dnshost control_agent = DetailDNSHostControlAgent(dnshost) presentation_agent = control_agent.get_presentation_agent() refresh_gui() # All widgets should be enabled flags = { 'name': True, 'domain': True, 'platform': True, 'description': True } self.assert_widgets_sensitive_flag(presentation_agent, flags) # When a name or description is set, correpsonding widget # should follow for name in ('name', 'description'): setattr(dnshost, name, 'abc') refresh_gui() self.assertEquals(presentation_agent[name].get_text(), 'abc', 'dnshost %s widget is wrong' % name) # Comboboxes value should reflect abstraction changes domain = SiteDefaultsManager.get_domains().keys()[0] platform = SiteDefaultsManager.get_platforms().keys()[0] for name, value in {'domain': domain, 'platform': platform}.items(): setattr(dnshost, name, value) refresh_gui() self.assertEquals(presentation_agent.get_combobox_selection( presentation_agent[name]), value, 'dnshost %s widget selection is wrong' % name) # Tests that when done flag is set, allw widgets are disabled dnshost.done = True refresh_gui() # Tests widgets sensitivity after enablement flags = { 'description': False, 'name': False, 'domain': False, 'platform': False, } self.assert_widgets_sensitive_flag(presentation_agent, flags)
def test_detail_database_abstraction_actions(self): """ Tests that database detail component's abstractions changes are correctly reported to GUI. """ site = SiteConfigurationManager.get_blank_site() database = site.database control_agent = DetailDatabaseControlAgent(database) presentation_agent = control_agent.get_presentation_agent() database.enabled = True refresh_gui() # All widgets should be enabled flags = { 'enabled': True, 'type': True, 'name': True, 'username': True, 'password': 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', 'username', 'password'): setattr(database, name, 'abc') refresh_gui() self.assertEquals(presentation_agent[name].get_text(), 'abc', 'database %s widget is wrong' % name) # Comboboxes value should reflect abstraction changes dbtype = SiteDefaultsManager.get_database_types().keys()[0] for name, value in {'type': dbtype}.items(): setattr(database, name, value) refresh_gui() self.assertEquals(presentation_agent.get_combobox_selection( presentation_agent[name]), value, 'database %s widget selection is wrong' % name) # Tests that when done flag is set, allw widgets are disabled database.done = True refresh_gui() # Tests widgets sensitivity after enablement flags = { 'enabled': False, 'type': False, 'name': False, 'username': False, 'password': False, } self.assert_widgets_sensitive_flag(presentation_agent, flags)
def test_detail_website_gui_actions(self): """ Tests that site detail component's presentation_agent works as expected, and that abstraction attributes are set correspondingly to GUI actions. """ site = SiteConfigurationManager.get_blank_site() website = site.website control_agent = DetailSiteControlAgent(website) 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, 'maintenance': True, 'template': True, 'access': True, } self.assert_widgets_sensitive_flag(presentation_agent, flags) # When a checkbox is enabled, the corresponding attribute should follow for name in ('enabled', 'maintenance'): presentation_agent[name].set_active(True) refresh_gui() self.assertTrue(getattr(website, name), 'site %s attribute is not enabled' % name) # Comboboxes value should be reported to abstraction template = SiteDefaultsManager.get_site_templates().keys()[0] access = SiteDefaultsManager.get_site_accesses().keys()[0] for name, value in {'template': template, 'access': access}.items(): presentation_agent.set_value(name, value) refresh_gui() self.assertEquals(getattr(website, name), value, 'site %s attribute is wrong' % name)
def test_detail_database_gui_actions(self): """ Tests that database detail component's presentation_agent works as expected, and that abstraction attributes are set correspondingly to GUI actions. """ site = SiteConfigurationManager.get_blank_site() database = site.database control_agent = DetailDatabaseControlAgent(database) presentation_agent = control_agent.get_presentation_agent() presentation_agent['enabled'].set_active(True) refresh_gui() # Enables component presentation_agent['enabled'].set_active(True) refresh_gui() # Tests widgets sensitivity after enablement flags = { 'enabled': True, 'type': True, 'name': True, 'username': True, 'password': True, } self.assert_widgets_sensitive_flag(presentation_agent, flags) # When a widget is enabled, the corresponding attribute should follow for name in ('enabled',): setattr(database, name, True) refresh_gui() self.assert_widgets_active_flag(presentation_agent, {name: True}) # When an entry is set, the abstraction should have corresponding # value set for name in ('name', 'username', 'password'): presentation_agent[name].set_text('abc') refresh_gui() self.assertEquals(getattr(database, name), 'abc', 'database %s attribute is wrong' % name) # Comboboxes value should be reported to abstraction dbtype = SiteDefaultsManager.get_database_types().keys()[0] for name, value in {'type': dbtype}.items(): presentation_agent.set_value(name, value) refresh_gui() self.assertEquals(getattr(database, name), value, 'site %s attribute is wrong' % name)
def __init__(self): """ Initializes control agent. """ BaseControlAgent.__init__(self) self._hosts = [] self._filter_name = '*' self._filter_name_re = re.compile(r"^[\w\d\*_-]*$") self._filter_domain = '*' self._filter_domain_re = re.compile(r"^[\w\d\*\._-]*$") pa = ListSitesPresentationAgent(self) domains = SiteDefaultsManager.get_domains() domains['*'] = '*' pa.set_items('filter_domain', domains) pa.get_event_bus().subscribe(UIActionEvent, self.action_evt_callback) pa.get_event_bus().subscribe(UIWidgetEvent, self.widget_evt_callback) self.set_presentation_agent(pa)
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 get_default_config_data(): """ Generates the default site used to initialize internal site structures """ return { # General attributes 'general' : { 'id' : (None, int, 'Id should be a number'), 'platform' : (SiteDefaultsManager.get_default_platform(), SiteDefaultsManager.get_platforms().keys(), 'Unknown platform'), 'domain' : (SiteDefaultsManager.get_default_domain(), SiteDefaultsManager.get_domains().keys(), 'Unknown domain'), 'name' : ('', '^[\d\w_-]*$', 'Name should be an alphanumeric string'), 'description' : ('', None), 'done' : (False, bool), }, # Repository related attriutes 'repository' : { 'enabled' : (False, bool), 'type' : (SiteDefaultsManager.get_default_repository_type(), SiteDefaultsManager.get_repository_types().keys(), 'Unsupported RCS type'), 'name' : ('', '^[\d\w_-]*$', 'Name should be an alphanumeric string or _, without spaces'), 'done' : (False, bool) }, # Sites related attributes (for each available platform) 'website' : { 'enabled' : (False, bool), 'access' : (SiteDefaultsManager.get_default_site_access(), SiteDefaultsManager.get_site_accesses().keys(), 'Unsupported access'), 'maintenance' : (False, bool), 'template' : ('standard', SiteDefaultsManager.get_site_templates().keys(), 'Unsupported site template'), 'done' : (False, bool) }, # Databases related attributes (for each available platform) 'database' : { 'enabled' : (False, bool), 'type' : (SiteDefaultsManager.get_default_database_type(), SiteDefaultsManager.get_database_types().keys(), 'Unsupported database type'), 'name' : ('', '^[a-z0-9_]+$', 'Name should be a simple alphanumeric string without spaces'), 'username' : ('', '^[a-z0-9_]+$', 'Username should be a simple alphanumeric string without spaces'), 'password' : ('', None), 'done' : (False, bool) }, }
def test_set_site(self): """ Tests that site attributes react as expected when setting attributes value """ config = SiteConfigurationManager.get_blank_site() # DNS Host attributes dnshost = config.dnshost dnshost.desc = 'desc' self.assertEquals(dnshost.desc, 'desc') dnshost.name = 'name' self.assertEquals(dnshost.name, 'name') self.assertRaises(ValidationError, lambda x: setattr(dnshost, 'name', x), "f@ke") dnshost.domain = SiteDefaultsManager.get_default_domain() self.assertEquals(dnshost.domain, SiteDefaultsManager.get_default_domain()) self.assertRaises(ValidationError, lambda x: setattr(dnshost, 'domain', x), "fake") # Repository related attributes repository = config.repository repository.name = 'name' self.assertEquals(repository.name, 'name') self.assertRaises(ValidationError, lambda x: setattr(repository, 'name', x), "f@ke") repository.type = SiteDefaultsManager.get_default_repository_type() self.assertEquals(repository.type, SiteDefaultsManager.get_default_repository_type()) self.assertRaises(ValidationError, lambda x: setattr(repository, 'type', x), "fake") repository.enabled = True self.assertEquals(repository.enabled, True) self.assertRaises(ValidationError, lambda x: setattr(repository, 'enabled', x), 'fake') repository.done = True self.assertEquals(repository.done, True) self.assertRaises(ValidationError, lambda x: setattr(repository, 'done', x), 'fake') # Web site related attributes site = config.website site.template = SiteDefaultsManager.get_default_site_template() self.assertEquals(site.template, SiteDefaultsManager.get_default_site_template()) self.assertRaises(ValidationError, lambda x: setattr(repository, 'done', x), "fake") site.access = SiteDefaultsManager.get_default_site_access() self.assertEquals(site.access, SiteDefaultsManager.get_default_site_access()) self.assertRaises(ValidationError, lambda x: setattr(repository, 'done', x), "fake") site.maintenance = True self.assertEquals(site.maintenance, True) self.assertRaises(ValidationError, lambda x: setattr(site, 'maintenance', x), 'fake') site.enabled = True self.assertEquals(site.enabled, True) self.assertRaises(ValidationError, lambda x: setattr(site, 'enabled', x), 'fake') site.done = True self.assertEquals(site.done, True) self.assertRaises(ValidationError, lambda x: setattr(site, 'done', x), 'fake') # Database related attribute database = config.database database.type = SiteDefaultsManager.get_default_database_type() self.assertEquals(database.type, SiteDefaultsManager.get_default_database_type()) self.assertRaises(ValidationError, lambda x: setattr(repository, 'done', x), "fake") database.name = 'name' self.assertEquals(database.name, 'name') self.assertRaises(ValidationError, lambda x: setattr(database, 'name', x), "f@ke") database.username = '******' self.assertEquals(database.username, 'username') self.assertRaises(ValidationError, lambda x: setattr(database, 'username', x), "f@ke") database.password = '******' self.assertEquals(database.password, 'password') database.enabled = True self.assertEquals(database.enabled, True) self.assertRaises(ValidationError, lambda x: setattr(database, 'enabled', x), 'fake') database.done = True self.assertEquals(database.done, True) self.assertRaises(ValidationError, lambda x: setattr(database, 'done', x), 'fake')
def test_default_site(self): """ Tests that default site builds correctly and that attributes work as expected. """ config = SiteConfigurationManager.get_blank_site() dnshost = config.dnshost self.assertEquals(dnshost.domain, SiteDefaultsManager.get_default_domain()) self.assertEquals(dnshost.name, u'') self.assertEquals(dnshost.platform, SiteDefaultsManager.get_default_platform()) self.assertTrue(dnshost.platform in \ SiteDefaultsManager.get_platforms()) self.assertEquals(dnshost.description, u'') repository = config.repository self.assertEquals(repository.enabled, False) self.assertEquals(repository.done, False) self.assertEquals(repository.name, u'') self.assertEquals(repository.type, SiteDefaultsManager.get_default_repository_type()) self.assertTrue(repository.type in \ SiteDefaultsManager.get_repository_types()) site = config.website self.assertEquals(site.enabled, False) self.assertEquals(site.done, False) self.assertEquals(site.maintenance, False) self.assertEquals(site.template, SiteDefaultsManager.get_default_site_template()) self.assertTrue(site.template in \ SiteDefaultsManager.get_site_templates()) self.assertEquals(site.access, SiteDefaultsManager.get_default_site_access()) self.assertTrue(site.access in \ SiteDefaultsManager.get_site_accesses()) database = config.database self.assertEquals(database.enabled, False) self.assertEquals(database.done, False) self.assertEquals(database.name, u'') self.assertEquals(database.username, u'') self.assertEquals(database.password, u'') self.assertEquals(database.type, SiteDefaultsManager.get_default_database_type()) self.assertTrue(database.type in \ SiteDefaultsManager.get_database_types())