From 88b33bf1b39f377f9731284669cc7bc6db932c47 Mon Sep 17 00:00:00 2001 From: Stephen De Vight Date: Tue, 12 Mar 2024 14:24:05 -0700 Subject: [PATCH] removing pagination from majors --- uw_adsel/__init__.py | 21 ++-------- .../api/v1/majors/details/0?Page=1&Limit=100 | 40 ------------------- .../details/0?Page=1&Limit=100&workspaceId=1 | 40 ------------------- .../api/v1/majors/details/0?Page=2&Limit=100 | 40 ------------------- .../api/v1/majors/details/1?workspaceId=1 | 24 +++++++++++ ...{1?Page=1&Limit=100 => 1?workspaceId=None} | 4 +- uw_adsel/tests/test_adsel.py | 12 +++--- 7 files changed, 36 insertions(+), 145 deletions(-) delete mode 100644 uw_adsel/resources/adsel/file/api/v1/majors/details/0?Page=1&Limit=100 delete mode 100644 uw_adsel/resources/adsel/file/api/v1/majors/details/0?Page=1&Limit=100&workspaceId=1 delete mode 100644 uw_adsel/resources/adsel/file/api/v1/majors/details/0?Page=2&Limit=100 create mode 100644 uw_adsel/resources/adsel/file/api/v1/majors/details/1?workspaceId=1 rename uw_adsel/resources/adsel/file/api/v1/majors/details/{1?Page=1&Limit=100 => 1?workspaceId=None} (93%) diff --git a/uw_adsel/__init__.py b/uw_adsel/__init__.py index ec94b3f..0a46c1c 100644 --- a/uw_adsel/__init__.py +++ b/uw_adsel/__init__.py @@ -308,25 +308,12 @@ def get_major_details_by_qtr_major(self, return major def get_majors_by_qtr(self, quarter_id, workspace_id=None): - majors = self._get_majors_by_page(quarter_id, 1, [], workspace_id) - return majors - - def _get_majors_by_page(self, - quarter_id, - page, - major_list=[], - workspace_id=None): - url = "{}/majors/details/{}?Page={}&Limit=100".format(self.API, - quarter_id, - page) - if workspace_id is not None: - url += "&" + urllib.parse.urlencode({'workspaceId': workspace_id}) + url = "{}/majors/details/{}?workspaceId={}".format(self.API, + quarter_id, + workspace_id) response = self._get_resource(url) majors = self._majors_from_json(response) - major_list += majors - if response['nextPage'] is not None: - self._get_majors_by_page(quarter_id, page+1, major_list) - return major_list + return majors def _majors_from_json(self, response): majors = [] diff --git a/uw_adsel/resources/adsel/file/api/v1/majors/details/0?Page=1&Limit=100 b/uw_adsel/resources/adsel/file/api/v1/majors/details/0?Page=1&Limit=100 deleted file mode 100644 index 5d19616..0000000 --- a/uw_adsel/resources/adsel/file/api/v1/majors/details/0?Page=1&Limit=100 +++ /dev/null @@ -1,40 +0,0 @@ -{ - "majors": [{ - "majorAbbr": "BIOL", - "academicQtrKeyId": 0, - "displayName": "Biology", - "college": "Science", - "division": "3A", - "majorPathway": 0, - "dtx": "string", - "majorProgramCode": "0_BIOL_1", - "assignedCount": 120, - "residentCount": 20, - "nonResidentCount": 50, - "internationalCount": 0, - "freshmanCount": 0, - "transferCount": 50, - "postBacCount": 0 - }, - { - "majorAbbr": "CHEM", - "academicQtrKeyId": 0, - "displayName": "Chemistry", - "college": "Science", - "division": "6B2", - "majorPathway": 0, - "dtx": "string", - "majorProgramCode": "0_CHEM_1", - "assignedCount": 220, - "residentCount": 20, - "nonResidentCount": 50, - "internationalCount": 50, - "freshmanCount": 50, - "transferCount": 50, - "postBacCount": 0 - } - ], - "nextPage": "https://foobartest.uw.edu/api/v1/majors/details/20194?Page=2&Limit=100", - "previousPage": null, - "totalCount": 4 -} \ No newline at end of file diff --git a/uw_adsel/resources/adsel/file/api/v1/majors/details/0?Page=1&Limit=100&workspaceId=1 b/uw_adsel/resources/adsel/file/api/v1/majors/details/0?Page=1&Limit=100&workspaceId=1 deleted file mode 100644 index cf10bec..0000000 --- a/uw_adsel/resources/adsel/file/api/v1/majors/details/0?Page=1&Limit=100&workspaceId=1 +++ /dev/null @@ -1,40 +0,0 @@ -{ - "majors": [{ - "majorAbbr": "BIOL", - "academicQtrKeyId": 0, - "displayName": "Biology", - "college": "Science", - "division": "3A", - "majorPathway": 0, - "dtx": "string", - "majorProgramCode": "0_BIOL_1", - "assignedCount": 523, - "residentCount": 20, - "nonResidentCount": 50, - "internationalCount": 0, - "freshmanCount": 0, - "transferCount": 50, - "postBacCount": 0 - }, - { - "majorAbbr": "CHEM", - "academicQtrKeyId": 0, - "displayName": "Chemistry", - "college": "Science", - "division": "6B2", - "majorPathway": 0, - "dtx": "string", - "majorProgramCode": "0_CHEM_1", - "assignedCount": 721, - "residentCount": 20, - "nonResidentCount": 50, - "internationalCount": 50, - "freshmanCount": 50, - "transferCount": 50, - "postBacCount": 0 - } - ], - "nextPage": null, - "previousPage": null, - "totalCount": 1 -} \ No newline at end of file diff --git a/uw_adsel/resources/adsel/file/api/v1/majors/details/0?Page=2&Limit=100 b/uw_adsel/resources/adsel/file/api/v1/majors/details/0?Page=2&Limit=100 deleted file mode 100644 index 5c59e33..0000000 --- a/uw_adsel/resources/adsel/file/api/v1/majors/details/0?Page=2&Limit=100 +++ /dev/null @@ -1,40 +0,0 @@ -{ - "majors": [{ - "majorAbbr": "CSE", - "academicQtrKeyId": 0, - "displayName": "Comp Sci Eng", - "college": "Engineering", - "division": "A4C", - "majorPathway": 0, - "dtx": "string", - "majorProgramCode": "0_CSE_1", - "assignedCount": 120, - "residentCount": 20, - "nonResidentCount": 50, - "internationalCount": 0, - "freshmanCount": 0, - "transferCount": 50, - "postBacCount": 0 - }, - { - "majorAbbr": "CHEM", - "academicQtrKeyId": 0, - "displayName": "Chemistry", - "college": "Science", - "division": "32D2", - "majorPathway": 0, - "dtx": "string", - "majorProgramCode": "0_CHEM_1", - "assignedCount": 120, - "residentCount": 20, - "nonResidentCount": 50, - "internationalCount": 0, - "freshmanCount": 0, - "transferCount": 50, - "postBacCount": 0 - } - ], - "nextPage": null, - "previousPage": "2", - "totalCount": 2 -} \ No newline at end of file diff --git a/uw_adsel/resources/adsel/file/api/v1/majors/details/1?workspaceId=1 b/uw_adsel/resources/adsel/file/api/v1/majors/details/1?workspaceId=1 new file mode 100644 index 0000000..5c94091 --- /dev/null +++ b/uw_adsel/resources/adsel/file/api/v1/majors/details/1?workspaceId=1 @@ -0,0 +1,24 @@ +{ + "majors": [ + { + "majorAbbr": "CHEM", + "academicQtrKeyId": 1, + "displayName": "Chemistry", + "college": "Science", + "division": "6B2", + "majorPathway": 0, + "dtx": "string", + "majorProgramCode": "0_CHEM_1", + "assignedCount": 120, + "residentCount": 20, + "nonResidentCount": 50, + "internationalCount": 0, + "freshmanCount": 10, + "transferCount": 50, + "postBacCount": 0 + } + ], + "nextPage": null, + "previousPage": "1", + "totalCount": 1 +} \ No newline at end of file diff --git a/uw_adsel/resources/adsel/file/api/v1/majors/details/1?Page=1&Limit=100 b/uw_adsel/resources/adsel/file/api/v1/majors/details/1?workspaceId=None similarity index 93% rename from uw_adsel/resources/adsel/file/api/v1/majors/details/1?Page=1&Limit=100 rename to uw_adsel/resources/adsel/file/api/v1/majors/details/1?workspaceId=None index afc282e..b9f004a 100644 --- a/uw_adsel/resources/adsel/file/api/v1/majors/details/1?Page=1&Limit=100 +++ b/uw_adsel/resources/adsel/file/api/v1/majors/details/1?workspaceId=None @@ -12,7 +12,7 @@ "residentCount": 20, "nonResidentCount": 50, "internationalCount": 0, - "freshmanCount": 0, + "freshmanCount": 10, "transferCount": 50, "postBacCount": 0 }, @@ -29,7 +29,7 @@ "residentCount": 20, "nonResidentCount": 50, "internationalCount": 0, - "freshmanCount": 0, + "freshmanCount": 10, "transferCount": 50, "postBacCount": 0 } diff --git a/uw_adsel/tests/test_adsel.py b/uw_adsel/tests/test_adsel.py index cb82234..0d6e776 100644 --- a/uw_adsel/tests/test_adsel.py +++ b/uw_adsel/tests/test_adsel.py @@ -24,16 +24,16 @@ def test_error(self): self.adsel._get_resource("/foobar/") def test_get_majors(self): - majors = self.adsel.get_majors_by_qtr(0) - self.assertEqual(len(majors), 4) + majors = self.adsel.get_majors_by_qtr(1) + self.assertEqual(len(majors), 2) self.assertEqual(majors[1].major_abbr, "CHEM") - self.assertEqual(majors[1].assigned_freshman, 50) + self.assertEqual(majors[1].assigned_freshman, 10) majors_unpaginated = self.adsel.get_majors_by_qtr(1) self.assertEqual(len(majors_unpaginated), 2) - workspace_majors = self.adsel.get_majors_by_qtr(0, 1) - self.assertEqual(len(workspace_majors), 2) - self.assertEqual(workspace_majors[1].assigned_count, 721) + workspace_majors = self.adsel.get_majors_by_qtr(1, 1) + self.assertEqual(len(workspace_majors), 1) + self.assertEqual(workspace_majors[0].assigned_count, 120) @mock.patch('uw_adsel.AdSel.get_now', side_effect=mocked_get_now) def test_get_quarters(self, mock_obj):