mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
CORS: cache and restore tempfile.tempdir when using test Configuration instances as it persists across tests and fails any tempfile related tests that follow, move test_config tests into test_webapp (cohesive subject v. ortho file struct)
This commit is contained in:
@@ -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()
|
||||
@@ -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 )
|
||||
|
||||
Reference in New Issue
Block a user