|
15 | 15 | from textwrap import dedent |
16 | 16 | import json |
17 | 17 | from threading import Thread |
| 18 | +import datetime |
18 | 19 |
|
19 | 20 | # Third-party imports |
20 | 21 | # ------------------- |
@@ -571,6 +572,109 @@ def test_assignments(test_client, runestone_db_tools, test_user): |
571 | 572 | assert "Error" in test_client.text |
572 | 573 |
|
573 | 574 |
|
| 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 | + |
574 | 678 | def test_deleteaccount(test_client, runestone_db_tools, test_user): |
575 | 679 | course_3 = runestone_db_tools.create_course('test_course_3') |
576 | 680 | the_user = test_user('user_to_delete', 'password_1', course_3) |
|
0 commit comments