From 63ba71316260173a6da75ea31a160096f808604f Mon Sep 17 00:00:00 2001 From: Fang Lin Date: Fri, 20 Sep 2024 21:01:00 -0700 Subject: [PATCH 1/4] Fix bug which caused primary_section_id to be null --- uw_sws/section.py | 24 ++++++++++++------------ uw_sws/tests/test_section.py | 2 ++ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/uw_sws/section.py b/uw_sws/section.py index 6c1461c..fb96698 100644 --- a/uw_sws/section.py +++ b/uw_sws/section.py @@ -368,18 +368,18 @@ def _json_to_section(section_data, section.auditors = int(section_data['Auditors']) section.allows_secondary_grading = section_data["SecondaryGradingOption"] - primary_section = section_data["PrimarySection"] - if (primary_section is not None and - primary_section["SectionID"] != section.section_id): - section.is_primary_section = False - section.primary_section_href = primary_section["Href"] - section.primary_section_id = primary_section["SectionID"] - section.primary_section_curriculum_abbr = primary_section[ - "CurriculumAbbreviation"] - section.primary_section_course_number = primary_section[ - "CourseNumber"] - else: - section.is_primary_section = True + primary_section = section_data.get("PrimarySection") + if primary_section is not None: + section.primary_section_href = primary_section.get("Href") + section.primary_section_id = primary_section.get("SectionID") + section.primary_section_curriculum_abbr = primary_section.get( + "CurriculumAbbreviation") + section.primary_section_course_number = primary_section.get( + "CourseNumber") + if section.primary_section_id == section.section_id: + section.is_primary_section = True + else: + section.is_primary_section = False section.linked_section_urls = [] for linked_section_type in section_data["LinkedSectionTypes"]: diff --git a/uw_sws/tests/test_section.py b/uw_sws/tests/test_section.py index 00de6b9..4bd9414 100644 --- a/uw_sws/tests/test_section.py +++ b/uw_sws/tests/test_section.py @@ -44,8 +44,10 @@ def test_section(self): section = get_section_by_label('2013,summer,PHIL,495/A') self.assertTrue(section.is_ind_study()) + self.assertTrue(section.is_primary_section) section = get_section_by_label('2013,summer,PHYS,121/AK') self.assertTrue(section.is_quiz()) + self.assertFalse(section.is_primary_section) section = get_section_by_label('2013,summer,PHYS,121/AQ') self.assertTrue(section.is_lab()) self.assertIsNotNone(section.json_data()) From a03b89120cf9010b39dcf8c97f0caee666e5d1e2 Mon Sep 17 00:00:00 2001 From: Fang Lin Date: Sat, 21 Sep 2024 09:27:49 -0700 Subject: [PATCH 2/4] Add test of section.primary_section* --- uw_sws/section.py | 8 +++----- uw_sws/tests/test_section.py | 9 +++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/uw_sws/section.py b/uw_sws/section.py index fb96698..dff4c75 100644 --- a/uw_sws/section.py +++ b/uw_sws/section.py @@ -371,15 +371,13 @@ def _json_to_section(section_data, primary_section = section_data.get("PrimarySection") if primary_section is not None: section.primary_section_href = primary_section.get("Href") - section.primary_section_id = primary_section.get("SectionID") section.primary_section_curriculum_abbr = primary_section.get( "CurriculumAbbreviation") section.primary_section_course_number = primary_section.get( "CourseNumber") - if section.primary_section_id == section.section_id: - section.is_primary_section = True - else: - section.is_primary_section = False + section.primary_section_id = primary_section.get("SectionID") + section.is_primary_section = ( + section.primary_section_id == section.section_id) section.linked_section_urls = [] for linked_section_type in section_data["LinkedSectionTypes"]: diff --git a/uw_sws/tests/test_section.py b/uw_sws/tests/test_section.py index 4bd9414..45a6ac0 100644 --- a/uw_sws/tests/test_section.py +++ b/uw_sws/tests/test_section.py @@ -45,9 +45,18 @@ def test_section(self): section = get_section_by_label('2013,summer,PHIL,495/A') self.assertTrue(section.is_ind_study()) self.assertTrue(section.is_primary_section) + self.assertEqual(section.primary_section_id, "A") + self.assertEqual( + section.primary_section_href, + "/student/v5/course/2013,summer,PHIL,495/A.json") + self.assertEqual( + section.primary_section_curriculum_abbr, "PHIL") + self.assertEqual( + section.primary_section_course_number, '495') section = get_section_by_label('2013,summer,PHYS,121/AK') self.assertTrue(section.is_quiz()) self.assertFalse(section.is_primary_section) + self.assertEqual(section.primary_section_id, "A") section = get_section_by_label('2013,summer,PHYS,121/AQ') self.assertTrue(section.is_lab()) self.assertIsNotNone(section.json_data()) From 7b0a0afe31cab3e3d83f4e2d44be067c7704dcc1 Mon Sep 17 00:00:00 2001 From: Fang Lin Date: Mon, 23 Sep 2024 09:39:17 -0700 Subject: [PATCH 3/4] handle PrimarySection null case --- uw_sws/section.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/uw_sws/section.py b/uw_sws/section.py index dff4c75..56bf222 100644 --- a/uw_sws/section.py +++ b/uw_sws/section.py @@ -378,7 +378,8 @@ def _json_to_section(section_data, section.primary_section_id = primary_section.get("SectionID") section.is_primary_section = ( section.primary_section_id == section.section_id) - + else: + section.is_primary_section = True section.linked_section_urls = [] for linked_section_type in section_data["LinkedSectionTypes"]: for linked_section_data in linked_section_type["LinkedSections"]: From 8f7c6a79cd52a8bb896e72294ff6dcb90e9b9f64 Mon Sep 17 00:00:00 2001 From: Fang Lin Date: Mon, 23 Sep 2024 09:42:29 -0700 Subject: [PATCH 4/4] tidy --- uw_sws/section.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/uw_sws/section.py b/uw_sws/section.py index 56bf222..bef777f 100644 --- a/uw_sws/section.py +++ b/uw_sws/section.py @@ -367,7 +367,7 @@ def _json_to_section(section_data, section.auditors = int(section_data['Auditors']) section.allows_secondary_grading = section_data["SecondaryGradingOption"] - + section.is_primary_section = True primary_section = section_data.get("PrimarySection") if primary_section is not None: section.primary_section_href = primary_section.get("Href") @@ -378,8 +378,7 @@ def _json_to_section(section_data, section.primary_section_id = primary_section.get("SectionID") section.is_primary_section = ( section.primary_section_id == section.section_id) - else: - section.is_primary_section = True + section.linked_section_urls = [] for linked_section_type in section_data["LinkedSectionTypes"]: for linked_section_data in linked_section_type["LinkedSections"]: