From e508d436ab32b7c8ce6f1f3f10c94724de55e28a Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 3 Jan 2020 22:55:52 +0100 Subject: [PATCH] tests: test rate limiting with freezegun (#38180) --- tests/test_form_pages.py | 5 +++-- tox.ini | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_form_pages.py b/tests/test_form_pages.py index 34f85367..e52537fd 100644 --- a/tests/test_form_pages.py +++ b/tests/test_form_pages.py @@ -1499,7 +1499,7 @@ def test_form_tracking_code(pub, nocache): assert resp.location == 'http://example.net/test/%s' % formdata_id resp = resp.follow() -def test_form_tracking_code_rate_limit(pub): +def test_form_tracking_code_rate_limit(pub, freezer): pub.load_site_options() if not pub.site_options.has_section('options'): pub.site_options.add_section('options') @@ -1508,13 +1508,14 @@ def test_form_tracking_code_rate_limit(pub): pub.site_options.write(fd) # twice + freezer.move_to('2018-12-01T00:00:00') get_app(pub).get('/code/ABC/load', status=404) get_app(pub).get('/code/ABC/load', status=404) # and out get_app(pub).get('/code/ABC/load', status=403) get_app(pub).get('/code/ABC/load', status=403) # wait two second - time.sleep(2) + freezer.move_to('2018-12-01T00:00:02') # and ok again get_app(pub).get('/code/ABC/load', status=404) diff --git a/tox.ini b/tox.ini index 7d15a4f8..2cda0d6a 100644 --- a/tox.ini +++ b/tox.ini @@ -21,6 +21,7 @@ deps = pytest-mock pytest-cov pytest-django + pytest-freezegun WebTest mechanize gadjo -- 2.24.0