Add in extra connections tests

Test reporting back to gerrit as a different user.
Test multiple gerrit instances.

Squashed with: Assign fake connections to test class dynamically

As multiple connections can be configured for testing purposes, it makes
more sense to be able to access them all comfortably.

Drawback of this change is, that the dynamicism makes the code less
readable and less obvious.
Previously: If50567dd5a087e9fe46cd4e30f9e0562cda794d7

Co-Authored-By: Jan Hruban <jan.hruban@gooddata.com>

Change-Id: I4652799c8b9a626bd2f7f6996d09c95da2953936
diff --git a/tests/base.py b/tests/base.py
index b0c7991..f3bfa4e 100755
--- a/tests/base.py
+++ b/tests/base.py
@@ -884,7 +884,8 @@
         # Make per test copy of Configuration.
         self.setup_config()
         self.config.set('zuul', 'layout_config',
-                        os.path.join(FIXTURE_DIR, "layout.yaml"))
+                        os.path.join(FIXTURE_DIR,
+                                     self.config.get('zuul', 'layout_config')))
         self.config.set('merger', 'git_dir', self.git_root)
 
         # For each project in config:
@@ -938,10 +939,8 @@
             self.sched.trigger_event_queue
         ]
 
-        # Set up connections and give out the default gerrit for testing
         self.configure_connections()
         self.sched.registerConnections(self.connections)
-        self.fake_gerrit = self.connections['gerrit']
 
         def URLOpenerFactory(*args, **kw):
             if isinstance(args[0], urllib2.Request):
@@ -1011,15 +1010,20 @@
 
             # TODO(jhesketh): load the required class automatically
             if con_driver == 'gerrit':
-                self.gerrit_changes_dbs[con_name] = {}
-                self.gerrit_queues_dbs[con_name] = Queue.Queue()
-                self.event_queues.append(self.gerrit_queues_dbs['gerrit'])
+                if con_config['server'] not in self.gerrit_changes_dbs.keys():
+                    self.gerrit_changes_dbs[con_config['server']] = {}
+                if con_config['server'] not in self.gerrit_queues_dbs.keys():
+                    self.gerrit_queues_dbs[con_config['server']] = \
+                        Queue.Queue()
+                    self.event_queues.append(
+                        self.gerrit_queues_dbs[con_config['server']])
                 self.connections[con_name] = FakeGerritConnection(
                     con_name, con_config,
-                    changes_db=self.gerrit_changes_dbs[con_name],
-                    queues_db=self.gerrit_queues_dbs[con_name],
+                    changes_db=self.gerrit_changes_dbs[con_config['server']],
+                    queues_db=self.gerrit_queues_dbs[con_config['server']],
                     upstream_root=self.upstream_root
                 )
+                setattr(self, 'fake_' + con_name, self.connections[con_name])
             elif con_driver == 'smtp':
                 self.connections[con_name] = \
                     zuul.connection.smtp.SMTPConnection(con_name, con_config)
@@ -1044,10 +1048,10 @@
                 zuul.connection.smtp.SMTPConnection(
                     '_legacy_smtp', dict(self.config.items('smtp')))
 
-    def setup_config(self):
+    def setup_config(self, config_file='zuul.conf'):
         """Per test config object. Override to set different config."""
         self.config = ConfigParser.ConfigParser()
-        self.config.read(os.path.join(FIXTURE_DIR, "zuul.conf"))
+        self.config.read(os.path.join(FIXTURE_DIR, config_file))
 
     def assertFinalState(self):
         # Make sure that git.Repo objects have been garbage collected.