-
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.
Merge branch 'olesya-crud-teacher-tests'
- Loading branch information
Showing
4 changed files
with
129 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = { | ||
|
@@ -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'} | ||
|
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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
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 | ||
|
||
|
||
TITLE="Test Title", | ||
CONTENT_TYPE="video", | ||
EXTERNAL_LINK="http://example.com", | ||
DESCRIPTION="Test Description" | ||
|
||
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 | ||
|
||
def create_dummy_sectionbase(section_id=None, title=TITLE, content_type=CONTENT_TYPE, | ||
external_link=EXTERNAL_LINK, description=DESCRIPTION, course_id=None): | ||
return SectionBase( | ||
section_id=section_id, | ||
title=title, | ||
content_type=content_type, | ||
external_link=external_link, | ||
description=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 = create_dummy_course(db, teacher) | ||
tag = dummies.create_dummy_tag(db) | ||
dummies.add_dummy_tag(db, course.course_id, tag.tag_id) | ||
|
||
section_1 = create_dummy_sectionbase(section_id=1, course_id=course.course_id) | ||
section_2 = create_dummy_sectionbase(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[1].section_id == section_2.section_id | ||
|
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