Skip to content

Commit

Permalink
Merge pull request #24 from uw-it-aca/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jlaney committed Apr 28, 2017
2 parents 605b9f9 + b817ef8 commit b164d19
Show file tree
Hide file tree
Showing 11 changed files with 439 additions and 1,210 deletions.
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
'mock',
'python-dateutil',
'pytz',
'lxml',
'Jinja2',
],
license='Apache License, Version 2.0',
description=('A library for connecting to the SWS at the University '
Expand Down
60 changes: 1 addition & 59 deletions uw_sws/dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import re
import random
from datetime import date, datetime, timedelta
from lxml import etree
from commonconf import settings
from os.path import abspath, dirname
import os
Expand Down Expand Up @@ -37,64 +36,7 @@ def _edit_mock_response(self, method, url, headers, body, response):
self._update_put(url, body, response)

def _update_put(self, url, body, response):
# For developing against crashes in grade submission
if re.match('/student/v\d/graderoster/2013,spring,ZERROR,101,S1,',
url):
response.data = "No employee found for ID 1234567890"
response.status = 500

# Submitted too late, sad.
if re.match('/student/v\d/graderoster/2013,spring,ZERROR,101,S2,',
url):
response.data = "grading period not active for year/quarter"
response.status = 404

if body is not None:
response.status = 200
response.headers = {"X-Data-Source": "SWS file mock data"}
response.data = self._make_grade_roster_submitted(body)
else:
response.status = 400
response.data = "Bad Request: no PUT body"

def _make_grade_roster_submitted(self, submitted_body):
root = etree.fromstring(submitted_body)
item_elements = root.findall('.//*[@class="graderoster_item"]')
for item in item_elements:
date_graded = item.find('.//*[@class="date_graded date"]')
if date_graded.text is None:
date_graded.text = '2013-06-01'

grade_submitter_source = item.find(
'.//*[@class="grade_submitter_source"]')
if grade_submitter_source.text is None:
grade_submitter_source.text = 'WEBCGB'

# Set the status code and message for each item, these elements
# aren't present in graderosters returned from GET
# Use settings.GRADEROSTER_PARTIAL_SUBMISSIONS to simulate failures
status_code_text = '200'
status_message_text = ''
if (getattr(settings,
'GRADEROSTER_PARTIAL_SUBMISSIONS',
False) and random.choice([True, False])):

status_code_text = '500'
status_message_text = 'Invalid grade'

status_code = item.find('.//*[@class="code"]')
if status_code is None:
status_code = etree.fromstring('<span class="code"/>')
item.append(status_code)
status_code.text = status_code_text

status_message = item.find('.//*[@class="message"]')
if status_message is None:
status_message = etree.fromstring('<span class="message"/>')
item.append(status_message)
status_message.text = status_message_text

return etree.tostring(root)
pass

def _update_get(self, url, response):
if "/student/v5/notice" in url:
Expand Down
68 changes: 34 additions & 34 deletions uw_sws/enrollment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from uw_pws import PWS
from uw_sws.models import (StudentGrades, StudentCourseGrade, Enrollment,
Major, Minor, SectionReference, Term,
IndependentStartSectionReference)
OffTermSectionReference)
from uw_sws import get_resource, parse_sws_date
from uw_sws.section import get_section_by_url
from uw_sws.term import get_term_by_year_and_quarter
Expand Down Expand Up @@ -89,21 +89,30 @@ def get_enrollment_by_regid_and_term(regid, term):
return _json_to_enrollment(get_resource(url), term)


def has_start_end_dates(registration_json_data):
start_date = registration_json_data.get('StartDate')
end_date = registration_json_data.get('EndDate')
return (start_date is not None and len(start_date) > 0 and
end_date is not None and len(start_date) > 0)


def _json_to_enrollment(json_data, term):
enrollment = Enrollment()
enrollment.regid = json_data['RegID']
enrollment.class_level = json_data['ClassLevel']
enrollment.is_honors = json_data['HonorsProgram']
enrollment.is_enroll_src_pce = is_reg_src_pce(json_data,
ENROLLMENT_SOURCE_PCE)

enrollment.independent_start_sections = []
if json_data.get('Registrations') is not None and\
len(json_data['Registrations']) > 0:
for registration in json_data['Registrations']:
if registration.get('IsIndependentStart'):
enrollment.independent_start_sections.append(
_json_to_independent_start_section(registration, term))
enrollment.is_enroll_src_pce = is_src_location_pce(json_data,
ENROLLMENT_SOURCE_PCE)
enrollment.off_term_sections = {}
# dictionary {section_label: OffTermSectionReference}
if enrollment.is_enroll_src_pce:
if json_data.get('Registrations') is not None and\
len(json_data['Registrations']) > 0:
for registration in json_data['Registrations']:
if has_start_end_dates(registration):
ot_section = _json_to_off_term_section(registration, term)
key = ot_section.section_ref.section_label()
enrollment.off_term_sections[key] = ot_section

enrollment.majors = []
if json_data.get('Majors') is not None and len(json_data['Majors']) > 0:
Expand All @@ -117,29 +126,21 @@ def _json_to_enrollment(json_data, term):
return enrollment


def _json_to_independent_start_section(json_data, aterm):
is_section = IndependentStartSectionReference()
is_section.section_ref = SectionReference(
def _json_to_off_term_section(json_data, aterm):
ot_section = OffTermSectionReference()
ot_section.section_ref = SectionReference(
term=aterm,
curriculum_abbr=json_data['Section']['CurriculumAbbreviation'],
course_number=json_data['Section']['CourseNumber'],
section_id=json_data['Section']['SectionID'],
url=json_data['Section']['Href']
)
is_section.feebase_type = json_data['FeeBaseType']
try:
is_section.end_date = parse_sws_date(json_data['EndDate'])
except Exception:
is_section.end_date = ""

try:
is_section.start_date = parse_sws_date(json_data['StartDate'])
except Exception:
is_section.start_date = ""

is_section.is_reg_src_pce = is_reg_src_pce(json_data,
REGISTRATION_SOURCE_PCE)
return is_section
ot_section.start_date = parse_sws_date(json_data['StartDate'])
ot_section.end_date = parse_sws_date(json_data['EndDate'])
ot_section.feebase_type = json_data['FeeBaseType']
ot_section.is_reg_src_pce = is_src_location_pce(json_data,
REGISTRATION_SOURCE_PCE)
return ot_section


def _json_to_major(json_data):
Expand All @@ -163,14 +164,13 @@ def _json_to_minor(json_data):
return minor


ENROLLMENT_SOURCE_PCE = re.compile('^EnrollmentSourceLocation=SDB_EOS;',
re.I)
REGISTRATION_SOURCE_PCE = re.compile('^RegistrationSourceLocation=SDB_EOS;',
re.I)
ENROLLMENT_SOURCE_PCE = re.compile('^EnrollmentSourceLocation=', re.I)
REGISTRATION_SOURCE_PCE = re.compile('^RegistrationSourceLocation=', re.I)


def is_reg_src_pce(json_data, pattern):
def is_src_location_pce(json_data, pattern):
try:
return re.match(pattern, json_data['Metadata']) is not None
return (re.match(pattern, json_data['Metadata']) is not None and
"EOS" in json_data['Metadata'])
except KeyError:
return False
188 changes: 0 additions & 188 deletions uw_sws/graderoster.py

This file was deleted.

Loading

0 comments on commit b164d19

Please sign in to comment.