def test_get_urlopen(self): url = 'http://some.url.com' ret_val = tvdb._get(url) self.assertEqual(ret_val, self.returned_xml) self.mock_urlopen.assert_called_once_with(url) self.assertEqual(self.mock_urlopen_result.close.call_count, 1)
def test_get_urlopen_with_httperror(self, mock_urlopen): mock_urlopen.side_effect = urllib2.HTTPError( 'http://url.com', code=404, msg="Not Found", hdrs='', fp=None, ) ret_val = tvdb._get('http://url.com') self.assertEqual(ret_val, '')
def test_get_urlopen_with_urlerror(self, mock_urlopen): mock_urlopen.side_effect = urllib2.URLError('Error Reason') ret_val = tvdb._get('http://url.com') self.assertEqual(ret_val, '')