示例#1
0
 def _testPostCommitRemaining(self):
     """Tests the post commit hook with remaining time command"""
     # Create a ticket of type task, and set it to assigned
     task = self.teh.create_ticket(Type.TASK, props={Key.OWNER: "tester", Key.REMAINING_TIME: "8"})
     # Create a file in the SVN reposoitory using the helper
     rev = self.teh.create_file("test_remaining.txt", "This is a test :-)", "tester", "Remaining #%d:4h" % task.id)
     apostc = AgiloSVNPostCommit(project=self.teh.get_env_path(), rev=rev, env=self.teh.get_env())
     apostc.execute()
     # Should set the task automatically to assigned
     task = self.teh.load_ticket(ticket=task)
     self.assertEqual(task[Key.REMAINING_TIME], "4")
     self.assertEqual(task[Key.STATUS], Status.ACCEPTED)
     # Now test with a wrong owner
     task = self.teh.create_ticket(Type.TASK, props={Key.OWNER: "somebody", Key.REMAINING_TIME: "8"})
     # Create a file in the SVN reposoitory using the helper
     rev = self.teh.create_file(
         "test_remaining_not_owner.txt", "This is a test :-)", "tester", "Remaining #%d:4h" % task.id
     )
     apostc = AgiloSVNPostCommit(project=self.teh.get_env_path(), rev=rev, env=self.teh.get_env())
     self.assertRaises(NotOwnerError, apostc.execute)
     # Now try to set remaining time on a Story
     story = self.teh.create_ticket(Type.USER_STORY)
     rev = self.teh.create_file(
         "test_remaining_story.txt", "This is a test :-)", "tester", "Remaining #%d:4h" % story.id
     )
     apostc = AgiloSVNPostCommit(project=self.teh.get_env_path(), rev=rev, env=self.teh.get_env())
     self.assertRaises(InvalidAttributeError, apostc.execute)
示例#2
0
 def _testPostCommitClose(self):
     """Tests the post commit hook with close command"""
     # Create a ticket of type task, and set it to assigned
     task = self.teh.create_ticket(Type.TASK, props={Key.REMAINING_TIME: "2"})
     # Create a file in the SVN repository using the helper
     rev = self.teh.create_file("test_not_assigend.txt", "This is a test :-)", "tester", "Closes #%d" % task.id)
     apostc = AgiloSVNPostCommit(project=self.teh.get_env_path(), rev=rev, env=self.teh.get_env())
     # Execute the commands
     self.assertRaises(NotAssignedError, apostc.execute)
     # Now set the task to assigned, change owner and try again
     task = self.teh.create_ticket(Type.TASK, props={Key.REMAINING_TIME: "2"})
     task[Key.STATUS] = Status.ASSIGNED
     task[Key.OWNER] = "somebody"
     task.save_changes("somebody", "Accepted the ticket")
     rev = self.teh.create_file("test_not_owner.txt", "This is a test :-)", "tester", "Closes #%d" % task.id)
     apostc = AgiloSVNPostCommit(project=self.teh.get_env_path(), rev=rev, env=self.teh.get_env())
     self.assertRaises(NotOwnerError, apostc.execute)
     # Now set the right owner, should succeed
     task = self.teh.create_ticket(Type.TASK, props={Key.OWNER: "tester", Key.REMAINING_TIME: "2"})
     task[Key.STATUS] = Status.ASSIGNED
     task.save_changes("tester", "It is mine again")
     # The command execute will save again in less than one second...
     sleep(1)
     rev = self.teh.create_file("test_ok.txt", "This is a test :-)", "tester", "Closes #%d" % task.id)
     apostc = AgiloSVNPostCommit(project=self.teh.get_env_path(), rev=rev, env=self.teh.get_env())
     apostc.execute()
     # Reload the task from Trac
     task = self.teh.load_ticket(task)
     self.assertEqual(task[Key.STATUS], Status.CLOSED)
     self.assertEqual(task[Key.REMAINING_TIME], "0")
示例#3
0
 def _testPostCommitMultipleDependencies(self):
     """Tests the post commit hook with multiple commands and dependencies"""
     story = self.teh.create_ticket(Type.USER_STORY, props={Key.STORY_POINTS: "13"})
     task1 = self.teh.create_ticket(Type.TASK, props={Key.OWNER: "tester", Key.REMAINING_TIME: "8"})
     task2 = self.teh.create_ticket(Type.TASK, props={Key.OWNER: "tester", Key.REMAINING_TIME: "4"})
     self.assertTrue(story.link_to(task1))
     self.assertTrue(story.link_to(task2))
     # Assign the task1, otherwise will not allow to close it
     task1[Key.STATUS] = Status.ASSIGNED
     task1.save_changes("tester", "Accepted the task...")
     # Assign the task2, otherwise will not allow to close it
     task2[Key.STATUS] = Status.ASSIGNED
     task2.save_changes("tester", "Accepted the task...")
     sleep(1)
     rev = self.teh.create_file(
         "test_multiple_ok.txt",
         "This is a test :-)",
         "tester",
         "This closes #%d and #%d, closes #%d for more details." % (task1.id, task2.id, story.id),
     )
     apostc = AgiloSVNPostCommit(project=self.teh.get_env_path(), rev=rev, env=self.teh.get_env())
     apostc.execute()
     # Reload the tickets from Trac
     task1 = self.teh.load_ticket(ticket=task1)
     task2 = self.teh.load_ticket(ticket=task2)
     story = self.teh.load_ticket(ticket=story)
     # Now check the commands have been executed successfully
     self.assertEqual(task1[Key.STATUS], Status.CLOSED)
     self.assertEqual(task1[Key.REMAINING_TIME], "0")
     self.assertEqual(task2[Key.STATUS], Status.CLOSED)
     self.assertEqual(task2[Key.REMAINING_TIME], "0")
     self.assertEqual(story[Key.STATUS], Status.CLOSED)
示例#4
0
 def _testPostCommitMultipleCommands(self):
     """Tests the post commit hook with multiple commands combinations"""
     # Create a some tickets
     task1 = self.teh.create_ticket(Type.TASK, props={Key.OWNER: "tester", Key.REMAINING_TIME: "8"})
     task2 = self.teh.create_ticket(Type.TASK, props={Key.OWNER: "tester", Key.REMAINING_TIME: "4"})
     story = self.teh.create_ticket(Type.USER_STORY, props={Key.STORY_POINTS: "13"})
     # Assign the task1, otherwise will not allow to close it
     task1[Key.STATUS] = Status.ASSIGNED
     task1.save_changes("tester", "Accepted the task...")
     sleep(1)
     # Create a file in the SVN repository using the helper
     rev = self.teh.create_file(
         "test_multiple.txt",
         "This is a test :-)",
         "tester",
         "This closes #%d and remaining #%d:2h, see #%d for more details." % (task1.id, task2.id, story.id),
     )
     apostc = AgiloSVNPostCommit(project=self.teh.get_env_path(), rev=rev, env=self.teh.get_env())
     apostc.execute()
     # Reload the tickets from Trac
     task1 = self.teh.load_ticket(ticket=task1)
     task2 = self.teh.load_ticket(ticket=task2)
     story = self.teh.load_ticket(ticket=story)
     # Now check the commands have been executed successfully
     self.assertEqual(task1[Key.STATUS], Status.CLOSED)
     self.assertEqual(task1[Key.REMAINING_TIME], "0")
     self.assertEqual(task2[Key.STATUS], Status.ACCEPTED)
     self.assertEqual(task2[Key.REMAINING_TIME], "2")
示例#5
0
 def _testPostCommitReference(self):
     """Tests the post commit hook with references command"""
     # Create a ticket of type task, and set it to assigned
     task = self.teh.create_ticket(Type.TASK, props={Key.REMAINING_TIME: "8"})
     # Create a file in the SVN repository using the helper
     rev = self.teh.create_file("test_reference.txt", "This is a test :-)", "tester", "See #%d" % task.id)
     apostc = AgiloSVNPostCommit(project=self.teh.get_env_path(), rev=rev, env=self.teh.get_env())
     apostc.execute()
示例#6
0
 def _testPostCommitReference(self):
     """Tests the post commit hook with references command"""
     # Create a ticket of type task, and set it to assigned
     task = self.teh.create_ticket(Type.TASK,
                                   props={Key.REMAINING_TIME: '8'})
     # Create a file in the SVN repository using the helper
     rev = self.teh.create_file('test_reference.txt', "This is a test :-)",
                                'tester', "See #%d" % task.id)
     apostc = AgiloSVNPostCommit(project=self.teh.get_env_path(),
                                 rev=rev,
                                 env=self.teh.get_env())
     apostc.execute()
示例#7
0
 def _testPostCommitDependencies(self):
     """Tests the post commit hook with some dependencies links"""
     # Create a some tickets
     story = self.teh.create_ticket(Type.USER_STORY,
                                    props={Key.STORY_POINTS: '13'})
     task1 = self.teh.create_ticket(Type.TASK,
                                    props={
                                        Key.OWNER: 'tester',
                                        Key.REMAINING_TIME: '8'
                                    })
     task2 = self.teh.create_ticket(Type.TASK,
                                    props={
                                        Key.OWNER: 'tester',
                                        Key.REMAINING_TIME: '4'
                                    })
     self.assertTrue(story.link_to(task1))
     self.assertTrue(story.link_to(task2))
     # Assign the task1, otherwise will not allow to close it
     task1[Key.STATUS] = Status.ASSIGNED
     task1.save_changes('tester', 'Accepted the task...')
     sleep(1)
     # Create a file in the SVN reposoitory using the helper
     rev = self.teh.create_file('test_multiple_dependencies.txt', "This is a test :-)", 'tester',
                                "This closes #%d and remaining #%d:2h, closes #%d for more details." % \
                                (task1.id, task2.id, story.id))
     apostc = AgiloSVNPostCommit(project=self.teh.get_env_path(),
                                 rev=rev,
                                 env=self.teh.get_env())
     self.assertRaises(DependenciesError, apostc.execute)
示例#8
0
 def _testPostCommitMultipleDependencies(self):
     """Tests the post commit hook with multiple commands and dependencies"""
     story = self.teh.create_ticket(Type.USER_STORY,
                                    props={Key.STORY_POINTS: '13'})
     task1 = self.teh.create_ticket(Type.TASK,
                                    props={
                                        Key.OWNER: 'tester',
                                        Key.REMAINING_TIME: '8'
                                    })
     task2 = self.teh.create_ticket(Type.TASK,
                                    props={
                                        Key.OWNER: 'tester',
                                        Key.REMAINING_TIME: '4'
                                    })
     self.assertTrue(story.link_to(task1))
     self.assertTrue(story.link_to(task2))
     # Assign the task1, otherwise will not allow to close it
     task1[Key.STATUS] = Status.ASSIGNED
     task1.save_changes('tester', 'Accepted the task...')
     # Assign the task2, otherwise will not allow to close it
     task2[Key.STATUS] = Status.ASSIGNED
     task2.save_changes('tester', 'Accepted the task...')
     sleep(1)
     rev = self.teh.create_file('test_multiple_ok.txt', "This is a test :-)", 'tester',
                                "This closes #%d and #%d, closes #%d for more details." % \
                                (task1.id, task2.id, story.id))
     apostc = AgiloSVNPostCommit(project=self.teh.get_env_path(),
                                 rev=rev,
                                 env=self.teh.get_env())
     apostc.execute()
     # Reload the tickets from Trac
     task1 = self.teh.load_ticket(ticket=task1)
     task2 = self.teh.load_ticket(ticket=task2)
     story = self.teh.load_ticket(ticket=story)
     # Now check the commands have been executed successfully
     self.assertEqual(task1[Key.STATUS], Status.CLOSED)
     self.assertEqual(task1[Key.REMAINING_TIME], '0')
     self.assertEqual(task2[Key.STATUS], Status.CLOSED)
     self.assertEqual(task2[Key.REMAINING_TIME], '0')
     self.assertEqual(story[Key.STATUS], Status.CLOSED)
示例#9
0
    def runTest(self):
        self._tester.login_as(Usernames.team_member)
        trac_env = self.testenv.get_trac_environment()
        teh = TestEnvHelper(trac_env, env_key=self.env_key)
        project_dir = self.testenv.dirname

        task_id = self.create_task(teh)
        rev = self.work_on_task(task_id, teh)
        AgiloSVNPostCommit(project=project_dir, rev=rev,
                           env=trac_env).execute()

        ticket_page = self.tester.navigate_to_ticket_page(task_id)
        self.assertEqual('1.5h', ticket_page.remaining_time())
示例#10
0
 def _testPostCommitClose(self):
     """Tests the post commit hook with close command"""
     # Create a ticket of type task, and set it to assigned
     task = self.teh.create_ticket(Type.TASK,
                                   props={Key.REMAINING_TIME: '2'})
     # Create a file in the SVN repository using the helper
     rev = self.teh.create_file('test_not_assigend.txt',
                                "This is a test :-)", 'tester',
                                "Closes #%d" % task.id)
     apostc = AgiloSVNPostCommit(project=self.teh.get_env_path(),
                                 rev=rev,
                                 env=self.teh.get_env())
     # Execute the commands
     self.assertRaises(NotAssignedError, apostc.execute)
     # Now set the task to assigned, change owner and try again
     task = self.teh.create_ticket(Type.TASK,
                                   props={Key.REMAINING_TIME: '2'})
     task[Key.STATUS] = Status.ASSIGNED
     task[Key.OWNER] = 'somebody'
     task.save_changes('somebody', 'Accepted the ticket')
     rev = self.teh.create_file('test_not_owner.txt', "This is a test :-)",
                                'tester', "Closes #%d" % task.id)
     apostc = AgiloSVNPostCommit(project=self.teh.get_env_path(),
                                 rev=rev,
                                 env=self.teh.get_env())
     self.assertRaises(NotOwnerError, apostc.execute)
     # Now set the right owner, should succeed
     task = self.teh.create_ticket(Type.TASK,
                                   props={
                                       Key.OWNER: 'tester',
                                       Key.REMAINING_TIME: '2'
                                   })
     task[Key.STATUS] = Status.ASSIGNED
     task.save_changes('tester', 'It is mine again')
     # The command execute will save again in less than one second...
     sleep(1)
     rev = self.teh.create_file('test_ok.txt', "This is a test :-)",
                                'tester', "Closes #%d" % task.id)
     apostc = AgiloSVNPostCommit(project=self.teh.get_env_path(),
                                 rev=rev,
                                 env=self.teh.get_env())
     apostc.execute()
     # Reload the task from Trac
     task = self.teh.load_ticket(task)
     self.assertEqual(task[Key.STATUS], Status.CLOSED)
     self.assertEqual(task[Key.REMAINING_TIME], '0')
示例#11
0
 def _testPostCommitMultipleCommands(self):
     """Tests the post commit hook with multiple commands combinations"""
     # Create a some tickets
     task1 = self.teh.create_ticket(Type.TASK,
                                    props={
                                        Key.OWNER: 'tester',
                                        Key.REMAINING_TIME: '8'
                                    })
     task2 = self.teh.create_ticket(Type.TASK,
                                    props={
                                        Key.OWNER: 'tester',
                                        Key.REMAINING_TIME: '4'
                                    })
     story = self.teh.create_ticket(Type.USER_STORY,
                                    props={Key.STORY_POINTS: '13'})
     # Assign the task1, otherwise will not allow to close it
     task1[Key.STATUS] = Status.ASSIGNED
     task1.save_changes('tester', 'Accepted the task...')
     sleep(1)
     # Create a file in the SVN repository using the helper
     rev = self.teh.create_file('test_multiple.txt', "This is a test :-)", 'tester',
                                "This closes #%d and remaining #%d:2h, see #%d for more details." % \
                                (task1.id, task2.id, story.id))
     apostc = AgiloSVNPostCommit(project=self.teh.get_env_path(),
                                 rev=rev,
                                 env=self.teh.get_env())
     apostc.execute()
     # Reload the tickets from Trac
     task1 = self.teh.load_ticket(ticket=task1)
     task2 = self.teh.load_ticket(ticket=task2)
     story = self.teh.load_ticket(ticket=story)
     # Now check the commands have been executed successfully
     self.assertEqual(task1[Key.STATUS], Status.CLOSED)
     self.assertEqual(task1[Key.REMAINING_TIME], '0')
     self.assertEqual(task2[Key.STATUS], Status.ACCEPTED)
     self.assertEqual(task2[Key.REMAINING_TIME], '2')
示例#12
0
 def _testPostCommitRemaining(self):
     """Tests the post commit hook with remaining time command"""
     # Create a ticket of type task, and set it to assigned
     task = self.teh.create_ticket(Type.TASK,
                                   props={
                                       Key.OWNER: 'tester',
                                       Key.REMAINING_TIME: '8'
                                   })
     # Create a file in the SVN reposoitory using the helper
     rev = self.teh.create_file('test_remaining.txt', "This is a test :-)",
                                'tester', "Remaining #%d:4h" % task.id)
     apostc = AgiloSVNPostCommit(project=self.teh.get_env_path(),
                                 rev=rev,
                                 env=self.teh.get_env())
     apostc.execute()
     # Should set the task automatically to assigned
     task = self.teh.load_ticket(ticket=task)
     self.assertEqual(task[Key.REMAINING_TIME], '4')
     self.assertEqual(task[Key.STATUS], Status.ACCEPTED)
     # Now test with a wrong owner
     task = self.teh.create_ticket(Type.TASK,
                                   props={
                                       Key.OWNER: 'somebody',
                                       Key.REMAINING_TIME: '8'
                                   })
     # Create a file in the SVN reposoitory using the helper
     rev = self.teh.create_file('test_remaining_not_owner.txt',
                                "This is a test :-)", 'tester',
                                "Remaining #%d:4h" % task.id)
     apostc = AgiloSVNPostCommit(project=self.teh.get_env_path(),
                                 rev=rev,
                                 env=self.teh.get_env())
     self.assertRaises(NotOwnerError, apostc.execute)
     # Now try to set remaining time on a Story
     story = self.teh.create_ticket(Type.USER_STORY)
     rev = self.teh.create_file('test_remaining_story.txt',
                                "This is a test :-)", 'tester',
                                "Remaining #%d:4h" % story.id)
     apostc = AgiloSVNPostCommit(project=self.teh.get_env_path(),
                                 rev=rev,
                                 env=self.teh.get_env())
     self.assertRaises(InvalidAttributeError, apostc.execute)
示例#13
0
def main(argv=None):
    if argv is None:
        argv = sys.argv
    try:
        env = log = rev = repo = None
        hook = 'pre'
        try:
            opts, args = getopt.getopt(
                argv[1:], "he:l:s:r:R:",
                ["help", "env=", "svn_hook=", "log=", "rev=", "repo="])
        except getopt.error, msg:
            raise Usage(msg)

        # option processing
        for option, value in opts:
            if option in ("-h", "--help"):
                raise Usage(help_message)
            if option in ("-e", "--env"):
                env = str(value)
            if option in ("-l", "--log"):
                log = unicode(value)
            if option in ("-s", "--svn_hook"):
                if value == 'post':
                    hook = value
            if option in ("-r", "--rev"):
                rev = value
            if option in ("-R", "--repo"):
                repo = value
        if (env is None or log is None) and (hook == 'post' and rev is None):
            raise Usage(help_message)
        else:
            if hook == 'pre':
                agilo_hook = AgiloSVNPreCommit(project=env, log=log)
            else:
                agilo_hook = AgiloSVNPostCommit(project=env,
                                                rev=rev,
                                                reponame=repo)
            try:
                if agilo_hook.execute():
                    return 0
            except Exception, e:
                print >> sys.stderr, str(e)
                return 2