Example #1
0
    def test_notification(self):
        test_helpers.deployHookKit('test_script_ping_url_config.json')

        os.system(('echo foo >> ' + test_helpers.repo_checkout +
                   '/testfile.py'))
        test_helpers.gitCommitWithMessage("Testing notifications")

 # Fork a listening socket for the hook to push into
        pid = os.fork()
        if pid:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            s.bind(('', 4891))
            s.listen(1)
            conn, addr = s.accept()
            server_data_received = conn.recv(1024)
            conn.sendall('HTTP/1.1 200 OK\r\n')
            conn.close()
# make sure the child process gets cleaned up
            os.waitpid(pid, 0)
        else:
            self.assertTrue(test_helpers.gitPush(),
                            "Pushing a commit and receiving a url ping")
            os._exit(0)

        self.assertEqual('GET / HTTP/1.1', server_data_received.split('\r')[0])
    def test_commit_merged_from_branch(self):
        test_helpers.deployHookKit(self.CONFIG_FILE)

        test_helpers.runCommandInPath('git checkout -b test',
                                      test_helpers.repo_checkout)

        os.system(
            ('echo foo >> ' + test_helpers.repo_checkout + '/testfile.py'))

        test_helpers.gitCommitWithMessage("I'm going to be a dupe commit!")

        test_helpers.runCommandInPath('git checkout master',
                                      test_helpers.repo_checkout)

        os.system(
            ('echo foo >> ' + test_helpers.repo_checkout + '/testfile2.py'))

        test_helpers.runCommandInPath('git add testfile2.py',
                                      test_helpers.repo_checkout)

        test_helpers.gitCommitWithMessage("I'm going to be a dupe commit!")

        test_helpers.runCommandInPath('git merge test',
                                      test_helpers.repo_checkout)

        result = test_helpers.gitPush()
        self.assertFalse(result,
                         "Pushing sha1 that already exists in other branch")
    def test_commit_merged_from_branch(self):
        test_helpers.deployHookKit(self.CONFIG_FILE)

        test_helpers.runCommandInPath('git checkout -b test',
                                      test_helpers.repo_checkout)

        os.system(('echo foo >> ' + test_helpers.repo_checkout +
                   '/testfile.py'))

        test_helpers.gitCommitWithMessage("I'm going to be a dupe commit!")

        test_helpers.runCommandInPath('git checkout master',
                                      test_helpers.repo_checkout)

        os.system(('echo foo >> ' + test_helpers.repo_checkout +
                   '/testfile2.py'))

        test_helpers.runCommandInPath('git add testfile2.py',
                                      test_helpers.repo_checkout)

        test_helpers.gitCommitWithMessage("I'm going to be a dupe commit!")

        test_helpers.runCommandInPath('git merge test',
                                      test_helpers.repo_checkout)

        result = test_helpers.gitPush()
        self.assertFalse(result,
                         "Pushing sha1 that already exists in other branch")
Example #4
0
    def test_notification(self):
        test_helpers.deployHookKit('test_script_ping_url_config.json')

        os.system(
            ('echo foo >> ' + test_helpers.repo_checkout + '/testfile.py'))
        test_helpers.gitCommitWithMessage("Testing notifications")

        # Fork a listening socket for the hook to push into
        pid = os.fork()
        if pid:
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            s.bind(('', 4891))
            s.listen(1)
            conn, addr = s.accept()
            server_data_received = conn.recv(1024)
            conn.sendall('HTTP/1.1 200 OK\r\n')
            conn.close()
            # make sure the child process gets cleaned up
            os.waitpid(pid, 0)
        else:
            self.assertTrue(test_helpers.gitPush(),
                            "Pushing a commit and receiving a url ping")
            os._exit(0)

        self.assertEqual('GET / HTTP/1.1', server_data_received.split('\r')[0])
Example #5
0
 def test_push_to_branch(self):
     test_helpers.deployHookKit('test_hookkit_config.json')
     os.system('echo A >> ' + test_helpers.repo_checkout + '/testfile.py')
     test_helpers.runCommandInPath('git checkout -b test_branch',
                                   test_helpers.repo_checkout)
     test_helpers.gitCommitWithMessage('foo bar commit to push to a branch')
     self.assertTrue(test_helpers.gitPush('origin test_branch'),
                     'Push to a branch should work.')
    def test_whitelist_branch_name(self):
        test_helpers.deployHookKit('test_script_branch_name_filter.json')

        os.system(
            ('echo foo >> ' + test_helpers.repo_checkout + '/testfile.py'))

        test_helpers.gitCommitWithMessage("test whitelist branch name")

        self.assertTrue(test_helpers.gitPush(), 'Push a whitelist branch name')
    def test_whitelist_branch_name(self):
        test_helpers.deployHookKit('test_script_branch_name_filter.json')

        os.system(('echo foo >> ' + test_helpers.repo_checkout +
                   '/testfile.py'))

        test_helpers.gitCommitWithMessage("test whitelist branch name")

        self.assertTrue(test_helpers.gitPush(), 'Push a whitelist branch name')
    def test_tricky_invalid_message(self):
        test_helpers.deployHookKit(self.CONFIG_FILE)

        os.system(('echo foo >> ' + test_helpers.repo_checkout +
                   '/testfile.py'))

        test_helpers.gitCommitWithMessage("I'm an invalid commit! #abc")
        self.assertFalse(test_helpers.gitPush(),
                         'Pushing invalid commit messages')
    def test_valid_message(self):
        test_helpers.deployHookKit(self.CONFIG_FILE)

        os.system(('echo foo >> ' + test_helpers.repo_checkout +
                   '/testfile.py'))

        test_helpers.gitCommitWithMessage("I'm a valid commit! #123")
        self.assertTrue(test_helpers.gitPush(),
                        "Pushing a valid commit messages")
Example #10
0
    def test_multiple_same_scripts_both_valid(self):
        test_helpers.deployHookKit('test_hookkit_config.json')

        os.system('echo A >> ' + test_helpers.repo_checkout + '/testfile.py')
        test_helpers.gitCommitWithMessage('Test message that should pass '
                                          'both: foo bar')

        self.assertTrue(test_helpers.gitPush(), 'Pushing a commit that should '
                                                'be valid for both hooks')
Example #11
0
    def test_multiple_same_scripts_both_invalid(self):
        test_helpers.deployHookKit('test_hookkit_config.json')

        os.system('echo A >> ' + test_helpers.repo_checkout + '/testfile.py')
        test_helpers.gitCommitWithMessage('Test message that should fail both '
                                          'hooks')

        self.assertFalse(test_helpers.gitPush(), 'Pushing a commit that '
                                                 'should be invalid for both '
                                                 'hooks')
Example #12
0
    def test_multiple_same_scripts_for_one_hook_valid_first_script(self):
        test_helpers.deployHookKit('test_hookkit_config.json')

        os.system('echo A >> ' + test_helpers.repo_checkout + '/testfile.py')
        test_helpers.gitCommitWithMessage('Test message that should pass '
                                          'first hook: foo')

        self.assertFalse(test_helpers.gitPush(), 'Pushing a commit that '
                                                 'violates the first script '
                                                 'for a hook - missing bar')
    def test_valid_code(self):
        test_helpers.deployHookKit('test_script_file_checker_config.json')

        os.system(('echo "print "valid indentation rocks"" >> ' +
                  test_helpers.repo_checkout + '/testfile.py'))

        test_helpers.gitCommitWithMessage('Testing File Checker with '
                                          'a valid file')

        self.assertTrue(test_helpers.gitPush(),
                        'Pushing a well formatted Python file')
    def test_invalid_code(self):
        test_helpers.deployHookKit('test_script_file_checker_config.json')

        os.system(('echo "   print "invalid indent makes snakes cry"" >> ' +
                  test_helpers.repo_checkout + '/testfile.py'))

        test_helpers.gitCommitWithMessage("Testing File Checker with an "
                                          "invalid file")

        self.assertFalse(test_helpers.gitPush(),
                         "Pushing a badly formatted Python file")
    def test_valid_message_with_special_characters(self):
        test_helpers.deployHookKit(self.CONFIG_FILE)

        os.system(('echo foo >> ' + test_helpers.repo_checkout +
                   '/testfile.py'))

        test_helpers.gitCommitWithMessage("adding **kwargs support for the "
                                          "service and unit tests #363")

        self.assertTrue(test_helpers.gitPush(),
                        "Pushing valid commit message with special characters")
Example #16
0
    def test_valid_code(self):
        test_helpers.deployHookKit('test_script_file_checker_config.json')

        os.system(('echo "print "valid indentation rocks"" >> ' +
                   test_helpers.repo_checkout + '/testfile.py'))

        test_helpers.gitCommitWithMessage('Testing File Checker with '
                                          'a valid file')

        self.assertTrue(test_helpers.gitPush(),
                        'Pushing a well formatted Python file')
Example #17
0
    def test_invalid_code(self):
        test_helpers.deployHookKit('test_script_file_checker_config.json')

        os.system(('echo "   print "invalid indent makes snakes cry"" >> ' +
                   test_helpers.repo_checkout + '/testfile.py'))

        test_helpers.gitCommitWithMessage("Testing File Checker with an "
                                          "invalid file")

        self.assertFalse(test_helpers.gitPush(),
                         "Pushing a badly formatted Python file")
    def test_invalid_commit(self):
        test_helpers.deployHookKit('test_script_repo_checker_config.json')

        os.system(('echo "Gobble gobble - a turkey lives here" >> ' +
                  test_helpers.repo_checkout + '/testfile.py'))

        test_helpers.gitCommitWithMessage('Testing Repo Checker with '
                                          'an invalid file')

        self.assertFalse(test_helpers.gitPush(),
                         'Pushing an invalid file')
    def test_valid_commit(self):
        test_helpers.deployHookKit('test_script_repo_checker_config.json')

        os.system(('echo "no thanksgivings birds here" >> ' +
                  test_helpers.repo_checkout + '/testfile.py'))

        test_helpers.gitCommitWithMessage('Testing Repo Checker with '
                                          'a valid file')

        self.assertTrue(test_helpers.gitPush(),
                        'Pushing a valid file')
    def test_valid_message_with_special_characters(self):
        test_helpers.deployHookKit(self.CONFIG_FILE)

        os.system(
            ('echo foo >> ' + test_helpers.repo_checkout + '/testfile.py'))

        test_helpers.gitCommitWithMessage("adding **kwargs support for the "
                                          "service and unit tests #363")

        self.assertTrue(
            test_helpers.gitPush(),
            "Pushing valid commit message with special characters")
    def test_invalid_file_checker_program(self):
        test_helpers.deployHookKit('test_script_file_checker_config_invalid'
                                   '_file_checker_program.json')

        os.system(('echo "print "valid indentation rocks"" >> ' +
                  test_helpers.repo_checkout + '/testfile.py'))

        test_helpers.gitCommitWithMessage('Testing File Checker with '
                                          'a valid file but broken checker')

        self.assertFalse(test_helpers.gitPush(),
                         "Pushing a valid commit to a server with and invalid "
                         "file checker configured should fail.")
Example #22
0
    def test_invalid_file_checker_program(self):
        test_helpers.deployHookKit('test_script_file_checker_config_invalid'
                                   '_file_checker_program.json')

        os.system(('echo "print "valid indentation rocks"" >> ' +
                   test_helpers.repo_checkout + '/testfile.py'))

        test_helpers.gitCommitWithMessage('Testing File Checker with '
                                          'a valid file but broken checker')

        self.assertFalse(
            test_helpers.gitPush(),
            "Pushing a valid commit to a server with and invalid "
            "file checker configured should fail.")
Example #23
0
    def test_invalid_code_that_shouldnt_be_scanned(self):
        test_helpers.deployHookKit('test_script_file_checker_config.json')

        os.system(('echo "    print "invalid indent - nobody checks it"" >> ' +
                   test_helpers.repo_checkout + '/testfile.cpp'))

        test_helpers.runCommandInPath('git add testfile.cpp',
                                      test_helpers.repo_checkout)

        test_helpers.gitCommitWithMessage('Testing File Checker with a '
                                          'file it should ignore')

        self.assertTrue(
            test_helpers.gitPush(), "Pushing a badly formatted file "
            "which shouldn't be scanned")
    def test_invalid_code_that_shouldnt_be_scanned(self):
        test_helpers.deployHookKit('test_script_file_checker_config.json')

        os.system(('echo "    print "invalid indent - nobody checks it"" >> ' +
                  test_helpers.repo_checkout + '/testfile.cpp'))

        test_helpers.runCommandInPath('git add testfile.cpp',
                                      test_helpers.repo_checkout)

        test_helpers.gitCommitWithMessage('Testing File Checker with a '
                                          'file it should ignore')

        self.assertTrue(test_helpers.gitPush(),
                        "Pushing a badly formatted file "
                        "which shouldn't be scanned")
    def test_commit_already_exists_in_other_branch(self):
        test_helpers.deployHookKit(self.CONFIG_FILE)
        os.system(('echo foo >> ' + test_helpers.repo_checkout +
                   '/testfile.py'))

        test_helpers.gitCommitWithMessage("I'm a valid commit!")
        test_helpers.gitPush()

        test_helpers.runCommandInPath('git checkout -b test',
                                      test_helpers.repo_checkout)

        result = test_helpers.runCommandInPath('git push origin test',
                                               test_helpers.repo_checkout)

        self.assertTrue(result,
                        "Pushing sha1 that already exists in other branch")
    def test_commit_already_exists_in_other_branch(self):
        test_helpers.deployHookKit(self.CONFIG_FILE)
        os.system(
            ('echo foo >> ' + test_helpers.repo_checkout + '/testfile.py'))

        test_helpers.gitCommitWithMessage("I'm a valid commit!")
        test_helpers.gitPush()

        test_helpers.runCommandInPath('git checkout -b test',
                                      test_helpers.repo_checkout)

        result = test_helpers.runCommandInPath('git push origin test',
                                               test_helpers.repo_checkout)

        self.assertTrue(result,
                        "Pushing sha1 that already exists in other branch")
Example #27
0
    def test_invalid_code_in_blacklisted_dir(self):
        test_helpers.deployHookKit('test_script_file_checker_config.json')

        os.system('mkdir ' + test_helpers.repo_checkout + '/blacklist')

        os.system(('echo "   print "invalid indent makes snakes cry"" >> ' +
                   test_helpers.repo_checkout + '/blacklist/testfile.py'))

        test_helpers.runCommandInPath('git add blacklist/testfile.py',
                                      test_helpers.repo_checkout)

        test_helpers.gitCommitWithMessage("Testing File Checker with an "
                                          "invalid file in blacklist dir")

        self.assertTrue(
            test_helpers.gitPush(), "Pushing a badly formatted Python file in"
            " a blacklisted directory should work")
    def test_invalid_code_in_blacklisted_dir(self):
        test_helpers.deployHookKit('test_script_file_checker_config.json')

        os.system('mkdir ' + test_helpers.repo_checkout + '/blacklist')

        os.system(('echo "   print "invalid indent makes snakes cry"" >> ' +
                  test_helpers.repo_checkout + '/blacklist/testfile.py'))

        test_helpers.runCommandInPath('git add blacklist/testfile.py',
                                      test_helpers.repo_checkout)

        test_helpers.gitCommitWithMessage("Testing File Checker with an "
                                          "invalid file in blacklist dir")

        self.assertTrue(test_helpers.gitPush(),
                        "Pushing a badly formatted Python file in"
                        " a blacklisted directory should work")
    def test_local_invalid_message(self):
        test_helpers.deployLocalHookKit(self.CONFIG_FILE)

        os.system(('echo foo >> ' + test_helpers.repo_checkout +
                   '/testfile.py'))

        result = test_helpers.gitCommitWithMessage("I'm an invalid commit!")
        self.assertFalse(result, 'Pushing invalid commit to local repo')
Example #30
0
    def test_move_and_edit_valid_code(self):
        test_helpers.deployHookKit('test_script_file_checker_config.json')

        os.system(('echo "print "valid indentation rocks"" >> ' +
                   test_helpers.repo_checkout + '/testfile.py'))

        test_helpers.gitCommitWithMessage('Testing File Checker with '
                                          'a valid file')

        test_helpers.runCommandInPath('git mv testfile.py testfile2.py',
                                      test_helpers.repo_checkout)

        os.system(('echo "print "valid indentation rocks again"" >> ' +
                   test_helpers.repo_checkout + '/testfile2.py'))

        test_helpers.gitCommitWithMessage('Testing File Checker with '
                                          'moving a valid file')

        self.assertTrue(test_helpers.gitPush(),
                        'Pushing a move of a well formatted Python file')
    def test_move_and_edit_valid_code(self):
        test_helpers.deployHookKit('test_script_file_checker_config.json')

        os.system(('echo "print "valid indentation rocks"" >> ' +
                  test_helpers.repo_checkout + '/testfile.py'))

        test_helpers.gitCommitWithMessage('Testing File Checker with '
                                          'a valid file')

        test_helpers.runCommandInPath('git mv testfile.py testfile2.py',
                                      test_helpers.repo_checkout)

        os.system(('echo "print "valid indentation rocks again"" >> ' +
                  test_helpers.repo_checkout + '/testfile2.py'))

        test_helpers.gitCommitWithMessage('Testing File Checker with '
                                          'moving a valid file')

        self.assertTrue(test_helpers.gitPush(),
                        'Pushing a move of a well formatted Python file')
    def test_combined_invalid_message(self):
        test_helpers.deployHookKit(self.CONFIG_FILE)

        os.system('echo A >> ' + test_helpers.repo_checkout + '/testfile.py')
        test_helpers.gitCommitWithMessage("I'm a valid commit! #123")
        os.system('echo A >> ' + test_helpers.repo_checkout + '/testfile.py')
        test_helpers.gitCommitWithMessage("I'm an invalid #123commit!")
        os.system('echo A >> ' + test_helpers.repo_checkout + '/testfile.py')
        test_helpers.gitCommitWithMessage("I'm a valid commit! #123")
        self.assertFalse(test_helpers.gitPush(),
                         "Pushing a combo of valid & invalid commit messages")
    def test_invalid_message_inbetween_push(self):
        test_helpers.deployHookKit(self.CONFIG_FILE)
        os.system(('echo foo >> ' + test_helpers.repo_checkout +
                   '/testfile.py'))

        test_helpers.gitCommitWithMessage("I'm a future invalid commit!")
        os.system(('echo foo >> ' + test_helpers.repo_checkout +
                   '/testfile.py'))

        test_helpers.gitCommitWithMessage("I'm a valid commit! #123")

        os.system(('echo foo >> ' + test_helpers.repo_checkout +
                   '/testfile.py'))

        self.assertTrue(test_helpers.gitPush(),
                        "Pushing valid commit messages")

        test_helpers.gitCommitWithMessage("I'm a future invalid commit!")
        self.assertFalse(test_helpers.gitPush(),
                         'Pushing invalid commit messages after push')
    def test_invalid_message_inbetween_push(self):
        test_helpers.deployHookKit(self.CONFIG_FILE)
        os.system(
            ('echo foo >> ' + test_helpers.repo_checkout + '/testfile.py'))

        test_helpers.gitCommitWithMessage("I'm a future invalid commit!")
        os.system(
            ('echo foo >> ' + test_helpers.repo_checkout + '/testfile.py'))

        test_helpers.gitCommitWithMessage("I'm a valid commit! #123")

        os.system(
            ('echo foo >> ' + test_helpers.repo_checkout + '/testfile.py'))

        self.assertTrue(test_helpers.gitPush(),
                        "Pushing valid commit messages")

        test_helpers.gitCommitWithMessage("I'm a future invalid commit!")
        self.assertFalse(test_helpers.gitPush(),
                         'Pushing invalid commit messages after push')