-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from uw-it-aca/feature/refactor
Feature/refactor
- Loading branch information
Showing
12 changed files
with
376 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[run] | ||
branch = True | ||
source = uw_myplan/ | ||
include = uw_myplan/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
sudo: false | ||
language: python | ||
python: | ||
- '2.7' | ||
- '3.4' | ||
- '3.5' | ||
- '3.6' | ||
before_script: | ||
- pip install -e . | ||
- pip install pep8 | ||
- pip install nose2 | ||
- pip install coverage | ||
- pip install commonconf | ||
- pip install python-coveralls | ||
script: | ||
- pep8 uw_myplan/ --exclude=uw_myplan/tests | ||
- coverage run --source=uw_myplan uw_myplan/test.py -v | ||
after_script: | ||
- coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import os | ||
from setuptools import setup | ||
|
||
README = """ | ||
See the README on `GitHub | ||
<https://github.com/uw-it-aca/uw-restclients-myplan>`_. | ||
""" | ||
|
||
# The VERSION file is created by travis-ci, based on the tag name | ||
version_path = 'uw_myplan/VERSION' | ||
VERSION = open(os.path.join(os.path.dirname(__file__), version_path)).read() | ||
VERSION = VERSION.replace("\n", "") | ||
|
||
# allow setup.py to be run from any path | ||
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir))) | ||
|
||
setup( | ||
name='UW-RestClients-MyPlan', | ||
version=VERSION, | ||
packages=['uw_myplan'], | ||
author="UW-IT AXDD", | ||
author_email="aca-it@uw.edu", | ||
include_package_data=True, | ||
install_requires=['UW-RestClients-Core>0.8,<1.0', | ||
], | ||
license='Apache License, Version 2.0', | ||
description=('A library for connecting to the UW MyPlan API'), | ||
long_description=README, | ||
url="https://github.com/uw-it-aca/uw-restclients-iasystem", | ||
classifiers=[ | ||
'Intended Audience :: Developers', | ||
'License :: OSI Approved :: Apache Software License', | ||
'Operating System :: OS Independent', | ||
'Programming Language :: Python', | ||
'Programming Language :: Python :: 2.7', | ||
'Programming Language :: Python :: 3.4', | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[MyPlan] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
""" | ||
This is the interface for interacting with MyPlan. | ||
https://wiki.cac.washington.edu/display/MyPlan/Plan+Resource+v1 | ||
""" | ||
|
||
from uw_myplan.dao import MyPlan_DAO | ||
from restclients_core.exceptions import DataFailureException | ||
from uw_myplan.models import MyPlan, MyPlanTerm, MyPlanCourse, \ | ||
MyPlanCourseSection | ||
import json | ||
|
||
|
||
def get_plan(regid, year, quarter, terms=4): | ||
dao = MyPlan_DAO() | ||
url = get_plan_url(regid, year, quarter, terms) | ||
|
||
response = dao.getURL(url, {"Accept": "application/json"}) | ||
if response.status != 200: | ||
raise DataFailureException(url, response.status, response.data) | ||
|
||
data = json.loads(response.data) | ||
|
||
plan = MyPlan() | ||
for term_data in data: | ||
term = MyPlanTerm() | ||
term.year = term_data["Term"]["Year"] | ||
term.quarter = term_data["Term"]["Quarter"] | ||
|
||
term.course_search_href = term_data["CourseSearchHref"] | ||
term.degree_audit_href = term_data["DegreeAuditHref"] | ||
term.myplan_href = term_data["MyPlanHref"] | ||
term.registration_href = term_data["RegistrationHref"] | ||
term.registered_courses_count = int( | ||
term_data["RegisteredCoursesCount"]) | ||
term.registered_sections_count = int( | ||
term_data["RegisteredSectionsCount"]) | ||
|
||
for course_data in term_data["Courses"]: | ||
course = MyPlanCourse() | ||
course.curriculum_abbr = course_data["CurriculumAbbreviation"] | ||
course.course_number = course_data["CourseNumber"] | ||
|
||
is_available = course_data["RegistrationAvailable"] | ||
course.registrations_available = is_available | ||
|
||
for section_data in course_data["Sections"]: | ||
section = MyPlanCourseSection() | ||
section.section_id = section_data["SectionId"] | ||
course.sections.append(section) | ||
|
||
term.courses.append(course) | ||
plan.terms.append(term) | ||
return plan | ||
|
||
|
||
def get_plan_url(regid, year, quarter, terms): | ||
return "/student/api/plan/v1/%s,%s,%s,%s" % (year, quarter, terms, regid) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import logging | ||
import os | ||
from os.path import abspath, dirname | ||
from restclients_core.dao import DAO | ||
|
||
|
||
class MyPlan_DAO(DAO): | ||
def service_name(self): | ||
return 'myplan' | ||
|
||
def service_mock_paths(self): | ||
return [abspath(os.path.join(dirname(__file__), "resources"))] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
from restclients_core import models | ||
|
||
|
||
class MyPlan(models.Model): | ||
def __init__(self): | ||
self.terms = [] | ||
|
||
def json_data(self): | ||
data = { | ||
"terms": [] | ||
} | ||
for term in self.terms: | ||
data["terms"].append(term.json_data()) | ||
|
||
return data | ||
|
||
|
||
class MyPlanTerm(models.Model): | ||
SPRING = 'spring' | ||
SUMMER = 'summer' | ||
AUTUMN = 'autumn' | ||
WINTER = 'winter' | ||
|
||
QUARTERNAME_CHOICES = ( | ||
(SPRING, 'Spring'), | ||
(SUMMER, 'Summer'), | ||
(AUTUMN, 'Autumn'), | ||
(WINTER, 'Winter'), | ||
) | ||
|
||
course_search_href = models.CharField(max_length=512) | ||
degree_audit_href = models.CharField(max_length=512) | ||
myplan_href = models.CharField(max_length=512) | ||
registration_href = models.CharField(max_length=512) | ||
registered_courses_count = models.SmallIntegerField( | ||
max_length=3, default=0) | ||
registered_sections_count = models.SmallIntegerField( | ||
max_length=3, default=0) | ||
|
||
def __init__(self): | ||
self.courses = [] | ||
|
||
quarter = models.CharField(max_length=6, | ||
choices=QUARTERNAME_CHOICES) | ||
year = models.PositiveSmallIntegerField() | ||
|
||
def json_data(self): | ||
data = { | ||
"year": self.year, | ||
"quarter": self.quarter, | ||
"course_search_href": self.course_search_href, | ||
"degree_audit_href": self.degree_audit_href, | ||
"myplan_href": self.myplan_href, | ||
"registration_href": self.registration_href, | ||
"registered_courses_count": self.registered_courses_count, | ||
"registered_sections_count": self.registered_sections_count, | ||
"courses": [], | ||
} | ||
|
||
for course in self.courses: | ||
data["courses"].append(course.json_data()) | ||
|
||
return data | ||
|
||
|
||
class MyPlanCourse(models.Model): | ||
def __init__(self): | ||
self.sections = [] | ||
|
||
curriculum_abbr = models.CharField(max_length=6, | ||
db_index=True) | ||
course_number = models.PositiveSmallIntegerField(db_index=True) | ||
registrations_available = models.BooleanField() | ||
|
||
def json_data(self): | ||
data = { | ||
'curriculum_abbr': self.curriculum_abbr, | ||
'course_number': self.course_number, | ||
'registrations_available': self.registrations_available, | ||
'sections': [], | ||
} | ||
|
||
for section in self.sections: | ||
data["sections"].append(section.json_data()) | ||
|
||
return data | ||
|
||
|
||
class MyPlanCourseSection(models.Model): | ||
section_id = models.CharField(max_length=2, | ||
db_index=True) | ||
|
||
def json_data(self): | ||
return { | ||
"section_id": self.section_id | ||
} |
81 changes: 81 additions & 0 deletions
81
.../resources/myplan/file/student/api/plan/v1/2013_spring_4_9136CCB8F66711D5BE060004AC494FFE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
[ | ||
{ | ||
"Term":{"Quarter":"Spring","Year":2013}, | ||
"RegistrationHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/registration/20132", | ||
"MyPlanHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/plan/20132", | ||
"AuditHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/audit", | ||
"PlanAuditHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/audit/plan", | ||
"DegreeAuditHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/audit/degree", | ||
"PlanValidationHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/planValidation/20132", | ||
"CourseSearchHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/course", | ||
"RegisteredCoursesCount":0, | ||
"RegisteredSectionsCount":0, | ||
"Courses":[ | ||
{ | ||
"CurriculumAbbreviation":"CSE", | ||
"CourseNumber":"101", | ||
"RegistrationAvailable":true, | ||
"Sections":[ | ||
{"SectionId":"A"}, | ||
{"SectionId":"AA"}, | ||
{"SectionId":"AB"} | ||
]}, | ||
{ | ||
"CurriculumAbbreviation":"CSE", | ||
"CourseNumber":"102", | ||
"RegistrationAvailable":false, | ||
"Sections":[ | ||
{"SectionId":"A"}, | ||
{"SectionId":"B"}, | ||
{"SectionId":"C"}]}]}, | ||
{ | ||
"Term":{"Quarter":"Summer","Year":2013}, | ||
"RegistrationHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/registration/20133", | ||
"MyPlanHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/plan/20133", | ||
"AuditHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/audit", | ||
"PlanAuditHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/audit/plan", | ||
"DegreeAuditHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/audit/degree", | ||
"PlanValidationHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/planValidation/20133", | ||
"CourseSearchHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/course", | ||
"RegisteredCoursesCount":0, | ||
"RegisteredSectionsCount":0, | ||
"Courses":[ | ||
{ | ||
"CurriculumAbbreviation":"CSE", | ||
"CourseNumber":"110", | ||
"RegistrationAvailable":true, | ||
"Sections":[ | ||
{"SectionId":"A"}] | ||
} | ||
] | ||
}, | ||
{ | ||
"Term":{"Quarter":"Autumn","Year":2013}, | ||
"RegistrationHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/registration/20134", | ||
"MyPlanHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/plan/20134", | ||
"AuditHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/audit", | ||
"PlanAuditHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/audit/plan", | ||
"DegreeAuditHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/audit/degree", | ||
"PlanValidationHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/planValidation/20134", | ||
"CourseSearchHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/course", | ||
"RegisteredCoursesCount":0, | ||
"RegisteredSectionsCount":0, | ||
"Courses":[ | ||
] | ||
}, | ||
{ | ||
"Term":{"Quarter":"Winter","Year":2014}, | ||
"RegistrationHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/registration/20141", | ||
"MyPlanHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/plan/20141", | ||
"AuditHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/audit", | ||
"PlanAuditHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/audit/plan", | ||
"DegreeAuditHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/audit/degree", | ||
"PlanValidationHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/planValidation/20141", | ||
"CourseSearchHref":"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/course", | ||
"RegisteredCoursesCount":0, | ||
"RegisteredSectionsCount":0, | ||
"Courses":[ | ||
] | ||
} | ||
|
||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# This is just a test runner for coverage | ||
from commonconf.backends import use_configparser_backend | ||
from os.path import abspath, dirname | ||
import os | ||
|
||
if __name__ == '__main__': | ||
path = abspath(os.path.join(dirname(__file__), | ||
"..", "travis-ci", "test.conf")) | ||
use_configparser_backend(path, 'MyPlan') | ||
|
||
from nose2 import discover | ||
discover() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from unittest import TestCase | ||
from uw_myplan import get_plan | ||
|
||
|
||
class MyPlanTestData(TestCase): | ||
def test_javerage(self): | ||
plan = get_plan(regid="9136CCB8F66711D5BE060004AC494FFE", year=2013, quarter="spring", terms=4) | ||
self.assertEquals(len(plan.terms), 4) | ||
|
||
self.assertEquals(plan.terms[0].year, 2013) | ||
self.assertEquals(plan.terms[1].year, 2013) | ||
self.assertEquals(plan.terms[2].year, 2013) | ||
self.assertEquals(plan.terms[3].year, 2014) | ||
|
||
self.assertEquals(plan.terms[0].quarter, 'Spring') | ||
self.assertEquals(plan.terms[1].quarter, 'Summer') | ||
self.assertEquals(plan.terms[2].quarter, 'Autumn') | ||
self.assertEquals(plan.terms[3].quarter, 'Winter') | ||
|
||
self.assertEquals(len(plan.terms[0].courses), 2) | ||
self.assertEquals(len(plan.terms[1].courses), 1) | ||
self.assertEquals(len(plan.terms[2].courses), 0) | ||
self.assertEquals(len(plan.terms[3].courses), 0) | ||
term_data = plan.terms[0] | ||
self.assertEquals(term_data.course_search_href, | ||
"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/course") | ||
self.assertEquals(term_data.degree_audit_href, | ||
"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/audit/degree") | ||
self.assertEquals(term_data.myplan_href, | ||
"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/plan/20132") | ||
self.assertEquals(term_data.registration_href, | ||
"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/registration/20132") | ||
self.assertEquals(term_data.registered_courses_count, 0) | ||
self.assertEquals(term_data.registered_sections_count, 0) | ||
self.assertEquals(term_data.courses[0].registrations_available, True) | ||
self.assertEquals(term_data.courses[0].curriculum_abbr, 'CSE') | ||
self.assertEquals(term_data.courses[0].course_number, '101') | ||
self.assertEquals(len(term_data.courses[0].sections), 3) | ||
self.assertEquals(term_data.courses[0].sections[0].section_id, 'A') | ||
self.assertEquals(term_data.courses[0].sections[1].section_id, 'AA') | ||
self.assertEquals(term_data.courses[0].sections[2].section_id, 'AB') | ||
|
||
def test_json(self): | ||
plan = get_plan(regid="9136CCB8F66711D5BE060004AC494FFE", | ||
year=2013, quarter="spring", | ||
terms=4) | ||
json_data = plan.json_data() | ||
term_data = json_data["terms"][0] | ||
self.assertEquals(term_data["courses"][0]["sections"][1]["section_id"], "AA") | ||
self.assertEquals(term_data["registered_courses_count"], 0) | ||
self.assertEquals(term_data["registration_href"], | ||
"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/registration/20132") | ||
self.assertEquals(term_data["course_search_href"], | ||
"https://uwkseval.cac.washington.edu/student/myplan/mplogin/netid?rd=/student/myplan/course") | ||
self.assertEquals(term_data["quarter"], "Spring") |