def test_APIresponse_in_GetResponse(self): expected = {u'cohortname': u'test1cohort', u'medcodes': [u'c68710004', u'c68710002', u'c68710001', u'c68710006', u'c68710005', u'c68710007'], u'userid': u'waliur', u'jobid': 10} requests.get = MagicMock(side_effect=mock_APIresponse_for_OnavInterface_getResponse()) responseObj = OnavInterface() response = responseObj.getResponse() self.assertEqual(response, expected)
def test_requests_dot_get_in_GetResponse(self): responseObj = OnavInterface() with patch('requests.get') as patched_get: requests.get = MagicMock(side_effect=mock_APIresponse_for_OnavInterface_getResponse()) responseObj.getResponse() # Ensure patched get was called and called only once patched_get.assert_called_with_once("https://cru.ucalgary.ca/getpendinglist")
def test_RequestException_in_GetResponse(self): responseObj = OnavInterface() requests.get = MagicMock(side_effect=mock_APIRequestException_for_OnavInterface_getResponse()) response = responseObj.getResponse() self.assertEqual(response, {'request_error': response.values().pop()})
def test_Timeout_in_GetResponse(self): responseObj = OnavInterface() requests.get = MagicMock(side_effect=mock_Timeout_for_OnavInterface_getResponse()) response = responseObj.getResponse() self.assertEqual(response, {'request_error': 'Timeout'})