Repository: ucfopen/canvasapi

Issue:
GroupedSubmission 'submissions' key:value deleted
# Describe the bug

In #280 we added the first instance of nesting a list of one type of object inside another. While this generally works well, there is a small side effect: The `'submissions'` key:value pair is removed from the `attributes` dict. This is potentially misleading, since one of the uses of calling `attributes` is to see what data was originally used to create the object (via `.to_json()`).

`'submissions'` being removed may give the (incorrect) impression that submissions were never returned from Canvas.


# To Reproduce

Steps to reproduce the behavior:

1. Create a `GroupedSubmission` object with nested submissions
2. Print the attributes of the created object (`print(grouped_submission.attributes)`)
3. Observe that there is no `'submissions'` key:value pair

# Expected behavior

`'submissions'` should be visible in the printed attributes, to assist in debugging.

# Environment information

- Python version (`python --version`)
3.7+

- CanvasAPI version (`pip show canvasapi`)
0.14.0

# Additional context

This is somewhat related to #56, as we'll need to be careful about deleting keys in the future.


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

Coverage remained the same at 100.0% when pulling **499de4205b2c7e941b389efa27d52b3ed98a7cf0 on Thetwam:issue/303-submissions-key-missing** into **34ecd3ee222d74bf552d28339b6beff75ccd6c27 on ucfopen:develop**.


Patch:
diff --git a/canvasapi/submission.py b/canvasapi/submission.py
index 588a24a..15df324 100644
--- a/canvasapi/submission.py
+++ b/canvasapi/submission.py
@@ -179,17 +179,16 @@ class Submission(CanvasObject):
 @python_2_unicode_compatible
 class GroupedSubmission(CanvasObject):
     def __init__(self, requester, attributes):
+        super(GroupedSubmission, self).__init__(requester, attributes)
+
         try:
             self.submissions = [
                 Submission(requester, submission)
                 for submission in attributes["submissions"]
             ]
-            del attributes["submissions"]
         except KeyError:
             self.submissions = list()
 
-        super(GroupedSubmission, self).__init__(requester, attributes)
-
     def __str__(self):
         return "{} submission(s) for User #{}".format(
             len(self.submissions), self.user_id


Test patch:
diff --git a/tests/test_submission.py b/tests/test_submission.py
index ffe0731..0bbe318 100644
--- a/tests/test_submission.py
+++ b/tests/test_submission.py
@@ -154,6 +154,29 @@ class TestGroupedSubmission(unittest.TestCase):
         self.assertIsInstance(grouped_submission.submissions, list)
         self.assertEqual(len(grouped_submission.submissions), 0)
 
+    def test__init__issue_303_regression(self):
+        """
+        Regression test for issue #303
+        https://github.com/ucfopen/canvasapi/issues/303
+        """
+        grouped_submission = GroupedSubmission(
+            self.canvas._Canvas__requester,
+            {
+                "user_id": 1,
+                "submissions": [
+                    {
+                        "id": 1,
+                        "assignments_id": 1,
+                        "user_id": 1,
+                        "html_url": "https://example.com/courses/1/assignments/1/submissions/1",
+                        "submission_type": "online_upload",
+                    }
+                ],
+            },
+        )
+        self.assertTrue(hasattr(grouped_submission, "submissions"))
+        self.assertIn("submissions", grouped_submission.attributes)
+
     # __str__()
     def test__str__(self):
         string = str(self.grouped_submission)