def test_get_federation_metadata(self): """ Ensures that an attempt to get the Federation Metadata from the url is handled properly in the good case. """ mock_response = mock.MagicMock() mock_response.status_code = 200 mock_response.text = METADATA with mock.patch('requests.get', return_value=mock_response) as mock_get: url = 'http://my_url.com' result = get_federation_metadata(url) # There shouldn't be a unicode BOM character self.assertEqual(result, METADATA.replace(u'\ufeff', '')) mock_get.assert_called_once_with(url)
def test_get_federation_metadata_server_error(self): """ Ensure the expected ValueError exception is raised if we don't get a valid response. """ mock_response = mock.MagicMock() mock_response.status_code = 404 mock_response.text = METADATA with mock.patch('requests.get', return_value=mock_response) as mock_get: with self.assertRaises(ValueError) as raised: url = 'http://my_url.com' result = get_federation_metadata(url) mock_get.assert_called_once_with(url) self.assertEqual(raised.exception.args[0], 'Metadata response: 404')