Skip to content

Commit

Permalink
- remove slow tests from test_flask_ext
Browse files Browse the repository at this point in the history
- remove unused code
  • Loading branch information
alisaifee committed May 26, 2014
1 parent 8e96fb6 commit b4b5f58
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 95 deletions.
32 changes: 0 additions & 32 deletions flask_limiter/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,6 @@ def hit(self, item, *identifiers):
"""
raise NotImplementedError

@abstractmethod
def check(self, item, *identifiers):
"""
checks whether the rate limit has been exceeded or not
:param item: a :class:`RateLimitItem` instance
:param identifiers: variable list of strings to uniquely identify the
limit
:return: True/False
"""
raise NotImplementedError

@abstractmethod
def get_remaining(self, item, *identifiers):
"""
Expand Down Expand Up @@ -80,16 +68,6 @@ def hit(self, item, *identifiers):
"""
return self.storage().acquire_entry(item.key_for(*identifiers), item.amount, item.expiry)

def check(self, item, *identifiers):
"""
checks whether the rate limit has been exceeded or not
:param item: a :class:`RateLimitItem` instance
:param identifiers: variable list of strings to uniquely identify the
limit
:return: True/False
"""
return self.storage().acquire_entry(item.key_for(*identifiers), item.amount, item.expiry, True)

def get_remaining(self, item, *identifiers):
"""
Expand Down Expand Up @@ -127,16 +105,6 @@ def hit(self, item, *identifiers):
self.storage().incr(item.key_for(*identifiers), item.expiry)
<= item.amount
)
def check(self, item, *identifiers):
"""
checks whether the rate limit has been exceeded or not
:param item: a :class:`RateLimitItem` instance
:param identifiers: variable list of strings to uniquely identify the
limit
:return: True/False
"""
return self.storage().get(item.key_for(*identifiers)) <= item.amount

def get_remaining(self, item, *identifiers):
"""
Expand Down
63 changes: 0 additions & 63 deletions tests/test_flask_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@
import hiro
import mock
from flask.ext.limiter.extension import Limiter
import redis
import pymemcache.client


class FlaskExtTests(unittest.TestCase):
def setUp(self):
redis.Redis().flushall()
pymemcache.client.Client(('localhost', 11211)).flush_all()

def test_combined_rate_limits(self):
app = Flask(__name__)
Expand Down Expand Up @@ -383,61 +378,3 @@ def t():
str(int(time.time() + 49))
)

def test_headers_moving_window_redis(self):

app = Flask(__name__)
app.config["RATELIMIT_STRATEGY"] = "moving-window"
app.config["RATELIMIT_STORAGE_URL"] = "redis://localhost:6379"
limiter = Limiter(app, global_limits=["10/minute"], headers_enabled=True)

@app.route("/t1")
@limiter.limit("10/second; 20per minute")
def t():
return "test"

with app.test_client() as cli:
for i in range(21):
resp = cli.get("/t1")
time.sleep(0.1)
self.assertEqual(
resp.headers.get('X-RateLimit-Limit'),
'20'
)
self.assertEqual(
resp.headers.get('X-RateLimit-Remaining'),
'0'
)
self.assertEqual(
resp.headers.get('X-RateLimit-Reset'),
str(int(time.time() + 1))
)

def test_headers_fixed_window_memcached(self):

app = Flask(__name__)
app.config["RATELIMIT_STRATEGY"] = "fixed-window"
app.config["RATELIMIT_STORAGE_URL"] = "memcached://localhost:11211"
limiter = Limiter(app, global_limits=["10/minute"], headers_enabled=True)

@app.route("/t1")
@limiter.limit("10/second; 20per minute")
def t():
return "test"

with app.test_client() as cli:
start = time.time()
for i in range(21):
resp = cli.get("/t1")
time.sleep(0.1)
self.assertEqual(
resp.headers.get('X-RateLimit-Limit'),
'20'
)
self.assertEqual(
resp.headers.get('X-RateLimit-Remaining'),
'0'
)
self.assertEqual(
resp.headers.get('X-RateLimit-Reset'),
str(int(start) + 60)
)

0 comments on commit b4b5f58

Please sign in to comment.