reviewboard: use built-in mechanism to disable caching; r=smacleod draft
authorGregory Szorc <gps@mozilla.com>
Mon, 11 Jan 2016 15:57:20 -0800
changeset 6716 391714d97a4bd51352c1ecb5b3ab802e3437d97d
parent 6715 d1a83e48de15967f3c0744248fab3fd3442c3c77
child 6717 c85f73a6b2af2290021cd24ea966215ef85e6f05
push id513
push usergszorc@mozilla.com
push dateWed, 13 Jan 2016 02:13:15 +0000
reviewerssmacleod
reviewboard: use built-in mechanism to disable caching; r=smacleod Modern versions of RBTools allow caching to be disabled by passing an argument to the constructor. This means our hack to define a custom transport class with caching disabled can be removed. We also disable caching in similar code that was also wrapping a RBTools client.
pylib/reviewboardmods/reviewboardmods/pushhooks.py
testing/vcttesting/reviewboard/__init__.py
--- a/pylib/reviewboardmods/reviewboardmods/pushhooks.py
+++ b/pylib/reviewboardmods/reviewboardmods/pushhooks.py
@@ -9,17 +9,16 @@ details.
 """
 
 from contextlib import contextmanager
 import os
 import tempfile
 
 from rbtools.api.client import RBClient
 from rbtools.api.errors import APIError
-from rbtools.api.transport.sync import SyncTransport
 
 
 def associate_ldap_username(url, ldap_username, privileged_username,
                             privileged_password, username, apikey):
     """Associate a Review Board user with an ldap username.
 
     Will return True if an ldap_username is successfully associated
     with a Review Board account, False otherwise.
@@ -77,22 +76,16 @@ def associate_ldap_username(url, ldap_us
             ldap.update(ldap_username=ldap_username)
 
     except APIError:
         return False
 
     return True
 
 
-class NoCacheTransport(SyncTransport):
-    """API transport with disabled caching."""
-    def enable_cache(self):
-        pass
-
-
 @contextmanager
 def ReviewBoardClient(url, username=None, password=None, apikey=None):
     """Obtain a RBClient instance via a context manager.
 
     This exists as a context manager because of gross hacks necessary for
     dealing with cookies. ``RBClient`` is coded such that it assumes it is
     being used under a user account and storing cookies is always acceptable.
     There is no way to disable cookie file writing or to tell it to use a file
@@ -101,24 +94,23 @@ def ReviewBoardClient(url, username=None
     We work around this deficiency by creating a temporary file and using it as
     the cookies database for the lifetime of the context manager. When the
     context manager exits, the temporary cookies file is deleted.
     """
     fd, path = tempfile.mkstemp()
     os.close(fd)
     try:
         if username and apikey:
-            rbc = RBClient(url, cookie_file=path,
-                           transport_cls=NoCacheTransport)
+            rbc = RBClient(url, cookie_file=path, allow_caching=False)
             login_resource = rbc.get_path(
                 'extensions/mozreview.extension.MozReviewExtension/'
                 'bugzilla-api-key-logins/')
             login_resource.create(username=username, api_key=apikey)
         else:
             rbc = RBClient(url, username=username, password=password,
-                           cookie_file=path, transport_cls=NoCacheTransport)
+                           cookie_file=path, allow_caching=False)
 
         yield rbc
     finally:
         try:
             os.unlink(path)
         except Exception:
             pass
--- a/testing/vcttesting/reviewboard/__init__.py
+++ b/testing/vcttesting/reviewboard/__init__.py
@@ -17,16 +17,17 @@ logger = logging.getLogger(__name__)
 
 
 @contextmanager
 def ReviewBoardClient(url, username, password):
     tempd = tempfile.mkdtemp()
     try:
         cookie_file = os.path.join(tempd, 'cookies')
         rbclient = RBClient(url, cookie_file=cookie_file,
+                            allow_caching=False,
                             username=username, password=password)
         yield rbclient
     finally:
         shutil.rmtree(tempd)
 
 
 class MozReviewBoard(object):
     """Interact with a Mozilla-flavored Review Board install."""