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:
Ben Busby 2021-11-16 20:05:42 -07:00
parent ba7409f230
commit 74e9317053
No known key found for this signature in database
GPG Key ID: 339B7B7EB5333D14
3 changed files with 7 additions and 5 deletions

View File

@ -15,8 +15,9 @@ class Endpoint(Enum):
element = 'element'
window = 'window'
def __repr__(self):
def __str__(self):
return self.value
def in_path(self, path: str) -> bool:
return path.startswith(self.value)
return path.startswith(self.value) or \
path.startswith(f'/{self.value}')

View File

@ -176,11 +176,11 @@ def home():
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):
if 'uuid' in session and session['uuid'] == session_id:
session['valid'] = True
return redirect(request.args.get('follow'))
return redirect(request.args.get('follow'), code=307)
else:
follow_url = request.args.get('follow')
req = PreparedRequest()

View File

@ -9,7 +9,8 @@ def test_autocomplete_get(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 len(rv.data) >= 1
assert b'the cat in the hat' in rv.data