def test_get_index_bad_json(self): err_msg = 'Unable to parse index data as JSON.' with mock.patch('requests.get', side_effect=mock_index_get_generator( DEFAULT_INDEX_URL, ValueError(err_msg))): with self.assertRaises(CLIError) as err: get_index() self.assertEqual(str(err.exception), ERR_TMPL_BAD_JSON.format(err_msg))
def test_get_index_404(self): bad_index_url = 'http://contoso.com/cli-index' with mock.patch('requests.get', side_effect=mock_index_get_generator( DEFAULT_INDEX_URL, {})): with self.assertRaises(CLIError) as err: get_index(index_url=bad_index_url) self.assertEqual(str(err.exception), ERR_TMPL_NON_200.format(404, bad_index_url))
def test_get_index_no_network(self): err_msg = 'Max retries exceeded with url...' with mock.patch('requests.get', side_effect=mock_index_get_generator(DEFAULT_INDEX_URL, ConnectionError(err_msg))): with self.assertRaises(CLIError) as err: get_index() self.assertEqual(str(err.exception), ERR_TMPL_NO_NETWORK.format(err_msg)) err_msg = 'Max retries exceeded with url...' with mock.patch('requests.get', side_effect=mock_index_get_generator(DEFAULT_INDEX_URL, HTTPError(err_msg))): with self.assertRaises(CLIError) as err: get_index() self.assertEqual(str(err.exception), ERR_TMPL_NO_NETWORK.format(err_msg))
def test_get_index_no_network(self): err_msg = 'Max retries exceeded with url...' with mock.patch('requests.get', side_effect=mock_index_get_generator( DEFAULT_INDEX_URL, ConnectionError(err_msg))): with self.assertRaises(CLIError) as err: get_index() self.assertEqual(str(err.exception), ERR_TMPL_NO_NETWORK.format(err_msg)) err_msg = 'Max retries exceeded with url...' with mock.patch('requests.get', side_effect=mock_index_get_generator( DEFAULT_INDEX_URL, HTTPError(err_msg))): with self.assertRaises(CLIError) as err: get_index() self.assertEqual(str(err.exception), ERR_TMPL_NO_NETWORK.format(err_msg))
def test_get_index_bad_json(self): err_msg = 'Unable to parse index data as JSON.' with mock.patch('requests.get', side_effect=mock_index_get_generator(DEFAULT_INDEX_URL, ValueError(err_msg))): with self.assertRaises(CLIError) as err: get_index() self.assertEqual(str(err.exception), ERR_TMPL_BAD_JSON.format(err_msg))
def test_get_index_404(self): bad_index_url = 'http://contoso.com/cli-index' with mock.patch('requests.get', side_effect=mock_index_get_generator(DEFAULT_INDEX_URL, {})): with self.assertRaises(CLIError) as err: get_index(index_url=bad_index_url) self.assertEqual(str(err.exception), ERR_TMPL_NON_200.format(404, bad_index_url))
def test_get_index(self): with mock.patch('requests.get', side_effect=mock_index_get_generator(DEFAULT_INDEX_URL, {})): self.assertEqual(get_index(), {})
def test_get_index(self): with mock.patch('requests.get', side_effect=mock_index_get_generator( DEFAULT_INDEX_URL, {})): self.assertEqual(get_index(), {})