From cc01ba10d4bb2c25040e597f9891ca475a33ff4c Mon Sep 17 00:00:00 2001 From: Jaydin_MacBook <74679492+TheManWhoLikesToCode@users.noreply.github.com> Date: Wed, 24 Jan 2024 16:45:43 -0500 Subject: [PATCH] Added Try Catch to missing instructors --- backend/blackboard_session.py | 10 +- backend/test_blackboard_scraper.py | 162 +++++++++++++++++++++++++---- 2 files changed, 147 insertions(+), 25 deletions(-) diff --git a/backend/blackboard_session.py b/backend/blackboard_session.py index cc40f19..66588cf 100644 --- a/backend/blackboard_session.py +++ b/backend/blackboard_session.py @@ -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]+)' diff --git a/backend/test_blackboard_scraper.py b/backend/test_blackboard_scraper.py index 3278b1c..4599f74 100644 --- a/backend/test_blackboard_scraper.py +++ b/backend/test_blackboard_scraper.py @@ -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 = ''' - + + + + + Course and Term Management + -
- + + + + + + + + + + + + + + + + + + + + + + + + + +
CourseCourse NameCourse IDInstructors
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + +
Term NameTerm DurationShow TermExpand Term
+ + + +
+ + +
- - - -
- + + ''' # Mock the POST request @@ -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 = ''' - - -
- -
- - - -
- - + + + + + Course and Term Management + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
CourseCourse NameCourse IDInstructors
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + +
Term NameTerm DurationShow TermExpand Term
+ + + +
+ + + +
+ + + ''' # Mock the POST request @@ -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(