Ejemplo n.º 1
0
 def test_push_branch_identical_to_master(self):
     test_helpers.deployHookKit('test_hookkit_config.json')
     os.system('echo A >> ' + test_helpers.repo_checkout + '/testfile.py')
     test_helpers.gitCommitWithMessage('foo bar commit to push to a branch')
     test_helpers.gitPush()
     test_helpers.runCommandInPath('git checkout -b test_branch',
                                   test_helpers.repo_checkout)
     self.assertTrue(test_helpers.gitPush('origin test_branch'),
                     'Push to a branch should work.')
    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")
Ejemplo n.º 3
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_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_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")
Ejemplo n.º 6
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_valid_branch_name(self):
        test_helpers.deployHookKit('test_script_branch_name_filter.json')

        test_helpers.runCommandInPath('git checkout -b 123-joe-bar',
                                      test_helpers.repo_checkout)

        self.assertTrue(test_helpers.gitPush('origin 123-joe-bar'),
                        'Pushing a valid branch name')
    def test_invalid_branch_name(self):
        test_helpers.deployHookKit('test_script_branch_name_filter.json')

        test_helpers.runCommandInPath('git checkout -b abc-foo-bar',
                                      test_helpers.repo_checkout)

        self.assertFalse(test_helpers.gitPush('origin abc-foo-bar'),
                         'Pushing an invalid branch name')
    def test_valid_branch_name(self):
        test_helpers.deployHookKit('test_script_branch_name_filter.json')

        test_helpers.runCommandInPath('git checkout -b 123-joe-bar',
                                      test_helpers.repo_checkout)

        self.assertTrue(test_helpers.gitPush('origin 123-joe-bar'),
                        'Pushing a valid branch name')
    def test_invalid_branch_name(self):
        test_helpers.deployHookKit('test_script_branch_name_filter.json')

        test_helpers.runCommandInPath('git checkout -b abc-foo-bar',
                                      test_helpers.repo_checkout)

        self.assertFalse(test_helpers.gitPush('origin abc-foo-bar'),
                         'Pushing an invalid branch name')
Ejemplo n.º 12
0
    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')
Ejemplo n.º 13
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')
Ejemplo n.º 14
0
    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")
    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')
Ejemplo n.º 17
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')
Ejemplo n.º 18
0
    def test_move_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.gitPush()

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

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

        self.assertTrue(test_helpers.gitPush(),
                        'Pushing a well formatted Python file that was moved')
Ejemplo n.º 19
0
    def test_move_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.gitPush()

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

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

        self.assertTrue(test_helpers.gitPush(),
                        'Pushing a well formatted Python file that was moved')
Ejemplo n.º 20
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')
Ejemplo n.º 21
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_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')
Ejemplo n.º 23
0
    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')
Ejemplo n.º 24
0
    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')
Ejemplo n.º 25
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_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')
Ejemplo n.º 27
0
    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_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_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")
Ejemplo n.º 30
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.")
Ejemplo n.º 31
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.")
Ejemplo n.º 32
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")
Ejemplo n.º 33
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")
Ejemplo n.º 34
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")
Ejemplo n.º 35
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")
Ejemplo n.º 36
0
    def test_move_and_edit_invalid_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 "invalid indentation makes me sad"" >> ' +
                   test_helpers.repo_checkout + '/testfile2.py'))

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

        self.assertFalse(test_helpers.gitPush(),
                         'Pushing a move of a badly formatted Python file')
Ejemplo n.º 37
0
    def test_move_and_edit_invalid_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 "invalid indentation makes me sad"" >> ' +
                  test_helpers.repo_checkout + '/testfile2.py'))

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

        self.assertFalse(test_helpers.gitPush(),
                         'Pushing a move of a badly formatted Python file')