Repository: ucfopen/canvasapi

Issue:
Rubric Associations
**What resource needs additional coverage?**
Rubric Associations

**What endpoints need to be covered?**
https://canvas.instructure.com/doc/api/rubrics.html

- [ ] Create a Rubric Association
- [ ] Update a Rubric Association
- [ ] Delete a Rubric Association


Discussion:

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 968076d..fe65c86 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,11 @@
 
 ## [Unreleased]
 
+### New Endpoint Coverage
+
+- Quiz Submission Events (Thanks, [@Goff-Davis](https://github.com/Goff-Davis))
+- Rubric Associations (Thanks, [@weining-li](https://github.com/weining-li))
+
 ### General
 
 - Throw `IndexError` when using negative indexes on `PaginatedList` objects (Thanks, [@UniversalSuperBox](https://github.com/UniversalSuperBox))
diff --git a/canvasapi/course.py b/canvasapi/course.py
index e42cd7a..d5ef716 100644
--- a/canvasapi/course.py
+++ b/canvasapi/course.py
@@ -467,6 +467,29 @@ class Course(CanvasObject):
 
         return rubric_dict
 
+    def create_rubric_association(self, **kwargs):
+        """
+        Create a new RubricAssociation.
+
+        :calls: `POST /api/v1/courses/:course_id/rubric_associations \
+        <https://canvas.instructure.com/doc/api/rubrics.html#method.rubric_associations.create>`_
+
+        :returns: Returns a RubricAssociation.
+        :rtype: :class:`canvasapi.rubric.RubricAssociation`
+        """
+        from canvasapi.rubric import RubricAssociation
+
+        response = self._requester.request(
+            "POST",
+            "courses/{}/rubric_associations".format(self.id),
+            _kwargs=combine_kwargs(**kwargs),
+        )
+
+        quiz_json = response.json()
+        quiz_json.update({"course_id": self.id})
+
+        return RubricAssociation(self._requester, quiz_json)
+
     def delete(self):
         """
         Permanently delete this course.
diff --git a/canvasapi/rubric.py b/canvasapi/rubric.py
index 4b58436..b323483 100644
--- a/canvasapi/rubric.py
+++ b/canvasapi/rubric.py
@@ -3,6 +3,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera
 from six import python_2_unicode_compatible
 
 from canvasapi.canvas_object import CanvasObject
+from canvasapi.util import combine_kwargs
 
 
 @python_2_unicode_compatible
@@ -15,3 +16,47 @@ class Rubric(CanvasObject):
 class RubricAssociation(CanvasObject):
     def __str__(self):
         return "{}, {}".format(self.id, self.association_type)
+
+    def delete(self, **kwargs):
+        """
+        Delete a RubricAssociation.
+
+        :calls: `DELETE /api/v1/courses/:course_id/rubric_associations/:id \
+        <https://canvas.instructure.com/doc/api/rubrics.html#method.rubric_associations.destroy>`_
+
+        :rtype: :class:`canvasapi.rubric.RubricAssociation`
+        """
+        from canvasapi.rubric import RubricAssociation
+
+        response = self._requester.request(
+            "DELETE",
+            "courses/{}/rubric_associations/{}".format(self.course_id, self.id),
+            _kwargs=combine_kwargs(**kwargs),
+        )
+
+        return RubricAssociation(self._requester, response.json())
+
+    def update(self, **kwargs):
+        """
+        Update a RubricAssociation.
+
+        :calls: `PUT /api/v1/courses/:course_id/rubric_associations/:id \
+        <https://canvas.instructure.com/doc/api/rubrics.html#method.rubric_associations.update>`_
+
+        :returns: Returns a RubricAssociation.
+        :rtype: :class:`canvasapi.rubric.RubricAssociation`
+        """
+        from canvasapi.rubric import RubricAssociation
+
+        response = self._requester.request(
+            "PUT",
+            "courses/{}/rubric_associations/{}".format(self.course_id, self.id),
+            _kwargs=combine_kwargs(**kwargs),
+        )
+
+        response_json = response.json()
+        response_json.update({"course_id": self.course_id})
+        if "association_type" in response_json:
+            super(RubricAssociation, self).set_attributes(response_json)
+
+        return self


Test patch:
diff --git a/tests/fixtures/course.json b/tests/fixtures/course.json
index 53b5e70..c65a1de 100644
--- a/tests/fixtures/course.json
+++ b/tests/fixtures/course.json
@@ -1910,5 +1910,14 @@
 			}
 		},
 		"status_code": 200
+	},
+	"create_rubric_association": {
+		"method": "POST",
+		"endpoint": "courses/1/rubric_associations",
+		"data": {
+			"id": 4,
+			"association_type": "Course"
+		},
+		"status_code": 200
 	}
 }
diff --git a/tests/fixtures/rubric.json b/tests/fixtures/rubric.json
new file mode 100644
index 0000000..78f8fcd
--- /dev/null
+++ b/tests/fixtures/rubric.json
@@ -0,0 +1,20 @@
+{
+	"update_rubric_association": {
+		"method": "PUT",
+		"endpoint": "courses/1/rubric_associations/4",
+		"data": {
+			"id": 5,
+			"association_type": "Assignment"
+		},
+		"status_code": 200
+	},
+	"delete_rubric_association": {
+		"method": "DELETE",
+		"endpoint": "courses/1/rubric_associations/4",
+		"data": {
+			"id": 4,
+			"association_type": "Assignment"
+		},
+		"status_code": 200
+	}
+}
diff --git a/tests/test_course.py b/tests/test_course.py
index 5080088..55cdc87 100644
--- a/tests/test_course.py
+++ b/tests/test_course.py
@@ -31,7 +31,7 @@ from canvasapi.outcome_import import OutcomeImport
 from canvasapi.paginated_list import PaginatedList
 from canvasapi.progress import Progress
 from canvasapi.quiz import Quiz, QuizExtension
-from canvasapi.rubric import Rubric
+from canvasapi.rubric import Rubric, RubricAssociation
 from canvasapi.section import Section
 from canvasapi.submission import GroupedSubmission, Submission
 from canvasapi.tab import Tab
@@ -1769,6 +1769,16 @@ class TestCourse(unittest.TestCase):
         self.assertEqual(rubric["rubric_association"].rubric_id, 1)
         self.assertEqual(rubric["rubric_association"].association_type, "Course")
 
+    # create_rubric_association()
+    def test_create_rubric_association(self, m):
+        register_uris({"course": ["create_rubric_association"]}, m)
+
+        rubric_association = self.course.create_rubric_association()
+
+        self.assertIsInstance(rubric_association, RubricAssociation)
+        self.assertEqual(rubric_association.id, 4)
+        self.assertEqual(rubric_association.association_type, "Course")
+
 
 @requests_mock.Mocker()
 class TestCourseNickname(unittest.TestCase):
diff --git a/tests/test_rubric.py b/tests/test_rubric.py
index c1e4959..d6bdae6 100644
--- a/tests/test_rubric.py
+++ b/tests/test_rubric.py
@@ -4,6 +4,7 @@ import unittest
 import requests_mock
 
 from canvasapi import Canvas
+from canvasapi.rubric import RubricAssociation
 from tests import settings
 from tests.util import register_uris
 
@@ -32,13 +33,44 @@ class TestRubricAssociation(unittest.TestCase):
 
         with requests_mock.Mocker() as m:
             register_uris(
-                {"course": ["get_by_id", "create_rubric_with_association"]}, m
+                {
+                    "course": [
+                        "get_by_id",
+                        "create_rubric_with_association",
+                        "create_rubric_association",
+                    ]
+                },
+                m,
             )
 
             self.course = self.canvas.get_course(1)
             self.rubric = self.course.create_rubric()
+            self.association = self.course.create_rubric_association()
 
     # __str__()
     def test__str__(self, m):
         string = str(self.rubric["rubric_association"])
         self.assertIsInstance(string, str)
+
+    # update
+    def test_update(self, m):
+        register_uris({"rubric": ["update_rubric_association"]}, m)
+
+        self.assertEqual(self.association.id, 4)
+
+        rubric_association = self.association.update()
+
+        self.assertEqual(rubric_association, self.association)
+        self.assertEqual(rubric_association.id, 5)
+        self.assertIsInstance(rubric_association, RubricAssociation)
+        self.assertEqual(rubric_association.association_type, "Assignment")
+
+    # delete
+    def test_delete(self, m):
+        register_uris({"rubric": ["delete_rubric_association"]}, m)
+
+        rubric_association = self.association.delete()
+
+        self.assertIsInstance(rubric_association, RubricAssociation)
+        self.assertEqual(rubric_association.id, 4)
+        self.assertEqual(rubric_association.association_type, "Assignment")