Skip to content

Commit

Permalink
Merge pull request #22 from uw-it-aca/fix/is-src-pce
Browse files Browse the repository at this point in the history
handle more more cases
  • Loading branch information
jlaney committed Apr 21, 2017
2 parents 3d92f49 + a1379c5 commit 1042839
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
19 changes: 9 additions & 10 deletions uw_sws/enrollment.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def _json_to_enrollment(json_data, term):
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.is_enroll_src_pce = is_src_location_pce(json_data,
ENROLLMENT_SOURCE_PCE)

enrollment.independent_start_sections = []
if json_data.get('Registrations') is not None and\
Expand Down Expand Up @@ -137,8 +137,8 @@ def _json_to_independent_start_section(json_data, aterm):
except Exception:
is_section.start_date = ""

is_section.is_reg_src_pce = is_reg_src_pce(json_data,
REGISTRATION_SOURCE_PCE)
is_section.is_reg_src_pce = is_src_location_pce(json_data,
REGISTRATION_SOURCE_PCE)
return is_section


Expand All @@ -163,14 +163,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
15 changes: 15 additions & 0 deletions uw_sws/tests/test_enrollment.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from uw_sws.term import get_current_term, get_next_term,\
get_term_by_year_and_quarter, get_term_after
from uw_sws.enrollment import get_grades_by_regid_and_term,\
is_src_location_pce, ENROLLMENT_SOURCE_PCE,\
get_enrollment_by_regid_and_term, enrollment_search_by_regid
from restclients_core.exceptions import DataFailureException

Expand Down Expand Up @@ -46,6 +47,20 @@ def test_javerage_major(self):
self.assertFalse(enrollement.has_independent_start_course())
self.assertFalse(enrollement.is_enroll_src_pce)

def test_is_src_location_pce(self):
self.assertFalse(is_src_location_pce(
{'Metadata': ''},
ENROLLMENT_SOURCE_PCE))
self.assertFalse(is_src_location_pce(
{'Metadata': "EnrollmentSourceLocation=SDB;"},
ENROLLMENT_SOURCE_PCE))
self.assertTrue(is_src_location_pce(
{'Metadata': "EnrollmentSourceLocation=SDB_EOS"},
ENROLLMENT_SOURCE_PCE))
self.assertTrue(is_src_location_pce(
{'Metadata': "EnrollmentSourceLocation=EOS"},
ENROLLMENT_SOURCE_PCE))

def test_offterm_enrolled_courses(self):
term = get_term_by_year_and_quarter(2013, 'winter')
enrollement = get_enrollment_by_regid_and_term(
Expand Down

0 comments on commit 1042839

Please sign in to comment.