From 24d457f0d03f537a4f49a07c769e760ddd04c203 Mon Sep 17 00:00:00 2001 From: skrzepto Date: Jul 21 2016 21:03:21 +0000 Subject: adding tests for source url, modified to catch files that dont exist --- diff --git a/hubs/app.py b/hubs/app.py index c152053..0007f66 100755 --- a/hubs/app.py +++ b/hubs/app.py @@ -453,7 +453,13 @@ def widget_edit_delete(hub, idx): def widget_source(name): from hubs.widgets import registry base = '/hubs/' - fname = base + registry[name].__file__.split(base, 1)[1] + fname = '' + + try: + fname = base + registry[name].__file__.split(base, 1)[1] + except KeyError: + flask.abort(404) + fname = fname.replace('.pyc', '.py') return flask.redirect(SOURCE_URL + fname) diff --git a/hubs/tests/test_fedora_hubs_flask_api.py b/hubs/tests/test_fedora_hubs_flask_api.py index 2eafd21..5ef5732 100644 --- a/hubs/tests/test_fedora_hubs_flask_api.py +++ b/hubs/tests/test_fedora_hubs_flask_api.py @@ -351,5 +351,12 @@ class HubsAPITest(hubs.tests.APPTest): 'blob/develop/f/hubs/widgets/about.py' self.assertTrue(expected_str in result.data) + def test_source_name_not_existent(self): + with tests.auth_set(app, None): + url = '/source/notexistent' + result = self.app.get(url) + self.assertEqual(result.status_code, 404) + + if __name__ == '__main__': unittest.main()