Ejemplo n.º 1
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()])