def test_default_create(self): """ Test generation of buildbot config. """ slave = BuildSlave( project = self.project, name = "test-slave", password = "******", ) slave.save() # check config type self.assertEqual(slave.get_config_type(), _("build slave")) # check generated arguments args = slave.get_config_args() self.assertEqual(args.get("name", None), slave.name) self.assertEqual(args.get("password", None), slave.password) self.assertEqual(args.get("missing_timeout", None), settings.DEFAULT_SLAVE_TIMEOUT * 60) self.assertEqual(args.get("max_builds", None), settings.DEFAULT_SLAVE_MAXBUILD) notify_list = args.get("notify_on_missing", None) self.assertEqual(type(notify_list), type([])) self.assertEqual(len(notify_list), 0) # try instantiating buildbot config object self.assert_valid_buildbot_config(slave.get_config_class(), args) # Check that the resulting config string is sensible self.assert_config_string_executable(slave)
def test_custom_create(self): """ Create build slave with custom options. """ slave = BuildSlave( project = self.project, name = "test-slave", password = "******", max_builds = 123, timeout = 51, ) slave.save() # check generated arguments args = slave.get_config_args() self.assertEqual(args.get("name", None), slave.name) self.assertEqual(args.get("password", None), slave.password) self.assertEqual(args.get("missing_timeout", None), 51 * 60) self.assertEqual(args.get("max_builds", None), 123) notify_list = args.get("notify_on_missing", None) self.assertEqual(type(notify_list), type([])) self.assertEqual(len(notify_list), 0) # add an admin that should receive notification on this slave admin = BuildAdmin(project=self.project, name="admin1", email="*****@*****.**") admin.save() self.assertNotEqual(admin.id, None) slave.admins.add(admin) # check new args notify_list = slave.get_config_args().get("notify_on_missing", None) self.assertEqual(len(notify_list), 1) self.assertEqual(notify_list[0], admin.email) # add admin that should receive ALL notifcations (including this one of course) admin2 = BuildAdmin(project=self.project, name="admin1", email="*****@*****.**", receive_slave_events=True, ) admin2.save() # check new args notify_list = slave.get_config_args().get("notify_on_missing", None) self.assertEqual(len(notify_list), 2) for i,e in enumerate(["*****@*****.**", "*****@*****.**"]): self.assertEqual(e, notify_list[i]) # ensure no duplicates admin.receive_slave_events = True admin.save() notify_list = slave.get_config_args().get("notify_on_missing", None) self.assertEqual(len(notify_list), 2) for i,e in enumerate(["*****@*****.**", "*****@*****.**"]): self.assertEqual(e, notify_list[i]) # try instantiating buildbot config object self.assert_valid_buildbot_config(slave.get_config_class(), slave.get_config_args()) # Check that the resulting config string is sensible self.assert_config_string_executable(slave)
def test_name_uniqueness(self): """ Ensure that a project cannot have multiple slaves with the same name """ self.assertFalse(self.project.has_buildslave) # create build slave s0 = BuildSlave( project = self.project, name = "test-slave", password = "******", ) s0.save() self.assertTrue(s0.id != None) self.assertEqual(unicode(s0), "test-slave") self.assertTrue(self.project.has_buildslave) s = BuildSlave( project = self.project, name = "test-slave", password = "******", ) self.assertRaises(IntegrityError, s.save) self.assertEqual(s.id, None) # ... but the the same name can be used for a different project np = Project( name = "Another Test Project", owner = self.user, ) np.save() s = BuildSlave( project = np, name = "test-slave", password = "******", ) s.save() self.assertNotEqual(s.id, None)