Remove defunct Rietveld end-to-end tests

R=tandrii@chromium.org

Bug: 770019
Change-Id: I55d74d67281bd3f79cfd5ba9f57eea082359573e
Reviewed-on: https://chromium-review.googlesource.com/693034
Commit-Queue: Aaron Gable <agable@chromium.org>
Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org>
changes/34/693034/3
Aaron Gable 8 years ago committed by Commit Bot
parent 35c5b9ad1b
commit 0a1f3f6ab3

@ -63,54 +63,6 @@ def CommonChecks(input_api, output_api, tests_to_black_list):
return results
def RunGitClTests(input_api, output_api):
"""Run all the shells scripts in the directory test.
"""
if input_api.platform == 'win32':
# Skip for now as long as the test scripts are bash scripts.
return []
# First loads a local Rietveld instance.
import sys
old_sys_path = sys.path
try:
sys.path = [input_api.PresubmitLocalPath()] + sys.path
from testing_support import local_rietveld
server = local_rietveld.LocalRietveld()
finally:
sys.path = old_sys_path
results = []
try:
# Start a local rietveld instance to test against.
server.start_server()
test_path = input_api.os_path.abspath(
input_api.os_path.join(input_api.PresubmitLocalPath(), 'tests'))
# test-lib.sh is not an actual test so it should not be run.
NON_TEST_FILES = ('test-lib.sh')
for test in input_api.os_listdir(test_path):
if test in NON_TEST_FILES or not test.endswith('.sh'):
continue
print('Running %s' % test)
try:
if input_api.verbose:
input_api.subprocess.check_call(
[input_api.os_path.join(test_path, test)], cwd=test_path)
else:
input_api.subprocess.check_output(
[input_api.os_path.join(test_path, test)], cwd=test_path,
stderr=input_api.subprocess.STDOUT)
except (OSError, input_api.subprocess.CalledProcessError), e:
results.append(output_api.PresubmitError('%s failed\n%s' % (test, e)))
except local_rietveld.Failure, e:
results.append(output_api.PresubmitError('\n'.join(str(i) for i in e.args)))
finally:
server.stop_server()
return results
def CheckChangeOnUpload(input_api, output_api):
# Do not run integration tests on upload since they are way too slow.
tests_to_black_list = [
@ -128,5 +80,4 @@ def CheckChangeOnCommit(input_api, output_api):
output.extend(input_api.canned_checks.CheckDoNotSubmit(
input_api,
output_api))
output.extend(RunGitClTests(input_api, output_api))
return output

@ -14,8 +14,6 @@ class Infra(config_util.Config):
@staticmethod
def fetch_spec(props):
# This is used by [depot_tools]/testing_support/local_rietveld.py
managed = props.get('managed', 'false').lower() == 'true'
return {
'type': 'gclient_git',
'gclient_git_spec': {
@ -24,7 +22,7 @@ class Infra(config_util.Config):
'name' : 'infra',
'url' : 'https://chromium.googlesource.com/infra/infra.git',
'deps_file': '.DEPS.git',
'managed' : managed,
'managed' : False,
}
],
},

@ -1,183 +0,0 @@
#!/usr/bin/env python
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Setups a local Rietveld instance to test against a live server for
integration tests.
It makes sure Google AppEngine SDK is found, download Rietveld and Django code
if necessary and starts the server on a free inbound TCP port.
"""
import logging
import optparse
import os
import shutil
import socket
import sys
import tempfile
import time
try:
import subprocess2
except ImportError:
sys.path.append(
os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
import subprocess2
DEPOT_TOOLS=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
class Failure(Exception):
pass
def test_port(port):
s = socket.socket()
try:
return s.connect_ex(('127.0.0.1', port)) == 0
finally:
s.close()
def find_free_port(start_port):
"""Search for a free port starting at specified port."""
for port in xrange(start_port, (2<<16)):
if not test_port(port):
return port
raise Failure('Having issues finding an available port')
class LocalRietveld(object):
"""Downloads everything needed to run a local instance of Rietveld."""
def __init__(self, base_dir=None):
# Paths
self.base_dir = base_dir
if not self.base_dir:
self.base_dir = os.path.dirname(os.path.abspath(__file__))
self.rietveld = os.path.join(self.base_dir, '_rietveld')
self.infra = os.path.join(self.base_dir, '_infra')
self.rietveld_app = os.path.join(
self.infra, 'infra', 'appengine', 'chromium_rietveld')
self.dev_app = os.path.join(
self.infra, 'google_appengine', 'dev_appserver.py')
self.test_server = None
self.port = None
self.tempdir = None
def install_prerequisites(self):
if os.path.exists(self.rietveld):
print "Removing old rietveld dir"
shutil.rmtree(self.rietveld)
sdk_path = os.path.join(self.base_dir, 'google_appengine')
if os.path.exists(sdk_path):
print "Removing old appengine SDK dir"
shutil.rmtree(sdk_path)
previous = os.environ.get('DEPOT_TOOLS_UPDATE')
os.environ['DEPOT_TOOLS_UPDATE'] = '0'
try:
if not os.path.isfile(os.path.join(self.infra, '.gclient')):
print('Checking out infra...')
shutil.rmtree(self.infra, ignore_errors=True)
try:
os.makedirs(self.infra)
subprocess2.call(
[sys.executable, os.path.join(DEPOT_TOOLS, 'fetch.py'),
'--force', 'infra', '--managed=true'],
cwd=self.infra)
except (OSError, subprocess2.CalledProcessError), e:
raise Failure('Failed to clone infra. \n%s' % e)
else:
print('Syncing infra...')
try:
subprocess2.call(
[sys.executable, os.path.join(DEPOT_TOOLS, 'gclient.py'),
'sync', '--force'],
cwd=self.infra)
except (OSError, subprocess2.CalledProcessError), e:
raise Failure('Failed to sync infra. \n%s' % e)
finally:
if previous is None:
del os.environ['DEPOT_TOOLS_UPDATE']
else:
os.environ['DEPOT_TOOLS_UPDATE'] = previous
def start_server(self, verbose=False):
self.install_prerequisites()
assert not self.tempdir
self.tempdir = tempfile.mkdtemp(prefix='rietveld_test')
self.port = find_free_port(10000)
admin_port = find_free_port(self.port + 1)
if verbose:
stdout = stderr = None
else:
stdout = subprocess2.PIPE
stderr = subprocess2.STDOUT
cmd = [
sys.executable,
self.dev_app,
'./app.yaml', # Explicitly specify file to avoid bringing up backends.
'--port', str(self.port),
'--admin_port', str(admin_port),
'--storage', self.tempdir,
'--clear_search_indexes',
'--skip_sdk_update_check',
]
# CHEAP TRICK
# By default you only want to bind on loopback but I'm testing over a
# headless computer so it's useful to be able to access the test instance
# remotely.
if os.environ.get('GAE_LISTEN_ALL', '') == 'true':
cmd.extend(('-a', '0.0.0.0'))
logging.info(' '.join(cmd))
self.test_server = subprocess2.Popen(
cmd, stdout=stdout, stderr=stderr, cwd=self.rietveld_app)
# Loop until port 127.0.0.1:port opens or the process dies.
while not test_port(self.port):
self.test_server.poll()
if self.test_server.returncode is not None:
if not verbose:
out = self.test_server.communicate()[0]
shutil.rmtree(self.tempdir)
self.tempdir = None
raise Failure(
'Test rietveld instance failed early on port %s\n%s' %
(self.port, out))
time.sleep(0.01)
def stop_server(self):
if self.test_server:
try:
self.test_server.kill()
except OSError:
pass
self.test_server.wait()
self.test_server = None
self.port = None
if self.tempdir:
shutil.rmtree(self.tempdir)
self.tempdir = None
def main():
parser = optparse.OptionParser()
parser.add_option('-v', '--verbose', action='store_true')
options, args = parser.parse_args()
if args:
parser.error('Unknown arguments: %s' % ' '.join(args))
instance = LocalRietveld()
try:
instance.start_server(verbose=options.verbose)
print 'Local rietveld instance started on port %d' % instance.port
while True:
time.sleep(0.1)
finally:
instance.stop_server()
if __name__ == '__main__':
main()

@ -1,45 +0,0 @@
#!/usr/bin/env bash
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Check that abandoning a branch also abandons its issue.
set -e
. ./test-lib.sh
setup_git_remote
setup_git_checkout
(
set -e
cd git_checkout
git config rietveld.server localhost:10000
# Create a branch and give it an issue.
git checkout -q -b abandoned
echo "some work done on a branch" >> test
git add test; git commit -q -m "branch work"
export GIT_EDITOR=$(which true)
test_expect_success "upload succeeds" \
"$GIT_CL upload --no-oauth2 -m test master | grep -q 'Issue created'"
# Switch back to master, delete the branch.
git checkout master
git branch -D abandoned
# Verify that "status" doesn't know about it anymore.
# The "exit" trickiness is inverting the exit status of grep.
test_expect_success "git-cl status dropped abandoned branch" \
"$GIT_CL_STATUS | grep -q abandoned && exit 1 || exit 0"
)
SUCCESS=$?
cleanup
if [ $SUCCESS == 0 ]; then
echo PASS
fi

@ -1,70 +0,0 @@
#!/usr/bin/env bash
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -e
. ./test-lib.sh
setup_git_remote
setup_git_checkout
(
set -e
cd git_checkout
git checkout -q --track -b work origin
echo "some work done on a branch" >> test
git add test; git commit -q -m "branch work"
echo "some other work done on a branch" >> test
git add test; git commit -q -m "branch work"
test_expect_success "git-cl upload wants a server" \
"$GIT_CL upload --no-oauth2 2>&1 | grep -q 'You must configure'"
git config rietveld.server localhost:10000
test_expect_success "git-cl status has no issue" \
"$GIT_CL_STATUS | grep -q 'No issue assigned'"
# Prevent the editor from coming up when you upload.
export GIT_EDITOR=$(which true)
test_expect_success "upload succeeds (needs a server running on localhost)" \
"$GIT_CL upload --no-oauth2 -m test master | grep -q 'Issue created'"
test_expect_success "git-cl status now knows the issue" \
"$GIT_CL_STATUS | grep -q 'Issue number'"
# Push a description to this URL.
URL=$($GIT_CL_STATUS | sed -ne '/Issue number/s/[^(]*(\(.*\))/\1/p')
curl --cookie dev_appserver_login="test@example.com:False" \
--data-urlencode subject="test" \
--data-urlencode description="foo-quux" \
--data-urlencode xsrf_token="$(print_xsrf_token)" \
$URL/edit
test_expect_success "git-cl land ok" \
"$GIT_CL land -f --no-oauth2"
test_expect_success "branch still has an issue" \
"$GIT_CL_STATUS | grep -q 'Issue number'"
git checkout -q master > /dev/null 2>&1
git pull -q > /dev/null 2>&1
test_expect_success "committed code has proper description" \
"git show | grep -q 'foo-quux'"
cd $GITREPO_PATH
test_expect_success "upstream repo has our commit" \
"git log master 2>/dev/null | grep -q 'foo-quux'"
)
SUCCESS=$?
cleanup
if [ $SUCCESS == 0 ]; then
echo PASS
fi

@ -1,54 +0,0 @@
#!/usr/bin/env bash
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Tests the "preupload and preland hooks" functionality, which lets you run
# hooks by installing a script into .git/hooks/pre-cl-* first.
set -e
. ./test-lib.sh
setup_git_remote
setup_git_checkout
setup_hooks() {
upload_retval=$1
land_retval=$2
echo > PRESUBMIT.py <<END
def CheckChangeOnUpload(input_api, output_api):
return $upload_retval
def CheckChangeOnCommit(input_api, output_api):
return $land_retval
END
}
(
set -e
cd git_checkout
# We need a server set up, but we don't use it. git config rietveld.server localhost:1
# Install hooks that will fail on upload and commit
setup_hooks 1 1
echo "some work done" >> test
git add test; git commit -q -m "work"
# Verify git cl upload fails.
test_expect_failure "git-cl upload hook fails" "$GIT_CL upload master"
# Verify git cl land fails.
test_expect_failure "git-cl land hook fails" "$GIT_CL land master"
)
SUCCESS=$?
#cleanup
if [ $SUCCESS == 0 ]; then
echo PASS
fi

@ -1,43 +0,0 @@
#!/usr/bin/env bash
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -e
. ./test-lib.sh
setup_git_remote
setup_git_checkout
(
set -e
cd git_checkout
git config rietveld.server localhost:10000
export GIT_EDITOR=$(which true)
git checkout -q -b work
echo "ben@chromium.org" > OWNERS
cat <<END > PRESUBMIT.py
def CheckChangeOnCommit(input_api, output_api):
return input_api.canned_checks.CheckOwners(input_api, output_api)
CheckChangeOnUpload = CheckChangeOnCommit
END
git add OWNERS PRESUBMIT.py ; git commit -q -m "add OWNERS"
test_expect_success "upload succeeds (needs a server running on localhost)" \
"$GIT_CL upload --no-oauth2 -m test master | grep -q 'Issue created'"
test_expect_failure "git-cl land fails w/ missing LGTM" \
"$GIT_CL land -f --no-oauth2"
)
SUCCESS=$?
cleanup
if [ $SUCCESS == 0 ]; then
echo PASS
fi

@ -1,44 +0,0 @@
#!/usr/bin/env bash
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -e
. ./test-lib.sh
setup_git_remote
setup_git_checkout
(
set -e
cd git_checkout
git checkout -q -b work
echo "some work done on a branch" >> test
git add test; git commit -q -m "branch work"
git config rietveld.server localhost:10000
# Prevent the editor from coming up when you upload.
export GIT_EDITOR=$(which true)
test_expect_success "upload succeeds (needs a server running on localhost)" \
"$GIT_CL upload --no-oauth2 -m test master | grep -q 'Issue created'"
test_expect_success "git-cl status now knows the issue" \
"$GIT_CL_STATUS | grep -q 'Issue number'"
ISSUE=$($GIT_CL_STATUS | awk '$0 ~ "Issue number:" { print $3 }')
git checkout -q -b test2 master
test_expect_success "$GIT_CL patch $ISSUE --no-oauth2"
)
SUCCESS=$?
cleanup
if [ $SUCCESS == 0 ]; then
echo PASS
fi

@ -1,42 +0,0 @@
#!/usr/bin/env bash
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -e
. ./test-lib.sh
setup_git_remote
setup_git_checkout
(
set -e
cd git_checkout
cat > .git/hooks/post-cl-land << _EOF
#!/usr/bin/env bash
git branch -m COMMITTED
_EOF
chmod +x .git/hooks/post-cl-land
git config rietveld.server localhost:1
git checkout -q -t origin/master -b work
echo "some work done" >> test
git add test; git commit -q -m "work \
TBR=foo"
test_expect_success "landed code" \
"$GIT_CL land --no-oauth2 -f --bypass-hooks -m 'land'"
test_expect_success "post-cl-land hook executed" \
"git symbolic-ref HEAD | grep -q COMMITTED"
)
SUCCESS=$?
cleanup
if [ $SUCCESS == 0 ]; then
echo PASS
fi

@ -1,72 +0,0 @@
#!/usr/bin/env bash
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -e
. ./test-lib.sh
setup_git_remote
setup_git_checkout
(
set -e
cd git_checkout
git checkout -q -t origin/master -b work
echo "some work done on a branch" >> test
git add test; git commit -q -m "branch work"
echo "some other work done on a branch" >> test
git add test; git commit -q -m "branch work"
test_expect_success "git-cl upload wants a server" \
"$GIT_CL upload --no-oauth2 2>&1 | grep -q 'You must configure'"
git config rietveld.server localhost:10000
test_expect_success "git-cl status has no issue" \
"$GIT_CL_STATUS | grep -q 'No issue assigned'"
# Prevent the editor from coming up when you upload.
export EDITOR=$(which true)
test_expect_success "upload succeeds (needs a server running on localhost)" \
"$GIT_CL upload --no-oauth2 -t test master | \
grep -q 'Issue created'"
test_expect_success "git-cl status now knows the issue" \
"$GIT_CL_STATUS | grep -q 'Issue number'"
# Check to see if the description contains the local commit messages.
# Should contain 'branch work' x 2.
test_expect_success "git-cl status has the right description for the log" \
"[ $($GIT_CL_STATUS --field desc | egrep '^branch work$' -c) -eq 2 ]"
test_expect_success "git-cl status has the right subject from message" \
"$GIT_CL_STATUS --field desc | head -n 1 | grep -q '^test$'"
test_expect_success "git-cl land ok" \
"$GIT_CL land --bypass-hooks"
git fetch origin
git checkout origin/master
test_expect_success "committed code has proper summary" \
"[ $(git log -n 1 --pretty=format:%s | egrep '^test$' -c) -eq 1 ]"
test_expect_success "committed code has proper description" \
"[ $(git log -n 1 --pretty=format:%b | egrep '^branch work$' -c) -eq 2 ]"
# # Have to sleep to let the server return the new status.
# sleep 5
# test_expect_success "branch issue is closed" \
# "$GIT_CL_STATUS | grep -q 'work :.*closed'"
)
SUCCESS=$?
cleanup
if [ $SUCCESS == 0 ]; then
echo PASS
fi

@ -1,598 +0,0 @@
#!/usr/bin/env python
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Unit tests for rietveld.py."""
import httplib
import logging
import os
import socket
import ssl
import StringIO
import sys
import tempfile
import time
import traceback
import unittest
import urllib2
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from testing_support.patches_data import GIT, RAW
from testing_support import auto_stub
from third_party import httplib2
import patch
import rietveld
def _api(files):
"""Mock a rietveld api request."""
return rietveld.json.dumps({'files': files})
def _file(
status, is_binary=False, num_chunks=1, chunk_id=789, property_changes=''):
"""Mock a file in a rietveld api request."""
return {
'status': status,
'is_binary': is_binary,
'num_chunks': num_chunks,
'id': chunk_id,
'property_changes': property_changes,
}
class BaseFixture(unittest.TestCase):
# Override.
TESTED_CLASS = Exception
def setUp(self):
super(BaseFixture, self).setUp()
# Access to a protected member XX of a client class
# pylint: disable=protected-access
self.rietveld = self.TESTED_CLASS('url', None, 'email')
self.rietveld._send = self._rietveld_send
self.requests = []
def tearDown(self):
self.assertEqual([], self.requests)
super(BaseFixture, self).tearDown()
def _rietveld_send(self, url, *args, **kwargs):
self.assertTrue(self.requests, url)
request = self.requests.pop(0)
self.assertEqual(2, len(request))
self.assertEqual(url, request[0])
return request[1]
def _check_patch(self,
p,
filename,
diff,
source_filename=None,
is_binary=False,
is_delete=False,
is_git_diff=False,
is_new=False,
patchlevel=0,
svn_properties=None):
svn_properties = svn_properties or []
self.assertEqual(p.filename, filename)
self.assertEqual(p.source_filename, source_filename)
self.assertEqual(p.is_binary, is_binary)
self.assertEqual(p.is_delete, is_delete)
if hasattr(p, 'is_git_diff'):
self.assertEqual(p.is_git_diff, is_git_diff)
self.assertEqual(p.is_new, is_new)
if hasattr(p, 'patchlevel'):
self.assertEqual(p.patchlevel, patchlevel)
if diff:
self.assertEqual(p.get(True), diff)
if hasattr(p, 'svn_properties'):
self.assertEqual(p.svn_properties, svn_properties)
class RietveldTest(BaseFixture):
TESTED_CLASS = rietveld.Rietveld
def test_get_patch_empty(self):
self.requests = [('/api/123/456', '{}')]
patches = self.rietveld.get_patch(123, 456)
self.assertTrue(isinstance(patches, patch.PatchSet))
self.assertEqual([], patches.patches)
def test_get_patch_no_status(self):
self.requests = [
( '/api/123/456',
_api(
{
'tools/clang_check/README.chromium': {
'status': None,
'id': 789,
}})),
('/download/issue123_456_789.diff', RAW.DELETE),
]
patches = self.rietveld.get_patch(123, 456)
self.assertEqual(1, len(patches.patches))
self._check_patch(
patches.patches[0],
'tools/clang_check/README.chromium',
RAW.DELETE,
is_delete=True)
def test_get_patch_2_files(self):
self.requests = [
('/api/123/456',
_api({'foo': _file('A'), 'file_a': _file('M', chunk_id=790)})),
('/download/issue123_456_789.diff', RAW.NEW),
('/download/issue123_456_790.diff', RAW.NEW_NOT_NULL),
]
patches = self.rietveld.get_patch(123, 456)
self.assertEqual(2, len(patches.patches))
self._check_patch(
patches.patches[0], 'file_a', RAW.NEW_NOT_NULL, is_new=True)
self._check_patch(patches.patches[1], 'foo', RAW.NEW, is_new=True)
def test_get_patch_add(self):
self.requests = [
('/api/123/456', _api({'foo': _file('A')})),
('/download/issue123_456_789.diff', RAW.NEW),
]
patches = self.rietveld.get_patch(123, 456)
self.assertEqual(1, len(patches.patches))
self._check_patch(patches.patches[0], 'foo', RAW.NEW, is_new=True)
def test_invalid_status(self):
self.requests = [
('/api/123/456', _api({'file_a': _file('B')})),
]
try:
self.rietveld.get_patch(123, 456)
self.fail()
except patch.UnsupportedPatchFormat, e:
self.assertEqual('file_a', e.filename)
def test_add_plus_merge(self):
# svn:mergeinfo is dropped.
properties = (
'\nAdded: svn:mergeinfo\n'
' Merged /branches/funky/file_b:r69-2775\n')
self.requests = [
('/api/123/456',
_api({'pp': _file('A+', property_changes=properties)})),
('/download/issue123_456_789.diff', GIT.COPY),
]
patches = self.rietveld.get_patch(123, 456)
self.assertEqual(1, len(patches.patches))
self._check_patch(
patches.patches[0],
'pp',
GIT.COPY,
is_git_diff=True,
is_new=True,
patchlevel=1,
source_filename='PRESUBMIT.py')
def test_add_plus_eol_style(self):
properties = '\nAdded: svn:eol-style\n + LF\n'
self.requests = [
('/api/123/456',
_api({'pp': _file('A+', property_changes=properties)})),
('/download/issue123_456_789.diff', GIT.COPY),
]
patches = self.rietveld.get_patch(123, 456)
self.assertEqual(1, len(patches.patches))
self._check_patch(
patches.patches[0],
'pp',
GIT.COPY,
is_git_diff=True,
is_new=True,
patchlevel=1,
source_filename='PRESUBMIT.py',
svn_properties=[('svn:eol-style', 'LF')])
def test_add_empty(self):
self.requests = [
('/api/123/456', _api({'__init__.py': _file('A ', num_chunks=0)})),
('/download/issue123_456_789.diff', RAW.CRAP_ONLY),
]
patches = self.rietveld.get_patch(123, 456)
self.assertEqual(1, len(patches.patches))
self._check_patch(
patches.patches[0],
'__init__.py',
RAW.CRAP_ONLY,
is_new=True)
def test_delete(self):
name = 'tools/clang_check/README.chromium'
self.requests = [
('/api/123/456', _api({name: _file('D')})),
('/download/issue123_456_789.diff', RAW.DELETE),
]
patches = self.rietveld.get_patch(123, 456)
self.assertEqual(1, len(patches.patches))
self._check_patch(patches.patches[0], name, RAW.DELETE, is_delete=True)
def test_delete_empty(self):
name = 'tests/__init__.py'
self.requests = [
('/api/123/456', _api({name: _file('D')})),
('/download/issue123_456_789.diff', GIT.DELETE_EMPTY),
]
patches = self.rietveld.get_patch(123, 456)
self.assertEqual(1, len(patches.patches))
self._check_patch(
patches.patches[0],
name,
GIT.DELETE_EMPTY,
is_delete=True,
is_git_diff=True,
patchlevel=1)
def test_m_plus(self):
properties = '\nAdded: svn:eol-style\n + LF\n'
self.requests = [
('/api/123/456',
_api({'chrome/file.cc': _file('M+', property_changes=properties)})),
('/download/issue123_456_789.diff', RAW.PATCH),
]
patches = self.rietveld.get_patch(123, 456)
self.assertEqual(1, len(patches.patches))
self._check_patch(
patches.patches[0],
'chrome/file.cc',
RAW.PATCH,
svn_properties=[('svn:eol-style', 'LF')])
def test_m_plus_unknown_prop(self):
properties = '\nAdded: svn:foobar\n + stuff\n'
self.requests = [
('/api/123/456',
_api({'file_a': _file('M+', property_changes=properties)})),
]
try:
self.rietveld.get_patch(123, 456)
self.fail()
except patch.UnsupportedPatchFormat, e:
self.assertEqual('file_a', e.filename)
def test_get_patch_moved(self):
self.requests = [
('/api/123/456', _api({'file_b': _file('A+')})),
('/download/issue123_456_789.diff', RAW.MINIMAL_RENAME),
]
patches = self.rietveld.get_patch(123, 456)
self.assertEqual(1, len(patches.patches))
self._check_patch(
patches.patches[0],
'file_b',
RAW.MINIMAL_RENAME,
source_filename='file_a',
is_new=True)
def test_svn_properties(self):
# pylint: disable=line-too-long
# To test one of these, run something like
# import json, pprint, urllib
# url = 'http://codereview.chromium.org/api/202046/1'
# pprint.pprint(json.load(urllib.urlopen(url))['files'])
# svn:mergeinfo across branches:
# http://codereview.chromium.org/202046/diff/1/third_party/libxml/xmlcatalog_dummy.cc
self.assertEqual(
[('svn:eol-style', 'LF')],
rietveld.Rietveld.parse_svn_properties(
u'\nAdded: svn:eol-style\n + LF\n', 'foo'))
# svn:eol-style property that is lost in the diff
# http://codereview.chromium.org/202046/diff/1/third_party/libxml/xmllint_dummy.cc
self.assertEqual(
[],
rietveld.Rietveld.parse_svn_properties(
u'\nAdded: svn:mergeinfo\n'
' Merged /branches/chrome_webkit_merge_branch/third_party/'
'libxml/xmldummy_mac.cc:r69-2775\n',
'foo'))
self.assertEqual(
[],
rietveld.Rietveld.parse_svn_properties(u'', 'foo'))
# http://codereview.chromium.org/api/7834045/15001
self.assertEqual(
[('svn:executable', '*'), ('svn:eol-style', 'LF')],
rietveld.Rietveld.parse_svn_properties(
'\n'
'Added: svn:executable\n'
' + *\n'
'Added: svn:eol-style\n'
' + LF\n',
'foo'))
# http://codereview.chromium.org/api/9139006/7001
self.assertEqual(
[('svn:mime-type', 'image/png')],
rietveld.Rietveld.parse_svn_properties(
'\n'
'Added: svn:mime-type\n'
' + image/png\n',
'foo'))
def test_bad_svn_properties(self):
try:
rietveld.Rietveld.parse_svn_properties(u'\n', 'foo')
self.fail()
except rietveld.patch.UnsupportedPatchFormat, e:
self.assertEqual('foo', e.filename)
# TODO(maruel): Change with no diff, only svn property change:
# http://codereview.chromium.org/6462019/
def test_search_all_empty(self):
url = (
'/search?format=json'
'&base=base'
'&created_after=2010-01-02'
'&created_before=2010-01-01'
'&modified_after=2010-02-02'
'&modified_before=2010-02-01'
'&owner=owner%40example.com'
'&reviewer=reviewer%40example.com'
'&closed=2'
'&commit=2'
'&private=2'
'&keys_only=True'
'&with_messages=True'
'&limit=23')
self.requests = [
(url, '{}'),
]
results = list(self.rietveld.search(
'owner@example.com',
'reviewer@example.com',
'base',
True,
True,
True,
'2010-01-01',
'2010-01-02',
'2010-02-01',
'2010-02-02',
23,
True,
True,
))
self.assertEqual([], results)
def test_results_cursor(self):
# Verify cursor iteration is transparent.
self.requests = [
('/search?format=json&base=base',
rietveld.json.dumps({
'cursor': 'MY_CURSOR',
'results': [{'foo': 'bar'}, {'foo': 'baz'}],
})),
('/search?format=json&base=base&cursor=MY_CURSOR',
rietveld.json.dumps({
'cursor': 'NEXT',
'results': [{'foo': 'prout'}],
})),
('/search?format=json&base=base&cursor=NEXT',
rietveld.json.dumps({
'cursor': 'VOID',
'results': [],
})),
]
expected = [
{'foo': 'bar'},
{'foo': 'baz'},
{'foo': 'prout'},
]
for i in self.rietveld.search(base='base'):
self.assertEqual(expected.pop(0), i)
self.assertEqual([], expected)
class CachingRietveldTest(BaseFixture):
# Tests only one request is done.
TESTED_CLASS = rietveld.CachingRietveld
def test_get_description(self):
self.requests = [
('/1/description', 'Blah blah blah'),
]
expected = 'Blah blah blah'
self.assertEqual(expected, self.rietveld.get_description(1))
self.assertEqual(expected, self.rietveld.get_description(1))
def test_get_issue_properties(self):
data = {'description': 'wow\r\nno CR!', 'messages': 'foo'}
self.requests = [
('/api/1?messages=true', rietveld.json.dumps(data)),
]
expected = {u'description': u'wow\nno CR!'}
expected_msg = {u'description': u'wow\nno CR!', u'messages': u'foo'}
self.assertEqual(expected, self.rietveld.get_issue_properties(1, False))
self.assertEqual(expected_msg, self.rietveld.get_issue_properties(1, True))
def test_get_patchset_properties(self):
self.requests = [
('/api/1/2', '{}'),
]
expected = {}
self.assertEqual(expected, self.rietveld.get_patchset_properties(1, 2))
self.assertEqual(expected, self.rietveld.get_patchset_properties(1, 2))
class ProbeException(Exception):
"""Deep-probe a value."""
value = None
def __init__(self, value):
super(ProbeException, self).__init__()
self.value = value
def MockSend(*args, **kwargs):
"""Mock upload.py's Send() to probe the timeout value"""
raise ProbeException(kwargs['timeout'])
def MockSendTimeout(*args, **kwargs):
"""Mock upload.py's Send() to raise SSLError"""
raise ssl.SSLError('The read operation timed out')
def MockSocketConnectTimeout(*args, **kwargs):
"""Mock upload.py's Send() to raise socket.timeout"""
raise socket.timeout('timed out')
class DefaultTimeoutTest(auto_stub.TestCase):
TESTED_CLASS = rietveld.Rietveld
def setUp(self):
super(DefaultTimeoutTest, self).setUp()
self.rietveld = self.TESTED_CLASS('url', None, 'email')
self.mock(self.rietveld.rpc_server, 'Send', MockSend)
self.sleep_time = 0
def test_timeout_get(self):
with self.assertRaises(ProbeException) as cm:
self.rietveld.get('/api/1234')
self.assertIsNotNone(cm.exception.value, 'Rietveld timeout was not set: %s'
% traceback.format_exc())
def test_timeout_post(self):
with self.assertRaises(ProbeException) as cm:
self.rietveld.post('/api/1234', [('key', 'data')])
self.assertIsNotNone(cm.exception.value, 'Rietveld timeout was not set: %s'
% traceback.format_exc())
def MockSleep(self, t):
self.sleep_time = t
def test_ssl_timeout_post(self):
self.mock(self.rietveld.rpc_server, 'Send', MockSendTimeout)
self.mock(time, 'sleep', self.MockSleep)
with self.assertRaises(ssl.SSLError):
self.rietveld.post('/api/1234', [('key', 'data')])
self.assertNotEqual(self.sleep_time, 0)
def test_socket_connect_timeout_post(self):
self.mock(self.rietveld.rpc_server, 'Send', MockSocketConnectTimeout)
self.mock(time, 'sleep', self.MockSleep)
with self.assertRaises(socket.timeout):
self.rietveld.post('/api/1234', [('key', 'data')])
self.assertNotEqual(self.sleep_time, 0)
class OAuthRpcServerTest(auto_stub.TestCase):
def setUp(self):
super(OAuthRpcServerTest, self).setUp()
self.rpc_server = rietveld.OAuthRpcServer(
'http://www.example.com', 'foo', 'bar')
def set_mock_response(self, status):
def mock_http_request(*args, **kwargs):
return (httplib2.Response({'status': status}), 'body')
self.mock(self.rpc_server._http, 'request', mock_http_request)
def test_404(self):
self.set_mock_response(404)
with self.assertRaises(urllib2.HTTPError) as ctx:
self.rpc_server.Send('/foo')
self.assertEquals(404, ctx.exception.code)
def test_200(self):
self.set_mock_response(200)
ret = self.rpc_server.Send('/foo')
self.assertEquals('body', ret)
class RietveldOAuthRpcServerTest(auto_stub.TestCase):
def setUp(self):
super(RietveldOAuthRpcServerTest, self).setUp()
with tempfile.NamedTemporaryFile() as private_key_file:
self.rietveld = rietveld.JwtOAuth2Rietveld(
'http://www.example.com', 'foo', private_key_file.name, maxtries=2)
self.mock(time, 'sleep', lambda duration: None)
def test_retries_500(self):
urls = []
def mock_http_request(url, *args, **kwargs):
urls.append(url)
return (httplib2.Response({'status': 500}), 'body')
self.mock(self.rietveld.rpc_server._http, 'request', mock_http_request)
with self.assertRaises(urllib2.HTTPError) as ctx:
self.rietveld.get('/foo')
self.assertEquals(500, ctx.exception.code)
self.assertEqual(2, len(urls)) # maxtries was 2
self.assertEqual(['https://www.example.com/foo'] * 2, urls)
def test_does_not_retry_404(self):
urls = []
def mock_http_request(url, *args, **kwargs):
urls.append(url)
return (httplib2.Response({'status': 404}), 'body')
self.mock(self.rietveld.rpc_server._http, 'request', mock_http_request)
with self.assertRaises(urllib2.HTTPError) as ctx:
self.rietveld.get('/foo')
self.assertEquals(404, ctx.exception.code)
self.assertEqual(1, len(urls)) # doesn't retry
def test_retries_404_when_requested(self):
urls = []
def mock_http_request(url, *args, **kwargs):
urls.append(url)
return (httplib2.Response({'status': 404}), 'body')
self.mock(self.rietveld.rpc_server._http, 'request', mock_http_request)
with self.assertRaises(urllib2.HTTPError) as ctx:
self.rietveld.get('/foo', retry_on_404=True)
self.assertEquals(404, ctx.exception.code)
self.assertEqual(2, len(urls)) # maxtries was 2
def test_socket_timeout(self):
urls = []
def mock_http_request(url, *args, **kwargs):
urls.append(url)
raise socket.error('timed out')
self.mock(self.rietveld.rpc_server._http, 'request', mock_http_request)
with self.assertRaises(socket.error):
self.rietveld.get('/foo')
self.assertEqual(2, len(urls)) # maxtries was 2
def test_other_socket_error(self):
urls = []
def mock_http_request(url, *args, **kwargs):
urls.append(url)
raise socket.error('something else')
self.mock(self.rietveld.rpc_server._http, 'request', mock_http_request)
with self.assertRaises(socket.error):
self.rietveld.get('/foo')
self.assertEqual(1, len(urls))
if __name__ == '__main__':
logging.basicConfig(level=[
logging.ERROR, logging.INFO, logging.DEBUG][min(2, sys.argv.count('-v'))])
unittest.main()

@ -1,57 +0,0 @@
#!/usr/bin/env bash
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# We should save a change's description when an upload fails.
set -e
. ./test-lib.sh
# Back up any previously-saved description the user might have.
BACKUP_FILE="$HOME/.git_cl_description_backup"
BACKUP_FILE_TMP="$BACKUP_FILE.tmp"
if [ -e "$BACKUP_FILE" ]; then
mv "$BACKUP_FILE" "$BACKUP_FILE_TMP"
fi
setup_git_remote
setup_git_checkout
(
set -e
cd git_checkout
DESC="this is the description"
# Create a branch and check in a file.
git checkout -q --track -b work origin
echo foo >> test
git add test; git commit -q -m "$DESC"
# Try to upload the change to an unresolvable hostname; git-cl should fail.
export GIT_EDITOR=$(which true)
git config rietveld.server bogus.example.com:80
test_expect_failure "uploading to bogus server" \
"$GIT_CL upload --no-oauth2 2>/dev/null"
# Check that the change's description was saved.
test_expect_success "description was backed up" \
"grep -q '$DESC' '$BACKUP_FILE'"
)
SUCCESS=$?
cleanup
# Restore the previously-saved description.
rm -f "$BACKUP_FILE"
if [ -e "$BACKUP_FILE_TMP" ]; then
mv "$BACKUP_FILE_TMP" "$BACKUP_FILE"
fi
if [ $SUCCESS == 0 ]; then
echo PASS
fi

@ -1,42 +0,0 @@
#!/usr/bin/env bash
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Check that we're able to submit from a directory that doesn't exist on the
# trunk. This tests for a previous bug where we ended up with an invalid CWD
# after switching to the merge branch.
set -e
. ./test-lib.sh
setup_git_remote
setup_git_checkout
(
set -e
cd git_checkout
git config rietveld.server localhost:10000
# Create a branch and give it an issue.
git checkout -q -b new
mkdir dir
cd dir
echo "some work done on a branch" >> test
git add test; git commit -q -m "branch work"
export GIT_EDITOR=$(which true)
test_expect_success "upload succeeds" \
"$GIT_CL upload --no-oauth2 -m test master | grep -q 'Issue created'"
test_expect_success "git-cl lands ok" \
"$GIT_CL land -f --no-oauth2"
)
SUCCESS=$?
cleanup
if [ $SUCCESS == 0 ]; then
echo PASS
fi

@ -1,85 +0,0 @@
#!/usr/bin/env bash
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Abort on error.
set -e
export DEPOT_TOOLS_UPDATE=0
export PYTHONUNBUFFERED=
PWD=$(pwd)
GITREPO_PATH=$PWD/git_remote
GITREPO_URL=file://$GITREPO_PATH
PATH="$(dirname $PWD):$PATH"
GIT_CL=$(dirname $PWD)/git-cl
GIT_CL_STATUS="$GIT_CL status -f"
# Set up a git repo that has a few commits to master.
setup_git_remote() {
echo "Setting up test upstream git repo..."
rm -rf git_remote
mkdir git_remote
(
cd git_remote
git init -q
git config user.name 'TestDood'
git config user.email 'TestDood@example.com'
echo "test" > test
git add test
git commit -qam "initial commit"
echo "test2" >> test
git commit -qam "second commit"
# Hack: make sure master is not the current branch
# otherwise push will give a warning
git checkout -q --detach master
)
}
# Set up a git checkout of the repo.
setup_git_checkout() {
echo "Setting up test git repo..."
rm -rf git_checkout
git clone -q $GITREPO_URL git_checkout
(
cd git_checkout
git config user.name 'TestDood'
git config user.email 'TestDood@example.com'
)
}
cleanup() {
rm -rf git_remote git_checkout
}
# Usage: test_expect_success "description of test" "test code".
test_expect_success() {
echo "TESTING: $1"
exit_code=0
sh -c "$2" || exit_code=$?
if [ $exit_code != 0 ]; then
echo "FAILURE: $1"
return $exit_code
fi
}
# Usage: test_expect_failure "description of test" "test code".
test_expect_failure() {
echo "TESTING: $1"
exit_code=0
sh -c "$2" || exit_code=$?
if [ $exit_code = 0 ]; then
echo "SUCCESS, BUT EXPECTED FAILURE: $1"
return $exit_code
fi
}
# Grab the XSRF token from the review server and print it to stdout.
print_xsrf_token() {
curl --cookie dev_appserver_login="test@example.com:False" \
--header 'X-Requesting-XSRF-Token: 1' \
http://localhost:10000/xsrf_token 2>/dev/null
}

@ -1,35 +0,0 @@
#!/usr/bin/env bash
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -e
. ./test-lib.sh
setup_git_remote
setup_git_checkout
(
set -e
cd git_checkout
git checkout -q -b work HEAD^
git checkout -q -t -b work2 work
echo "some work done on a branch that tracks a local branch" >> test
git add test; git commit -q -m "local tracking branch work"
git config rietveld.server localhost:10000
# Prevent the editor from coming up when you upload.
export GIT_EDITOR=$(which true)
test_expect_success "upload succeeds (needs a server running on localhost)" \
"$GIT_CL upload --no-oauth2 -m test | grep -q 'Issue created'"
)
SUCCESS=$?
cleanup
if [ $SUCCESS == 0 ]; then
echo PASS
fi

@ -1,37 +0,0 @@
#!/usr/bin/env bash
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -e
. ./test-lib.sh
setup_git_remote
setup_git_checkout
(
set -e
cd git_checkout
git checkout -q -b work HEAD^
echo "some work done on a branch" >> test
git add test; git commit -q -m "branch work"
git config rietveld.server localhost:10000
# Prevent the editor from coming up when you upload.
export GIT_EDITOR=$(which true)
test_expect_success "upload succeeds (needs a server running on localhost)" \
"$GIT_CL upload --no-oauth2 -m test | grep -q 'Issue created'"
test_expect_failure "description shouldn't contain unrelated commits" \
"$GIT_CL_STATUS | grep -q 'second commit'"
)
SUCCESS=$?
cleanup
if [ $SUCCESS == 0 ]; then
echo PASS
fi
Loading…
Cancel
Save