Initial support for IceCubes (#532)

This commit is contained in:
Dan Watson 2023-03-09 12:47:33 -05:00 committed by GitHub
parent 56da914340
commit 6f4abd5aae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 17 deletions

View file

@ -6,6 +6,9 @@
.pre-commit-config.yaml
.venv
/fly.*
/static-collected
/takahe/local_settings.py
__pycache__/
media
notes.md
venv

View file

@ -1,28 +1,27 @@
import secrets
from hatchway import Schema, api_view
from hatchway import QueryOrBody, api_view
from .. import schemas
from ..models import Application
class CreateApplicationSchema(Schema):
client_name: str
redirect_uris: str
scopes: None | str = None
website: None | str = None
@api_view.post
def add_app(request, details: CreateApplicationSchema) -> schemas.Application:
def add_app(
request,
client_name: QueryOrBody[str],
redirect_uris: QueryOrBody[str],
scopes: QueryOrBody[None | str] = None,
website: QueryOrBody[None | str] = None,
) -> schemas.Application:
client_id = "tk-" + secrets.token_urlsafe(16)
client_secret = secrets.token_urlsafe(40)
application = Application.objects.create(
name=details.client_name,
website=details.website,
name=client_name,
website=website,
client_id=client_id,
client_secret=client_secret,
redirect_uris=details.redirect_uris,
scopes=details.scopes or "read",
redirect_uris=redirect_uris,
scopes=scopes or "read",
)
return schemas.Application.from_orm(application)

View file

@ -47,6 +47,12 @@ def instance_info_v1(request):
"image_size_limit": (1024**2) * 10,
"image_matrix_limit": 2000 * 2000,
},
"polls": {
"max_options": 4,
"max_characters_per_option": 50,
"min_expiration": 300,
"max_expiration": 2629746,
},
},
"contact_account": None,
"rules": [],

View file

@ -4,10 +4,8 @@ import pytest
@pytest.mark.django_db
def test_create(api_client):
"""
Tests creating an app
Tests creating an app with mixed query/body params (some clients do this)
"""
response = api_client.post(
"/api/v1/apps", {"client_name": "test", "redirect_uris": ""}
)
response = api_client.post("/api/v1/apps?client_name=test", {"redirect_uris": ""})
assert response.status_code == 200
assert response.json()["name"] == "test"