Skip to content

Commit

Permalink
Merge pull request #308 from uw-it-aca/qa
Browse files Browse the repository at this point in the history
Qa
  • Loading branch information
fanglinfang committed Mar 15, 2016
2 parents 34da559 + d494e78 commit 1e6d524
Show file tree
Hide file tree
Showing 196 changed files with 3,068 additions and 1,319 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
source = myuw
28 changes: 17 additions & 11 deletions myuw/dao/affiliation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@
import os
import json
import logging
import traceback
from django.conf import settings
from myuw.logger.logback import log_info
from myuw.logger.logback import log_info, log_exception
from myuw.dao.schedule import get_current_quarter_schedule
from myuw.dao.pws import get_netid_of_current_user
from myuw.dao.gws import is_grad_student, is_undergrad_student
from myuw.dao.gws import is_pce_student, is_student_employee, is_employee
from myuw.dao.gws import is_seattle_student, is_bothell_student
from myuw.dao.gws import is_tacoma_student, is_faculty
from myuw.dao.gws import is_grad_student, is_undergrad_student, is_student,\
is_pce_student, is_student_employee, is_employee, is_faculty,\
is_seattle_student, is_bothell_student, is_tacoma_student
from myuw.dao.enrollment import get_main_campus
from myuw.models import UserMigrationPreference

logger = logging.getLogger(__name__)

logger = logging.getLogger(__name__)
MANDATORY_SWITCH = "mandatory_switch"
OPTIN_SWITCH = "optin_switch"


def get_all_affiliations(request):
"""
return a dictionary of affiliation indicators.
["student"]: True if the user is currently an UW student.
["grad"]: True if the user is currently an UW graduate student.
["undergrad"]: True if the user is currently an UW undergraduate student.
["pce"]: True if the user is currently an UW PCE student.
Expand All @@ -50,15 +51,15 @@ def get_all_affiliations(request):

enrolled_campuses = get_current_quarter_course_campuses(request)
is_fyp = False

try:
is_fyp = is_mandatory_switch_user()
except Exception as ex:
# This fails in unit tests w/o userservice
is_fyp = False
pass

data = {"grad": is_grad_student(),
"undergrad": is_undergrad_student(),
"student": is_student(),
"pce": is_pce_student(),
"stud_employee": is_student_employee(),
"employee": is_employee(),
Expand Down Expand Up @@ -110,8 +111,6 @@ def _get_official_campuses(campuses):
official_campuses = {'official_seattle': False,
'official_bothell': False,
'official_tacoma': False}
if campuses is None:
return {}
for campus in campuses:
if campus == "Seattle":
official_campuses['official_seattle'] = True
Expand All @@ -127,7 +126,14 @@ def get_current_quarter_course_campuses(request):
Returns a dictionary indicating the campuses that the student
has enrolled in the current quarter.
"""
return _get_campuses_by_schedule(get_current_quarter_schedule(request))
try:
current_quarter_sche = get_current_quarter_schedule(request)
except Exception as ex:
log_exception(logger,
'get_current_quarter_course_campuses',
traceback.format_exc())
current_quarter_sche = None
return _get_campuses_by_schedule(current_quarter_sche)


def get_base_campus(request):
Expand Down
3 changes: 1 addition & 2 deletions myuw/dao/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ def get_buildings_by_schedule(schedule):
for the given class schedule. Return None if the schedule
contains no section.
"""
if schedule is None or len(schedule.sections) == 0:
return None
buildings = {}

for section in schedule.sections:
if section.final_exam and section.final_exam.building:
code = section.final_exam.building
Expand Down
7 changes: 4 additions & 3 deletions myuw/dao/calendar_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@ def _get_calendars(enrollments):
def _get_enrollments(request):
majors = []
minors = []
try:
enrollment = get_current_quarter_enrollment(request)

enrollment = get_current_quarter_enrollment(request)
if enrollment is not None:
if len(enrollment.majors) > 0:
for major in enrollment.majors:
majors.append(major.major_name)

if len(enrollment.minors) > 0:
for minor in enrollment.minors:
minors.append(minor.short_name)

except Exception:
pass
return {'is_grad': is_grad_student(),
'majors': majors,
'minors': minors}
Expand Down
18 changes: 6 additions & 12 deletions myuw/dao/canvas.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import logging
from restclients.canvas.enrollments import Enrollments as CanvasEnrollments
from restclients.canvas.sections import Sections
from restclients.canvas.courses import Courses
from myuw.dao.pws import get_regid_of_current_user
from myuw.logger.timer import Timer
from myuw.logger.logback import log_resp_time, log_exception
import logging
import traceback


logger = logging.getLogger(__name__)
Expand All @@ -14,23 +13,19 @@
def get_canvas_enrolled_courses():
"""
Returns calendar information for the current term.
Raises: DataFailureException
"""
timer = Timer()
try:
regid = get_regid_of_current_user()
return get_indexed_data_for_regid(regid)
except AttributeError:
# If course is not in canvas, skip
pass
except Exception as ex:
log_exception(logger,
'get_canvas_enrolled_courses',
traceback.format_exc())
return []
finally:
log_resp_time(logger,
'get_canvas_enrolled_courses',
timer)
return []


def get_indexed_data_for_regid(regid):
Expand All @@ -43,18 +38,17 @@ def get_indexed_data_for_regid(regid):


def get_indexed_by_decrosslisted(by_primary, sws_sections):

for section in sws_sections:
base_id = section.section_label()
alternate_id = None
try:
sis_id = section.canvas_section_sis_id()
canvas_section = Sections().get_section_by_sis_id(sis_id)
primary_course = Courses().get_course(canvas_section.course_id)
alternate_id = primary_course.sws_course_id()
except Exception as ex:
alternate_id = section.section_label()

base_id = section.section_label()
# primary section doesn't have canvas_section_sis_id
alternate_id = base_id

if base_id not in by_primary:
if alternate_id in by_primary:
Expand Down
26 changes: 25 additions & 1 deletion myuw/dao/card_display_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
https://docs.google.com/document/d/14q26auOLPU34KFtkUmC_bkoo5dAwegRzgpwmZEQMhaU
"""

import logging
from django.conf import settings
from datetime import datetime, timedelta
from myuw.dao.term import get_comparison_datetime,\
Expand All @@ -14,6 +15,10 @@
get_eod_7d_after_class_start, get_eod_current_term_last_final_exam
from myuw.dao.term import get_bod_class_start_quarter_after as\
get_bod_quarter_after
from myuw.dao.iasystem import in_coursevel_fetch_window


logger = logging.getLogger(__name__)


def in_show_grades_period(term, request):
Expand Down Expand Up @@ -65,6 +70,7 @@ def get_values_by_date(now, request):
"is_after_summer_b": is_in_summer_b_term(request),
"current_summer_term": "%s,%s" % (last_term.year, "summer"),
"last_term": "%s,%s" % (last_term.year, last_term.quarter),
"in_coursevel_fetch_window": in_coursevel_fetch_window(request),
}


Expand All @@ -73,6 +79,9 @@ def is_before_bof_term(now, request):
The term switches after the grade submission deadline.
@return true if it is before the begining of the 1st day of instruction
"""
logger.debug("%s is_before_bof_term %s ==> %s" % (
now, get_bod_current_term_class_start(request),
now < get_bod_current_term_class_start(request)))
return now < get_bod_current_term_class_start(request)


Expand All @@ -81,6 +90,9 @@ def is_before_eof_7d_after_class_start(now, request):
@return true if it is before the end of the 7 days
after the instruction start day
"""
logger.debug("%s is_before_eof_7d_after_class_start %s ==> %s" % (
now, get_eod_7d_after_class_start(request),
now < get_eod_7d_after_class_start(request)))
return now < get_eod_7d_after_class_start(request)


Expand All @@ -89,27 +101,38 @@ def is_after_7d_before_last_instruction(now, request):
@return true if it is after the begining of 7 days
before instruction end
"""
logger.debug("%s is_after_7d_before_last_instruction %s ==> %s" % (
now, get_bod_7d_before_last_instruction(request),
now > get_bod_7d_before_last_instruction(request)))
return now > get_bod_7d_before_last_instruction(request)


def is_before_last_day_of_classes(now, request):
"""
@return true if it is before the end of the last day of classes
"""
logger.debug("%s is_before_last_day_of_classes %s ==> %s" % (
now, get_eod_current_term_last_instruction(request),
now < get_eod_current_term_last_instruction(request)))
return now < get_eod_current_term_last_instruction(request)


def is_after_last_day_of_classes(now, request):
"""
@return true if it is on or after the last day of classes
"""
logger.debug("%s is_after_last_day_of_classes ==> %s" % (
now, (not is_before_last_day_of_classes(now, request))))
return not is_before_last_day_of_classes(now, request)


def is_before_eof_finals_week(now, request):
"""
@return true if it is before the end of the last day of finalsweek
"""
logger.debug("%s is_before_eof_finals_week %s ==> %s" % (
now, get_eod_current_term_last_final_exam(request),
now < get_eod_current_term_last_final_exam(request)))
return now < get_eod_current_term_last_final_exam(request)


Expand Down Expand Up @@ -190,7 +213,8 @@ def set_js_overrides(request, values):
'myuw_before_end_of_reg_display': before_reg,
'myuw_before_first_day': 'is_before_first_day_of_term',
'myuw_before_end_of_first_week': 'is_before_eof_7days_of_term',
'myuw_after_eval_start': 'is_after_7d_before_last_instruction'
'myuw_after_eval_start': 'is_after_7d_before_last_instruction',
'myuw_in_coursevel_fetch_window': 'in_coursevel_fetch_window'
}

for key, value in MAP.iteritems():
Expand Down
28 changes: 7 additions & 21 deletions myuw/dao/course_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""

import logging
import traceback
from myuw.models import CourseColor
from myuw.dao.pws import get_regid_of_current_user
from myuw.logger.timer import Timer
Expand All @@ -20,26 +19,13 @@ def get_colors_by_schedule(schedule):


def get_colors_by_regid_and_schedule(regid, schedule):
if schedule is None or len(schedule.sections) == 0:
return None
timer = Timer()
try:
return _indexed_colors_by_section_label(
CourseColor.objects.filter(
regid=regid,
year=schedule.term.year,
quarter=schedule.term.quarter),
regid,
schedule)
except Exception as ex:
log_exception(logger,
'query CourseColor',
traceback.format_exc())
finally:
log_resp_time(logger,
'query CourseColor',
timer)
return None
return _indexed_colors_by_section_label(
CourseColor.objects.filter(
regid=regid,
year=schedule.term.year,
quarter=schedule.term.quarter),
regid,
schedule)


def _indexed_colors_by_section_label(query, regid, schedule):
Expand Down
13 changes: 4 additions & 9 deletions myuw/dao/enrollment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""

import logging
import traceback
from restclients.sws.enrollment import get_enrollment_by_regid_and_term
from myuw.logger.timer import Timer
from myuw.logger.logback import log_resp_time, log_exception, log_info
Expand All @@ -23,22 +22,18 @@ def get_current_quarter_enrollment(request):
try:
return get_enrollment_by_regid_and_term(regid,
get_current_quarter(request))
except Exception:
log_exception(logger,
id,
traceback.format_exc())
finally:
log_resp_time(logger,
id,
timer)
return None


def get_main_campus(request):
enrollment = get_current_quarter_enrollment(request)
if enrollment is None:
return None
campuses = []
try:
enrollment = get_current_quarter_enrollment(request)
except Exception:
return campuses
for major in enrollment.majors:
campuses.append(major.campus)
return campuses
6 changes: 0 additions & 6 deletions myuw/dao/finance.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""

import logging
import traceback
from restclients.sws.financial import get_account_balances_by_regid
from myuw.logger.timer import Timer
from myuw.logger.logback import log_resp_time, log_exception, log_info
Expand All @@ -25,15 +24,10 @@ def _get_account_balances_by_regid(user_regid):
id = "%s %s" % ('_get_account_balances_by_regid', user_regid)
try:
return get_account_balances_by_regid(user_regid)
except Exception:
log_exception(logger,
id,
traceback.format_exc())
finally:
log_resp_time(logger,
id,
timer)
return None


def get_account_balances_for_current_user():
Expand Down
Loading

0 comments on commit 1e6d524

Please sign in to comment.