✅ Added tests and fixed some small bugs
This commit is contained in:
@@ -95,7 +95,6 @@ async def upload_image(edit_id: str, pow_data: str, file: UploadFile = File()):
|
||||
raise HTTPException(status_code=401, detail="Edit ID not found!")
|
||||
if session_data is None:
|
||||
raise HTTPException(status_code=401, detail="Edit ID not found!")
|
||||
|
||||
if uploaded_images == 0 and not check_hashcash(pow_data, pow_data_server, "8"):
|
||||
raise HTTPException(status_code=401, detail="Edit ID not found!")
|
||||
if uploaded_images != 0 and not check_hashcash(pow_data, pow_data_server, "8"):
|
||||
@@ -103,7 +102,10 @@ async def upload_image(edit_id: str, pow_data: str, file: UploadFile = File()):
|
||||
file_bytes = await file.read()
|
||||
if len(file_bytes) > 2000000:
|
||||
raise HTTPException(status_code=400, detail="File too large")
|
||||
pm_data = puremagic.magic_string(file_bytes)[0]
|
||||
try:
|
||||
pm_data = puremagic.magic_string(file_bytes)[0]
|
||||
except puremagic.PureError:
|
||||
raise HTTPException(status_code=400, detail="Image couldn't be identified!")
|
||||
if pm_data.extension not in allowed_image_extensions:
|
||||
raise HTTPException(status_code=400, detail="Image-type now allowed!")
|
||||
session_data = EditSessionData.parse_raw(session_data)
|
||||
|
||||
@@ -5,8 +5,9 @@ import json
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
import ormar.exceptions
|
||||
from aiohttp import ClientSession
|
||||
from fastapi import APIRouter, Depends, Response, File, UploadFile
|
||||
from fastapi import APIRouter, Depends, Response, File, UploadFile, HTTPException
|
||||
|
||||
from classquiz.auth import get_current_user
|
||||
from classquiz.config import storage, settings
|
||||
@@ -22,7 +23,10 @@ image_index_delimiter = b"\xc5\xc5\x00"
|
||||
|
||||
@router.get("/{quiz_id}")
|
||||
async def export_quiz(quiz_id: uuid.UUID, user: User = Depends(get_current_user)):
|
||||
quiz: Quiz = await Quiz.objects.filter(Quiz.id == quiz_id).first()
|
||||
try:
|
||||
quiz: Quiz = await Quiz.objects.filter(Quiz.id == quiz_id).first()
|
||||
except ormar.exceptions.NoMatch:
|
||||
raise HTTPException(status_code=404, detail="Quiz not found")
|
||||
image_urls = {}
|
||||
for i, question in enumerate(quiz.questions):
|
||||
if question["image"] is None:
|
||||
|
||||
@@ -185,7 +185,6 @@ async def update_quiz(quiz_id: str, quiz_input: QuizInput, user: User = Depends(
|
||||
raise HTTPException(status_code=400, detail="badly formed quiz id")
|
||||
# Check Cover-Image
|
||||
|
||||
print(quiz_input.cover_image)
|
||||
if quiz_input.cover_image == "":
|
||||
quiz_input.cover_image = None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user