def test_bad_keyfile(self, mock): """Test a non-valid keyfile""" responsemock = Mock() responsemock.read.return_value = 'Not A Certificate' mock.return_value = responsemock with self.assertRaises(ValueError) as context_manager: utils.grab_keyfile('http://www.fakeurl.com') the_exception = context_manager.exception self.assertEqual(the_exception.args[0], 'Invalid Certificate File')
def test_grab_keyfile(self, mock): """Test the grab_keyfile plugin""" responsemock = Mock() responsemock.read.return_value = self.pemfile mock.return_value = responsemock result = utils.grab_keyfile('http://www.fakeurl.com') mock.assert_called_with('http://www.fakeurl.com') self.assertEqual(result, self.pemfile)