Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/delesray/poodle
Browse files Browse the repository at this point in the history
  • Loading branch information
miray-mustafov committed Jun 7, 2024
2 parents 2c68393 + 4c377a4 commit b68cb78
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/app/crud/crud_teacher.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async def edit_account(db: Session, teacher: Teacher, updates: TeacherEdit):
return teacher


async def get_info(teacher, teacher_email):
async def get_info(teacher: Teacher, teacher_email: str):
return TeacherSchema(
teacher_id=teacher.teacher_id,
email=teacher_email,
Expand Down
24 changes: 21 additions & 3 deletions src/app/tests/api/api_v1/endpoints/teacher_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
last_name="dummyName",
account=dummy_account
)

dummy_student_account = Account(account_id=2, email='[email protected]')
dummy_student = Student(
student_id=2
student_id=2,
account=dummy_student_account
)

teacher_request = {
Expand Down Expand Up @@ -629,4 +630,21 @@ def test_generate_courses_reports_invalid_sort(client: TestClient):
response = client.get('/teachers/reports?min_progress=0.0&sort=invalid')

assert response.status_code == status.HTTP_400_BAD_REQUEST
assert response.json() == {'detail': 'Invalid sort parameter'}
assert response.json() == {'detail': 'Invalid sort parameter'}


# def test_approve_enrollment_returns_success_msg(client: TestClient, mocker):
# mocker.patch('app.api.api_v1.routes.teachers.get_course_by_id', return_value=dummy_course)
# mocker.patch('app.api.api_v1.routes.teachers.crud_teacher.is_teacher_owner', return_value=True)
# mocker.patch('app.api.api_v1.routes.teachers.crud_student.get_by_email', return_value=dummy_student)
# mocker.patch('app.api.api_v1.routes.teachers.crud_teacher.student_enroll_response', return_value='Request response submitted')

# response = client.put('/courses/requests', json={
# "student": dummy_student.account.email,
# "course_id": dummy_course.course_id,
# "response": "Approve"
# })

# assert response.status_code == 201
# assert response.json() == {'detail': 'Request response submitted'}

115 changes: 115 additions & 0 deletions src/app/tests/crud/crud_teacher_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import pytest
from sqlalchemy.orm import Session
from crud import crud_teacher
from db.models import Teacher, Course, Status, Section
from fastapi import status, HTTPException
from schemas.course import CourseCreate, CourseInfo
from schemas.teacher import TeacherEdit
from schemas.tag import TagBase
from schemas.section import SectionBase
from tests import dummies


async def create_dummy_course(db: Session, teacher: Teacher):
course = Course(
course_id=1,
title="dummy",
description='dummy',
objectives='dummy',
owner_id=teacher.teacher_id,
)
db.add(course)
db.commit()
return course


async def create_dummy_section(db, section_id, course_id):
section = Section(
section_id=section_id,
title='section',
content_type='text',
course_id=course_id
)
db.add(section)
db.commit()

return section

def create_dummy_sectionbase(section_id=None, course_id=None):
return SectionBase(
section_id=section_id,
title="Test Title",
content_type="video",
external_link="http://example.com",
description="Test Description",
course_id=course_id
)

@pytest.mark.asyncio
async def test_edit_account_returns_updated_teacher_account(db):
_, teacher = await dummies.create_dummy_teacher(db)

updates = TeacherEdit(
first_name="UpdatedFirst",
last_name="UpdatedLast",
phone_number="1234567890",
linked_in="newLinkedInProfile"
)

updated_teacher = await crud_teacher.edit_account(db, teacher, updates)

assert updated_teacher.first_name == "UpdatedFirst"
assert updated_teacher.last_name == "UpdatedLast"
assert updated_teacher.phone_number == "1234567890"
assert updated_teacher.linked_in == "newLinkedInProfile"


@pytest.mark.asyncio
async def test_get_my_courses_returns_list_of_courses(db):
_, teacher = await dummies.create_dummy_teacher(db)
course = await create_dummy_course(db, teacher)

courses = await crud_teacher.get_my_courses(db, teacher)

assert len(courses) == 1
assert courses[0].course_id == course.course_id


@pytest.mark.asyncio
async def test_make_course_returns_created_CourseSectionsTags_model(db):
_, teacher = await dummies.create_dummy_teacher(db)
new_course = CourseCreate(
title="New Course",
description="New Course Description",
objectives="Objectives",
is_premium=False,
tags=[TagBase(name="NewTag")],
sections=[create_dummy_sectionbase()]
)

course_with_tags_and_sections = await crud_teacher.make_course(db, teacher, new_course)

assert course_with_tags_and_sections.course.title == new_course.title
assert len(course_with_tags_and_sections.tags) == 1
assert len(course_with_tags_and_sections.sections) == 1


@pytest.mark.asyncio
async def test_get_entire_course_returns_CourseSectionsTags_model_with_sorting(db):
_, teacher = await dummies.create_dummy_teacher(db)
course = await create_dummy_course(db, teacher)
tag = await dummies.create_dummy_tag(db)
await dummies.add_dummy_tag(db, course.course_id, tag.tag_id)

section_1 = await create_dummy_section(db, section_id=1, course_id=course.course_id)
section_2 = await create_dummy_section(db, section_id=2, course_id=course.course_id)

course_with_details = await crud_teacher.get_entire_course(db, course, teacher, sort='asc', sort_by='section_id')

assert course_with_details.course.course_id == course.course_id
assert len(course_with_details.tags) == 1
assert len(course_with_details.sections) == 2
assert course_with_details.sections[0].section_id == section_1.section_id
assert course_with_details.sections[1].section_id == section_2.section_id


2 changes: 1 addition & 1 deletion src/app/tests/dummies.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async def create_dummy_student(db: Session, is_premium=0) -> tuple[Account, Stud
return account, student


async def create_dummy_teacher(db: Session):
async def create_dummy_teacher(db: Session) -> tuple[Account, Teacher]:
account_id = 2
account = Account(
account_id=account_id,
Expand Down

0 comments on commit b68cb78

Please sign in to comment.