Repository: ucfopen/canvasapi

Issue:
create_module_item() requires content_id for type SubHeader
# Describe the bug

In `create_module_item()`, I get an error `RequiredFieldMissing: Dictionary with key 'content_id' is required.` when trying to create a module item of type `SubHeader`.

The Canvas API documentation says that `content_id` is "Required, except for 'ExternalUrl', 'Page', and 'SubHeader' types." [Modules API # Create a module item](https://canvas.instructure.com/doc/api/modules.html#method.context_module_items_api.create)

I think that currently the Python API checks to see if `content_id` is present regardless of what type of `module_item` is created.

# To Reproduce

```python
from canvasapi import Canvas
API_URL = "your_api_url"
API_KEY = "your_api_key"
canvas = Canvas(API_URL, API_KEY)
course = canvas.get_course(a_course_id)
module = course.create_module({'name':'a_module_name'})

# produces error RequiredFieldMissing: Dictionary with key 'content_id' is required.
module_item = module.create_module_item({'title':'a_title','type':'SubHeader'})

# workaround, add blank content_id
module_item = module.create_module_item({'title':'a_title','type':'SubHeader','content_id':''})
```

# Expected behavior

A module item of type `SubHeader` should be created without specifying a `content_id`.

# Environment information

- Python version (`python --version`)
3.8.1
- CanvasAPI version (`pip show canvasapi`)
0.15.0
# Additional context
No additional context.

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

Coverage remained the same at 100.0% when pulling **6e4229e98317b32475caf0a5589a44078b13c2e6 on aileenpongnon:issue/350-create-module-item** into **d8c0022e020ae0cfdbebecdf4df431dfc3ebf86b on ucfopen:develop**.


Patch:
diff --git a/canvasapi/module.py b/canvasapi/module.py
index f235acb..fe6b3b2 100644
--- a/canvasapi/module.py
+++ b/canvasapi/module.py
@@ -122,8 +122,12 @@ class Module(CanvasObject):
         :returns: The created module item.
         :rtype: :class:`canvasapi.module.ModuleItem`
         """
+
+        unrequired_types = ["ExternalUrl", "Page", "SubHeader"]
+
         if isinstance(module_item, dict) and "type" in module_item:
-            if "content_id" in module_item:
+            # content_id is not required for unrequired_types
+            if module_item["type"] in unrequired_types or "content_id" in module_item:
                 kwargs["module_item"] = module_item
             else:
                 raise RequiredFieldMissing(


Test patch:
diff --git a/tests/test_module.py b/tests/test_module.py
index 9f434d1..010c057 100644
--- a/tests/test_module.py
+++ b/tests/test_module.py
@@ -86,8 +86,9 @@ class TestModule(unittest.TestCase):
         register_uris({"module": ["create_module_item"]}, m)
 
         module_item = self.module.create_module_item(
-            module_item={"type": "Page", "content_id": 1}
+            module_item={"type": "Assignment", "content_id": 1}
         )
+
         self.assertIsInstance(module_item, ModuleItem)
         self.assertTrue(hasattr(module_item, "course_id"))
         self.assertEqual(module_item.course_id, self.course.id)
@@ -98,7 +99,13 @@ class TestModule(unittest.TestCase):
 
     def test_create_module_item_fail2(self, m):
         with self.assertRaises(RequiredFieldMissing):
-            self.module.create_module_item(module_item={"type": "Page"})
+            self.module.create_module_item(module_item={"type": "Assignment"})
+
+    def test_create_module_item_unrequired_success(self, m):
+        register_uris({"module": ["create_module_item"]}, m)
+
+        module_item = self.module.create_module_item(module_item={"type": "SubHeader"})
+        self.assertIsInstance(module_item, ModuleItem)
 
     # __str__
     def test__str__(self, m):