[CalendarServer-changes] [7722] CalendarServer/branches/users/glyph/disable-quota/txdav/common/ datastore/test/util.py

source_changes at macosforge.org source_changes at macosforge.org
Thu Jul 7 02:34:47 PDT 2011


Revision: 7722
          http://trac.macosforge.org/projects/calendarserver/changeset/7722
Author:   glyph at apple.com
Date:     2011-07-07 02:34:47 -0700 (Thu, 07 Jul 2011)
Log Message:
-----------
allow customization of deriveQuota's behavior for specific tests

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/disable-quota/txdav/common/datastore/test/util.py

Modified: CalendarServer/branches/users/glyph/disable-quota/txdav/common/datastore/test/util.py
===================================================================
--- CalendarServer/branches/users/glyph/disable-quota/txdav/common/datastore/test/util.py	2011-07-07 09:34:36 UTC (rev 7721)
+++ CalendarServer/branches/users/glyph/disable-quota/txdav/common/datastore/test/util.py	2011-07-07 09:34:47 UTC (rev 7722)
@@ -211,15 +211,37 @@
 
     @type testID: C{str}
     """
-    h = md5(testCase.id())
-    seed = int(h.hexdigest(), 16)
-    r = Random(seed)
-    baseline = 2000
-    fuzz = r.randint(1, 1000)
-    return baseline + fuzz
+    testID = testCase.id()
+    testMethodName = testID.split(".")[-1]
+    method = getattr(testCase, testMethodName)
+    notSet = object()
+    specialQuota = getattr(method, _SPECIAL_QUOTA, notSet)
+    if specialQuota is notSet:
+        h = md5(testID)
+        seed = int(h.hexdigest(), 16)
+        r = Random(seed)
+        baseline = 2000
+        fuzz = r.randint(1, 1000)
+        return baseline + fuzz
+    else:
+        return specialQuota
 
 
 
+_SPECIAL_QUOTA = "__special_quota__"
+
+def withSpecialQuota(quotaValue):
+    """
+    Test method decorator that will cause L{deriveQuota} to return a different
+    value for test cases that run that test method.
+    """
+    def thunk(function):
+        setattr(function, _SPECIAL_QUOTA, quotaValue)
+        return function
+    return thunk
+
+
+
 @inlineCallbacks
 def populateCalendarsFrom(requirements, store):
     """
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110707/28c073a2/attachment-0001.html>


More information about the calendarserver-changes mailing list