Skip to content

Commit

Permalink
Added Try Catch to missing instructors
Browse files Browse the repository at this point in the history
  • Loading branch information
TheManWhoLikesToCode committed Jan 24, 2024
1 parent 21d0fbe commit cc01ba1
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 25 deletions.
10 changes: 6 additions & 4 deletions backend/blackboard_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,12 @@ def get_courses(self):
# Process instructors and format course names
for course in courses_list:
try:
instructor_name = course.find("div").find(
"span", class_="name").text.strip()
last_name = instructor_name.split()[-1].rstrip(';')
if not last_name:
try:
instructor_name = course.find("div").find("span", class_="name").text.strip()
last_name = instructor_name.split()[-1].rstrip(';')
if not last_name:
last_name = "No Instructor"
except:
last_name = "No Instructor"

pattern = r'([A-Z]+-[0-9]+-[0-9]+[A-Z]?)|([A-Z]+-[0-9]+)'
Expand Down
162 changes: 141 additions & 21 deletions backend/test_blackboard_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,77 @@ def test_enable_instructors_logged_in(self):
with patch.object(session, '_get_request') as mock_get_request:
mock_get_request.return_value.status_code = 200
mock_get_request.return_value.content = '''
<html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Course and Term Management</title>
</head>
<body>
<form id="moduleEditForm">
<input type="hidden" value="fake_nonce_value">
<form method="post" action="tabAction?tab_tab_group_id=_1_1&amp;forwardUrl=proc_edit/_4_1/bbcourseorg&amp;recallUrl=%2Fwebapps%2Fportal%2Fexecute%2Ftabs%2FtabAction%3Ftab_tab_group_id%3D_1_1" id="moduleEditForm">
<input type="hidden" name="blackboard.platform.security.NonceUtil.nonce" value="3355f352-678e-4821-bd3d-a6f548fd7cf9">
<input type="hidden" name="cmd" id="cmd" value="processEdit">
<input type="hidden" name="serviceLevel" id="serviceLevel" value="">
<!-- Course Table -->
<table id="blockAttributes_table_jsListFULL_Student_35314_1">
<!-- Table Headers (simplified for brevity) -->
<thead>
<tr>
<th>Course</th>
<th>Course Name</th>
<th>Course ID</th>
<th>Instructors</th>
</tr>
</thead>
<tbody id="blockAttributes_table_jsListFULL_Student_35314_1_body">
<!-- Course Rows -->
<tr id="blockAttributes_table_jsListFULL_Student_35314_1_row:_52268_1">
<td align="LEFT" class="" id="miniListElement-showcoursename:row_0">
<input id="amc.showcourse._52268_1" type="checkbox" value="true" name="amc.showcourse._52268_1" checked="checked">
</td>
<td align="LEFT" class="" id="miniListElement-showcourseid:row_0">
<input id="amc.showcourseid._52268_1" type="checkbox" value="true" name="amc.showcourseid._52268_1" checked="checked">
</td>
<td align="LEFT" class="" id="miniListElement-showinstructors:row_0">
<input id="amc.showinstructors._52268_1" type="checkbox" value="true" name="amc.showinstructors._52268_1" checked="checked">
</td>
</tr>
<!-- Additional course rows can be added here -->
</tbody>
</table>
<!-- Term Table -->
<table id="termDisplay_table_jsListTermDisplay">
<!-- Table Headers (simplified for brevity) -->
<thead>
<tr>
<th>Term Name</th>
<th>Term Duration</th>
<th>Show Term</th>
<th>Expand Term</th>
</tr>
</thead>
<tbody id="termDisplay_table_jsListTermDisplay_body">
<!-- Term Rows -->
<tr id="termDisplay_table_jsListTermDisplay_row:_243_1">
<td align="LEFT" class="" id="miniListElement-showterm:row_0">
<input id="amc.showterm._243_1" type="checkbox" value="true" name="amc.showterm._243_1" checked="checked">
</td>
<td align="LEFT" class="" id="miniListElement-expandterm:row_0">
<input id="termCourses__243_1" type="checkbox" value="true" name="termCourses__243_1" checked="checked">
</td>
</tr>
<!-- Additional term rows can be added here -->
</tbody>
</table>
<!-- Submit Button -->
<input id="bottom_Submit" class="submit button-1" name="bottom_Submit" type="submit" value="Submit">
</form>
<table id="blockAttributes_table_jsListFULL_Student_1_1_body">
<tr id="FULL_Student_1_1_row:_123_456"></tr>
<tr id="FULL_Student_1_1_row:_789_101"></tr>
</table>
</body>
</html>
</html>
'''

# Mock the POST request
Expand Down Expand Up @@ -225,17 +285,77 @@ def test_enable_instructors_post_request_failed(self):
with patch.object(session, '_get_request') as mock_get_request:
mock_get_request.return_value.status_code = 200
mock_get_request.return_value.content = '''
<html>
<body>
<form id="moduleEditForm">
<input type="hidden" value="fake_nonce_value">
</form>
<table id="blockAttributes_table_jsListFULL_Student_1_1_body">
<tr id="FULL_Student_1_1_row:_123_456"></tr>
<tr id="FULL_Student_1_1_row:_789_101"></tr>
</table>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Course and Term Management</title>
</head>
<body>
<form method="post" action="tabAction?tab_tab_group_id=_1_1&amp;forwardUrl=proc_edit/_4_1/bbcourseorg&amp;recallUrl=%2Fwebapps%2Fportal%2Fexecute%2Ftabs%2FtabAction%3Ftab_tab_group_id%3D_1_1" id="moduleEditForm">
<input type="hidden" name="blackboard.platform.security.NonceUtil.nonce" value="3355f352-678e-4821-bd3d-a6f548fd7cf9">
<input type="hidden" name="cmd" id="cmd" value="processEdit">
<input type="hidden" name="serviceLevel" id="serviceLevel" value="">
<!-- Course Table -->
<table id="blockAttributes_table_jsListFULL_Student_35314_1">
<!-- Table Headers (simplified for brevity) -->
<thead>
<tr>
<th>Course</th>
<th>Course Name</th>
<th>Course ID</th>
<th>Instructors</th>
</tr>
</thead>
<tbody id="blockAttributes_table_jsListFULL_Student_35314_1_body">
<!-- Course Rows -->
<tr id="blockAttributes_table_jsListFULL_Student_35314_1_row:_52268_1">
<td align="LEFT" class="" id="miniListElement-showcoursename:row_0">
<input id="amc.showcourse._52268_1" type="checkbox" value="true" name="amc.showcourse._52268_1" checked="checked">
</td>
<td align="LEFT" class="" id="miniListElement-showcourseid:row_0">
<input id="amc.showcourseid._52268_1" type="checkbox" value="true" name="amc.showcourseid._52268_1" checked="checked">
</td>
<td align="LEFT" class="" id="miniListElement-showinstructors:row_0">
<input id="amc.showinstructors._52268_1" type="checkbox" value="true" name="amc.showinstructors._52268_1" checked="checked">
</td>
</tr>
<!-- Additional course rows can be added here -->
</tbody>
</table>
<!-- Term Table -->
<table id="termDisplay_table_jsListTermDisplay">
<!-- Table Headers (simplified for brevity) -->
<thead>
<tr>
<th>Term Name</th>
<th>Term Duration</th>
<th>Show Term</th>
<th>Expand Term</th>
</tr>
</thead>
<tbody id="termDisplay_table_jsListTermDisplay_body">
<!-- Term Rows -->
<tr id="termDisplay_table_jsListTermDisplay_row:_243_1">
<td align="LEFT" class="" id="miniListElement-showterm:row_0">
<input id="amc.showterm._243_1" type="checkbox" value="true" name="amc.showterm._243_1" checked="checked">
</td>
<td align="LEFT" class="" id="miniListElement-expandterm:row_0">
<input id="termCourses__243_1" type="checkbox" value="true" name="termCourses__243_1" checked="checked">
</td>
</tr>
<!-- Additional term rows can be added here -->
</tbody>
</table>
<!-- Submit Button -->
<input id="bottom_Submit" class="submit button-1" name="bottom_Submit" type="submit" value="Submit">
</form>
</body>
</html>
'''

# Mock the POST request
Expand Down Expand Up @@ -331,8 +451,8 @@ def test_get_courses_with_instructors_logged_in(self):

# Check the response
expected_courses = {
'CILE-400-1, Gebhardt, Summer 2023': 'https://learn.kettering.edu/webapps/blackboard/execute/launcher?type=Course&id=_51316_1&url=',
'COOP-002-01, No Instructor, Winter 2024': 'https://learn.kettering.edu/webapps/blackboard/execute/launcher?type=Course&id=_52268_1&url='
'CILE-400-01, Gebhardt, Summer 2023': '/webapps/blackboard/execute/launcher?type=Course&id=_51316_1&url=',
'COOP-002-01, No Instructor, Winter 2024': '/webapps/blackboard/execute/launcher?type=Course&id=_52268_1&url='
}
self.assertEqual(session.courses, expected_courses)
self.assertAlmostEqual(
Expand Down

0 comments on commit cc01ba1

Please sign in to comment.