Ejemplo n.º 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())
class AbstractTestShellCommand(BbotuiModelTestCase):
    """
    Abstract class for the following TestCases. pre-instantiates
    self.project and self.builder
    """
    def setUp(self):
        # call method in parent class (instantiates self.project)
        super(AbstractTestShellCommand, self).setUp()
        
        # create builder
        self.builder = Builder(project=self.project, name="test builder")
        self.builder.save()
        self.assertTrue(self.builder.id != None)
Ejemplo n.º 3
0
 def setUp(self):
     super(TestObjPaginator, self).setUp()
     p = self.project
     
     self.builder_empty = Builder(project=p, name="empty builder")
     self.builder_empty.save()
     self.builder = Builder(project=p, name="builder")
     self.builder.save()
     b = self.builder
     
     self.stepcount = 10
     for i in xrange(self.stepcount):
         step = CompileStep(builder=b, name="step-%d"%i)
         step.save()
 def setUp(self):
     # call method in parent class (instantiates self.project)
     super(AbstractTestShellCommand, self).setUp()
     
     # create builder
     self.builder = Builder(project=self.project, name="test builder")
     self.builder.save()
     self.assertTrue(self.builder.id != None)
Ejemplo n.º 5
0
    def test_move_down(self):
        """
        Tests step.move_down()
        """
        b = Builder(project=self.project, name="my builder")
        b.save()
        
        s = []
        # create 3 steps, mix and match step types
        s.append(CompileStep(
            builder = b,
            name = "compile the code",
            command = "make",
        ))
        s.append(ConfigureStep(
            builder = b,
            name = "configure the code",
            command = "./configure",
        ))
        s.append(ShellCommandStep(
            builder = b,
            name = "run some command",
            command = "./run",
        ))
        for step in s:
            step.save()
            self.assertNotEqual(step.id, None)

        # check initial positions
        self._update_and_confirm_order(s, [0,1,2])
        
        # do a series of moves
        s[2].move_down()
        self._update_and_confirm_order(s, [0,1,2]) # bottom elem cannot move down
        s[0].move_down()
        self._update_and_confirm_order(s, [1,0,2])
        s[0].move_down()
        self._update_and_confirm_order(s, [1,2,0])
        s[1].move_down()
        self._update_and_confirm_order(s, [2,1,0])
 def test_simple_creation(self):
     """
     Basic Change based scheduler
     """
     sched = ChangeScheduler(project = self.project, name = "change")
     sched.save()
     self.assertNotEqual(sched.id, None)
     self.assertEqual(unicode(sched), "change")
     self.assertEqual(sched.cast().get_config_type(), _("change 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), "change")
     self.assertEqual(args.get("treeStableTimer", None), settings.DEFAULT_TREE_STABLE_TIMER * 60)
     # 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 filter class
     self.assertEqual(sched.cast().get_filter_class(), None)
     self.assertEqual(sched.cast().get_filter_args(), None)
     
     # Check that the resulting config string is sensible
     self.assert_config_string_executable(sched.cast())
     self.assertEqual(None, sched.get_filter_str())
Ejemplo n.º 7
0
    def test_position_integrity(self):
        """
        Ensure that position cannot be duplicated
        """
        b = Builder(project=self.project, name="my builder")
        b.save()
        s = CompileStep(
            builder = b,
            name = "compile the code",
            command = "make",
        )
        s.save()
        self.assertNotEqual(s.id, None)
        self.assertEqual(s.position, 0)

        s2 = CompileStep(
            builder = b,
            name = "compile the code 2",
            command = "make",
        )
        s2.save()
        s2.position = 0
        self.assertRaises(IntegrityError, s2.save)
Ejemplo n.º 8
0
class AbstractTestCheckout(BbotuiModelTestCase):
    """
    Abstract class for test cases in this file. Instantiates 
    self.project, self.builder, self.svn, self.git.
    """

    def setUp(self):
        # call method in parent class (instantiates self.project)
        super(AbstractTestCheckout, self).setUp()

        # create builder
        self.builder = Builder(project=self.project, name="test builder")
        self.builder.save()
        self.assertTrue(self.builder.id != None)

        # create svn repos
        self.svn = SVNRepository(project=self.project, name="test svn repo", url="http://some.url/svn/proj/trunk")
        self.svn.save()
        self.assertTrue(self.svn.id != None)

        # create git repos
        self.git = GitRepository(project=self.project, name="test git repo", url="http://some.url/abc.git")
        self.git.save()
        self.assertTrue(self.git.id != None)
Ejemplo n.º 9
0
 def test_name_uniqueness(self):
     """
     Ensure that a builder cannot have multiple steps with the same name or position
     """
     b = Builder(project=self.project, name="my builder")
     b.save()
     s = CompileStep(
         builder = b,
         name = "compile the code",
         command = "make",
     )
     s.save()
     self.assertNotEqual(s.id, None)
     
     # another step, same name
     s2 = CompileStep(
         builder = b,
         name = "compile the code",
         command = "make",
     )
     self.assertRaises(IntegrityError, s2.save)
     self.assertEqual(s2.id, None)
     # try a different name
     s2.name = "another name"
     s2.save()
     self.assertNotEqual(s2.id, None)
     
     # try forcing same position
     s2.position = s.position
     self.assertRaises(IntegrityError, s2.save)
  
     # should be ok to have dups with a different builder
     b2 = Builder(project=self.project, name="my builder2")
     b2.save()
     s3 = CompileStep(
         builder = b2,
         name = "compile the code",
         command = "make",
     )
     s3.save()
     self.assertNotEqual(s3.id, None)
Ejemplo n.º 10
0
 def test_swap_position_edge_cases(self):
     """
     Step.swap_positions(s1,s2) should not be used manually, but if it is used,
     we should make sure we handle some of the edge cases.
     """
     
     # cannot swap steps with negative positions
     # (in practice, negative position is used as temp values, so this can
     # in fact happen during race conditions when move routines are not used
     # within views with @transactionnn.commit_on_success)
     b = Builder(project=self.project, name="my builder")
     b.save()
     s1 = ConfigureStep(
         builder = b,
         name = "configure the code",
         command = "./configure",
     )
     s1.save()
     s2 = ShellCommandStep(
         builder = b,
         name = "run some command",
         command = "./run",
     )
     s2.save()
     s2.position = -2
     s2.save()
     self.assertRaises(Step.SimultaneousUpdateError, Step.swap_positions, s1, s2)
     
     
     # cannot swap steps from different builders
     b2 = Builder(project=self.project, name="my builder 2")
     b2.save()
     s3 = ShellCommandStep(
         builder = b2,
         name = "run some command",
         command = "./run",
     )
     s3.save()
     self.assertRaises(ValueError, Step.swap_positions, s1, s3)
Ejemplo n.º 11
0
    def test_with_deleted_steps(self):
        """
        If any step is deleted, this affects step_count as well as move_up,
        move_down, and addition of new step.
        """
        b = Builder(project=self.project, name="my builder")
        b.save()
        
        s = []
        # create 3 steps, mix and match step types
        s.append(CompileStep(
            builder = b,
            name = "compile the code",
            command = "make",
        ))
        s.append(ConfigureStep(
            builder = b,
            name = "configure the code",
            command = "./configure",
        ))
        s.append(ShellCommandStep(
            builder = b,
            name = "run some command",
            command = "./run",
        ))
        for step in s:
            step.save()
            self.assertNotEqual(step.id, None)

        # check initial positions
        self._update_and_confirm_order(s, [0,1,2])
        
        # get ori order
        ids = [x.id for x in s]

        # delete first item
        d = s.pop(0)
        d.delete()
        self._update_refs(s)
        ids.pop(0)

        self.assertListEqual(ids, [x.id for x in b.step_set.all()])
        
        # move bottom one up
        s[1].move_up()
        self._update_refs(s)
        ids[0],ids[1] = ids[1],ids[0]
        self.assertListEqual(ids, [x.id for x in b.step_set.all()])
        
        # move it up again (should remain the same)
        s[1].move_up()
        self._update_refs(s)
        self.assertListEqual(ids, [x.id for x in b.step_set.all()])
        
        # move bottom one down (should remain the same)
        s[0].move_down()
        self._update_refs(s)
        self.assertListEqual(ids, [x.id for x in b.step_set.all()])
        
        # add new step
        step = ConfigureStep(
            builder = b,
            name = "configure the code2",
            command = "./configure",
        )
        step.save()
        self.assertNotEqual(step.id, None)
        s.append(step)
        self._update_refs(s)
        ids.append(step.id)
        self.assertListEqual(ids, [x.id for x in b.step_set.all()])
        
        # move new step down
        step.move_down()
        self._update_refs(s)
        self.assertListEqual(ids, [x.id for x in b.step_set.all()])
        
        # move new step up
        step.move_up()
        self._update_refs(s)
        
        ids[-1],ids[-2] = ids[-2],ids[-1]
        self.assertListEqual(ids, [x.id for x in b.step_set.all()])
        
        
Ejemplo n.º 12
0
 def test_mixed_steps(self):
     p = self.project
     b = Builder(project=p, name="my builder")
     b.save()
     self.assertEqual(b.is_complete, False)
     
     # add shell command step
     step_shell = ShellCommandStep(
         builder = b,
         name = "a shell command",
         command = "./some_command",
     )
     step_shell.save()
     self.assertNotEqual(step_shell.id, None)
     self.assertEqual(step_shell.position, 0)
     self.assertEqual(b.step_count, 1)
     
     # add compile step
     step_compile = CompileStep(
         builder = b,
         name = "compile the code",
         command = "make",
     )
     step_compile.save()
     self.assertNotEqual(step_compile.id, None)
     self.assertEqual(step_compile.position, 1)
     self.assertEqual(b.step_count, 2)
     
     # add configure step
     step_configure = ConfigureStep(
         builder = b,
         name = "configure the code",
         command = "./configure",
     )
     step_configure.save()
     self.assertNotEqual(step_configure.id, None)
     self.assertEqual(step_configure.position, 2)
     self.assertEqual(b.step_count, 3)
     
     # add test step
     step_test = TestStep(
         builder = b,
         name = "test the code",
         command = "make",
         arguments = "test",
     )
     step_test.save()
     self.assertNotEqual(step_test.id, None)
     self.assertEqual(step_test.position, 3)
     self.assertEqual(b.step_count, 4)
     
     
     expect = [_("shell command"), _("compile"), _("configure"), _("test")]
     for i,s in enumerate(b.step_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 r.cast()
         self.assertEqual(expect[i], s.cast().get_config_type())
         
         self.assertEqual(type(s.cast().get_config_class()), type(()))
         self.assertEqual(type(s.cast().get_config_args()), type({}))
Ejemplo n.º 13
0
class TestObjPaginator(BbotuiModelTestCase):
    
    def setUp(self):
        super(TestObjPaginator, self).setUp()
        p = self.project
        
        self.builder_empty = Builder(project=p, name="empty builder")
        self.builder_empty.save()
        self.builder = Builder(project=p, name="builder")
        self.builder.save()
        b = self.builder
        
        self.stepcount = 10
        for i in xrange(self.stepcount):
            step = CompileStep(builder=b, name="step-%d"%i)
            step.save()
        
    def test_page_for_id(self):
        
        # test on empty builder
        p = ObjPaginator(self.builder_empty.step_set.all())
        self.assertRaises(InvalidInput, p.page_for_id, -1)
        self.assertRaises(InvalidInput, p.page_for_id, 0)
        self.assertRaises(InvalidInput, p.page_for_id, "str")
    
        # test on qs with content
        count = self.stepcount # expect ids = [1:count]
        p = ObjPaginator(self.builder.step_set.all())
        self.assertRaises(InvalidInput, p.page_for_id, 0)
        self.assertRaises(InvalidInput, p.page_for_id, count+1)
        self.assertRaises(InvalidInput, p.page_for_id, "str")
        
        for i in xrange(1, count+1):
            page = p.page_for_id(i)
            self.assertEqual(page.obj.id, i)
            
    def test_page_navigation(self):
        count = self.stepcount # expect ids = [1:count]
        p = ObjPaginator(self.builder.step_set.all())
        
        # first page has no prev
        page = p.page_for_id(1)
        self.assertFalse(page.has_previous())
        self.assertTrue(page.has_next())
        self.assertEqual(None, page.get_previous_obj())
        self.assertEqual(None, page.previous_obj)
        
        # last page has no next
        page = p.page_for_id(count)
        self.assertFalse(page.has_next())
        self.assertTrue(page.has_previous())
        self.assertEqual(None, page.get_next_obj())
        self.assertEqual(None, page.next_obj)
        
        # something in between should have next and previous
        self.assertTrue(count > 3) # make sure we have enough elems
        page = p.page_for_id(count-2)
        self.assertTrue(page.has_next())
        self.assertTrue(page.has_previous())
        self.assertNotEqual(None, page.get_next_obj())
        self.assertNotEqual(None, page.next_obj)
        self.assertNotEqual(None, page.get_previous_obj())
        self.assertNotEqual(None, page.previous_obj)
        
        # use page as linked list and iterate till the end
        # well, not quite a linked list since next/prev_obj links to
        #  obj and not the next Page.
        page = p.page_for_id(1)
        for i in xrange(1, count): # till second last
            self.assertNotEqual(None, page)
            self.assertEqual(i, page.obj.id)
            page = p.page_for_id(page.next_obj.id)
        self.assertNotEqual(None, page)
        self.assertEqual(count, page.obj.id)
        self.assertEqual(None, page.next_obj)
        
        # not run backwards
        for i in xrange(count,1,-1): # till second
            self.assertNotEqual(None, page)
            self.assertEqual(i, page.obj.id)
            page = p.page_for_id(page.previous_obj.id)
        self.assertNotEqual(None, page)
        self.assertEqual(1, page.obj.id)
        self.assertEqual(None, page.previous_obj)
        
        
Ejemplo n.º 14
0
 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())