-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrated Channel: Moodle - Inactivate courses instead of permanentl…
…y delete courses
- Loading branch information
1 parent
3284586
commit 66ce31a
Showing
2 changed files
with
87 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ def setUp(self): | |
self.user_email = '[email protected]' | ||
self.moodle_course_id = random.randint(1, 1000) | ||
self._get_courses_response = bytearray('{{"courses": [{{"id": {}}}]}}'.format(self.moodle_course_id), 'utf-8') | ||
self._get_courses_response_empty = bytearray('{}', 'utf-8') | ||
self.empty_get_courses_response = bytearray('{"courses": []}', 'utf-8') | ||
self.moodle_module_id = random.randint(1, 1000) | ||
self.moodle_module_name = 'module' | ||
|
@@ -129,6 +130,11 @@ def test_successful_create_content_metadata(self): | |
|
||
client = MoodleAPIClient(self.enterprise_config) | ||
client._post = unittest.mock.MagicMock(name='_post', return_value=SUCCESSFUL_RESPONSE) # pylint: disable=protected-access | ||
client._get_courses = unittest.mock.MagicMock(name='_get_courses') # pylint: disable=protected-access | ||
mock_response = Response() | ||
mock_response.status_code = 200 | ||
mock_response._content = self._get_courses_response_empty | ||
client._get_courses.return_value = mock_response # pylint: disable=protected-access | ||
client.create_content_metadata(SERIALIZED_DATA) | ||
client._post.assert_called_once_with(expected_data) # pylint: disable=protected-access | ||
|
||
|
@@ -142,6 +148,11 @@ def test_duplicate_shortname_create_content_metadata(self): | |
|
||
client = MoodleAPIClient(self.enterprise_config) | ||
client._post = unittest.mock.MagicMock(name='_post', return_value=SHORTNAMETAKEN_RESPONSE) # pylint: disable=protected-access | ||
client._get_courses = unittest.mock.MagicMock(name='_get_courses') # pylint: disable=protected-access | ||
mock_response = Response() | ||
mock_response.status_code = 200 | ||
mock_response._content = self._get_courses_response_empty | ||
client._get_courses.return_value = mock_response # pylint: disable=protected-access | ||
client.create_content_metadata(SERIALIZED_DATA) | ||
client._post.assert_called_once_with(expected_data) # pylint: disable=protected-access | ||
|
||
|
@@ -152,9 +163,13 @@ def test_duplicate_courseidnumber_create_content_metadata(self): | |
""" | ||
expected_data = SERIALIZED_DATA.copy() | ||
expected_data['wsfunction'] = 'core_course_create_courses' | ||
|
||
client = MoodleAPIClient(self.enterprise_config) | ||
client._post = unittest.mock.MagicMock(name='_post', return_value=COURSEIDNUMBERTAKEN_RESPONSE) # pylint: disable=protected-access | ||
client._get_courses = unittest.mock.MagicMock(name='_get_courses') # pylint: disable=protected-access | ||
mock_response = Response() | ||
mock_response.status_code = 200 | ||
mock_response._content = self._get_courses_response_empty | ||
client._get_courses.return_value = mock_response # pylint: disable=protected-access | ||
client.create_content_metadata(SERIALIZED_DATA) | ||
client._post.assert_called_once_with(expected_data) # pylint: disable=protected-access | ||
|
||
|
@@ -168,6 +183,11 @@ def test_multi_duplicate_create_content_metadata(self): | |
|
||
client = MoodleAPIClient(self.enterprise_config) | ||
client._post = unittest.mock.MagicMock(name='_post', return_value=SHORTNAMETAKEN_RESPONSE) # pylint: disable=protected-access | ||
client._get_courses = unittest.mock.MagicMock(name='_get_courses') # pylint: disable=protected-access | ||
mock_response = Response() | ||
mock_response.status_code = 200 | ||
mock_response._content = self._get_courses_response_empty | ||
client._get_courses.return_value = mock_response # pylint: disable=protected-access | ||
with self.assertRaises(MoodleClientError): | ||
client.create_content_metadata(MULTI_SERIALIZED_DATA) | ||
client._post.assert_called_once_with(expected_data) # pylint: disable=protected-access | ||
|
@@ -179,9 +199,14 @@ def test_multi_duplicate_courseidnumber_create_content_metadata(self): | |
""" | ||
expected_data = MULTI_SERIALIZED_DATA.copy() | ||
expected_data['wsfunction'] = 'core_course_create_courses' | ||
|
||
client = MoodleAPIClient(self.enterprise_config) | ||
client._post = unittest.mock.MagicMock(name='_post', return_value=COURSEIDNUMBERTAKEN_RESPONSE) # pylint: disable=protected-access | ||
client._get_courses = unittest.mock.MagicMock(name='_get_courses') # pylint: disable=protected-access | ||
mock_response = Response() | ||
mock_response.status_code = 200 | ||
mock_response._content = self._get_courses_response_empty | ||
client._get_courses.return_value = mock_response # pylint: disable=protected-access | ||
with self.assertRaises(MoodleClientError): | ||
client.create_content_metadata(MULTI_SERIALIZED_DATA) | ||
client._post.assert_called_once_with(expected_data) # pylint: disable=protected-access | ||
|
@@ -205,8 +230,9 @@ def test_update_content_metadata(self): | |
def test_delete_content_metadata(self): | ||
""" | ||
Test core logic for formatting a delete request to Moodle. | ||
Mark a course visible:0 rather than doing a true delete | ||
""" | ||
expected_data = {'wsfunction': 'core_course_delete_courses', 'courseids[]': self.moodle_course_id} | ||
expected_data = {'wsfunction': 'core_course_update_courses', 'courses[0][id]': self.moodle_course_id, 'courses[0][visible]': 0} | ||
|
||
client = MoodleAPIClient(self.enterprise_config) | ||
client._post = unittest.mock.MagicMock(name='_post', return_value=SUCCESSFUL_RESPONSE) # pylint: disable=protected-access | ||
|
@@ -352,3 +378,27 @@ def test_get_course_final_grade_module_custom_name(self): | |
|
||
# The base transmitter expects the create course completion response to be a tuple of (code, body) | ||
assert client.get_course_final_grade_module(2) == (1337, 'foobar') | ||
|
||
def test_successful_update_existing_content_metadata(self): | ||
""" | ||
Test core logic of create_content_metadata to ensure | ||
if a course already exists(hidden) then client sets its | ||
visibility: 1 instead of creating a new course | ||
""" | ||
expected_data = SERIALIZED_DATA.copy() | ||
expected_data['wsfunction'] = 'core_course_update_courses' | ||
expected_data['courses[0][visible]'] = 1 | ||
expected_data['courses[0][id]'] = self.moodle_course_id | ||
|
||
client = MoodleAPIClient(self.enterprise_config) | ||
client._post = unittest.mock.MagicMock(name='_post', return_value=SUCCESSFUL_RESPONSE) # pylint: disable=protected-access | ||
client._get_courses = unittest.mock.MagicMock(name='_get_courses') # pylint: disable=protected-access | ||
mock_response = Response() | ||
mock_response.status_code = 200 | ||
mock_response._content = self._get_courses_response | ||
|
||
client._get_course_id = unittest.mock.MagicMock(name='_get_course_id') # pylint: disable=protected-access | ||
client._get_course_id.return_value = self.moodle_course_id # pylint: disable=protected-access | ||
client._get_courses.return_value = mock_response # pylint: disable=protected-access | ||
client.create_content_metadata(SERIALIZED_DATA) | ||
client._post.assert_called_once_with(expected_data) # pylint: disable=protected-access |