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

Commit baca85e

Browse files
committed
Merge branch 'bjones1-misc_bugs'
2 parents 7db82a7 + e4fc8b8 commit baca85e

File tree

5 files changed

+34
-19
lines changed

5 files changed

+34
-19
lines changed

controllers/admin.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,20 +1822,26 @@ def _add_q_meta_info(qrow):
18221822
requires_login=True,
18231823
)
18241824
def get_assignment():
1825-
assignment_id = request.vars["assignmentid"]
1825+
try:
1826+
assignment_id = int(request.vars.assignmentid)
1827+
except:
1828+
assignment_row = None
1829+
else:
1830+
assignment_row = db(db.assignments.id == assignment_id).select().first()
18261831
# Assemble the assignment-level properties
1827-
if assignment_id == "undefined":
1832+
if not assignment_row:
18281833
logger.error(
1829-
"UNDEFINED assignment {} {}".format(
1830-
auth.user.course_name, auth.user.username
1834+
"UNDEFINED assignment {} {} {}".format(
1835+
request.vars.assignmentid, auth.user.course_name, auth.user.username
18311836
)
18321837
)
1833-
session.flash = "Error assignment ID is undefined"
1834-
return redirect(URL("assignments", "index"))
1838+
session.flash = "Error: assignment ID {} does not exist".format(
1839+
request.vars.assignmentid
1840+
)
1841+
return redirect(URL("assignments", "chooseAssignment.html"))
18351842

18361843
_set_assignment_max_points(assignment_id)
18371844
assignment_data = {}
1838-
assignment_row = db(db.assignments.id == assignment_id).select().first()
18391845
assignment_data["assignment_points"] = assignment_row.points
18401846
try:
18411847
assignment_data["due_date"] = assignment_row.duedate.strftime("%Y/%m/%d %H:%M")

controllers/default.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,13 @@ def removecourse():
412412
redirect(URL("default", "courses"))
413413

414414
if settings.academy_mode:
415-
course_id_query = db(db.courses.course_name == request.args[0]).select(
416-
db.courses.id
415+
course_id_query = (
416+
db(db.courses.course_name == request.args[0]).select(db.courses.id).first()
417417
)
418+
# Redirect if this course wasn't found.
419+
if not course_id_query:
420+
redirect(URL("default", "courses"))
421+
418422
# todo: properly encode course_names to handle courses with special characters
419423
# Check if they're about to remove their currently active course
420424
auth_query = db(db.auth_user.id == auth.user.id).select()
@@ -426,7 +430,7 @@ def removecourse():
426430
else:
427431
db(
428432
(db.user_courses.user_id == auth.user.id)
429-
& (db.user_courses.course_id == course_id_query[0].id)
433+
& (db.user_courses.course_id == course_id_query.id)
430434
).delete()
431435

432436
redirect("/%s/default/courses" % request.application)

tests/conftest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,10 @@ def validate(
566566
admin_client.get("default/ticket/" + error_code)
567567
assert admin_client.status == 200
568568
# Save it to a file.
569-
traceback_file = url.replace("/", "-") + "_traceback.html"
569+
traceback_file = (
570+
"".join(c if c not in "\/:*?<>|" else "_" for c in url)
571+
+ "_traceback.html"
572+
)
570573
with open(traceback_file, "wb") as f:
571574
f.write(_html_prep(admin_client.text))
572575
print("Traceback saved to {}.".format(traceback_file))

tests/test_course_1/_sources/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ This book generates data for use with the test suite.
55

66
.. toctree::
77
:maxdepth: 2
8+
:numbered:
89

910
test_chapter_1/toctree
1011
lp_demo.py

tests/test_server.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#
1313
# Standard library
1414
# ----------------
15-
from io import open
1615
from textwrap import dedent
1716
import json
1817
from threading import Thread
@@ -101,7 +100,7 @@ def test_killer(test_assignment, test_client, test_user_1, runestone_db_tools):
101100
("default/user/login", False, "Login", 1),
102101
("default/user/register", False, "Registration", 1),
103102
("default/user/logout", True, "Logged out", 1),
104-
# One profile error is a result of removing the input field for the e-mail, but web2py still tries to label it, which is an error.
103+
# One validation error is a result of removing the input field for the e-mail, but web2py still tries to label it, which is an error.
105104
("default/user/profile", True, "Profile", 2),
106105
("default/user/change_password", True, "Change password", 1),
107106
# Runestone doesn't support this.
@@ -114,14 +113,11 @@ def test_killer(test_assignment, test_client, test_user_1, runestone_db_tools):
114113
# FIXME: This produces an exception.
115114
#'default/user/groups', True, 'Groups', 1),
116115
("default/user/not_authorized", False, "Not authorized", 1),
117-
# Returns a 404.
118-
# ('default/user/navbar'=(False, 'xxx', 1),
119116
# *Other pages*
120117
#
121118
# TODO: What is this for?
122119
# ('default/call', False, 'Not found', 0),
123-
# TODO: weird returned HTML. ???
124-
# ('default/index', True, 'Course Selection', 1),
120+
("default/index", True, "Course Selection", 1),
125121
("default/about", False, "About Us", 1),
126122
("default/error", False, "Error: the document does not exist", 1),
127123
("default/ack", False, "Acknowledgements", 1),
@@ -132,14 +128,16 @@ def test_killer(test_assignment, test_client, test_user_1, runestone_db_tools):
132128
# Should work in both cases.
133129
("default/reportabug", False, "Report a Bug", 1),
134130
("default/reportabug", True, "Report a Bug", 1),
135-
# TODO: weird returned HTML. ???
136131
# ('default/sendreport', True, 'Could not create issue', 1),
137132
("default/terms", False, "Terms and Conditions", 1),
138133
("default/privacy", False, "Runestone Academy Privacy Policy", 1),
139134
("default/donate", False, "Support Runestone Interactive", 1),
140-
# TODO: This soesn't really test the body of either of these
135+
# TODO: This doesn't really test much of the body of either of these.
141136
("default/coursechooser", True, "Course Selection", 1),
137+
# If we choose an invalid course, then we go to the profile to allow the user to add that course. The second validation failure seems to be about the ``for`` attribute of the ```<label class="readonly" for="auth_user_email" id="auth_user_email__label">`` tag, since the id ``auth_user_email`` isn't defined elsewhere.
138+
("default/coursechooser/xxx", True, "Course IDs for open courses", 2),
142139
("default/removecourse", True, "Course Selection", 1),
140+
("default/removecourse/xxx", True, "Course Selection", 1),
143141
("dashboard/studentreport", True, "Recent Activity", 1,),
144142
# **Designer**
145143
# -------------
@@ -203,6 +201,9 @@ def test_validate_user_pages(
203201
# ('admin/removeassign', 'Cannot remove assignment with id of', 1),
204202
# ('admin/removeinstructor', 'xxx', 1),
205203
# ('admin/removeStudents', 'xxx', 1),
204+
("admin/get_assignment", "Error: assignment ID", 1),
205+
("admin/get_assignment?assignmentid=junk", "Error: assignment ID", 1),
206+
("admin/get_assignment?assignmentid=100", "Error: assignment ID", 1),
206207
# TODO: added to the ``createAssignment`` endpoint so far.
207208
# **Dashboard**
208209
# --------------

0 commit comments

Comments
 (0)