From e1f2cc7caf273275087776dbc2910579d296eb80 Mon Sep 17 00:00:00 2001 From: Stephen De Vight Date: Tue, 29 Oct 2024 12:33:04 -0700 Subject: [PATCH 1/2] adsel azure WIP --- uw_adsel/__init__.py | 6 ++++++ uw_adsel/adselazure_dao.py | 15 +++++++++++++++ uw_adsel/resources/adsel_azure/cohort | 17 +++++++++++++++++ uw_adsel/tests/test_adsel.py | 6 ++++++ 4 files changed, 44 insertions(+) create mode 100644 uw_adsel/adselazure_dao.py create mode 100644 uw_adsel/resources/adsel_azure/cohort diff --git a/uw_adsel/__init__.py b/uw_adsel/__init__.py index e8bab49..0b6a652 100644 --- a/uw_adsel/__init__.py +++ b/uw_adsel/__init__.py @@ -7,6 +7,7 @@ from restclients_core.exceptions import DataFailureException from restclients_core.dao import MockDAO from uw_adsel.dao import ADSEL_DAO +from uw_adsel.adselazure_dao import ADSEL_AZURE_DAO from uw_adsel.models import Major, Cohort, Quarter, Activity, Application, \ Decision, AdminMajor, AdminCohort, Workspace import dateutil.parser @@ -21,7 +22,12 @@ MAJOR_TYPE = "major" COHORT_TYPE = "cohort" +class AdSelAzure(AdSel): + API = '' + + def __init(self): + self.DAO = ADSEL_AZURE_DAO() class AdSel(object): """ The AdSel object has methods for interacting with the AdSel API. diff --git a/uw_adsel/adselazure_dao.py b/uw_adsel/adselazure_dao.py new file mode 100644 index 0000000..18bb318 --- /dev/null +++ b/uw_adsel/adselazure_dao.py @@ -0,0 +1,15 @@ +""" +Contains UW AdSEL Azure DAO implementations. +""" +from restclients_core.dao import DAO +from os.path import abspath, dirname +import os + + +class ADSEL_AZURE_DAO(DAO): + def service_name(self): + return 'adsel_azure' + + def service_mock_paths(self): + path = [abspath(os.path.join(dirname(__file__), "resources"))] + return path diff --git a/uw_adsel/resources/adsel_azure/cohort b/uw_adsel/resources/adsel_azure/cohort new file mode 100644 index 0000000..9bc2a70 --- /dev/null +++ b/uw_adsel/resources/adsel_azure/cohort @@ -0,0 +1,17 @@ +{ + "summaryPostStatus": "string", + "items": [ + { + "status": "string", + "application": { + "admissionSelectionId": 0, + "applicationNbr": 0, + "systemKey": 0 + }, + "cohortNbr": 0, + "majorAbbr": "string", + "message": "string" + } + ], + "message": "string" +} \ No newline at end of file diff --git a/uw_adsel/tests/test_adsel.py b/uw_adsel/tests/test_adsel.py index c119041..d704a16 100644 --- a/uw_adsel/tests/test_adsel.py +++ b/uw_adsel/tests/test_adsel.py @@ -35,6 +35,12 @@ def test_get_majors(self): self.assertEqual(len(workspace_majors), 1) self.assertEqual(workspace_majors[0].assigned_count, 120) + def test_assign(self): + cohort = CohortAssignment(cohort_number=1, campus=2) + submit = self.adsel.assign_cohorts_manual(cohort) + print(submit) + self.assertFalse(True) + @mock.patch('uw_adsel.AdSel.get_now', side_effect=mocked_get_now) def test_get_quarters(self, mock_obj): quarters = self.adsel.get_quarters() From bb858d9bd1dbe23ecbd15b7845a80c8fd9fdd100 Mon Sep 17 00:00:00 2001 From: Stephen De Vight Date: Tue, 29 Oct 2024 15:45:54 -0700 Subject: [PATCH 2/2] add support for assigning cohorts via new host --- uw_adsel/__init__.py | 25 ++++++++++++------- .../resources/adsel_azure/{ => file}/cohort | 2 +- uw_adsel/tests/test_adsel.py | 9 +++---- uw_adsel/tests/test_adselazure.py | 13 ++++++++++ 4 files changed, 34 insertions(+), 15 deletions(-) rename uw_adsel/resources/adsel_azure/{ => file}/cohort (86%) create mode 100644 uw_adsel/tests/test_adselazure.py diff --git a/uw_adsel/__init__.py b/uw_adsel/__init__.py index 0b6a652..b0a6a12 100644 --- a/uw_adsel/__init__.py +++ b/uw_adsel/__init__.py @@ -22,12 +22,7 @@ MAJOR_TYPE = "major" COHORT_TYPE = "cohort" -class AdSelAzure(AdSel): - - API = '' - def __init(self): - self.DAO = ADSEL_AZURE_DAO() class AdSel(object): """ The AdSel object has methods for interacting with the AdSel API. @@ -50,10 +45,7 @@ def assign_cohorts_bulk(self, cohort_assignment): return {"response": response, "request": request} def assign_cohorts_manual(self, cohort_assignment): - url = "{}/assignments/cohort".format(self.API) - request = cohort_assignment.json_data() - response = self._post_resource(url, request) - return {"response": response, "request": request} + return AdSelAzure().assign_cohorts_manual(cohort_assignment) def assign_purple_gold(self, pg_assignments): url = "{}/assignments/purpleAndGold".format(self.API) @@ -551,3 +543,18 @@ def _post_headers(self): def _log_error(self, url, response): logger.error("{0} ==> status:{1} data:{2}".format( url, response.status, response.data)) + + +class AdSelAzure(AdSel): + """ + The AdSel object has methods for interacting with endpoints + deployed to azureapi + """ + def __init__(self): + self.DAO = ADSEL_AZURE_DAO() + + def assign_cohorts_manual(self, cohort_assignment): + url = "/cohort" + request = cohort_assignment.json_data() + response = self._post_resource(url, request) + return {"response": response, "request": request} diff --git a/uw_adsel/resources/adsel_azure/cohort b/uw_adsel/resources/adsel_azure/file/cohort similarity index 86% rename from uw_adsel/resources/adsel_azure/cohort rename to uw_adsel/resources/adsel_azure/file/cohort index 9bc2a70..bc00bb9 100644 --- a/uw_adsel/resources/adsel_azure/cohort +++ b/uw_adsel/resources/adsel_azure/file/cohort @@ -1,5 +1,5 @@ { - "summaryPostStatus": "string", + "summaryPostStatus": "AzureSubmitSuccess", "items": [ { "status": "string", diff --git a/uw_adsel/tests/test_adsel.py b/uw_adsel/tests/test_adsel.py index d704a16..571ee6d 100644 --- a/uw_adsel/tests/test_adsel.py +++ b/uw_adsel/tests/test_adsel.py @@ -1,9 +1,8 @@ from unittest import TestCase, mock from restclients_core.exceptions import DataFailureException -from uw_adsel.utilities import fdao_adsel_override from uw_adsel import AdSel -from uw_adsel.models import CohortAssignment, MajorAssignment, Application,\ - PurpleGoldApplication, PurpleGoldAssignment, DecisionAssignment,\ +from uw_adsel.models import CohortAssignment, MajorAssignment, Application, \ + PurpleGoldApplication, PurpleGoldAssignment, DecisionAssignment, \ DepartmentalDecisionApplication from datetime import datetime @@ -38,8 +37,8 @@ def test_get_majors(self): def test_assign(self): cohort = CohortAssignment(cohort_number=1, campus=2) submit = self.adsel.assign_cohorts_manual(cohort) - print(submit) - self.assertFalse(True) + self.assertEqual(submit['response']['summaryPostStatus'], + "AzureSubmitSuccess") @mock.patch('uw_adsel.AdSel.get_now', side_effect=mocked_get_now) def test_get_quarters(self, mock_obj): diff --git a/uw_adsel/tests/test_adselazure.py b/uw_adsel/tests/test_adselazure.py new file mode 100644 index 0000000..2e7ef17 --- /dev/null +++ b/uw_adsel/tests/test_adselazure.py @@ -0,0 +1,13 @@ +from unittest import TestCase +from uw_adsel import AdSelAzure +from uw_adsel.models import CohortAssignment + + +class AdselTest(TestCase): + adsel = AdSelAzure() + + def test_assign_cohort(self): + cohort = CohortAssignment(cohort_number=1, campus=2) + submit = self.adsel.assign_cohorts_manual(cohort) + self.assertEqual(submit['response']['summaryPostStatus'], + "AzureSubmitSuccess")