Remove print/console.log statements
This commit is contained in:
parent
86f61e74b5
commit
6ce6a19acf
@ -1,6 +1,7 @@
|
||||
import pydantic.json
|
||||
import json
|
||||
from sqlmodel import SQLModel, create_engine, Session, select
|
||||
|
||||
import pydantic.json
|
||||
from sqlmodel import SQLModel, create_engine, Session
|
||||
|
||||
sqlite_file_name = "database7.db"
|
||||
sqlite_url = f"sqlite:///{sqlite_file_name}"
|
||||
@ -10,7 +11,7 @@ def _custom_json_serializer(*args, **kwargs) -> str:
|
||||
"""
|
||||
Encodes json in the same way that pydantic does.
|
||||
"""
|
||||
print('JSON SERIALIZATION')
|
||||
|
||||
return json.dumps(*args, default=pydantic.json.pydantic_encoder, **kwargs)
|
||||
|
||||
engine = create_engine(sqlite_url, echo=False, connect_args={"check_same_thread": False}, json_serializer=_custom_json_serializer)
|
||||
|
@ -20,7 +20,7 @@ class FileField(str, metaclass=FileFieldMeta):
|
||||
|
||||
@classmethod
|
||||
def validate(cls, value: str | IO, values):
|
||||
print('VALID FILE', values)
|
||||
|
||||
upload_root = get_or_create_dir(
|
||||
add_fast_api_root(cls.upload_root))
|
||||
if not isinstance(value, str):
|
||||
|
@ -1,19 +1,21 @@
|
||||
from fastapi import Query, HTTPException, status
|
||||
import os
|
||||
import shutil
|
||||
from typing import IO, List
|
||||
|
||||
from fastapi import Depends
|
||||
from fastapi import Query, HTTPException, status
|
||||
from sqlmodel import Session, select, or_, col
|
||||
from generateur.generateur_main import generate_from_data, generate_from_path
|
||||
|
||||
from database.auth.models import User
|
||||
from database.db import get_session
|
||||
from fastapi import Depends
|
||||
from database.exercices.models import ExampleEnum, ExerciceCreate, Exercice, ExerciceEdit, ExerciceRead, ExercicesTagLink, Tag, TagCreate, Supports, ExerciceReadFull
|
||||
from database.exercices.models import ExampleEnum, ExerciceCreate, Exercice, ExerciceEdit, ExercicesTagLink, Tag, \
|
||||
TagCreate, Supports, ExerciceReadFull
|
||||
from generateur.generateur_main import generate_from_data
|
||||
from services.auth import get_current_user, get_current_user_optional
|
||||
from services.database import generate_unique_code
|
||||
from services.io import add_fast_api_root, get_ancestor, get_or_create_dir
|
||||
|
||||
|
||||
|
||||
def create_exo_db(exercice: ExerciceCreate, user: User,supports: Supports, exo_source: IO, db: Session):
|
||||
example = {
|
||||
"type": ExampleEnum.csv if supports['csv'] == True else ExampleEnum.web if supports['web'] == True else None,
|
||||
@ -190,9 +192,9 @@ def serialize_exo(*, exo: Exercice, user_id: User = None, db: Session):
|
||||
tags = parse_exo_tags(exo_id=exo.id, user_id=user_id,
|
||||
db=db) if user_id is not None else []
|
||||
is_author = user_id is not None and check_author(exo=exo, user_id=user_id)
|
||||
print('USER', exo.dict(), exo)
|
||||
|
||||
if exo.original is not None:
|
||||
print('TEST', db.exec(select(User).where(User.id == exo.original.author_id)).all())
|
||||
|
||||
author = db.exec(select(User).where(
|
||||
User.id == exo.original.author_id)).all()[0]
|
||||
original = {**exo.original.dict(), 'author': author.username}
|
||||
|
@ -286,7 +286,7 @@ def leave_room(member: Member, db: Session):
|
||||
def serialize_member(member: Member, private: bool = False, admin: bool = False,
|
||||
m2: Member | None = None) -> MemberRead | Waiter:
|
||||
member_obj = member.user or member.anonymous
|
||||
print("OHLA", member_obj, private, member.user_id == None)
|
||||
|
||||
if not member.waiting:
|
||||
return MemberRead(username=member_obj.username, online=member.online,
|
||||
clientId=str(member_obj.clientId) if (private == True and member.user_id == None) else "",
|
||||
@ -379,7 +379,7 @@ def getMemberRank(m: Member, p: Parcours, db: Session):
|
||||
|
||||
def getMemberAvgRank(m: Member, p: Parcours, db: Session):
|
||||
challenger = db.exec(select(Challenger).where(Challenger.member_id == m.id)).first()
|
||||
print('CHALLE', challenger)
|
||||
|
||||
if challenger is None or challenger.avg is None:
|
||||
return None
|
||||
return getAvgRank(challenger, p, db)
|
||||
@ -583,8 +583,8 @@ def validate_challenge_input(obj: List[CorrectionData], corr: TmpCorrection):
|
||||
for i in range(len(data)):
|
||||
exo_corr = data[i]
|
||||
exo = obj[i]
|
||||
print('EXO', exo)
|
||||
print('EXO', exo.data)
|
||||
|
||||
|
||||
if len(exo.data) != len(exo_corr['data']):
|
||||
return
|
||||
zipped = zip(exo_corr['data'], exo.data)
|
||||
@ -628,7 +628,7 @@ def corrige_challenge(obj: List[List[ParsedGeneratorOut]], corr: TmpCorrection)
|
||||
return
|
||||
zipped = zip(exo_corr, exo)
|
||||
for e, f in zipped:
|
||||
print("HO\n\n")
|
||||
|
||||
for k, l in zip(e['inputs'], f.inputs):
|
||||
k["value"] = str(l.value)
|
||||
total += 1
|
||||
@ -703,7 +703,7 @@ def checkValidated(challenger: Challenger, db: Session, challenge: Challenge | N
|
||||
def create_challenge(data: List[CorrigedData], challenger: Member, parcours: Parcours, time: int, mistakes: int,
|
||||
isCorriged: bool, db: Session):
|
||||
challenger_obj: Challenger = getChallenger(parcours, challenger, db)
|
||||
print('VALIDATING', time <= parcours.time * 60 and mistakes <= parcours.max_mistakes, time, parcours.time)
|
||||
|
||||
validated = time <= parcours.time * 60 and mistakes <= parcours.max_mistakes
|
||||
|
||||
challenge = Challenge(data=data, challenger_pid=challenger_obj.parcours_id, challenger_mid=challenger_obj.member_id,
|
||||
@ -730,7 +730,7 @@ def create_challenge(data: List[CorrigedData], challenger: Member, parcours: Par
|
||||
db.commit()
|
||||
db.refresh(challenge)
|
||||
db.refresh(challenger_obj)
|
||||
print('RETURN,', challenge, challenger_obj)
|
||||
|
||||
return challenge, challenger_obj
|
||||
|
||||
|
||||
|
@ -1,13 +1,11 @@
|
||||
import os
|
||||
import shutil
|
||||
from typing import BinaryIO, List
|
||||
from schemas.exercices import TagIn, TagIn_schema
|
||||
from services.database import generate_unique_code
|
||||
from services.io import add_fast_api_root, get_ancestor, get_filename_from_path, get_parent_dir, remove_fastapi_root, remove_if_exists, get_or_create_dir
|
||||
from typing import BinaryIO
|
||||
|
||||
from database.exercices.models import Exercice, Tag
|
||||
from schemas.exercices import Exercice_schema
|
||||
|
||||
from services.database import generate_unique_code
|
||||
from services.io import add_fast_api_root, get_ancestor, get_parent_dir, remove_if_exists, get_or_create_dir
|
||||
|
||||
|
||||
async def create_exo_db(*args, **kwargs) -> Exercice:
|
||||
@ -57,14 +55,14 @@ async def clone_exo_db(id_code: str, user_id):
|
||||
|
||||
exo_obj = await Exercice_schema.from_tortoise_orm(exo)
|
||||
exo_obj = exo_obj.dict(exclude_unset=True)
|
||||
print("eaoiuezaoiueza", exo_obj)
|
||||
|
||||
exo_obj.pop('tags')
|
||||
exo_obj = exclude_dict_key(exo_obj, 'tags')
|
||||
exo_obj = exclude_dict_key(exo_obj, 'author')
|
||||
#exo_obj.pop('exercices')
|
||||
|
||||
path = clone_exo_source(exo.exo_source, new_id_code)
|
||||
print('\n\npatiuar', path, exo_obj, '\n',
|
||||
|
||||
exclude_dict_key(exo_obj, 'tags'))
|
||||
new_exo = Exercice(**{**exo_obj, 'id_code': new_id_code, 'exo_source': path,
|
||||
"isOriginal": False, 'author_id': user_id}, origin_id=exo.id)
|
||||
|
@ -7,6 +7,6 @@ def exos(nb, username, password):
|
||||
for i in range(nb):
|
||||
r = requests.post('http://localhost:8002/exercices', data={"name": "Test" + str(i), "consigne": "consigne", "private": False}, files={
|
||||
'file': ('test.py', open('./tests/testing_exo_source/exo_source.py', 'rb'))}, headers={"Authorization": "Bearer " + token})
|
||||
print('DONE')
|
||||
|
||||
|
||||
exos(100, "lilianTest2", "Pomme937342")
|
@ -37,7 +37,7 @@ def Csv_generator(path, nb_in_serie, nb_page, police, consigne, writer):
|
||||
if len(text_longueur) > longueur_max:
|
||||
consigne_lines.append(text_longueur)
|
||||
text_longueur = ''
|
||||
# print(text_longueur)
|
||||
#
|
||||
else:
|
||||
consigne_lines.append(consigne)
|
||||
serie_page_vertical = int(PAGE_LINES[police] /
|
||||
|
@ -62,7 +62,7 @@ class Id_codeField(str):
|
||||
|
||||
@classmethod
|
||||
def validate(cls, value, values, config, field):
|
||||
print("validator", cls, value, values, config, field)
|
||||
|
||||
return value
|
||||
|
||||
class Test(SQLModel, table=True):
|
||||
@ -71,13 +71,13 @@ class Test(SQLModel, table=True):
|
||||
|
||||
''' @validator('id_code', always=True)
|
||||
def test(cls,value, values):
|
||||
print('VAlIDATE')
|
||||
|
||||
session= get_session()
|
||||
session = next(session)
|
||||
y = session.exec(select(cls)).all()
|
||||
print(y)
|
||||
|
||||
code = generate_unique_code(cls, s=session)
|
||||
print(code)
|
||||
|
||||
return code '''
|
||||
|
||||
@app.on_event("startup")
|
||||
@ -100,7 +100,7 @@ def test(test_1: str, test_2: str, test_3: str = Depends(t), test_4: str = Depen
|
||||
@app.exception_handler(ValidationError)
|
||||
async def validation_exception_handler(request: Request, exc: RequestValidationError|ValidationError):
|
||||
errors = {}
|
||||
print(exc.errors())
|
||||
|
||||
for e in exc.errors():
|
||||
locs = [e for e in e['loc'] if type(e) == str]
|
||||
errors[locs[-1] + "_error"] = e['msg']
|
||||
|
@ -120,7 +120,7 @@ def get_public_exercices(user: User | None = Depends(get_current_user_optional),
|
||||
statement = statement.where(sub)
|
||||
statement = statement.order_by(col(Exercice.id).desc())
|
||||
page = p(db, statement)
|
||||
print('¨PAGE', page)
|
||||
|
||||
exercices = page.items
|
||||
page.items = [
|
||||
serialize_exo(exo=e, user_id=user.id, db=db) for e in exercices]
|
||||
|
@ -8,7 +8,7 @@ from database.auth.crud import get_user_from_token
|
||||
from database.room.crud import change_room_name, change_room_status, serialize_member, check_user_in_room, \
|
||||
create_anonymous, create_member, get_member, get_member_from_token, get_member_from_reconnect_code, connect_member, \
|
||||
disconnect_member, get_waiter, accept_waiter, leave_room, refuse_waiter
|
||||
from database.room.models import Room, Member, MemberRead, Waiter, Challenger
|
||||
from database.room.models import Room, Member, MemberRead, Waiter
|
||||
from services.websocket import Consumer
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@ -69,11 +69,11 @@ class RoomConsumer(Consumer):
|
||||
# await self.broadcast(type="connect", payload={"member": serialize_member(self.member)}, exclude=True)
|
||||
|
||||
async def disconnect_self(self):
|
||||
print(self.manager.active_connections[self.room.id_code])
|
||||
|
||||
self.manager.remove(self.room.id_code, self)
|
||||
print(self.manager.active_connections[self.room.id_code])
|
||||
|
||||
if isinstance(self.member, Member):
|
||||
print('MEMBER', self.member)
|
||||
|
||||
try:
|
||||
disconnect_member(self.member, self.db)
|
||||
except StaleDataError:
|
||||
@ -111,7 +111,7 @@ class RoomConsumer(Consumer):
|
||||
return self.member is not None and self.member.is_admin == True
|
||||
|
||||
async def isMember(self):
|
||||
print('S', self.member, self.ws, self.ws.state, self.ws.application_state.__str__())
|
||||
|
||||
if self.member is None:
|
||||
await self.send_error("Vous n'êtes connecté à aucune salle")
|
||||
return self.member is not None and self.member.waiting == False
|
||||
@ -126,10 +126,10 @@ class RoomConsumer(Consumer):
|
||||
if reconnect_code is None and token is None:
|
||||
await self.direct_send(type="error", payload={"msg": "Veuillez spécifier une méthode de connection"})
|
||||
return
|
||||
print("login", token)
|
||||
|
||||
if token is not None:
|
||||
member = get_member_from_token(token, self.room.id, self.db)
|
||||
print('MEMBER', member)
|
||||
|
||||
if member == False:
|
||||
await self.send_error("Token expired", code=422)
|
||||
return
|
||||
@ -233,7 +233,7 @@ class RoomConsumer(Consumer):
|
||||
async def change_name(self, name: str):
|
||||
if len(name) < 20:
|
||||
self.room = change_room_name(self.room, name, self.db)
|
||||
print('SENDING')
|
||||
|
||||
await self.broadcast(type="new_name", payload={"name": name})
|
||||
|
||||
return
|
||||
@ -251,7 +251,7 @@ class RoomConsumer(Consumer):
|
||||
|
||||
@Consumer.event('leave', conditions=[isMember])
|
||||
async def leave(self):
|
||||
print('LEAVED', self.member, isinstance(self.member, Member), isinstance(self.member, Challenger))
|
||||
|
||||
if self.member.is_admin is True:
|
||||
await self.send_error("Vous ne pouvez pas quitter une salle dont vous êtes l'administrateur")
|
||||
return
|
||||
@ -316,8 +316,8 @@ class RoomConsumer(Consumer):
|
||||
return {}
|
||||
|
||||
async def disconnect(self):
|
||||
print('DISCONNECTED', self.member)
|
||||
print(self.manager.active_connections[self.room.id_code])
|
||||
|
||||
|
||||
self.manager.remove(self.room.id_code, self)
|
||||
|
||||
for p in self.room.parcours:
|
||||
|
@ -18,7 +18,7 @@ class RoomManager:
|
||||
self.active_connections[group].append(member)
|
||||
|
||||
async def _send(self, connection: "RoomConsumer", message, group: str):
|
||||
print('SENDING', connection.ws.application_state, connection.ws.client_state)
|
||||
|
||||
if connection.ws.application_state == WebSocketState.DISCONNECTED or connection.ws.client_state == WebSocketState.DISCONNECTED:
|
||||
self.remove(group, connection)
|
||||
elif connection.ws.application_state == WebSocketState.CONNECTED and connection.ws.client_state == WebSocketState.CONNECTED:
|
||||
@ -34,7 +34,7 @@ class RoomManager:
|
||||
return True
|
||||
|
||||
async def broadcast(self, message: Any | Callable, group: str, conditions: list[Callable] = [], exclude: list["RoomConsumer"] = [], ):
|
||||
print('BROADCaST', self.active_connections)
|
||||
|
||||
|
||||
|
||||
if group in self.active_connections:
|
||||
@ -43,17 +43,17 @@ class RoomManager:
|
||||
await self._send(connection, message, group)
|
||||
|
||||
async def send_to(self, group, id_code, msg):
|
||||
print('SENDING TO')
|
||||
|
||||
if group in self.active_connections:
|
||||
members = [c for c in self.active_connections[group]
|
||||
if c.member.id_code == id_code]
|
||||
print('MEM', members)
|
||||
|
||||
for m in members:
|
||||
await self._send(m, msg, group)
|
||||
|
||||
async def send_to_admin(self, group, msg):
|
||||
if group in self.active_connections:
|
||||
print('MEMBERS', self.active_connections[group], [(c.ws.state, c.ws.client_state, c.ws.application_state) for c in self.active_connections[group]])
|
||||
|
||||
members = [c for c in self.active_connections[group]
|
||||
if c.member is not None and c.member.is_admin is True]
|
||||
for m in members:
|
||||
|
@ -90,7 +90,7 @@ async def update_parcours(*, room_id: str, parcours: ParcoursCreate, member: Mem
|
||||
await m.broadcast({"type": "edit_parcours", "data": {
|
||||
"parcours": ParcoursReadUpdate(**parcours_obj.dict(), update_challenges=update_challenges).dict()}},
|
||||
parcours_old.id_code)
|
||||
print('BROADCASTING')
|
||||
|
||||
await m.broadcast(
|
||||
lambda m: {"type": "update_challenges", "data": {"challenger": {"id_code": m.id_code, "name": getUsername(m), "validated": getMemberValidated(m, parcours_obj, db)},
|
||||
"challenges": [Challenges(
|
||||
@ -118,7 +118,7 @@ class Exos(BaseModel):
|
||||
@router.get('/room/{room_id}/challenge/{parcours_id}')
|
||||
def challenge_route(parcours: Parcours = Depends(get_parcours), exercices: List[Exos] = Depends(get_exercices),
|
||||
member: Member = Depends(get_member_dep), db: Session = Depends(get_session)):
|
||||
print('GENERATE', exercices)
|
||||
|
||||
correction = [parseGeneratorOut(generate_from_path(add_fast_api_root(
|
||||
e['exercice'].exo_source), e['quantity'], "web")) for e in exercices]
|
||||
|
||||
@ -161,21 +161,21 @@ async def send_challenge(*, challenge: List[CorrectionData], correction: TmpCorr
|
||||
await m.broadcast(lambda m: {"type": "newRanks", "data": {"rank": getMemberRank(m, correction.parcours, db),
|
||||
"avgRank": getMemberAvgRank(m, correction.parcours, db)}},
|
||||
parcours.id_code)
|
||||
print('WOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOoo')
|
||||
|
||||
await m.send_to(parcours.room.id_code, member.id_code, {"type": "parcours_stats", "data": {
|
||||
"parcours": ParcoursReadShort(name=parcours.name, best_note=challenger.best, validated=challenger.validated,
|
||||
id_code=parcours.id_code, avg=challenger.avg).dict()}})
|
||||
|
||||
print('CHALLENGE', chall)
|
||||
|
||||
rank, avgRank = getRank(
|
||||
challenger, parcours, db), getAvgRank(challenger, parcours, db)
|
||||
print('RANKS', rank, avgRank)
|
||||
|
||||
if rank <= 3 or avgRank <= 3:
|
||||
await m.broadcast({"type": "newTops", "data": {
|
||||
"tops": getTops(correction.parcours, db),
|
||||
"avgTops": getAvgTops(correction.parcours, db),
|
||||
}}, parcours.id_code)
|
||||
print('CHALLENGE', chall)
|
||||
|
||||
db.delete(correction)
|
||||
returnValue = {**chall.dict()}
|
||||
db.commit()
|
||||
|
@ -1,9 +1,10 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from math import ceil
|
||||
from typing import TypeVar, Generic, Sequence
|
||||
|
||||
from fastapi_pagination import Params
|
||||
from fastapi_pagination.bases import AbstractPage, AbstractParams, BasePage
|
||||
from math import ceil
|
||||
from fastapi_pagination.bases import AbstractParams, BasePage
|
||||
from pydantic import conint
|
||||
|
||||
T = TypeVar("T")
|
||||
@ -24,7 +25,7 @@ class Page(BasePage[T], Generic[T]):
|
||||
total: int,
|
||||
params: AbstractParams,
|
||||
) -> Page[T]:
|
||||
print("PARAMS", params)
|
||||
|
||||
totalPage = ceil(total/params.size)
|
||||
return cls(
|
||||
total=total,
|
||||
|
@ -74,7 +74,7 @@ class Consumer:
|
||||
''' if self.ws.state == WebSocketState.DISCONNECTED:
|
||||
return '''
|
||||
type = payload.get('type', None)
|
||||
print('TYPE', type, self.member)
|
||||
|
||||
|
||||
if type is not None:
|
||||
event_wrapper = self.sendings.get(type, None)
|
||||
@ -91,7 +91,7 @@ class Consumer:
|
||||
try:
|
||||
validated_payload = model(self=self, **data)
|
||||
except ValidationError as e:
|
||||
print("ERROR", e)
|
||||
|
||||
await self.ws.send_json({"type": "error", "data": {"msg": "Oops there was an error"}})
|
||||
return
|
||||
|
||||
@ -142,5 +142,5 @@ class Consumer:
|
||||
data = await self.ws.receive_json()
|
||||
await self.receive(data)
|
||||
except WebSocketDisconnect:
|
||||
print('DISCONNECTION')
|
||||
|
||||
await self.disconnect()
|
||||
|
@ -1,4 +1,3 @@
|
||||
t = "test = 12"
|
||||
locs ={}
|
||||
exec(t, globals(), locs)
|
||||
print(locs)
|
@ -6,7 +6,7 @@ VALID_PASSWORD = 'Test12345'
|
||||
def test_register(client: TestClient, username = VALID_USERNAME):
|
||||
r = client.post('/register', data={"username": username, 'password': VALID_PASSWORD, 'password_confirm': VALID_PASSWORD})
|
||||
data = r.json()
|
||||
print(data)
|
||||
|
||||
assert r.status_code == 200
|
||||
assert 'access_token' in data
|
||||
assert 'refresh_token' in data
|
||||
@ -16,7 +16,7 @@ def test_register_username_too_long(client: TestClient):
|
||||
r = client.post('/register', data={"username": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
|
||||
'password':VALID_PASSWORD, 'password_confirm':VALID_PASSWORD})
|
||||
data = r.json()
|
||||
print(data)
|
||||
|
||||
assert r.status_code == 422
|
||||
assert data['detail']['username_error'] == 'ensure this value has at most 20 characters'
|
||||
|
||||
@ -24,7 +24,7 @@ def test_register_mdp_not_corresponding(client: TestClient):
|
||||
r = client.post('/register', data={"username": VALID_USERNAME,
|
||||
'password': "Test12345", 'password_confirm': 'Test1234'})
|
||||
data = r.json()
|
||||
print(data)
|
||||
|
||||
assert r.status_code == 422
|
||||
assert data['detail']['password_confirm_error'] == 'Les mots de passe ne correspondent pas'
|
||||
|
||||
@ -32,7 +32,7 @@ def test_register_mdp_missing_number(client: TestClient):
|
||||
r = client.post('/register', data={"username": "lilian",
|
||||
'password': "Testttttt", 'password_confirm': 'Testttttt'})
|
||||
data = r.json()
|
||||
print(data)
|
||||
|
||||
assert r.status_code == 422
|
||||
assert data['detail']['password_error'] == 'Le mot de passe doit contenir au moins un chiffre'
|
||||
|
||||
@ -40,7 +40,7 @@ def test_register_mdp_missing_maj(client: TestClient):
|
||||
r = client.post('/register', data={"username":VALID_USERNAME,
|
||||
'password': "testttttt1", 'password_confirm': 'testttttt1'})
|
||||
data = r.json()
|
||||
print(data)
|
||||
|
||||
assert r.status_code == 422
|
||||
assert data['detail']['password_error'] == 'Le mot de passe doit contenir au moins une majuscule'
|
||||
|
||||
@ -48,7 +48,7 @@ def test_register_mdp_too_short(client: TestClient):
|
||||
r = client.post('/register', data={"username": VALID_USERNAME,
|
||||
'password': "t", 'password_confirm': 't'})
|
||||
data = r.json()
|
||||
print(data)
|
||||
|
||||
assert r.status_code == 422
|
||||
assert data['detail'][
|
||||
'password_error'] == 'Le mot de passe est trop court (8 caractères minimum)'
|
||||
@ -60,7 +60,7 @@ def test_register_username_indisponible(client: TestClient):
|
||||
rr = client.post('/register', data={"username": VALID_USERNAME,
|
||||
'password':VALID_PASSWORD, 'password_confirm':VALID_PASSWORD})
|
||||
data = rr.json()
|
||||
print(data)
|
||||
|
||||
assert rr.status_code == 400
|
||||
assert data['detail'][
|
||||
'username_error'] == "Nom d'utilisateur indisponible"
|
||||
@ -70,7 +70,7 @@ def test_login(client: TestClient):
|
||||
|
||||
r = client.post('/login', data={"username": VALID_USERNAME, 'password': VALID_PASSWORD})
|
||||
data = r.json()
|
||||
print(data)
|
||||
|
||||
assert r.status_code == 200
|
||||
assert 'access_token' in data
|
||||
assert 'refresh_token' in data
|
||||
@ -81,7 +81,7 @@ def test_login_invalid_password(client: TestClient):
|
||||
|
||||
r = client.post('/login', data={"username": VALID_USERNAME, 'password': 'Test1234'})
|
||||
data = r.json()
|
||||
print(data)
|
||||
|
||||
assert r.status_code == 401
|
||||
assert data['detail'][
|
||||
'password_error'] == "Mot de passe invalide"
|
||||
@ -89,7 +89,7 @@ def test_login_invalid_password(client: TestClient):
|
||||
def test_login_user_not_found(client: TestClient):
|
||||
r = client.post('/login', data={"username": VALID_USERNAME, 'password': VALID_PASSWORD})
|
||||
data = r.json()
|
||||
print(data)
|
||||
|
||||
assert r.status_code == 401
|
||||
assert data['detail'][
|
||||
'username_error'] == "Utilisateur introuvable"
|
||||
@ -101,7 +101,7 @@ def test_check_token(client: TestClient):
|
||||
r = client.post(
|
||||
'/check-access', headers={'Authorization': 'Bearer ' + token})
|
||||
data = r.json()
|
||||
print(data)
|
||||
|
||||
assert r.status_code == 200
|
||||
assert data['username'] == 'lilian'
|
||||
|
||||
@ -122,7 +122,7 @@ def test_update_user(client: TestClient):
|
||||
r = client.put(
|
||||
'/user', headers={'Authorization': 'Bearer ' + token}, data= {'username': 'lilian2', 'email': 'example@example.com', 'firstname': 'test', 'name': "test"})
|
||||
data = r.json()
|
||||
print(data)
|
||||
|
||||
assert r.status_code == 200
|
||||
assert data['username'] == 'lilian2'
|
||||
assert data['email'] == 'example@example.com'
|
||||
@ -135,7 +135,7 @@ def test_update_user_invalid(client: TestClient):
|
||||
r = client.put(
|
||||
'/user', headers={'Authorization': 'Bearer ' + token}, data={'username': 'lilian222222222222222', 'email': 'example@example.com', 'firstname': 'test', 'name': "test"})
|
||||
data = r.json()
|
||||
print(data)
|
||||
|
||||
assert r.status_code == 422
|
||||
assert data['detail']['username_error'] == 'ensure this value has at most 20 characters'
|
||||
|
||||
@ -145,7 +145,7 @@ def test_update_username_missing(client: TestClient):
|
||||
r = client.put(
|
||||
'/user', headers={'Authorization': 'Bearer ' + token}, data={ 'email': 'example@example.com', 'firstname': 'test', 'name': "test"})
|
||||
data = r.json()
|
||||
print(data)
|
||||
|
||||
assert r.status_code == 422
|
||||
assert data['detail']['username_error'] == 'field required'
|
||||
def test_update_username_missing(client: TestClient):
|
||||
@ -153,7 +153,7 @@ def test_update_username_missing(client: TestClient):
|
||||
r = client.put(
|
||||
'/user', data={ 'email': 'example@example.com', 'firstname': 'test', 'name': "test"})
|
||||
data = r.json()
|
||||
print(data)
|
||||
|
||||
assert r.status_code == 401
|
||||
assert data['detail'] == 'Not authenticated'
|
||||
|
||||
@ -168,7 +168,7 @@ def test_delete_user(client: TestClient):
|
||||
'/user', data={'username': VALID_USERNAME, 'password': VALID_PASSWORD})
|
||||
|
||||
data = r.json()
|
||||
print(data)
|
||||
|
||||
assert r.status_code == 200
|
||||
assert data['ok'] == True
|
||||
|
||||
@ -179,7 +179,7 @@ def test_delete_invalid_password(client: TestClient):
|
||||
r = client.delete(
|
||||
'/user', data={"username": VALID_USERNAME, 'password': 'Test1234'})
|
||||
data = r.json()
|
||||
print(data)
|
||||
|
||||
assert r.status_code == 401
|
||||
assert data['detail'][
|
||||
'password_error'] == "Mot de passe invalide"
|
||||
@ -189,7 +189,7 @@ def test_delete_user_not_found(client: TestClient):
|
||||
r = client.delete(
|
||||
'/user', data={"username": VALID_USERNAME, 'password': VALID_PASSWORD})
|
||||
data = r.json()
|
||||
print(data)
|
||||
|
||||
assert r.status_code == 401
|
||||
assert data['detail'][
|
||||
'username_error'] == "Utilisateur introuvable"
|
||||
|
@ -1,7 +1,8 @@
|
||||
from typing import List
|
||||
from pydantic import BaseModel
|
||||
import time
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
from pydantic import BaseModel
|
||||
|
||||
from tests.test_auth import test_register
|
||||
|
||||
|
||||
@ -14,7 +15,7 @@ def test_create(client: TestClient, name="test_exo", consigne="consigne", privat
|
||||
username = user['username']
|
||||
r = client.post('/exercices', data={"name": name, "consigne": consigne, "private": private}, files={
|
||||
'file': ('test.py', open('tests/testing_exo_source/exo_source.py', 'rb'))}, headers={"Authorization": "Bearer " + token})
|
||||
print(r.json())
|
||||
|
||||
assert r.status_code == 201
|
||||
assert 'id_code' in r.json()
|
||||
assert {**r.json(), 'id_code': None} == {'name': name, 'consigne': consigne, 'private': private, 'id_code': None, 'author': {'username': username}, 'original': None, 'tags': [], 'exo_source': 'test.py', 'supports': {
|
||||
@ -32,7 +33,7 @@ def test_create_bad_import(client: TestClient, name="test_exo", consigne="consig
|
||||
username = user['username']
|
||||
r = client.post('/exercices', data={"name": name, "consigne": consigne, "private": private}, files={
|
||||
'file': ('test.py', open('tests/testing_exo_source/exo_source_bad_import.py', 'rb'))}, headers={"Authorization": "Bearer " + token})
|
||||
print(r.json())
|
||||
|
||||
assert r.status_code == 422
|
||||
return r.json()
|
||||
|
||||
@ -47,7 +48,7 @@ def test_create_bad_use__(client: TestClient, name="test_exo", consigne="consign
|
||||
username = user['username']
|
||||
r = client.post('/exercices', data={"name": name, "consigne": consigne, "private": private}, files={
|
||||
'file': ('test.py', open('tests/testing_exo_source/exo_source_use__.py', 'rb'))}, headers={"Authorization": "Bearer " + token})
|
||||
print(r.json())
|
||||
|
||||
assert r.status_code == 422
|
||||
return r.json()
|
||||
|
||||
@ -58,7 +59,7 @@ def test_create_invalid(client: TestClient):
|
||||
|
||||
r = client.post('/exercices', data={"name": "e"*51, "consigne": "e"*201, "private": False}, files={
|
||||
'file': ('test.py', open('tests/testing_exo_source/exo_source.py', 'rb'))}, headers={"Authorization": "Bearer " + token})
|
||||
print('RESP', r.json())
|
||||
|
||||
assert r.status_code == 422
|
||||
assert r.json()['detail'] == {'name_error': 'ensure this value has at most 50 characters',
|
||||
'consigne_error': 'ensure this value has at most 200 characters'}
|
||||
@ -70,7 +71,7 @@ def test_create_too_long(client: TestClient):
|
||||
|
||||
r = client.post('/exercices', data={"name": "e", "consigne": "e", "private": False}, files={
|
||||
'file': ('test.py', open('tests/testing_exo_source/exo_source_infinite.py', 'rb'))}, headers={"Authorization": "Bearer " + token})
|
||||
print('RESP', r.json())
|
||||
|
||||
assert r.status_code == 422
|
||||
assert r.json()['detail'] == {'exo_source_error': 'Script took too long', }
|
||||
|
||||
@ -79,7 +80,7 @@ def test_create_name_missing(client: TestClient):
|
||||
token = test_register(client)['access']
|
||||
|
||||
r = client.post('/exercices', headers={"Authorization": "Bearer " + token})
|
||||
print(r.json())
|
||||
|
||||
assert r.status_code == 422
|
||||
assert r.json()['detail'] == {
|
||||
'name_error': 'field required', 'file_error': 'field required'}
|
||||
@ -90,7 +91,7 @@ def test_create_missing_main(client: TestClient):
|
||||
|
||||
r = client.post('/exercices', data={"name": "test_exo", "consigne": "consigne", "private": False}, files={
|
||||
'file': ('test.py', open('tests/testing_exo_source/exo_source_missing_main.py', 'rb'))}, headers={"Authorization": "Bearer " + token})
|
||||
print(r.json())
|
||||
|
||||
assert r.status_code == 422
|
||||
assert r.json()['detail'] == {
|
||||
'exo_source_error': "Fonction 'main' introuvable"}
|
||||
@ -101,7 +102,7 @@ def test_create_invalid_source(client: TestClient):
|
||||
|
||||
r = client.post('/exercices', data={"name": "test_exo", "consigne": "consigne", "private": False}, files={
|
||||
'file': ('test.py', open('tests/testing_exo_source/exo_source_invalid.py', 'rb'))}, headers={"Authorization": "Bearer " + token})
|
||||
print(r.json())
|
||||
|
||||
assert r.status_code == 422
|
||||
assert r.json()['detail'] == {
|
||||
'exo_source_error': "Exercice non valide (compatible avec aucun support)"}
|
||||
@ -113,7 +114,7 @@ def test_clone(client: TestClient):
|
||||
token = test_register(client, username="lilian2")['access']
|
||||
rr = client.post('/clone/' + id_code,
|
||||
headers={'Authorization': 'Bearer ' + token})
|
||||
print(rr.json())
|
||||
|
||||
assert rr.status_code == 200
|
||||
assert 'id_code' in rr.json()
|
||||
assert {**rr.json(), 'id_code': None} == {'name': 'test_exo', 'consigne': 'consigne', 'private': False, 'id_code': None, 'author': {'username': 'lilian2'}, 'original': {"id_code": id_code, "name": create['name'], 'author': 'lilian'}, 'tags': [], 'exo_source': 'test.py', 'supports': {
|
||||
@ -126,7 +127,7 @@ def test_clone_private(client: TestClient):
|
||||
token = test_register(client, username="lilian2")['access']
|
||||
rr = client.post('/clone/' + id_code,
|
||||
headers={'Authorization': 'Bearer ' + token})
|
||||
print(rr.json())
|
||||
|
||||
assert rr.status_code == 401
|
||||
assert rr.json() == {'detail': 'Cet exercice est privé'}
|
||||
|
||||
@ -137,7 +138,7 @@ def test_update(client: TestClient):
|
||||
consigne="testconsigne")['id_code']
|
||||
r = client.put('/exercice/' + id_code, data={"name": "name", "private": True}, files={
|
||||
'file': ('test2.py', open('tests/testing_exo_source/exo_source.py', 'rb'))}, headers={"Authorization": "Bearer " + token})
|
||||
print(r.json())
|
||||
|
||||
assert r.status_code == 200
|
||||
assert 'id_code' in r.json()
|
||||
assert r.json() == {'name': "name", 'consigne': "testconsigne", 'private': True, 'id_code': id_code, 'author': {'username': 'lilian'}, 'original': None, 'tags': [], 'exo_source': 'test2.py', 'supports': {
|
||||
@ -149,7 +150,7 @@ def test_update_no_file(client: TestClient):
|
||||
id_code = test_create(client, user={'token': token, 'username': "lilian"},
|
||||
consigne="testconsigne")['id_code']
|
||||
r = client.put('/exercice/' + id_code, data={"name": "name", "private": True}, headers={"Authorization": "Bearer " + token})
|
||||
print(r.json())
|
||||
|
||||
assert r.status_code == 200
|
||||
assert 'id_code' in r.json()
|
||||
assert r.json() == {'name': "name", 'consigne': "testconsigne", 'private': True, 'id_code': id_code, 'author': {'username': 'lilian'}, 'original': None, 'tags': [], 'exo_source': 'test.py', 'supports': {
|
||||
@ -163,7 +164,7 @@ def test_update_missing_name(client: TestClient):
|
||||
'id_code']
|
||||
r = client.put('/exercice/' + id_code, data={"consigne": "consigne", "private": False}, files={
|
||||
'file': ('test2.py', open('tests/testing_exo_source/exo_source.py', 'rb'))}, headers={"Authorization": "Bearer " + token})
|
||||
print(r.json())
|
||||
|
||||
assert r.status_code == 422
|
||||
assert r.json()['detail'] == {'name_error': 'field required'}
|
||||
|
||||
@ -174,7 +175,7 @@ def test_update_missing_main(client: TestClient):
|
||||
'id_code']
|
||||
r = client.put('/exercice/' + id_code, data={"consigne": "consigne", "private": False}, files={
|
||||
'file': ('test2.py', open('tests/testing_exo_source/exo_source_missing_main.py', 'rb'))}, headers={"Authorization": "Bearer " + token})
|
||||
print(r.json())
|
||||
|
||||
assert r.status_code == 422
|
||||
assert r.json()['detail'] == {
|
||||
'exo_source_error': "Fonction 'main' introuvable"}
|
||||
@ -186,7 +187,7 @@ def test_update_invalid(client: TestClient):
|
||||
'id_code']
|
||||
r = client.put('/exercice/' + id_code, data={"consigne": "consigne", "private": False}, files={
|
||||
'file': ('test2.py', open('tests/testing_exo_source/exo_source_invalid.py', 'rb'))}, headers={"Authorization": "Bearer " + token})
|
||||
print(r.json())
|
||||
|
||||
assert r.status_code == 422
|
||||
assert r.json()['detail'] == {
|
||||
'exo_source_error': "Exercice non valide (compatible avec aucun support)"}
|
||||
@ -199,7 +200,7 @@ def test_update_too_long(client: TestClient):
|
||||
'id_code']
|
||||
r = client.put('/exercice/' + id_code, data={'name': 'e'*51, "consigne": "e"*201, "private": False}, files={
|
||||
'file': ('test2.py', open('tests/testing_exo_source/exo_source.py', 'rb'))}, headers={"Authorization": "Bearer " + token})
|
||||
print(r.json())
|
||||
|
||||
assert r.status_code == 422
|
||||
assert r.json()['detail'] == {'name_error': 'ensure this value has at most 50 characters',
|
||||
'consigne_error': 'ensure this value has at most 200 characters'}
|
||||
@ -211,7 +212,7 @@ def test_delete(client: TestClient):
|
||||
'id_code']
|
||||
r = client.delete('/exercice/' + id_code,
|
||||
headers={'Authorization': 'Bearer ' + token})
|
||||
print(r.json())
|
||||
|
||||
assert r.status_code == 200
|
||||
assert r.json()['detail'] == 'Exercice supprimé avec succès'
|
||||
|
||||
@ -220,7 +221,7 @@ def test_delete_not_found(client: TestClient):
|
||||
token = test_register(client, username="lilian")['access']
|
||||
r = client.delete('/exercice/' + "test",
|
||||
headers={'Authorization': 'Bearer ' + token})
|
||||
print(r.json())
|
||||
|
||||
assert r.status_code == 404
|
||||
assert r.json()['detail'] == 'Exercice introuvable'
|
||||
|
||||
@ -246,7 +247,7 @@ def test_add_tags(client: TestClient, name='name', tags: List[Tags] = [{'label':
|
||||
id_code = exo['id_code']
|
||||
r = client.post(f'/exercice/{id_code}/tags', json=tags,
|
||||
headers={'Authorization': 'Bearer ' + token})
|
||||
print("DATA", tags, "\n\n",r.json())
|
||||
|
||||
data = r.json()
|
||||
labels = [l['label'] for l in tags]
|
||||
assert r.status_code == 200
|
||||
@ -261,7 +262,7 @@ def test_add_tags_invalid_color(client: TestClient):
|
||||
id_code = exo['id_code']
|
||||
r = client.post(f'/exercice/{id_code}/tags', json=[
|
||||
{'label': "name", 'color': "color", 'id_code': "id_code"}], headers={'Authorization': 'Bearer ' + token})
|
||||
print(r.json())
|
||||
|
||||
data = r.json()
|
||||
assert r.status_code == 422
|
||||
assert data['detail'] == {
|
||||
@ -274,7 +275,7 @@ def test_add_tags_too_long(client: TestClient):
|
||||
id_code = exo['id_code']
|
||||
r = client.post(f'/exercice/{id_code}/tags', json=[
|
||||
{'label': "n"*21, 'color': "#ff0000", 'id_code': "id_code"}], headers={'Authorization': 'Bearer ' + token})
|
||||
print(r.json())
|
||||
|
||||
data = r.json()
|
||||
assert r.status_code == 422
|
||||
assert data['detail'] == {
|
||||
@ -288,7 +289,7 @@ def test_remove_tag(client: TestClient):
|
||||
tag_id = exo["tags"][0]["id_code"]
|
||||
r = client.delete(f'/exercice/{id_code}/tags/{tag_id}',
|
||||
headers={'Authorization': 'Bearer ' + token})
|
||||
print(r.json())
|
||||
|
||||
assert r.json() == {
|
||||
**exo['exo'], 'tags': exo['tags'][1:]}
|
||||
|
||||
@ -300,7 +301,7 @@ def test_remove_tag_not_found(client: TestClient):
|
||||
tag_id = "none"
|
||||
r = client.delete(f'/exercice/{id_code}/tags/{tag_id}',
|
||||
headers={'Authorization': 'Bearer ' + token})
|
||||
print(r.json())
|
||||
|
||||
assert r.json()['detail'] == 'Tag introuvable'
|
||||
|
||||
|
||||
@ -311,7 +312,7 @@ def test_remove_tag_exo_not_found(client: TestClient):
|
||||
id_code = "tets"
|
||||
r = client.delete(f'/exercice/{id_code}/tags/{tag_id}',
|
||||
headers={'Authorization': 'Bearer ' + token})
|
||||
print(r.json())
|
||||
|
||||
assert r.json()['detail'] == 'Exercice introuvable'
|
||||
|
||||
|
||||
@ -323,7 +324,7 @@ def test_remove_tag_not_owner(client: TestClient):
|
||||
tag_id = exo['tags'][0]['id_code']
|
||||
r = client.delete(f'/exercice/{id_code}/tags/{tag_id}',
|
||||
headers={'Authorization': 'Bearer ' + token2})
|
||||
print(r.json())
|
||||
|
||||
assert r.json()['detail'] == "Vous n'êtes pas le propriétaire du tag"
|
||||
|
||||
|
||||
@ -333,8 +334,8 @@ def test_exo_exo_source(client: TestClient):
|
||||
id_code = exo['id_code']
|
||||
r = client.get(f"/exercice/{id_code}/exo_source",
|
||||
headers={'Authorization': 'Bearer ' + token})
|
||||
print(r.text)
|
||||
print(r.headers)
|
||||
|
||||
|
||||
assert r.text == open('tests/testing_exo_source/exo_source.py', 'r').read()
|
||||
assert r.headers['content-disposition'].split('filename=')[-1] == 'test.py'
|
||||
|
||||
@ -350,7 +351,7 @@ def test_get_users_exos(client: TestClient):
|
||||
|
||||
r = client.get('/exercices/user',
|
||||
headers={'Authorization': 'Bearer ' + token1})
|
||||
print(r.json())
|
||||
|
||||
assert r.json()['page'] == 1
|
||||
assert r.json()['size'] == 50
|
||||
assert r.json()["items"] == [prv]
|
||||
@ -387,7 +388,7 @@ def test_get_users_exos_page(client: TestClient):
|
||||
|
||||
r = client.get('/exercices/user',
|
||||
headers={'Authorization': 'Bearer ' + token1}, params={"page": 2, "size": 10})
|
||||
print(r.json())
|
||||
|
||||
assert r.json()['page'] == 2
|
||||
assert r.json()['size'] == 10
|
||||
assert r.json()["items"] == [prv11, prv12]
|
||||
@ -424,7 +425,7 @@ def test_get_users_exos_page_up(client: TestClient):
|
||||
|
||||
r = client.get('/exercices/user',
|
||||
headers={'Authorization': 'Bearer ' + token1}, params={"page": 2, "size": 10})
|
||||
print(r.json())
|
||||
|
||||
assert r.json()['page'] == 2
|
||||
assert r.json()['size'] == 10
|
||||
assert r.json()["items"] == []
|
||||
@ -451,7 +452,7 @@ def test_get_user_with_search(client: TestClient):
|
||||
|
||||
r = client.get('/exercices/user', params={"search": "test"},
|
||||
headers={'Authorization': 'Bearer ' + token1})
|
||||
print(r.json())
|
||||
|
||||
assert r.json()['items'] == [exo1, exo2]
|
||||
|
||||
|
||||
@ -475,7 +476,7 @@ def test_get_user_with_search(client: TestClient):
|
||||
|
||||
r = client.get('/exercices/user', params={"search": "test"},
|
||||
headers={'Authorization': 'Bearer ' + token1})
|
||||
print(r.json())
|
||||
|
||||
assert r.json()['items'] == [exo1, exo2]
|
||||
|
||||
|
||||
@ -507,7 +508,7 @@ def test_get_user_with_tags(client: TestClient):
|
||||
tags3 = exo3['tags']
|
||||
r = client.get('/exercices/user', params={'tags': [*[t['id_code'] for t in tags2], 'notexisting']},
|
||||
headers={'Authorization': 'Bearer ' + token1})
|
||||
print("DATA", r.json())
|
||||
|
||||
assert r.json()['items'] == [exo2['exo'], exo3['exo']]
|
||||
|
||||
|
||||
@ -536,7 +537,7 @@ def test_get_user_with_tags_and_search(client: TestClient):
|
||||
tags3 = exo3['tags']
|
||||
r = client.get('/exercices/user', params={"search": "yes", 'tags': [t['id_code'] for t in tags2]},
|
||||
headers={'Authorization': 'Bearer ' + token1})
|
||||
print(r.json())
|
||||
|
||||
assert r.json()['items'] == [exo3['exo']]
|
||||
|
||||
|
||||
@ -553,7 +554,7 @@ def test_get_public_auth(client: TestClient):
|
||||
|
||||
r = client.get('/exercices/public',
|
||||
headers={'Authorization': 'Bearer ' + token2})
|
||||
print(r.json())
|
||||
|
||||
assert r.json()['items'] == [{**public2, 'is_author': False}]
|
||||
|
||||
|
||||
@ -573,7 +574,7 @@ def test_get_public_auth_with_search(client: TestClient):
|
||||
|
||||
r = client.get('/exercices/public',
|
||||
params={'search': "yes"}, headers={'Authorization': 'Bearer ' + token2})
|
||||
print(r.json())
|
||||
|
||||
assert r.json()['items'] == [{**public2, 'is_author': False}]
|
||||
|
||||
|
||||
@ -589,7 +590,7 @@ def test_get_public_no_auth(client: TestClient):
|
||||
client, user={'token': token1, 'username': "lilian"})
|
||||
|
||||
r = client.get('/exercices/public')
|
||||
print(r.json())
|
||||
|
||||
assert r.json()['items'] == [{**public1, 'is_author': False},
|
||||
{**public2, 'is_author': False}]
|
||||
|
||||
@ -618,7 +619,7 @@ def test_get_exo_auth(client: TestClient):
|
||||
|
||||
r = client.get('/exercice/' + exo['exo']['id_code'],
|
||||
headers={'Authorization': 'Bearer ' + token2})
|
||||
print(r.json(), exo)
|
||||
|
||||
assert r.json() == {**exo['exo'], "tags": [], 'is_author': False}
|
||||
|
||||
|
||||
@ -632,7 +633,7 @@ def test_get_exo_auth_with_tags(client: TestClient):
|
||||
r = client.get('/exercice/' + exo['exo']['id_code'],
|
||||
headers={'Authorization': 'Bearer ' + token})
|
||||
|
||||
print(r.json(), exo)
|
||||
|
||||
assert r.json() == {**exo['exo']}
|
||||
|
||||
|
||||
@ -657,7 +658,7 @@ def test_get_tags(client: TestClient):
|
||||
tags2 = exo2['tags']
|
||||
|
||||
r = client.get('/tags', headers={'Authorization': 'Bearer ' + token2})
|
||||
print(r.json())
|
||||
|
||||
assert r.json() == tags2
|
||||
|
||||
|
||||
|
@ -8,7 +8,7 @@ from tests.test_exos import test_create
|
||||
def test_create_room_no_auth(client: TestClient, public=False):
|
||||
r = client.post('/room', json={"name": "test_room",
|
||||
"public": public}, params={'username': "lilian"})
|
||||
print(r.json())
|
||||
|
||||
assert "room" in r.json()
|
||||
assert "member" in r.json()
|
||||
assert r.json()['member'] is not None
|
||||
@ -18,7 +18,7 @@ def test_create_room_no_auth(client: TestClient, public=False):
|
||||
def test_create_room_no_auth_invalid(client: TestClient):
|
||||
r = client.post('/room', json={"name": "test_room" * 21,
|
||||
"public": False}, params={'username': "lilian" * 21})
|
||||
print(r.json())
|
||||
|
||||
assert r.json() == {'detail': {'username_error': 'ensure this value has at most 20 characters',
|
||||
'name_error': 'ensure this value has at most 20 characters'}}
|
||||
|
||||
@ -28,7 +28,7 @@ def test_create_room_auth(client: TestClient, token=None, public=False):
|
||||
token = test_register(client=client)['access']
|
||||
r = client.post('/room', json={"name": "test_room",
|
||||
"public": public}, headers={"Authorization": "Bearer " + token})
|
||||
print(r.json())
|
||||
|
||||
assert "room" in r.json()
|
||||
assert "member" in r.json()
|
||||
assert r.json()['member'] == None
|
||||
@ -81,7 +81,7 @@ def test_login_no_auth_not_in_room(client: TestClient):
|
||||
ws.send_json({"type": "login", "data": {
|
||||
"reconnect_code": "lol"}})
|
||||
data = ws.receive_json()
|
||||
print(data)
|
||||
|
||||
assert data == {'type': "error", "data": {"code": 401,
|
||||
"msg": "Utilisateur introuvable dans cette salle"}}
|
||||
|
||||
@ -93,7 +93,7 @@ def test_login_auth(client: TestClient):
|
||||
with client.websocket_connect(f"/ws/room/" + room['room']) as ws:
|
||||
ws.send_json({"type": "login", "data": {"token": token}})
|
||||
data = ws.receive_json()
|
||||
print(data)
|
||||
|
||||
assert "id_code" in data["data"]['member']
|
||||
assert data == {'type': "loggedIn", "data": {"member": {**data["data"]['member'],
|
||||
"username": "lilian", "isAdmin": True, "isUser": True,
|
||||
@ -107,7 +107,7 @@ def test_login_auth_not_in_room(client: TestClient):
|
||||
with client.websocket_connect(f"/ws/room/" + room['room']) as ws:
|
||||
ws.send_json({"type": "login", "data": {"token": token}})
|
||||
data = ws.receive_json()
|
||||
print(data)
|
||||
|
||||
assert data == {'type': "error", "data": {"code": 401,
|
||||
"msg": "Utilisateur introuvable dans cette salle"}}
|
||||
|
||||
@ -139,7 +139,7 @@ def test_join_auth(client: TestClient):
|
||||
assert mdata == {"type": "accepted", "data": {"member": {
|
||||
"username": "lilian2", "isUser": True, "isAdmin": False, "reconnect_code": "",
|
||||
"id_code": mdata['data']["member"]["id_code"], "clientId": "", "online": True}}}
|
||||
print("MDATABUS", mdata)
|
||||
|
||||
adata = admin.receive_json()
|
||||
|
||||
assert adata == {'type': "joined", 'data': {
|
||||
@ -601,7 +601,7 @@ def test_create_parcours_no_auth(client: TestClient):
|
||||
{"exercice_id": exo2['id_code'], "quantity": 5},
|
||||
{"exercice_id": exo3['id_code'],
|
||||
"quantity": 12}]})
|
||||
print('resonse', r.json(), exo3)
|
||||
|
||||
assert r.json() == {"id_code": r.json()['id_code'], "memberRank": None, "name": "test_parcours", "pb": None,
|
||||
"rank": None, "ranking": [], "tops": [], "validated": False, "challenges": {},
|
||||
"name": "test_parcours", "time": 10 * 60,
|
||||
@ -925,7 +925,7 @@ def test_corrige_auth(client: TestClient):
|
||||
r = client.post(f'/room/{room["room"]}/parcours', headers={"Authorization": "Bearer " + token},
|
||||
json={"name": "test_parcours", "time": 10 * 60, "max_mistakes": 10, "exercices": [
|
||||
{"exercice_id": exo1['id_code'], "quantity": 3}]})
|
||||
print(r.json())
|
||||
|
||||
parcours_id = r.json()['id_code']
|
||||
memberws.receive_json()
|
||||
admin.receive_json() # new parcours
|
||||
|
@ -16,7 +16,7 @@
|
||||
afterNavigate(() => {
|
||||
open = false;
|
||||
});
|
||||
$: console.log("USERNAME", $username);
|
||||
$:
|
||||
</script>
|
||||
|
||||
<nav data-sveltekit-preload-data="hover" class:open>
|
||||
|
@ -62,7 +62,7 @@
|
||||
cancel()
|
||||
}).catch((e) => {
|
||||
loading=false
|
||||
console.log(e)
|
||||
|
||||
error('Erreur', 'Une erreur est survenue lors de la modification de l\'exercice')
|
||||
});
|
||||
} else {
|
||||
|
@ -82,7 +82,7 @@
|
||||
tags: [...selected.map((t) => t.id_code)]
|
||||
})
|
||||
.then((r) => {
|
||||
console.log("R", r);
|
||||
|
||||
if (activePage > r.totalPage && r.total != 0 && r.totalPage != 0) {
|
||||
activePage = r.totalPage;
|
||||
//$p.url.searchParams.set('page', String(activePage));
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
export let label: string;
|
||||
export let color: string;
|
||||
console.log(color)
|
||||
|
||||
export let remove: Function | null = null;
|
||||
let removed = false;
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
$: console.log('ID', id, invi);
|
||||
$:
|
||||
</script>
|
||||
|
||||
<div class="tags" bind:this={tg} {id}>
|
||||
|
@ -21,7 +21,7 @@
|
||||
};
|
||||
let test: HTMLInputElement;
|
||||
export const focus = () => {
|
||||
console.log('FOCUS', test)
|
||||
|
||||
test.focus();
|
||||
};
|
||||
</script>
|
||||
|
@ -10,7 +10,7 @@
|
||||
//export let isMultiple = false;
|
||||
|
||||
const color = chroma("rgb(255,0,0)");
|
||||
console.log(color.rgb(), color);
|
||||
|
||||
</script>
|
||||
|
||||
<!-- you need to use itemActions and pass given events -->
|
||||
|
@ -8,7 +8,7 @@
|
||||
let show = type != 'password';
|
||||
const id = Math.random().toString(36).substr(2, 9);
|
||||
const toggle = () => {
|
||||
console.log('OOGLE ')
|
||||
|
||||
const element = document.getElementById(id) as HTMLInputElement;
|
||||
if (element === null) return;
|
||||
element.type = show === true ? 'password' : 'text';
|
||||
|
@ -31,12 +31,12 @@
|
||||
}}
|
||||
on:change={
|
||||
(s)=>{
|
||||
console.log('CHANGES', s)
|
||||
|
||||
selected = s.detail
|
||||
}
|
||||
}
|
||||
on:createoption={(opt) => {
|
||||
console.log('NEW OPT', opt);
|
||||
|
||||
|
||||
selected.push({ ...opt.detail });
|
||||
}}
|
||||
|
@ -186,7 +186,7 @@
|
||||
hidden={!$challengeStore.corriged}
|
||||
class="primary-btn"
|
||||
on:click={() => {
|
||||
console.log('RETRY CLICKED')
|
||||
|
||||
challenge($room.id_code, id_code, !$member.isUser ? $member.clientId : null).then((p) => {
|
||||
challengeStore.set({ ...p, corriged: false });
|
||||
remaining = null;
|
||||
|
@ -18,12 +18,12 @@
|
||||
let mainDiv: HTMLDivElement;
|
||||
|
||||
const toggleFocus = (e: FocusEvent) => {
|
||||
console.log(mainDiv,e.relatedTarget, mainDiv.contains(e.relatedTarget as Node))
|
||||
|
||||
if (hidden == true && !mainDiv.contains(e.relatedTarget as Node)) {
|
||||
hidden = false;
|
||||
console.log("PASEED");
|
||||
|
||||
setTimeout(() => {
|
||||
console.log("HOPIDOP");
|
||||
|
||||
close = true;
|
||||
}, 300);
|
||||
}
|
||||
|
@ -92,7 +92,7 @@
|
||||
!$isAuth ? $member?.clientId : null
|
||||
)
|
||||
.then((r) => {
|
||||
console.log(r);
|
||||
|
||||
parcours.set(r);
|
||||
$page.url.searchParams.delete('edit');
|
||||
|
||||
@ -100,7 +100,7 @@
|
||||
|
||||
})
|
||||
.catch((r) => {
|
||||
console.log(r);
|
||||
|
||||
error('Echec lors de la modification du parcours', `Raison: ${r.detail}`);
|
||||
});
|
||||
}
|
||||
@ -120,7 +120,7 @@
|
||||
goto(`?${$page.url.searchParams.toString()}`);
|
||||
return
|
||||
}
|
||||
console.log('CLICKED');
|
||||
|
||||
$page.url.searchParams.delete('p');
|
||||
goto(`?${$page.url.searchParams.toString()}`);
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
||||
editing = true;
|
||||
name = $room.name;
|
||||
r.focus();
|
||||
console.log("OPENED")
|
||||
|
||||
}}
|
||||
>
|
||||
{$room.name}<span on:dblclick|stopPropagation>#{$room.id_code}</span>
|
||||
|
@ -9,7 +9,7 @@
|
||||
const member: Writable<Waiting | null> = getContext("member");
|
||||
|
||||
onMount(() => {
|
||||
console.log("MOUNT, $member");
|
||||
|
||||
if ($member == null || !$member.waiter_id) {
|
||||
goto("?");
|
||||
}
|
||||
|
@ -16,11 +16,11 @@
|
||||
visible = true;
|
||||
closed = false;
|
||||
component = c;
|
||||
console.log('edi', editing, c, p)
|
||||
|
||||
if (editing) {
|
||||
console.log('EDITINGF', props)
|
||||
|
||||
props = { ...props, ...p };
|
||||
console.log(props)
|
||||
|
||||
} else {
|
||||
props = p;
|
||||
}
|
||||
@ -41,7 +41,7 @@
|
||||
}
|
||||
setContext('modal', { show, close });
|
||||
function keyPress(e: KeyboardEvent) {
|
||||
console.log('HOP');
|
||||
|
||||
if (e.key == 'Escape' && visible == true) {
|
||||
visible = false;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@
|
||||
| undefined
|
||||
) => {
|
||||
if (browser) {
|
||||
console.log('PREVIOUS', previous, typeof url == 'number', previous);
|
||||
|
||||
if (typeof url == 'number' && previous != null) {
|
||||
const id = Math.abs(url);
|
||||
if (previous.length > id) {
|
||||
|
@ -62,7 +62,7 @@ export const getExos = (
|
||||
size?: number;
|
||||
}
|
||||
) => {
|
||||
console.log('SENDINF', data, stringify(data, { arrayFormat: 'brackets' }));
|
||||
|
||||
return exoInstance({
|
||||
url: '/exercices/' + category,
|
||||
method: 'GET',
|
||||
|
@ -21,7 +21,7 @@
|
||||
const { logout, username, isAuth, initialLoading } = getContext("auth");
|
||||
|
||||
$: !$initialLoading && $isAuth && dashBoardRequest().then((res) => {
|
||||
console.log(res);
|
||||
|
||||
user.set(res);
|
||||
});
|
||||
const { show, close } = getContext("modal");
|
||||
@ -59,7 +59,7 @@
|
||||
close()
|
||||
success("Sécurité", "Mot de passe mises à jour avec succès")
|
||||
}).catch((e)=>{
|
||||
console.log('Erreur', e)
|
||||
|
||||
error("Sécurité","Une erreur est survenue")
|
||||
})
|
||||
}, validate: "Changer mon mot de passe", cancel: close, cancelMsg: "Garder le mot de passe actuel"})
|
||||
|
@ -132,7 +132,7 @@
|
||||
AskPseudo,
|
||||
{
|
||||
validate: (p: string) => {
|
||||
console.log("OH", p, p.startsWith("#"));
|
||||
|
||||
if (p.startsWith("#")) {
|
||||
ws.send({ type: "login", data: { reconnect_code: p.replace("#", "") } });
|
||||
} else {
|
||||
@ -407,7 +407,7 @@
|
||||
});
|
||||
});
|
||||
$: onEvent($events[0]);
|
||||
$: console.log($page.params.slug, $page, $page.params, $page.url.searchParams.get("p"));
|
||||
$:
|
||||
let fade = false;
|
||||
|
||||
beforeNavigate((n) => {
|
||||
@ -424,7 +424,7 @@
|
||||
}
|
||||
});
|
||||
afterNavigate((n) => {
|
||||
console.log("AGTER", n);
|
||||
|
||||
let oldParcoursId =
|
||||
n.from?.url.searchParams.get("p") ||
|
||||
n.from?.url.searchParams.get("corr") ||
|
||||
@ -448,7 +448,7 @@
|
||||
} else */
|
||||
});
|
||||
|
||||
$: console.log("edit", $page.url.searchParams.get("a"));
|
||||
$:
|
||||
onDestroy(() => {
|
||||
|
||||
ws.close(1000);
|
||||
|
@ -21,7 +21,7 @@
|
||||
<button
|
||||
class="primary-btn"
|
||||
on:click={() => {
|
||||
console.log('(NAME)', name)
|
||||
|
||||
loading = true
|
||||
createRoom({ name }, !$isAuth ? pseudo : null).then((r) => {
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
}).catch((e) => {
|
||||
error("Erreur", "Une erreur est survenue lors de la création de la salle")
|
||||
loading= false
|
||||
console.log(e);
|
||||
|
||||
});
|
||||
}}
|
||||
>
|
||||
|
@ -7,7 +7,7 @@
|
||||
let password = '';
|
||||
|
||||
const { login, isAuth, initialLoading } = getContext('auth');
|
||||
console.log('TEST1', initialLoading, isAuth);
|
||||
|
||||
$: {
|
||||
!$initialLoading && !!$isAuth && goto('/dashboard');
|
||||
}
|
||||
|
@ -66,7 +66,7 @@
|
||||
loading = true
|
||||
register($username.value, $password.value, $confirm.value).then(()=>{loading=false}).catch((r) => {
|
||||
loading = false
|
||||
console.log('ERREUR', r);
|
||||
|
||||
|
||||
errors = { ...errors, ...r.data.detail };
|
||||
});
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -230,7 +230,7 @@ describe('Participants', () => {
|
||||
key: 'ws',
|
||||
value: {
|
||||
send: (t, d) => {
|
||||
console.log('update', d.public);
|
||||
|
||||
if (t === 'set_visibility') {
|
||||
roomStore.update((r) => {
|
||||
r.public = d.public;
|
||||
@ -456,7 +456,7 @@ describe('Input challenge', () => {
|
||||
await fireEvent.click(inputElement);
|
||||
const validToggle = input.getByTestId('valid');
|
||||
const invalid = input.getByTestId('invalid');
|
||||
console.log(invalid);
|
||||
|
||||
|
||||
await fireEvent.mouseDown(validToggle);
|
||||
expect(get(valid)).toBeTruthy();
|
||||
@ -768,7 +768,7 @@ describe('Challenges', () => {
|
||||
await fireEvent.click(extend);
|
||||
|
||||
challenges.getByText((t, e) => {
|
||||
console.log('PH', t, e?.textContent);
|
||||
|
||||
return e.textContent == '6 fautes en 10s';
|
||||
});
|
||||
});
|
||||
@ -808,7 +808,7 @@ describe('Challenges', () => {
|
||||
const extendText2 = challenges.getByText('test2');
|
||||
await fireEvent.click(extendText2);
|
||||
challenges.getByText((t, e) => {
|
||||
console.log('PH', t, e?.textContent);
|
||||
|
||||
return e.textContent == '10 fautes en 01 : 10s';
|
||||
});
|
||||
expect(
|
||||
|
@ -7,7 +7,7 @@ export const errorMsg = (
|
||||
},
|
||||
name: string
|
||||
): string[] => {
|
||||
console.log(form.errors)
|
||||
|
||||
return [
|
||||
form.hasError(`${name}.required`) && 'Champ requis',
|
||||
form.hasError(`${name}.min`) && 'Trop court',
|
||||
@ -22,7 +22,7 @@ export const errorMsg = (
|
||||
|
||||
export const checkFile = () => {
|
||||
return async (value: Array<File>) => {
|
||||
console.log('VALIDATION', value)
|
||||
|
||||
if (value.length == 0) {
|
||||
return { valid:false, name: 'required' };
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ export const compareObject = (obj1: object, obj2: object) => {
|
||||
const key = keys[i];
|
||||
const v1 = obj1[key as keyof typeof obj1];
|
||||
const v2 = obj2[key as keyof typeof obj2];
|
||||
console.log(obj1, obj2, v1, v2, key);
|
||||
|
||||
if (v1 != undefined && v2 != undefined) {
|
||||
if (v1 != v2) {
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user