diff --git a/test/unit/test_config.py b/test/unit/test_config.py deleted file mode 100644 index bf8f001b685..00000000000 --- a/test/unit/test_config.py +++ /dev/null @@ -1,45 +0,0 @@ -""" -Unit tests for ``galaxy.config`` -""" -import os -import imp -import unittest - -import logging -log = logging.getLogger( __name__ ) - -test_utils = imp.load_source( 'test_utils', - os.path.join( os.path.dirname( __file__), './unittest_utils/utility.py' ) ) -# import galaxy_mock -import re -import galaxy.config - - -class Config_TestCase( test_utils.unittest.TestCase ): - - def test_default_allowed_origin_hostnames( self ): - """Shouldn't have any allowed""" - config = galaxy.config.Configuration() - self.assertTrue( isinstance( config, galaxy.config.Configuration ) ) - self.assertEqual( config.allowed_origin_hostnames, None ) - - def test_parse_allowed_origin_hostnames( self ): - """Should return a list of (possibly) mixed strings and regexps""" - config = galaxy.config.Configuration() - - # falsy listify value should return None - self.assertEqual( config._parse_allowed_origin_hostnames({ - "allowed_origin_hostnames" : "" - }), None ) - - # should parse regex if using fwd slashes, string otherwise - hostnames = config._parse_allowed_origin_hostnames({ - "allowed_origin_hostnames" : "/host\d{2}/,geocities.com,miskatonic.edu" - }) - self.assertTrue( isinstance( hostnames[0], re._pattern_type ) ) - self.assertTrue( isinstance( hostnames[1], str ) ) - self.assertTrue( isinstance( hostnames[2], str ) ) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/unit/web/framework/test_webapp.py b/test/unit/web/framework/test_webapp.py index 795409e2b8c..867ff516ecf 100644 --- a/test/unit/web/framework/test_webapp.py +++ b/test/unit/web/framework/test_webapp.py @@ -12,6 +12,8 @@ test_utils = imp.load_source( 'test_utils', os.path.join( os.path.dirname( __file__), '../../unittest_utils/utility.py' ) ) import galaxy_mock +import re +import tempfile from galaxy.web.framework import webapp as Webapp import galaxy.config @@ -23,6 +25,15 @@ class StubGalaxyWebTransaction( Webapp.GalaxyWebTransaction ): class GalaxyWebTransaction_Headers_TestCase( test_utils.unittest.TestCase ): + def setUp( self ): + # galaxy uses the tempfile.tempdir interface of the tempfile module, changing this value when a Configuration + # is created. This change persists across tests (since it's scoped to the module) and breaks following tests. + # TODO: most likely this should be changed at the core level to remove tempfile.tempdir - then remove this + self._saved_tempfile_tempdir = tempfile.tempdir + + def teardown( self ): + tempfile.tempdir = self._saved_tempfile_tempdir + def _new_trans( self, allowed_origin_hostnames=None ): app = galaxy_mock.MockApp() app.config = galaxy.config.Configuration( @@ -39,6 +50,29 @@ class GalaxyWebTransaction_Headers_TestCase( test_utils.unittest.TestCase ): def assert_cors_header_missing( self, headers ): self.assertFalse( 'access-control-allow-origin' in headers ) + def test_default_allowed_origin_hostnames( self ): + """Shouldn't have any allowed""" + config = galaxy.config.Configuration() + self.assertTrue( isinstance( config, galaxy.config.Configuration ) ) + self.assertEqual( config.allowed_origin_hostnames, None ) + + def test_parse_allowed_origin_hostnames( self ): + """Should return a list of (possibly) mixed strings and regexps""" + config = galaxy.config.Configuration() + + # falsy listify value should return None + self.assertEqual( config._parse_allowed_origin_hostnames({ + "allowed_origin_hostnames" : "" + }), None ) + + # should parse regex if using fwd slashes, string otherwise + hostnames = config._parse_allowed_origin_hostnames({ + "allowed_origin_hostnames" : "/host\d{2}/,geocities.com,miskatonic.edu" + }) + self.assertTrue( isinstance( hostnames[0], re._pattern_type ) ) + self.assertTrue( isinstance( hostnames[1], str ) ) + self.assertTrue( isinstance( hostnames[2], str ) ) + def test_default_set_cors_headers( self ): """No CORS headers should be set (or even checked) by default""" trans = self._new_trans( allowed_origin_hostnames=None )