def test_handle_spaces(self): """ Assert that unnecessary spaces will be removed and all other spaces correctly substituted. """ assert (clean_url(' /hello you/wonderful/person ') == '/hello_you/wonderful/person')
def test_clean_simple_url(self): """ Assert a simple URL remains unchanged. """ simple_url = '/test' assert clean_url(simple_url) == simple_url
def test_clean_deep_url(self): """ Assert a deep URL remains unchanged. """ deep_url = '/test/two/three/yo' assert clean_url(deep_url) == deep_url
def validate_url(form, field): sanitized_url = clean_url(field.data) system_urls_lead_parts = get_app_routes_leading_elements() # Disallow create already used urls. # NOTE I'm not sure whether Windows slashes do not need to be # sanitized later. At least space to underscore is necessary to check # now - or maybe in the Wiki object itself. # Leading url part (before slash) must not equals to system urls # leading parts (/create/, /edit/ and so on). if (current_wiki.exists(sanitized_url) or sanitized_url.split('/')[0] in system_urls_lead_parts): raise ValidationError('The URL "%s" exists already.' % sanitized_url)
def clean_url(self, url): return clean_url(url)
def test_handle_uppercase(self): """ Assert that uppercase characters will be substituted. """ assert clean_url("HELLo") == "hello"