def test_sanitize_url(self, get_api_core_config_location_mock): """ Ensures host is cleaned-up properly. """ # Ensure https is added if no scheme is specified. self.assertEquals( "https://no.scheme.com", sanitize_url("no.scheme.com") ) # Ensure that we lowercase the URL. self.assertEquals( "https://caps.site.com", sanitize_url("https://CAPS.site.com") ) # Ensure https is not modified if specified. self.assertEquals( "https://no.scheme.com", sanitize_url("https://no.scheme.com") ) # Ensure http is left as is if specified. self.assertEquals( "http://no.scheme.com", sanitize_url("http://no.scheme.com") ) # Ensure any scheme is left as is if specified. self.assertEquals( "invalid-scheme://no.scheme.com", sanitize_url("invalid-scheme://no.scheme.com") ) # Ensures a suffixed slash gets removed. self.assertEquals( "https://no.suffixed.slash.com", sanitize_url("https://no.suffixed.slash.com/") ) # Ensures anything after the host is dropped. self.assertEquals( "https://no.suffixed.slash.com", sanitize_url("https://no.suffixed.slash.com/path/to/a/resource") ) # Ensures anything after the host is dropped. self.assertEquals( "http://localhost", sanitize_url("http://localhost") ) self.assertEquals( "https://localhost", sanitize_url("localhost") ) self.assertEquals( "https://127.0.0.1", sanitize_url("127.0.0.1") ) self.assertEquals( "https://test.shotgunstudio.com", sanitize_url("test.shotgunstudio.com/") ) self.assertEquals( "https://test.shotgunstudio.com", sanitize_url("test.shotgunstudio.com/a") )
def test_sanitize_url(self, get_api_core_config_location_mock): """ Ensures host is cleaned-up properly. """ # Ensure https is added if no scheme is specified. self.assertEquals("https://no.scheme.com", sanitize_url("no.scheme.com")) # Ensure that we lowercase the URL. self.assertEquals("https://caps.site.com", sanitize_url("https://CAPS.site.com")) # Ensure https is not modified if specified. self.assertEquals("https://no.scheme.com", sanitize_url("https://no.scheme.com")) # Ensure http is left as is if specified. self.assertEquals("http://no.scheme.com", sanitize_url("http://no.scheme.com")) # Ensure any scheme is left as is if specified. self.assertEquals("invalid-scheme://no.scheme.com", sanitize_url("invalid-scheme://no.scheme.com")) # Ensures a suffixed slash gets removed. self.assertEquals("https://no.suffixed.slash.com", sanitize_url("https://no.suffixed.slash.com/")) # Ensures anything after the host is dropped. self.assertEquals( "https://no.suffixed.slash.com", sanitize_url("https://no.suffixed.slash.com/path/to/a/resource")) # Ensures anything after the host is dropped. self.assertEquals("http://localhost", sanitize_url("http://localhost")) self.assertEquals("https://localhost", sanitize_url("localhost")) self.assertEquals("https://127.0.0.1", sanitize_url("127.0.0.1")) self.assertEquals("https://test.shotgunstudio.com", sanitize_url("test.shotgunstudio.com/")) self.assertEquals("https://test.shotgunstudio.com", sanitize_url("test.shotgunstudio.com/a"))