from eve.tests import TestBase
from redis import Redis
import time


class TestRateLimit(TestBase):
    def setUp(self):
        super(TestRateLimit, self).setUp()
        self.app.redis = Redis()
        self.app.config['RATE_LIMIT_GET'] = (1, 1)
        self.app.redis.flushdb()

    def test_ratelimit_home(self):
        self.get_ratelimit("/")

    def test_ratelimit_resource(self):
        self.get_ratelimit(self.known_resource_url)

    def test_ratelimit_item(self):
        self.get_ratelimit(self.item_id_url)

    def get_ratelimit(self, url):
        self.assertRateLimit(self.test_client.get(url))
        r = self.test_client.get(url)
        self.assertEqual(r.status_code, 429)
        self.assertTrue('Rate limit exceeded' in r.data)

        time.sleep(1)
        self.assertRateLimit(self.test_client.get(url))

    def assertRateLimit(self, r):
        self.assertTrue('X-RateLimit-Remaining' in r.headers)
        self.assertEqual(r.headers['X-RateLimit-Remaining'], '0')
        self.assertTrue('X-RateLimit-Limit' in r.headers)
        self.assertEqual(r.headers['X-RateLimit-Limit'], '1')
        # renouncing on testing the actual Reset value:
        self.assertTrue('X-RateLimit-Reset' in r.headers)

@@ -512,24 +512,406 @@
 em_id_url)%0A%0A
+    def test_noratelimits(self):%0A        self.app.config%5B'RATE_LIMIT_GET'%5D = None%0A        self.app.redis.flushdb()%0A        r = self.test_client.get(%22/%22)%0A        self.assert200(r.status_code)%0A        self.assertTrue('X-RateLimit-Remaining' not in r.headers)%0A        self.assertTrue('X-RateLimit-Limit' not in r.headers)%0A        self.assertTrue('X-RateLimit-Reset' not in r.headers)%0A%0A
     def get_

Test for disabled Rate Limit