Exemple #1
0
 def _testPreCommit(self):
     """Tests the pre commit hook validation"""
     wrong_log = "This ticket doesn't exists, close #cacca and #9999, see #9999"
     aprec = AgiloSVNPreCommit(project=self.teh.get_env_path(), log=wrong_log, env=self.teh.get_env())
     try:
         aprec.execute()
         self.fail()
     except Exception, e:
         # print "Error <%s>: %s" % (e.__class__.__name__, str(e))
         self.assertTrue(len(str(e)) > 0)
Exemple #2
0
 def _testPreCommit(self):
     """Tests the pre commit hook validation"""
     wrong_log = "This ticket doesn't exists, close #cacca and #9999, see #9999"
     aprec = AgiloSVNPreCommit(project=self.teh.get_env_path(),
                               log=wrong_log,
                               env=self.teh.get_env())
     try:
         aprec.execute()
         self.fail()
     except Exception, e:
         #print "Error <%s>: %s" % (e.__class__.__name__, str(e))
         self.assertTrue(len(str(e)) > 0)
Exemple #3
0
 def _testParsingCommands(self):
     """Tests some combinations of valid and invalid commands for both hooks"""
     valid_logs = [
         "I have closed #3123 and #123",
         "See #123 and #1873, remaining #45:5h",
         "Today is not a very good day but still I manage to close #12",
         "This is cacca #342 and #412, see #241",
         "This closes #cacca and #123, see #24",
         "This ticket doesn't exists, close #cacca and #999, see #3123"
     ]
     invalid_logs = [
         "This is a totally messed up #134", "This for sure #231 is wrong",
         "what about running #231 and #nothing for #112", ""
     ]
     for log in valid_logs:
         try:
             AgiloSVNPreCommit(project=self.teh.get_env_path(),
                               log=log,
                               env=self.teh.get_env()).execute()
         except InvalidAttributeError, e:
             #print "Error: <%s>" % str(e)
             pass
         except Exception, e:
             print "Error <%s>: %s" % (e.__class__.__name__, str(e))
             self.fail()
Exemple #4
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
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
Exemple #6
0
 def parse(self, commit_message):
     return AgiloSVNPreCommit(project=self.teh.get_env_path(),
                              log=commit_message,
                              env=self.env).execute()
Exemple #7
0
class TestSVNHooks(AgiloFunctionalTestCase):
    """Test case to test the SVN pre and post hook, acting on agilo rules."""
    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')

    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)

    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()

    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')

    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)

    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)

    def _testPreCommit(self):
        """Tests the pre commit hook validation"""
        wrong_log = "This ticket doesn't exists, close #cacca and #9999, see #9999"
        aprec = AgiloSVNPreCommit(project=self.teh.get_env_path(),
                                  log=wrong_log,
                                  env=self.teh.get_env())
        try:
            aprec.execute()
            self.fail()
        except Exception, e:
            #print "Error <%s>: %s" % (e.__class__.__name__, str(e))
            self.assertTrue(len(str(e)) > 0)
        # Now create a real ticket and should work
        task = self.teh.create_ticket(Type.TASK)
        story = self.teh.create_ticket(Type.USER_STORY)
        right_log = "see #%d and #%d" % (task.id, story.id)
        aprec = AgiloSVNPreCommit(project=self.teh.get_env_path(),
                                  log=right_log,
                                  env=self.teh.get_env())
        self.assertTrue(aprec.execute())
Exemple #8
0
        ]
        for log in valid_logs:
            try:
                AgiloSVNPreCommit(project=self.teh.get_env_path(),
                                  log=log,
                                  env=self.teh.get_env()).execute()
            except InvalidAttributeError, e:
                #print "Error: <%s>" % str(e)
                pass
            except Exception, e:
                print "Error <%s>: %s" % (e.__class__.__name__, str(e))
                self.fail()
        for log in invalid_logs:
            try:
                AgiloSVNPreCommit(project=self.teh.get_env_path(),
                                  log=log,
                                  env=self.teh.get_env()).execute()
                self.fail()
            except Exception, e:
                #print "Error <%s>: %s" % (e.__class__.__name__, str(e))
                pass

    def runTest(self):
        """Tests SVN Hooks with various commands"""
        self._testParsingCommands()
        self._testPostCommitClose()
        self._testPostCommitDependencies()
        self._testPostCommitMultipleCommands()
        self._testPostCommitMultipleDependencies()
        self._testPostCommitReference()
        self._testPostCommitRemaining()