|
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 | # ------------------- |
@@ -567,6 +568,103 @@ def test_assignments(test_client, runestone_db_tools, test_user): |
567 | 568 | assert "Error" in test_client.text |
568 | 569 |
|
569 | 570 |
|
| 571 | +def test_instructor_practice_admin(test_client, runestone_db_tools, test_user): |
| 572 | + course_4 = runestone_db_tools.create_course('test_course_1') |
| 573 | + test_student_1 = test_user('test_student_1', 'password_1', course_4) |
| 574 | + test_student_1.logout() |
| 575 | + test_instructor_1 = test_user('test_instructor_1', 'password_1', course_4) |
| 576 | + test_instructor_1.make_instructor() |
| 577 | + test_instructor_1.login() |
| 578 | + db = runestone_db_tools.db |
| 579 | + |
| 580 | + course_start_date = datetime.datetime.strptime(course_4.term_start_date, '%Y-%m-%d').date() |
| 581 | + |
| 582 | + today = datetime.datetime.today() |
| 583 | + start_date = course_start_date + datetime.timedelta(days=13) |
| 584 | + end_date = datetime.datetime.today().date() + datetime.timedelta(days=30) |
| 585 | + max_practice_days = 40 |
| 586 | + max_practice_questions = 400 |
| 587 | + day_points = 1 |
| 588 | + question_points = 0.2 |
| 589 | + questions_to_complete_day = 5 |
| 590 | + graded = 0 |
| 591 | + |
| 592 | + # Test the practice tool settings for the course. |
| 593 | + flashcard_creation_method = 2 |
| 594 | + test_client.post('admin/practice', |
| 595 | + data = {"StartDate": start_date, |
| 596 | + "EndDate": end_date, |
| 597 | + "graded": graded, |
| 598 | + 'maxPracticeDays': max_practice_days, |
| 599 | + 'maxPracticeQuestions': max_practice_questions, |
| 600 | + 'pointsPerDay': day_points, |
| 601 | + 'pointsPerQuestion': question_points, |
| 602 | + 'questionsPerDay': questions_to_complete_day, |
| 603 | + 'flashcardsCreationType': 2, |
| 604 | + 'question_points': question_points}) |
| 605 | + |
| 606 | + practice_settings_1 = db( |
| 607 | + (db.course_practice.auth_user_id == test_instructor_1.user_id) & |
| 608 | + (db.course_practice.course_name == course_4.course_name) & |
| 609 | + (db.course_practice.start_date == start_date) & |
| 610 | + (db.course_practice.end_date == end_date) & |
| 611 | + (db.course_practice.flashcard_creation_method == flashcard_creation_method) & |
| 612 | + (db.course_practice.graded == graded) |
| 613 | + ).select().first() |
| 614 | + assert practice_settings_1 |
| 615 | + if practice_settings_1.spacing == 1: |
| 616 | + assert practice_settings_1.max_practice_days == max_practice_days |
| 617 | + assert practice_settings_1.day_points == day_points |
| 618 | + assert practice_settings_1.questions_to_complete_day == questions_to_complete_day |
| 619 | + else: |
| 620 | + assert practice_settings_1.max_practice_questions == max_practice_questions |
| 621 | + assert practice_settings_1.question_points == question_points |
| 622 | + |
| 623 | + # Test instructor adding a subchapter to the practice tool for students. |
| 624 | + |
| 625 | + # I need to call set_tz_offset to set timezoneoffset in the session. |
| 626 | + test_client.post('ajax/set_tz_offset', |
| 627 | + data = { 'timezoneoffset': 0 }) |
| 628 | + |
| 629 | + # 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. |
| 630 | + test_client.post('admin/add_practice_items', |
| 631 | + data = { 'data': '["Test chapter 1/Subchapter B"]' }) |
| 632 | + |
| 633 | + |
| 634 | + practice_settings_1 = db( |
| 635 | + (db.user_topic_practice.user_id == test_student_1.user_id) & |
| 636 | + (db.user_topic_practice.course_name == course_4.course_name) & |
| 637 | + (db.user_topic_practice.chapter_label == "test_chapter_1") & |
| 638 | + (db.user_topic_practice.sub_chapter_label == "subchapter_b") |
| 639 | + ).select().first() |
| 640 | + assert practice_settings_1 |
| 641 | + |
| 642 | + # Testing whether a student can answer a practice question. |
| 643 | + # test_client.logout() |
| 644 | + # test_student_1.login() |
| 645 | + |
| 646 | + # ts = datetime.datetime.utcnow() |
| 647 | + # ts -= datetime.timedelta(microseconds=ts.microsecond) |
| 648 | + |
| 649 | + # test_client.post('ajax/hsblog', |
| 650 | + # data = {'event': 'mChoice', |
| 651 | + # 'act': 'answer:1:correct', |
| 652 | + # 'answer': 1, |
| 653 | + # 'correct': 'T', |
| 654 | + # 'div_id': 'subc_b_1', |
| 655 | + # 'course': course_4.course_name, |
| 656 | + # 'timezoneoffset': 0}) |
| 657 | + |
| 658 | + # mchoice_answers_1 = db( |
| 659 | + # (db.mchoice_answers.sid == test_student_1.user_id) & |
| 660 | + # (db.mchoice_answers.course_name == course_4.course_name) & |
| 661 | + # (db.mchoice_answers.correct == "test_chapter_1") & |
| 662 | + # (db.mchoice_answers.sub_chapter_label == "subchapter_b") |
| 663 | + # ).select().first() |
| 664 | + # assert practice_settings_1 |
| 665 | + # db.mchoice_answers.insert(sid=sid,timestamp=ts, div_id=div_id, answer=answer, correct=correct, course_name=course) |
| 666 | + |
| 667 | + |
570 | 668 | def test_deleteaccount(test_client, runestone_db_tools, test_user): |
571 | 669 | course_3 = runestone_db_tools.create_course('test_course_3') |
572 | 670 | the_user = test_user('user_to_delete', 'password_1', course_3) |
|
0 commit comments