Repository: ucfopen/canvasapi

Issue:
AssignmentOverride sub-objects in Assignment
When an `Assignment` object contains an attribute `"overrides"`, parse the data as a list of `AssignmentOverride` objects, rather than a list of dicts.

This will be essentially a limited implementation of what we want to do with #56.

Keep #303 and its ramifications in mind.

Discussion:
coveralls: 
[![Coverage Status](https://coveralls.io/builds/27085263/badge)](https://coveralls.io/builds/27085263)

Coverage remained the same at 100.0% when pulling **661abd08d858d1a976af516f78095295cdeeec42 on Thetwam:issue/307-assignment-override-sub-objects** into **b27475309446415fa428e253c2163e0469805cf3 on ucfopen:develop**.


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 62ec157..05bcd18 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@
 ### General
 
 - Throw `IndexError` when using negative indexes on `PaginatedList` objects (Thanks, [@UniversalSuperBox](https://github.com/UniversalSuperBox))
+- `Assignment.overrides` now returns a list of `AssignmentOverride` objects.
 
 ### Deprecation Warnings
 
diff --git a/canvasapi/assignment.py b/canvasapi/assignment.py
index 3637e8f..93f413e 100644
--- a/canvasapi/assignment.py
+++ b/canvasapi/assignment.py
@@ -16,6 +16,15 @@ from canvasapi.util import combine_kwargs, obj_or_id
 
 @python_2_unicode_compatible
 class Assignment(CanvasObject):
+    def __init__(self, requester, attributes):
+        super(Assignment, self).__init__(requester, attributes)
+
+        if "overrides" in attributes:
+            self.overrides = [
+                AssignmentOverride(requester, override)
+                for override in attributes["overrides"]
+            ]
+
     def __str__(self):
         return "{} ({})".format(self.name, self.id)
 


Test patch:
diff --git a/tests/fixtures/assignment.json b/tests/fixtures/assignment.json
index 3fc2885..e457e63 100644
--- a/tests/fixtures/assignment.json
+++ b/tests/fixtures/assignment.json
@@ -255,6 +255,27 @@
 		},
 		"status_code": 200
 	},
+	"get_assignment_with_overrides": {
+		"method": "GET",
+		"endpoint": "courses/1/assignments/1",
+		"data": {
+			"id": 1,
+			"course_id": 1,
+			"name": "Assignment 1",
+			"description": "Do this assignment",
+			"overrides": [
+				{
+					"id": 1,
+					"assignment_id": 1,
+					"student_ids": [1],
+					"group_id": 1,
+					"course_section_id": 1,
+					"title": "Assignment Override 1"
+				}
+			]
+		},
+		"status_code": 200
+	},
 	"override_group_alias": {
 		"method": "GET",
 		"endpoint": "groups/1/assignments/1/override",
diff --git a/tests/test_assignment.py b/tests/test_assignment.py
index d272a92..3ddab02 100644
--- a/tests/test_assignment.py
+++ b/tests/test_assignment.py
@@ -31,6 +31,16 @@ class TestAssignment(unittest.TestCase):
             self.course = self.canvas.get_course(1)
             self.assignment = self.course.get_assignment(1)
 
+    def test__init__overrides(self, m):
+        register_uris({"assignment": ["get_assignment_with_overrides"]}, m)
+
+        assignment = self.course.get_assignment(1)
+
+        self.assertTrue(hasattr(assignment, "overrides"))
+        self.assertIsInstance(assignment.overrides, list)
+        self.assertEqual(len(assignment.overrides), 1)
+        self.assertIsInstance(assignment.overrides[0], AssignmentOverride)
+
     # create_override()
     def test_create_override(self, m):
         register_uris({"assignment": ["create_override"]}, m)