def test_parse_allowed_origin_hostnames(self): """Should return a list of (possibly) mixed strings and regexps""" config = CORSParsingMockConfig() # 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_parse_allowed_origin_hostnames( self ): """Should return a list of (possibly) mixed strings and regexps""" config = CORSParsingMockConfig() # 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_parse_allowed_origin_hostnames(self): """Should return a list of (possibly) mixed strings and regexps""" config = CORSParsingMockConfig() # 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": r"/host\d{2}/,geocities.com,miskatonic.edu" }) # re._pattern_type has been changed to re.Pattern in python 3.7 try: Pattern = re.Pattern except AttributeError: Pattern = re._pattern_type self.assertTrue(isinstance(hostnames[0], Pattern)) self.assertTrue(isinstance(hostnames[1], str)) self.assertTrue(isinstance(hostnames[2], str))