Example #1
0
 def test_multiple_schedulers(self):
     p = self.project
     self.assertFalse(p.has_scheduler)
     
     b = Builder(project = p, name="test builder")
     b.save()
     
     # create cron scheduler
     cr = CronScheduler(project=p, name="cron")
     cr.save()
     self.assertEqual(1, p.scheduler_set.count())
     self.assertEqual(unicode(cr), "cron")
     self.assertFalse(p.has_scheduler) # scheduler has no assigned builder
     cr.builders.add(b)
     self.assertTrue(p.has_scheduler)
     
     
     # create change scheduler
     ch = ChangeScheduler(project=p, name="change")
     ch.save()
     self.assertEqual(2, p.scheduler_set.count())
     self.assertEqual(unicode(ch), "change")
     
     # check that they can be downcasted properly
     expect = [_("cron scheduler"), _("change scheduler")]
     for i,s in enumerate(p.scheduler_set.all()):
         # calling method on parent class should raise exception
         self.assertRaises(NotImplementedError, s.get_config_type)
         self.assertRaises(NotImplementedError, s.get_config_class)
         self.assertRaises(NotImplementedError, s.get_config_args)
         # should work with .cast()
         self.assertEqual(expect[i], s.cast().get_config_type())
Example #2
0
 def test_name_uniqueness(self):
     """
     Ensure that a project cannot have multiple notifiers with the same name
     """
     p = self.project
     cr = CronScheduler(project=p, name="cron1")
     cr.save()
     
     ch = ChangeScheduler(project=p, name="cron1")
     self.assertRaises(IntegrityError, ch.save)
     self.assertEqual(ch.id, None)
     
     # the same name can be used in a different project
     p2 = Project(name="another p", owner=self.user)
     p2.save()
     ch.project = p2
     ch.save()
     self.assertNotEqual(ch.id, None)
     
     
 def test_simple_creation(self):
     """
     Basic cron-like scheduler
     """
     sched = CronScheduler(project = self.project, name = "cron")
     sched.save()
     self.assertNotEqual(sched.id, None)
     self.assertEqual(unicode(sched), "cron")
     self.assertEqual(sched.cast().get_config_type(), _("cron scheduler"))
     
      # add builders
     builders = ["builder1", "builder2", "builder3"]
     for bname in builders:
         b = Builder(project=self.project, name=bname)
         b.save()
         sched.builders.add(b)
     self.assertEqual(sched.builders.count(), len(builders))
     
     args = sched.cast().get_config_args()
     # check default arguments
     self.assertEqual(args.get("name", None), "cron")
     self.assertEqual(args.get("minute", None), "*")
     self.assertEqual(args.get("hour", None), "*")
     self.assertEqual(args.get("month", None), "*")
     self.assertEqual(args.get("dayOfWeek", None), "*")
     self.assertEqual(args.get("dayOfMonth", None), "*")
     self.assertEqual(args.get("onlyIfChanged", None), True)
     # check builderName
     bn = args.get("builderNames", [])
     self.assertEqual(len(bn), len(builders))
     for i,b in enumerate(builders):
         self.assertEqual(bn[i], b)
     
     # try instantiating buildbot config object
     self.assert_valid_buildbot_config(sched.cast().get_config_class(), args)
     
     # Check that the resulting config string is sensible
     self.assert_config_string_executable(sched.cast())
     
     # Check that changes in options are reflected in generated config
     sched.name = "newcode"
     sched.minute = 30
     sched.hour = 13
     sched.month = 5
     sched.day_of_month = 3
     sched.day_of_week = 4
     sched.only_if_code_changed = False
     sched.save()
     args = sched.cast().get_config_args()
     self.assertEqual(args.get("name", None), "newcode")
     self.assertEqual(args.get("minute", None), 30)
     self.assertEqual(args.get("hour", None), 13)
     self.assertEqual(args.get("month", None), 5)
     self.assertEqual(args.get("dayOfWeek", None), 4)
     self.assertEqual(args.get("dayOfMonth", None), 3)
     self.assertEqual(args.get("onlyIfChanged", None), False)
     
     # try instantiating buildbot config object
     self.assert_valid_buildbot_config(sched.cast().get_config_class(), args)
     
     # Check that the resulting config string is sensible
     self.assert_config_string_executable(sched.cast())