Override __str__ for endpoint f-strings
By default, f-strings use __str__ not __repr__, unless supplied with a "!r" at the end of the str. Rather than going through and making the strings work for the overridden __repr__ for endpoints, it's easier just to convert the method over to __str__. Also cleaned up some broken routes and formatting.
This commit is contained in:
parent
ba7409f230
commit
74e9317053
|
@ -15,8 +15,9 @@ class Endpoint(Enum):
|
||||||
element = 'element'
|
element = 'element'
|
||||||
window = 'window'
|
window = 'window'
|
||||||
|
|
||||||
def __repr__(self):
|
def __str__(self):
|
||||||
return self.value
|
return self.value
|
||||||
|
|
||||||
def in_path(self, path: str) -> bool:
|
def in_path(self, path: str) -> bool:
|
||||||
return path.startswith(self.value)
|
return path.startswith(self.value) or \
|
||||||
|
path.startswith(f'/{self.value}')
|
||||||
|
|
|
@ -176,11 +176,11 @@ def home():
|
||||||
return redirect(url_for('.index'))
|
return redirect(url_for('.index'))
|
||||||
|
|
||||||
|
|
||||||
@app.route(f'{Endpoint.session}/<session_id>', methods=['GET', 'PUT', 'POST'])
|
@app.route(f'/{Endpoint.session}/<session_id>', methods=['GET', 'PUT', 'POST'])
|
||||||
def session_check(session_id):
|
def session_check(session_id):
|
||||||
if 'uuid' in session and session['uuid'] == session_id:
|
if 'uuid' in session and session['uuid'] == session_id:
|
||||||
session['valid'] = True
|
session['valid'] = True
|
||||||
return redirect(request.args.get('follow'))
|
return redirect(request.args.get('follow'), code=307)
|
||||||
else:
|
else:
|
||||||
follow_url = request.args.get('follow')
|
follow_url = request.args.get('follow')
|
||||||
req = PreparedRequest()
|
req = PreparedRequest()
|
||||||
|
|
|
@ -9,7 +9,8 @@ def test_autocomplete_get(client):
|
||||||
|
|
||||||
|
|
||||||
def test_autocomplete_post(client):
|
def test_autocomplete_post(client):
|
||||||
rv = client.post(f'/{Endpoint.autocomplete}', data=dict(q='the+cat+in+the'))
|
rv = client.post(f'/{Endpoint.autocomplete}',
|
||||||
|
data=dict(q='the+cat+in+the'))
|
||||||
assert rv._status_code == 200
|
assert rv._status_code == 200
|
||||||
assert len(rv.data) >= 1
|
assert len(rv.data) >= 1
|
||||||
assert b'the cat in the hat' in rv.data
|
assert b'the cat in the hat' in rv.data
|
||||||
|
|
Loading…
Reference in New Issue
Block a user