Skip to content

Commit

Permalink
Merge pull request #52 from ucfopen/develop
Browse files Browse the repository at this point in the history
Release v0.6.0
  • Loading branch information
Thetwam authored Aug 15, 2017
2 parents af2c080 + eec6992 commit 84f7963
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 12 deletions.
2 changes: 2 additions & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ Patches and Suggestions
=======================
- Adrian Goetz [@a-goetz](https://github.com/a-goetz)
- Anthony Rodriguez [@AnthonyRodriguez726](https://github.com/AnthonyRodriguez726)
- Daniel Grobani [@dgrobani](https://github.com/dgrobani)
- Devin Singh [@devints47](https://github.com/devints47)
- Elise Heron [@thedarkestknight](https://github.com/thedarkestknight)
- Ian Turgeon [@iturgeon](https://github.com/iturgeon)
- John Raible [@rebelaide](https://github.com/rebelaide)
- Nathan Dabu [@nathaned](https://github.com/nathaned)
- Philip Carter [@phillyc](https://github.com/phillyc)
- Sigurður Baldursson [@sigurdurb](https://github.com/sigurdurb)
- Tuan Pham [@tuanvpham](https://github.com/tuanvpham)
- William Funk [@WilliamRADFunk](https://github.com/WilliamRADFunk)
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [0.6.0] - 2017-08-15
### General
- Added support for SIS IDs to get accounts, courses, groups and sections. (Thanks for the suggestion, [@sigurdurb](https://github.com/sigurdurb)!)

## [0.5.1] - 2017-08-02
### General
- Moved documentation to [Read the Docs](http://canvasapi.readthedocs.io).
Expand Down Expand Up @@ -107,6 +111,7 @@
- Fixed some incorrectly defined parameters
- Fixed an issue where tests would fail due to an improperly configured requires block

[0.6.0]: https://github.com/ucfopen/canvasapi/compare/v0.5.1...v0.6.0
[0.5.1]: https://github.com/ucfopen/canvasapi/compare/v0.5.0...v0.5.1
[0.5.0]: https://github.com/ucfopen/canvasapi/compare/v0.4.0...v0.5.0
[0.4.0]: https://github.com/ucfopen/canvasapi/compare/v0.3.0...v0.4.0
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[![CanvasAPI on PyPI](https://img.shields.io/pypi/v/canvasapi.svg)](https://pypi.python.org/pypi/canvasapi)
[![License](https://img.shields.io/pypi/l/canvasapi.svg)](https://pypi.python.org/pypi/canvasapi)
[![Python Versions](https://img.shields.io/pypi/pyversions/canvasapi.svg)](https://pypi.python.org/pypi/canvasapi)
[![Documentation Status](https://readthedocs.org/projects/canvasapi/badge/?version=latest)](http://canvasapi.readthedocs.io/en/latest/?badge=latest)
[![Build Status](https://travis-ci.org/ucfopen/canvasapi.svg?branch=master)](https://travis-ci.org/ucfopen/canvasapi)
[![Coverage Status](https://coveralls.io/repos/github/ucfopen/canvasapi/badge.svg?branch=master)](https://coveralls.io/github/ucfopen/canvasapi?branch=master)
Expand Down
2 changes: 1 addition & 1 deletion canvasapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

__all__ = ["Canvas"]

__version__ = '0.5.1'
__version__ = '0.6.0'
63 changes: 52 additions & 11 deletions canvasapi/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from canvasapi.group import Group, GroupCategory
from canvasapi.paginated_list import PaginatedList
from canvasapi.requester import Requester
from canvasapi.section import Section
from canvasapi.user import User
from canvasapi.util import combine_kwargs

Expand Down Expand Up @@ -42,20 +43,30 @@ def create_account(self, **kwargs):
)
return Account(self.__requester, response.json())

def get_account(self, account_id):
def get_account(self, account_id, use_sis_id=False, **kwargs):
"""
Retrieve information on an individual account.
:calls: `GET /api/v1/accounts/:id \
<https://canvas.instructure.com/doc/api/accounts.html#method.accounts.show>`_
:param account_id: The ID of the account to retrieve.
:type account_id: int
:type account_id: int or str
:param use_sis_id: Whether or not account_id is an sis ID.
Defaults to `False`.
:type use_sis_id: bool
:rtype: :class:`canvasapi.account.Account`
"""
if use_sis_id:
uri_str = 'accounts/sis_account_id:{}'
else:
uri_str = 'accounts/{}'

response = self.__requester.request(
'GET',
'accounts/%s' % (account_id)
uri_str.format(account_id),
**combine_kwargs(**kwargs)
)
return Account(self.__requester, response.json())

Expand Down Expand Up @@ -102,20 +113,28 @@ def get_course_accounts(self):
'course_accounts',
)

def get_course(self, course_id, **kwargs):
def get_course(self, course_id, use_sis_id=False, **kwargs):
"""
Retrieve a course by its ID.
:calls: `GET /courses/:id \
<https://canvas.instructure.com/doc/api/courses.html#method.courses.show>`_
:param course_id: The ID of the course to retrieve.
:type course_id: int
:type course_id: int or str
:param use_sis_id: Whether or not course_id is an sis ID.
Defaults to `False`.
:type use_sis_id: bool
:rtype: :class:`canvasapi.course.Course`
"""
if use_sis_id:
uri_str = 'courses/sis_course_id:{}'
else:
uri_str = 'courses/{}'

response = self.__requester.request(
'GET',
'courses/%s' % (course_id),
uri_str.format(course_id),
**combine_kwargs(**kwargs)
)
return Course(self.__requester, response.json())
Expand Down Expand Up @@ -251,19 +270,30 @@ def get_course_nickname(self, course_id):
)
return CourseNickname(self.__requester, response.json())

def get_section(self, section_id):
def get_section(self, section_id, use_sis_id=False, **kwargs):
"""
Get details about a specific section.
:calls: `GET /api/v1/sections/:id \
<https://canvas.instructure.com/doc/api/sections.html#method.sections.show>`_
:param section_id: The ID of the section to get.
:type section_id: int or str
:param use_sis_id: Whether or not section_id is an sis ID.
Defaults to `False`.
:type use_sis_id: bool
:rtype: :class:`canvasapi.section.Section`
"""
from canvasapi.section import Section
if use_sis_id:
uri_str = 'sections/sis_section_id:{}'
else:
uri_str = 'sections/{}'

response = self.__requester.request(
'GET',
'sections/%s' % (section_id)
uri_str.format(section_id),
**combine_kwargs(**kwargs)
)
return Section(self.__requester, response.json())

Expand Down Expand Up @@ -340,19 +370,30 @@ def create_group(self, **kwargs):
)
return Group(self.__requester, response.json())

def get_group(self, group_id, **kwargs):
def get_group(self, group_id, use_sis_id=False, **kwargs):
"""
Return the data for a single group. If the caller does not
have permission to view the group a 401 will be returned.
:calls: `GET /api/v1/groups/:group_id \
<https://canvas.instructure.com/doc/api/groups.html#method.groups.show>`_
:param group_id: The ID of the group to get.
:type group_id: int or str
:param use_sis_id: Whether or not group_id is an sis ID.
Defaults to `False`.
:type use_sis_id: bool
:rtype: :class:`canvasapi.group.Group`
"""
if use_sis_id:
uri_str = 'groups/sis_group_id:{}'
else:
uri_str = 'groups/{}'

response = self.__requester.request(
'GET',
'groups/%s' % (group_id),
uri_str.format(group_id),
**combine_kwargs(**kwargs)
)
return Group(self.__requester, response.json())
Expand Down
15 changes: 15 additions & 0 deletions tests/fixtures/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,21 @@
},
"status_code": 200
},
"get_by_sis_id": {
"method": "GET",
"endpoint": "accounts/sis_account_id:test-sis-id",
"data": {
"id": 10,
"sis_account_id": "test-sis-id",
"name": "Account From SIS",
"parent_account_id": null,
"root_account_id": null,
"default_storage_quota_mb": 500,
"default_user_storage_quota_mb": 50,
"default_group_storage_quota_mb": 50,
"default_time_zone": "America/New_York"
}
},
"get_courses": {
"method": "GET",
"endpoint": "accounts/1/courses",
Expand Down
16 changes: 16 additions & 0 deletions tests/fixtures/course.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,22 @@
},
"status_code": 200
},
"get_by_sis_id": {
"method": "GET",
"endpoint": "courses/sis_course_id:test-sis-id",
"data": {
"id": 1,
"sis_course_id": "test-sis-id",
"course_code": "SIS101",
"name": "SIS Course",
"workflow_state": "available",
"account_id": 1,
"root_account_id": 1,
"enrollment_term_id": 1,
"grading_standard_id": 1
},
"status_code": 200
},
"get_external_tools": {
"method": "GET",
"endpoint": "courses/1/external_tools",
Expand Down
11 changes: 11 additions & 0 deletions tests/fixtures/group.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
},
"status_code": 200
},
"get_by_sis_id": {
"method": "GET",
"endpoint": "groups/sis_group_id:test-sis-id",
"data": {
"id": 10,
"sis_group_id": "test-sis-id",
"name": "SIS Group",
"description": "best SIS group ever"
},
"status_code": 200
},
"pages_get_page": {
"method": "GET",
"endpoint": "groups/1/pages/my-url",
Expand Down
11 changes: 11 additions & 0 deletions tests/fixtures/section.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@
},
"status_code": 200
},
"get_by_sis_id": {
"method": "GET",
"endpoint": "sections/sis_section_id:test-sis-id",
"data":{
"id": 10,
"sis_section_id": "test-sis-id",
"course_id": 1,
"name": "SIS Section"
},
"status_code": 200
},
"list_enrollments": {
"method": "GET",
"endpoint": "sections/1/enrollments",
Expand Down
32 changes: 32 additions & 0 deletions tests/test_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ def test_get_account(self, m):

self.assertIsInstance(account, Account)

def test_get_account_sis_id(self, m):
register_uris({'account': ['get_by_sis_id']}, m)

account = self.canvas.get_account('test-sis-id', use_sis_id=True)

self.assertIsInstance(account, Account)
self.assertEqual(account.name, 'Account From SIS')

def test_get_account_fail(self, m):
register_uris({'generic': ['not_found']}, m)

Expand Down Expand Up @@ -82,6 +90,14 @@ def test_get_course(self, m):
self.assertIsInstance(course, Course)
self.assertTrue(hasattr(course, 'name'))

def test_get_course_sis_id(self, m):
register_uris({'course': ['get_by_sis_id']}, m)

course = self.canvas.get_course('test-sis-id', use_sis_id=True)

self.assertIsInstance(course, Course)
self.assertEqual(course.name, 'SIS Course')

def test_get_course_with_start_date(self, m):
register_uris({'course': ['start_at_date']}, m)

Expand Down Expand Up @@ -225,6 +241,14 @@ def test_get_section(self, m):

self.assertIsInstance(info, Section)

def test_get_section_sis_id(self, m):
register_uris({'section': ['get_by_sis_id']}, m)

section = self.canvas.get_section('test-sis-id', use_sis_id=True)

self.assertIsInstance(section, Section)
self.assertEqual(section.name, 'SIS Section')

# create_group()
def test_create_group(self, m):
register_uris({'group': ['create']}, m)
Expand All @@ -245,6 +269,14 @@ def test_get_group(self, m):
self.assertTrue(hasattr(group, 'name'))
self.assertTrue(hasattr(group, 'description'))

def test_get_group_sis_id(self, m):
register_uris({'group': ['get_by_sis_id']}, m)

group = self.canvas.get_group('test-sis-id', use_sis_id=True)

self.assertIsInstance(group, Group)
self.assertEqual(group.name, 'SIS Group')

# get_group_category()
def test_get_group_category(self, m):
register_uris({'group': ['get_category_by_id']}, m)
Expand Down

0 comments on commit 84f7963

Please sign in to comment.