Skip to content
This repository was archived by the owner on Jun 30, 2024. It is now read-only.

Commit 205a10e

Browse files
committed
Added unittest for the instructor adding sections/subsections to the students' practice tool.
1 parent 4ce2b1a commit 205a10e

File tree

3 files changed

+109
-6
lines changed

3 files changed

+109
-6
lines changed

controllers/admin.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -440,13 +440,10 @@ def add_practice_items():
440440
now = datetime.datetime.utcnow()
441441
now_local = now - datetime.timedelta(hours=float(session.timezoneoffset))
442442

443-
students = db((db.auth_user.course_name == auth.user.course_name)) \
444-
.select()
445-
chapters = db((db.chapters.course_id == course.base_course)) \
446-
.select()
443+
students = db((db.auth_user.course_name == auth.user.course_name)).select()
444+
chapters = db((db.chapters.course_id == course.base_course)).select()
447445
for chapter in chapters:
448-
subchapters = db((db.sub_chapters.chapter_id == chapter.id)) \
449-
.select()
446+
subchapters = db((db.sub_chapters.chapter_id == chapter.id)).select()
450447
for subchapter in subchapters:
451448
subchapterTaught = db((db.sub_chapter_taught.course_name == auth.user.course_name) &
452449
(db.sub_chapter_taught.chapter_label == chapter.chapter_label) &

tests/test_course_1/_sources/test_chapter_1/subchapter_b.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Lets add one activity to this Subchapter!
1111
:correct: b
1212
:feedback_a: It usually takes longer to read a program because the structure is as important as the content and must be interpreted in smaller pieces for understanding.
1313
:feedback_b: It usually takes longer to read a program because the structure is as important as the content and must be interpreted in smaller pieces for understanding.
14+
:practice: T
1415

1516
True or False: Reading a program is like reading other kinds of text.
1617

@@ -54,6 +55,7 @@ Lets add one activity to this Subchapter!
5455

5556
.. activecode:: units1
5657
:autograde: unittest
58+
:practice: T
5759

5860
def add(a,b):
5961
return 4

tests/test_server.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from textwrap import dedent
1616
import json
1717
from threading import Thread
18+
import datetime
1819

1920
# Third-party imports
2021
# -------------------
@@ -571,6 +572,109 @@ def test_assignments(test_client, runestone_db_tools, test_user):
571572
assert "Error" in test_client.text
572573

573574

575+
def test_instructor_practice_admin(test_client, runestone_db_tools, test_user):
576+
course_4 = runestone_db_tools.create_course('test_course_1')
577+
test_student_1 = test_user('test_student_1', 'password_1', course_4)
578+
test_student_1.logout()
579+
test_instructor_1 = test_user('test_instructor_1', 'password_1', course_4)
580+
test_instructor_1.make_instructor()
581+
test_instructor_1.login()
582+
db = runestone_db_tools.db
583+
584+
course_start_date = datetime.datetime.strptime(course_4.term_start_date, '%Y-%m-%d').date()
585+
586+
today = datetime.datetime.today()
587+
start_date = course_start_date + datetime.timedelta(days=13)
588+
end_date = datetime.datetime.today().date() + datetime.timedelta(days=30)
589+
max_practice_days = 40
590+
max_practice_questions = 400
591+
day_points = 1
592+
question_points = 0.2
593+
questions_to_complete_day = 5
594+
graded = 0
595+
596+
# Test the practice tool settings for the course.
597+
flashcard_creation_method = 2
598+
test_client.post('admin/practice',
599+
data = {"StartDate": start_date,
600+
"EndDate": end_date,
601+
"graded": graded,
602+
'maxPracticeDays': max_practice_days,
603+
'maxPracticeQuestions': max_practice_questions,
604+
'pointsPerDay': day_points,
605+
'pointsPerQuestion': question_points,
606+
'questionsPerDay': questions_to_complete_day,
607+
'flashcardsCreationType': 2,
608+
'question_points': question_points})
609+
610+
practice_settings_1 = db(
611+
(db.course_practice.auth_user_id == test_instructor_1.user_id) &
612+
(db.course_practice.course_name == course_4.course_name) &
613+
(db.course_practice.start_date == start_date) &
614+
(db.course_practice.end_date == end_date) &
615+
(db.course_practice.flashcard_creation_method == flashcard_creation_method) &
616+
(db.course_practice.graded == graded)
617+
).select().first()
618+
assert practice_settings_1
619+
if practice_settings_1.spacing == 1:
620+
assert practice_settings_1.max_practice_days == max_practice_days
621+
assert practice_settings_1.day_points == day_points
622+
assert practice_settings_1.questions_to_complete_day == questions_to_complete_day
623+
else:
624+
assert practice_settings_1.max_practice_questions == max_practice_questions
625+
assert practice_settings_1.question_points == question_points
626+
627+
# Test instructor adding a subchapter to the practice tool for students.
628+
629+
f = open("demofile2.txt", "w")
630+
631+
course_1 = db(db.courses.id > 0) \
632+
.select().first()
633+
f.write("\n\n\n****course_1: " + str(course_1))
634+
f.write("\n\n\n****course_4.course_name: " + course_4.course_name)
635+
chapters = db((db.chapters.course_id > 0)) \
636+
.select()
637+
for chapter in chapters:
638+
f.write("chapter: " + str(chapter) + "\n")
639+
subchapters = db((db.sub_chapters.chapter_id == chapter.id)) \
640+
.select()
641+
for subchapter in subchapters:
642+
f.write("subchapter: " + str(subchapter) + "\n")
643+
644+
# I need to call set_tz_offset to set timezoneoffset in the session.
645+
test_client.post('ajax/set_tz_offset',
646+
data = { 'timezoneoffset': 0 })
647+
648+
# The reason I'm manually stringifying the list value is that test_client.post does something strange with compound objects instead of passing them to json.dumps.
649+
test_client.post('admin/add_practice_items',
650+
data = { 'data': '["Test chapter 1/Subchapter B"]' })
651+
652+
import pdb; pdb.set_trace()
653+
654+
655+
user_topic_practices = db((db.user_topic_practice.id > 0)) \
656+
.select()
657+
f.write("len(user_topic_practices): " + str(len(user_topic_practices)) + "\n")
658+
for user_topic_practice in user_topic_practices:
659+
f.write("user_topic_practice: " + str(user_topic_practice) + "\n")
660+
questions = db((db.questions.id > 0)) \
661+
.select()
662+
f.write("len(questions): " + str(len(questions)) + "\n")
663+
# for question in questions:
664+
# f.write("question: " + str(question) + "\n")
665+
practice_settings_1 = db(
666+
(db.user_topic_practice.user_id == test_student_1.user_id) &
667+
(db.user_topic_practice.course_name == course_4.course_name) &
668+
(db.user_topic_practice.chapter_label == "test_chapter_1") &
669+
(db.user_topic_practice.sub_chapter_label == "subchapter_b")
670+
).select().first()
671+
assert practice_settings_1
672+
673+
f.close()
674+
# test_client.logout()
675+
# test_student_1.login()
676+
677+
574678
def test_deleteaccount(test_client, runestone_db_tools, test_user):
575679
course_3 = runestone_db_tools.create_course('test_course_3')
576680
the_user = test_user('user_to_delete', 'password_1', course_3)

0 commit comments

Comments
 (0)