Skip to content

Commit

Permalink
Merge pull request #1693 from uw-it-aca/feature/MUWM-4653
Browse files Browse the repository at this point in the history
Feature/muwm 4653
  • Loading branch information
devights authored Feb 3, 2020
2 parents 48da6a5 + c805726 commit 9f56cd8
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 1 deletion.
52 changes: 52 additions & 0 deletions myuw/test/api/test_affiliation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import json
from myuw.test.api import MyuwApiTest, require_url


class TestApiAffiliation(MyuwApiTest):

@require_url('myuw_affiliation')
def test_javerage(self):
self.set_user('fffjjj')
response = self.get_response_by_reverse('myuw_affiliation')
self.assertEquals(response.status_code, 400)

self.set_user('javerage')
response = self.get_response_by_reverse('myuw_affiliation')
self.assertEquals(response.status_code, 200)
data = json.loads(response.content)
self.assertEquals(data["class_level"], "SENIOR")
self.assertFalse(data["instructor"])
self.assertFalse(data["applicant"])
self.assertFalse(data["grad"])
self.assertFalse(data["grad_c2"])
self.assertFalse(data["undergrad_c2"])
self.assertFalse(data["employee"])
self.assertFalse(data["faculty"])
self.assertFalse(data["clinician"])
self.assertFalse(data["staff_employee"])
self.assertFalse(data["bothell"])
self.assertFalse(data["tacoma"])
self.assertFalse(data["F1"])
self.assertFalse(data["J1"])
self.assertFalse(data["intl_stud"])
self.assertFalse(data["fyp"])
self.assertFalse(data["aut_transfer"])
self.assertFalse(data["win_transfer"])
self.assertFalse(data["grad"])
self.assertFalse(data["alum_asso"])
self.assertFalse(data["alumni"])
self.assertFalse(data["retiree"])
self.assertFalse(data["past_employee"])
self.assertFalse(data["past_stud"])
self.assertFalse(data["no_1st_class_affi"])
self.assertFalse(data["official_bothell"])
self.assertFalse(data["official_tacoma"])
self.assertTrue(data["undergrad"])
self.assertTrue(data["registered_stud"])
self.assertTrue(data["pce"])
self.assertTrue(data["stud_employee"])
self.assertTrue(data["seattle"])
self.assertTrue(data["official_seattle"])
self.assertTrue(data["hxt_viewer"])
self.assertTrue(data["enrolled_stud"])
self.assertTrue(data["2fa_permitted"])
6 changes: 5 additions & 1 deletion myuw/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from myuw.views.academic_calendar import academic_calendar
from myuw.views.future_quarters import future_quarters
from myuw.views.textbooks import textbooks
from myuw.views.api.applications import Applications
from myuw.views.category import category
from myuw.views.display_dates import override
from myuw.views.message_admin import manage_messages
Expand All @@ -23,6 +22,8 @@
from myuw.views.husky_experience import husky_experience
from myuw.views.link import outbound_link
from myuw.views.resources import resources
from myuw.views.api.affiliation import Affiliation
from myuw.views.api.applications import Applications
from myuw.views.api.banner_message import CloseBannerMsg, TurnOffPopup
from myuw.views.api.current_schedule import StudClasScheCurQuar
from myuw.views.api.instructor_section import (InstSectionDetails,
Expand Down Expand Up @@ -99,6 +100,9 @@
re_path(r'^api/v1/academic_events/current/$',
AcademicEvents.as_view(), {'current': True},
name="myuw_academic_calendar_current"),
re_path(r'^api/v1/affiliation/?$',
Affiliation.as_view(),
name="myuw_affiliation"),
re_path(r'^api/v1/book/current/?$',
TextbookCur.as_view(),
name="myuw_current_book"),
Expand Down
41 changes: 41 additions & 0 deletions myuw/views/api/affiliation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import logging
import traceback
from myuw.dao.affiliation import get_all_affiliations
from myuw.dao.user import get_updated_user
from myuw.logger.timer import Timer
from myuw.logger.logresp import log_api_call, log_exception
from myuw.views import prefetch_resources
from myuw.views.error import handle_exception, unknown_uwnetid
from myuw.views.api import ProtectedAPI

logger = logging.getLogger(__name__)


class Affiliation(ProtectedAPI):

def get(self, request, *args, **kwargs):
"""
Performs actions on resource at /api/v1/affiliation/.
GET returns 200 with the current user's affiliation
@return status 401: no valid authentication token
status 543: data error
"""
timer = Timer()
try:
person = get_updated_user(request)
except Exception as ex:
log_exception(logger, str(ex), traceback.format_exc(chain=False))
return unknown_uwnetid()

try:
prefetch_resources(request,
prefetch_group=True,
prefetch_enrollment=True,
prefetch_instructor=True,
prefetch_sws_person=True)

resp = get_all_affiliations(request)
log_api_call(timer, request, "Get Affiliation")
return self.json_response(resp)
except Exception:
handle_exception(logger, timer, traceback)

0 comments on commit 9f56cd8

Please sign in to comment.