-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
352 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
from aiohttp.abc import StreamResponse | ||
from aiohttp.web_exceptions import HTTPUnauthorized | ||
|
||
|
||
class AuthRequiredMixin: | ||
raise NotImplementedError | ||
async def _iter(self) -> StreamResponse: | ||
if not getattr(self.request, "admin", None): | ||
raise HTTPUnauthorized | ||
return await super()._iter() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,111 @@ | ||
import pytest | ||
from sqlalchemy.ext.asyncio import AsyncSession | ||
|
||
from app.quiz.models import Theme, Question, Answer | ||
from app.quiz.models import ( | ||
Answer, | ||
AnswerModel, | ||
Question, | ||
QuestionModel, | ||
Theme, | ||
ThemeModel, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
async def theme_1(store) -> Theme: | ||
theme = await store.quizzes.create_theme(title="web-development") | ||
yield theme | ||
def answers(store) -> list[Answer]: | ||
return [ | ||
Answer(title="1", is_correct=True), | ||
Answer(title="2", is_correct=False), | ||
Answer(title="3", is_correct=False), | ||
Answer(title="4", is_correct=False), | ||
] | ||
|
||
|
||
@pytest.fixture | ||
async def theme_2(store) -> Theme: | ||
theme = await store.quizzes.create_theme(title="backend") | ||
yield theme | ||
async def theme_1(db_session: AsyncSession) -> Theme: | ||
title = "web-development" | ||
new_theme = ThemeModel(title=title) | ||
async with db_session.begin() as session: | ||
session.add(new_theme) | ||
|
||
return Theme(id=new_theme.id, title=title) | ||
|
||
|
||
@pytest.fixture | ||
async def theme_2(db_session: AsyncSession) -> Theme: | ||
title = "backend" | ||
new_theme = ThemeModel(title=title) | ||
async with db_session.begin() as session: | ||
session.add(new_theme) | ||
|
||
return Theme(id=new_theme.id, title=title) | ||
|
||
|
||
@pytest.fixture | ||
async def question_1(store, theme_1) -> Question: | ||
question = await store.quizzes.create_question( | ||
title="how are you?", | ||
async def question_1(db_session, theme_1: Theme) -> Question: | ||
title = "how are you?" | ||
async with db_session.begin() as session: | ||
question = QuestionModel( | ||
title=title, | ||
theme_id=theme_1.id, | ||
answers=[ | ||
AnswerModel( | ||
title="well", | ||
is_correct=True, | ||
), | ||
AnswerModel( | ||
title="bad", | ||
is_correct=False, | ||
), | ||
], | ||
) | ||
|
||
session.add(question) | ||
|
||
return Question( | ||
id=question.id, | ||
title=title, | ||
theme_id=theme_1.id, | ||
answers=[ | ||
Answer( | ||
title="well", | ||
is_correct=True, | ||
), | ||
Answer( | ||
title="bad", | ||
is_correct=False, | ||
), | ||
title=a.title, | ||
is_correct=a.is_correct, | ||
) | ||
for a in question.answers | ||
], | ||
) | ||
yield question | ||
|
||
|
||
@pytest.fixture | ||
async def question_2(store, theme_1) -> Question: | ||
question = await store.quizzes.create_question( | ||
title="are you doing fine?", | ||
async def question_2(db_session, theme_1: Theme) -> Question: | ||
title = "are you doing fine?" | ||
async with db_session.begin() as session: | ||
question = QuestionModel( | ||
title=title, | ||
theme_id=theme_1.id, | ||
answers=[ | ||
AnswerModel( | ||
title="yep", | ||
is_correct=True, | ||
), | ||
AnswerModel( | ||
title="nop", | ||
is_correct=False, | ||
), | ||
], | ||
) | ||
|
||
session.add(question) | ||
|
||
return Question( | ||
id=question.id, | ||
title=question.title, | ||
theme_id=theme_1.id, | ||
answers=[ | ||
Answer( | ||
title="yep", | ||
is_correct=True, | ||
), | ||
Answer( | ||
title="nop", | ||
is_correct=False, | ||
), | ||
title=a.title, | ||
is_correct=a.is_correct, | ||
) | ||
for a in question.answers | ||
], | ||
) | ||
yield question |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.