def get_frontend_download_url(service_id, document_id, key): scheme = current_app.config['HTTP_SCHEME'] netloc = current_app.config['FRONTEND_HOSTNAME'] path = 'd/{}/{}'.format(uuid_to_base64(service_id), uuid_to_base64(document_id)) query = urlencode({'key': bytes_to_base64(key)}) return urlunsplit([scheme, netloc, path, query, None])
def get_frontend_download_url(service_id, document_id, key, filename): scheme = current_app.config['HTTP_SCHEME'] netloc = current_app.config['FRONTEND_HOSTNAME'] path = 'd/{}/{}'.format(uuid_to_base64(service_id), uuid_to_base64(document_id)) query_params = {'key': bytes_to_base64(key), 'filename': filename} query = urlencode({k: v for k, v in query_params.items() if v}, quote_via=quote) return urlunsplit([scheme, netloc, path, query, None])
def test_base64_converter_to_url(python_val): assert uuid_to_base64(python_val) == 'AAAAAAAAAAAAAAAAAAAAAQ'
def test_base64_converter_to_url_raises_validation_error(): with pytest.raises(Exception): uuid_to_base64(object())
def to_url(self, value): try: return uuid_to_base64(value) except Exception: raise ValidationError()