From d57b0611c6335a2bd158a67d3ee36ea8974c48cb Mon Sep 17 00:00:00 2001
From: Darragh Bailey <dbailey@hp.com>
Date: Tue, 10 Jun 2014 14:05:03 +0100
Subject: [PATCH] Ensure username is set for all tests

Keep username/password defining and setting within the same module to
ensure any changes are kept in sync. Additionally remove the '--add'
option as git-review only supports one value for gitreview.username so
it should not be treated as a multi value config option.

Change-Id: I9ae64d8d1884e13a442da6f4d28407ca103e7b00
---
 git_review/tests/__init__.py        | 10 ++++++++++
 git_review/tests/test_git_review.py | 12 +-----------
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/git_review/tests/__init__.py b/git_review/tests/__init__.py
index a3a313d..edf41e1 100644
--- a/git_review/tests/__init__.py
+++ b/git_review/tests/__init__.py
@@ -186,6 +186,9 @@ class BaseGitReviewTestCase(testtools.TestCase, GerritHelpers):
         self._run_git('remote', 'add', 'gerrit', self.project_uri)
         self.addCleanup(shutil.rmtree, self.test_dir)
 
+        # ensure user is configured for all tests
+        self._configure_gitreview_username()
+
     def attach_on_exception(self, filename):
         @self.addOnException
         def attach_file(exc_info):
@@ -258,6 +261,9 @@ class BaseGitReviewTestCase(testtools.TestCase, GerritHelpers):
         os.environ['PATH'] = self.ssh_dir + os.pathsep + os.environ['PATH']
         os.environ['GIT_SSH'] = self._dir('ssh', 'ssh')
 
+    def _configure_gitreview_username(self):
+        self._run_git('config', 'gitreview.username', 'test_user')
+
     def _pick_gerrit_port_and_dir(self):
         pid = os.getpid()
         host = '127.%s.%s.%s' % (self._test_counter, pid >> 8, pid & 255)
@@ -282,3 +288,7 @@ class HttpMixin(object):
     @property
     def project_uri(self):
         return self.project_http_uri
+
+    def _configure_gitreview_username(self):
+        # trick to set http password
+        self._run_git('config', 'gitreview.username', 'test_user:test_pass')
diff --git a/git_review/tests/test_git_review.py b/git_review/tests/test_git_review.py
index 1a5edd0..89fe470 100644
--- a/git_review/tests/test_git_review.py
+++ b/git_review/tests/test_git_review.py
@@ -31,13 +31,9 @@ class GitReviewTestCase(tests.BaseGitReviewTestCase):
         self.assertIn('remote: New Changes:', self._run_git_review())
         self.assertIn('Change-Id:', self._run_git('log', '-1'))
 
-    def _configure_gitreview_username(self):
-        self._run_git('config', '--add', 'gitreview.username', 'test_user')
-
     def test_git_review_s(self):
         """Test git-review -s."""
         self._run_git('remote', 'rm', 'gerrit')
-        self._configure_gitreview_username()
         self._run_git_review('-s')
         self._simple_change('test file modified', 'test commit message')
         self.assertIn('Change-Id:', self._run_git('log', '-1'))
@@ -45,7 +41,6 @@ class GitReviewTestCase(tests.BaseGitReviewTestCase):
     def test_git_review_s_in_detached_head(self):
         """Test git-review -s in detached HEAD state."""
         self._run_git('remote', 'rm', 'gerrit')
-        self._configure_gitreview_username()
         master_sha1 = self._run_git('rev-parse', 'master')
         self._run_git('checkout', master_sha1)
         self._run_git_review('-s')
@@ -60,7 +55,6 @@ class GitReviewTestCase(tests.BaseGitReviewTestCase):
 
         # Review setup with an outdated repo
         self._run_git('remote', 'rm', 'gerrit')
-        self._configure_gitreview_username()
         self._run_git_review('-s')
         self._simple_change('test file modified', 'test commit message 2')
         self.assertIn('Change-Id:', self._run_git('log', '-1'))
@@ -253,8 +247,4 @@ class GitReviewTestCase(tests.BaseGitReviewTestCase):
 
 class HttpGitReviewTestCase(tests.HttpMixin, GitReviewTestCase):
     """Class for the git-review tests over HTTP(S)."""
-
-    def _configure_gitreview_username(self):
-        # trick to set http password
-        self._run_git('config', '--add', 'gitreview.username',
-                      'test_user:test_pass')
+    pass