tests: test rate limiting with freezegun (#38180)

This commit is contained in:
Benjamin Dauvergne 2020-01-03 22:55:52 +01:00
parent b81166887d
commit e508d436ab
2 changed files with 4 additions and 2 deletions

View File

@ -1499,7 +1499,7 @@ def test_form_tracking_code(pub, nocache):
assert resp.location == 'http://example.net/test/%s' % formdata_id assert resp.location == 'http://example.net/test/%s' % formdata_id
resp = resp.follow() resp = resp.follow()
def test_form_tracking_code_rate_limit(pub): def test_form_tracking_code_rate_limit(pub, freezer):
pub.load_site_options() pub.load_site_options()
if not pub.site_options.has_section('options'): if not pub.site_options.has_section('options'):
pub.site_options.add_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) pub.site_options.write(fd)
# twice # 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)
get_app(pub).get('/code/ABC/load', status=404) get_app(pub).get('/code/ABC/load', status=404)
# and out # and out
get_app(pub).get('/code/ABC/load', status=403) get_app(pub).get('/code/ABC/load', status=403)
get_app(pub).get('/code/ABC/load', status=403) get_app(pub).get('/code/ABC/load', status=403)
# wait two second # wait two second
time.sleep(2) freezer.move_to('2018-12-01T00:00:02')
# and ok again # and ok again
get_app(pub).get('/code/ABC/load', status=404) get_app(pub).get('/code/ABC/load', status=404)

View File

@ -21,6 +21,7 @@ deps =
pytest-mock pytest-mock
pytest-cov pytest-cov
pytest-django pytest-django
pytest-freezegun
WebTest WebTest
mechanize mechanize
gadjo gadjo