From ab85ce39eb5d56212d165d9f049d7403f976450b Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Thu, 8 Sep 2011 12:04:55 +0200
Subject: [PATCH] baserlib.ResourceBase: Allow overriding of LUXI client
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This enables unittesting of RAPI resources.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: RenΓ© Nussbaumer <rn@google.com>
---
 lib/rapi/baserlib.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/rapi/baserlib.py b/lib/rapi/baserlib.py
index bc3851945..deffd12d6 100644
--- a/lib/rapi/baserlib.py
+++ b/lib/rapi/baserlib.py
@@ -274,16 +274,19 @@ class ResourceBase(object):
   POST_ACCESS = [rapi.RAPI_ACCESS_WRITE]
   DELETE_ACCESS = [rapi.RAPI_ACCESS_WRITE]
 
-  def __init__(self, items, queryargs, req):
+  def __init__(self, items, queryargs, req, _client_cls=luxi.Client):
     """Generic resource constructor.
 
     @param items: a list with variables encoded in the URL
     @param queryargs: a dictionary with additional options from URL
+    @param req: Request context
+    @param _client_cls: L{luxi} client class (unittests only)
 
     """
     self.items = items
     self.queryargs = queryargs
     self._req = req
+    self._client_cls = _client_cls
 
   def _GetRequestBody(self):
     """Returns the body data.
@@ -366,7 +369,7 @@ class ResourceBase(object):
     """
     # Could be a function, pylint: disable=R0201
     try:
-      return luxi.Client()
+      return self._client_cls()
     except luxi.NoMasterError, err:
       raise http.HttpBadGateway("Can't connect to master daemon: %s" % err)
     except luxi.PermissionError:
-- 
GitLab