[themotte/rDrama#451] Decorator when we do not want to rate limit in tests
This commit is contained in:
parent
0dcca12c04
commit
f78345a4fb
1 changed files with 20 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
|
||||
from bs4 import BeautifulSoup
|
||||
import functools
|
||||
import json
|
||||
import random
|
||||
import re
|
||||
|
@ -14,6 +15,25 @@ def formkey_from(text):
|
|||
def generate_text():
|
||||
return ''.join(random.choices(string.ascii_lowercase, k=40))
|
||||
|
||||
# Annotation to put around tests that don't care about rate limits
|
||||
def no_rate_limit(test_function):
|
||||
@functools.wraps(test_function)
|
||||
def wrapped(*args, **kwargs):
|
||||
from files.__main__ import app, limiter
|
||||
was_enabled = limiter.enabled
|
||||
app.config['RATE_LIMITER_ENABLED'] = False
|
||||
limiter.enabled = False
|
||||
try:
|
||||
result = test_function(*args, **kwargs)
|
||||
app.config['RATE_LIMITER_ENABLED'] = was_enabled
|
||||
limiter.enabled = was_enabled
|
||||
return result
|
||||
except Exception as e:
|
||||
app.config['RATE_LIMITER_ENABLED'] = was_enabled
|
||||
limiter.enabled = was_enabled
|
||||
raise e
|
||||
return wrapped
|
||||
|
||||
# this is meant to be a utility class that stores post and comment references so you can use them in other calls
|
||||
# it's pretty barebones and will probably be fleshed out
|
||||
class ItemData:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue