예제 #1
0
 def test_GET_no_delay(self):
     # Test a limit handles 1 GET per second.
     limit = Limit("GET", "*", ".*", 1, 1)
     when(limit)._get_time().thenReturn(0.0)
     delay = limit("GET", "/anything")
     self.assertEqual(None, delay)
     self.assertEqual(0, limit.next_request)
     self.assertEqual(0, limit.last_request)
예제 #2
0
    def test_GET_delay(self):
        # Test two calls to 1 GET per second limit.
        limit = Limit("GET", "*", ".*", 1, 1)
        when(limit)._get_time().thenReturn(0.0)

        delay = limit("GET", "/anything")
        self.assertEqual(None, delay)

        delay = limit("GET", "/anything")
        self.assertEqual(1, delay)
        self.assertEqual(1, limit.next_request)
        self.assertEqual(0, limit.last_request)

        when(limit)._get_time().thenReturn(4.0)

        delay = limit("GET", "/anything")
        self.assertEqual(None, delay)
        self.assertEqual(4, limit.next_request)
        self.assertEqual(4, limit.last_request)
예제 #3
0
import StringIO
from xml.dom import minidom
from reddwarf.quota.models import Quota
import testtools
import webob

from mockito import when, mock, any
from reddwarf.common import limits
from reddwarf.common.limits import Limit
from reddwarf.limits import views
from reddwarf.limits.service import LimitsController
from reddwarf.openstack.common import jsonutils
from reddwarf.quota.quota import QUOTAS

TEST_LIMITS = [
    Limit("GET", "/delayed", "^/delayed", 1, limits.PER_MINUTE),
    Limit("POST", "*", ".*", 7, limits.PER_MINUTE),
    Limit("PUT", "*", "", 10, limits.PER_MINUTE),
]


class BaseLimitTestSuite(testtools.TestCase):
    """Base test suite which provides relevant stubs and time abstraction."""
    def setUp(self):
        super(BaseLimitTestSuite, self).setUp()
        self.absolute_limits = {
            "max_instances": 55,
            "max_volumes": 100,
            "max_backups": 40
        }