10
10
from tests import dummies
11
11
12
12
13
- TITLE = "Test Title" ,
14
- CONTENT_TYPE = "video" ,
15
- EXTERNAL_LINK = "http://example.com" ,
16
- DESCRIPTION = "Test Description"
17
-
18
13
async def create_dummy_course (db : Session , teacher : Teacher ):
19
14
course = Course (
20
15
course_id = 1 ,
@@ -27,14 +22,26 @@ async def create_dummy_course(db: Session, teacher: Teacher):
27
22
db .commit ()
28
23
return course
29
24
30
- def create_dummy_sectionbase (section_id = None , title = TITLE , content_type = CONTENT_TYPE ,
31
- external_link = EXTERNAL_LINK , description = DESCRIPTION , course_id = None ):
25
+
26
+ async def create_dummy_section (db , section_id , course_id ):
27
+ section = Section (
28
+ section_id = section_id ,
29
+ title = 'section' ,
30
+ content_type = 'text' ,
31
+ course_id = course_id
32
+ )
33
+ db .add (section )
34
+ db .commit ()
35
+
36
+ return section
37
+
38
+ def create_dummy_sectionbase (section_id = None , course_id = None ):
32
39
return SectionBase (
33
40
section_id = section_id ,
34
- title = title ,
35
- content_type = content_type ,
36
- external_link = external_link ,
37
- description = description ,
41
+ title = "Test Title" ,
42
+ content_type = "video" ,
43
+ external_link = "http://example.com" ,
44
+ description = "Test Description" ,
38
45
course_id = course_id
39
46
)
40
47
@@ -90,17 +97,19 @@ async def test_make_course_returns_created_CourseSectionsTags_model(db):
90
97
@pytest .mark .asyncio
91
98
async def test_get_entire_course_returns_CourseSectionsTags_model_with_sorting (db ):
92
99
_ , teacher = await dummies .create_dummy_teacher (db )
93
- course = create_dummy_course (db , teacher )
94
- tag = dummies .create_dummy_tag (db )
95
- dummies .add_dummy_tag (db , course .course_id , tag .tag_id )
100
+ course = await create_dummy_course (db , teacher )
101
+ tag = await dummies .create_dummy_tag (db )
102
+ await dummies .add_dummy_tag (db , course .course_id , tag .tag_id )
96
103
97
- section_1 = create_dummy_sectionbase ( section_id = 1 , course_id = course .course_id )
98
- section_2 = create_dummy_sectionbase ( section_id = 2 , course_id = course .course_id )
104
+ section_1 = await create_dummy_section ( db , section_id = 1 , course_id = course .course_id )
105
+ section_2 = await create_dummy_section ( db , section_id = 2 , course_id = course .course_id )
99
106
100
107
course_with_details = await crud_teacher .get_entire_course (db , course , teacher , sort = 'asc' , sort_by = 'section_id' )
101
108
102
109
assert course_with_details .course .course_id == course .course_id
103
110
assert len (course_with_details .tags ) == 1
104
111
assert len (course_with_details .sections ) == 2
112
+ assert course_with_details .sections [0 ].section_id == section_1 .section_id
105
113
assert course_with_details .sections [1 ].section_id == section_2 .section_id
114
+
106
115
0 commit comments