How to test a class method using mock:
You can patch the entire requests module with:
@mock.patch('requests.get')
But it's better to keep it specific as per:
@mock.patch('rca.shortcourses.access_planit.requests.get')
""" Patch the request module totally to force the timeout so we can test the
result of the try/expect.
Test here that data returned from a timeout is a empty dict
"""
@mock.patch('rca.shortcourses.access_planit.requests.get')
def test_data_if_timeout(self, mock_get):
#logging.disable(logging.CRITICAL) # Don't log exceptions... is this bad?
mock_get.side_effect = Timeout
data = AccessPlanitXML(course_id=1)
xml_data = data.get_data()
self.assertEqual(xml_data, {})